:root {
  --navy: #0a2463;
  --navy-2: #1d4fb5;
  --gold: #ffc83d;
  --red: #c8102e;
  --bg: #f8f2e4;
  --surface: #ffffff;
  --ink: #13213f;
  --muted: #5b6480;
  --line: #e3d9c2;
  --chip: #efe6d0;
  --shadow: 0 10px 30px rgba(10, 36, 99, 0.12);
  --sans: "Noto Sans TC", "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1430;
    --surface: #131f42;
    --ink: #eef1f8;
    --muted: #a5aec8;
    --line: #26345e;
    --chip: #1c2a53;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body.locked { overflow: hidden; }
body.has-tray { padding-bottom: 96px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

button, input { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #0a2463; }
.btn.big { min-height: 56px; font-size: 1.12rem; }
.btn.ghost { background: transparent; }
.btn.line-light { background: transparent; border-color: rgba(255, 255, 255, 0.6); color: #fff; }

.icon-btn {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--chip); }

.link-btn {
  border: 0; background: none; padding: 0 2px;
  color: var(--navy-2); font-weight: 700; text-decoration: underline; cursor: pointer;
}

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- 首頁主視覺 ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #071a47 0%, var(--navy) 45%, var(--navy-2) 100%);
  color: #fff;
  padding: 56px 0 64px;
}
.hero-in { position: relative; z-index: 1; }
.kicker {
  display: inline-block;
  margin: 0 0 18px;
  padding: 4px 14px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
}
.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(2.4rem, 8vw, 4.6rem);
  line-height: 1.18;
}
.hero h1 em { font-style: normal; color: var(--gold); }
.lede { max-width: 34em; margin: 18px 0 26px; font-size: 1.08rem; color: rgba(255, 255, 255, 0.86); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; }
.countdown { margin: 24px 0 0; color: rgba(255, 255, 255, 0.8); }
.countdown b { font-size: 1.6rem; color: var(--gold); margin: 0 2px; }
.sun {
  position: absolute;
  right: -40px; bottom: -6px;
  width: min(520px, 80vw);
  color: var(--gold);
  opacity: 0.22;
}

/* ---------- 圖庫 ---------- */
main { padding-top: 36px; }
.gallery-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.gallery-head h2 { margin: 0; font-family: var(--serif); font-size: 1.8rem; }
.gallery-head small { font-family: var(--sans); font-size: 0.95rem; color: var(--muted); font-weight: 500; }

.chips, .style-pick, .filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters { margin: 18px 0 8px; }
.chip {
  min-height: 40px;
  padding: 6px 16px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--chip);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.chip.active { background: var(--navy); color: #fff; }
.chip.swatch { display: inline-flex; align-items: center; gap: 8px; }
.chip.swatch::before {
  content: "";
  width: 18px; height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sw) 55%, var(--sw2) 55%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.chip.active.swatch { border-color: var(--gold); }

.hint { margin: 6px 0 18px; color: var(--muted); font-size: 0.95rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 22px;
}
.item { display: flex; flex-direction: column; gap: 10px; }
.thumb {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--chip);
  box-shadow: var(--shadow);
  cursor: zoom-in;
  aspect-ratio: 4 / 5;
  transition: transform 0.15s;
}
.thumb:hover { transform: translateY(-3px) rotate(-0.4deg); }
.thumb canvas { display: block; width: 100%; height: 100%; }
.item-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-meta b { font-size: 0.98rem; line-height: 1.35; }
.pick {
  flex: none;
  min-height: 36px;
  padding: 4px 12px;
  border: 2px solid var(--navy);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) { .pick { border-color: var(--gold); } }
.pick.on { background: var(--gold); border-color: var(--gold); color: #0a2463; }

/* ---------- 頁尾 ---------- */
/* ---------- 友站：柯志恩 ---------- */
.ally { margin-top: 48px; }
.ally-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 24px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.ally-card:hover { transform: translateY(-2px); }
.ally-card + .ally-card { margin-top: 14px; }
.game-cta { background: linear-gradient(135deg, var(--red), #8f0b21); }
.isle-cta { background: linear-gradient(135deg, #1b7fa6, var(--navy)); }
.ally-kicker { color: var(--gold); font-size: 0.85rem; font-weight: 700; letter-spacing: 0.08em; }
.ally-card strong { font-size: 1.2rem; line-height: 1.4; }
.ally-go { margin-top: 4px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.foot { margin-top: 32px; padding-top: 24px; padding-bottom: 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }
.foot summary { cursor: pointer; font-weight: 700; }
.foot ul { padding-left: 1.2em; }
.foot li { margin: 4px 0; }

/* ---------- 三支箭托盤 ---------- */
.tray {
  position: fixed;
  left: 50%; bottom: 14px;
  z-index: 20;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(760px, calc(100% - 24px));
  padding: 10px 10px 10px 14px;
  border-radius: 20px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.3);
  padding-bottom: calc(10px + env(safe-area-inset-bottom) * 0.5);
}
.tray[hidden] { display: none; }
.tray-slots { display: flex; gap: 6px; flex: 1; min-width: 0; }
.slot {
  flex: 1 1 0;
  min-width: 0;
  max-width: 12em;
  padding: 6px 10px;
  border: 1px dashed rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(255, 255, 255, 0.6);
  background: none;
}
.slot.full { border-style: solid; border-color: var(--gold); color: #fff; cursor: pointer; }
.tray .btn { flex: none; min-height: 44px; }

/* ---------- 覆蓋層共用 ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; }
.overlay[hidden] { display: none; }

/* ---------- 測驗 ---------- */
.quiz {
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 26, 71, 0.72);
  backdrop-filter: blur(4px);
}
.quiz-card {
  width: min(520px, 100%);
  padding: 22px 22px 26px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.quiz-top { display: flex; align-items: center; justify-content: space-between; }
.quiz-step { color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.quiz h2 { margin: 6px 0 18px; font-family: var(--serif); font-size: 1.7rem; line-height: 1.3; }
.quiz-opts { display: grid; gap: 10px; }
.opt {
  min-height: 56px;
  padding: 12px 18px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  text-align: left;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}
.opt:hover { border-color: var(--gold); }

/* ---------- 工作室 ---------- */
.studio { display: flex; flex-direction: column; background: var(--bg); }
.studio-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.studio-bar h2 { margin: 0; flex: 1; font-family: var(--serif); font-size: 1.2rem; }
.studio-pos { color: var(--muted); font-size: 0.9rem; font-weight: 700; padding-right: 6px; }
.friend { padding: 10px 16px; background: var(--gold); color: #0a2463; font-weight: 700; font-size: 0.95rem; }
.friend[hidden] { display: none; }
.friend .link-btn { color: #0a2463; }

.studio-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
}
.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 0;
  padding: 20px;
}
.canvas-box {
  height: 100%;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}
.canvas-box canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 110px);
  max-height: calc(100dvh - 110px);
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.nav {
  flex: none;
  width: 48px; height: 48px;
  border: 0; border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}
.nav[hidden] { display: none; }

.panel {
  overflow-y: auto;
  padding: 18px 20px 28px;
  border-left: 1px solid var(--line);
  background: var(--surface);
}
.field { margin-bottom: 16px; }
.field[hidden] { display: none; }
.label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 0.92rem; color: var(--muted); }
.field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.field input:focus { border-color: var(--navy-2); outline: none; }

.trio-list { display: grid; gap: 6px; }
.trio-row { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border-radius: 12px; background: var(--bg); }
.trio-row span { flex: 1; font-weight: 700; font-size: 0.95rem; }
.mini {
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: var(--chip);
  cursor: pointer;
}
.mini:disabled { opacity: 0.35; cursor: default; }
.trio-list .link-btn { justify-self: start; margin-top: 4px; }

.share { display: grid; gap: 10px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.share .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.share .sns { grid-template-columns: repeat(4, 1fr); }
.share .sns .btn { padding: 8px 4px; font-size: 0.88rem; }
.tip { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }
.game-link {
  display: block;
  margin-top: 6px;
  padding: 12px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--red), #8f0b21);
  color: #fff;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
.game-link:hover { filter: brightness(1.08); }

/* 手機：預覽在上、控制面板在下，整頁捲動 */
@media (max-width: 860px) {
  .studio { overflow-y: auto; }
  .studio-body { display: block; flex: none; }
  .stage { padding: 14px 8px; }
  .canvas-box canvas { max-height: 64vh; max-height: 64dvh; }
  .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; z-index: 1; opacity: 0.92; }
  .nav.prev { left: 6px; }
  .nav.next { right: 6px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
}

@media (max-width: 520px) {
  .wrap { padding: 0 16px; }
  .hero { padding: 40px 0 52px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .item-meta { flex-direction: column; align-items: stretch; }
  .item-meta b { font-size: 0.9rem; }
  .tray { flex-direction: column; align-items: stretch; }
  .tray .btn { width: 100%; }
  body.has-tray { padding-bottom: 150px; }
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%; top: 20px;
  z-index: 60;
  transform: translate(-50%, -20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #13213f;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* 抽籤號次：白底紅圈、紅色數字 2 */
.candno { display: flex; width: fit-content; align-items: center; gap: 0.6rem; margin: 0 0 0.6rem; color: #fff; font-family: var(--serif); font-weight: 900; font-size: 1.3rem; }
.candno b, .candno-sm b { display: inline-grid; place-items: center; box-sizing: border-box; width: 2.6rem; height: 2.6rem; border: 0.28rem solid #d4101f; border-radius: 50%; background: #fff; color: #d4101f; font-family: var(--sans, inherit); font-weight: 900; font-size: 1.45rem; line-height: 1; }
