/* ============================================================
   基礎樣式：色彩、版面、工具列、頁尾、對話框與共用元件
   ============================================================ */
:root {
  --plum: #241536;
  --plum-2: #3a2258;
  --plum-3: #4c2f73;
  --cream: #fbf6ec;
  --paper: #fffdf8;
  --ink: #2a2433;
  --ink-2: #5f566b;
  --ink-3: #6f6479;
  --gold: #e9c46a;
  --gold-2: #f6dfa6;
  --rose: #c96a7b;
  --rose-2: #f3d7d2;
  --teal: #4f8a8b;
  --violet: #6f4fc9;
  --green: #6f9b6a;
  --line: rgba(42, 36, 51, .14);
  --footer-h: 46px;
  --header-h: 64px;
  --radius: 20px;
  --shadow: 0 18px 50px rgba(18, 9, 30, .3);
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", "MingLiU", Georgia, serif;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  background-color: #1d102b;
  background-image:
    radial-gradient(ellipse at 16% -8%, rgba(233, 196, 106, .22), transparent 42%),
    radial-gradient(ellipse at 92% 2%, rgba(123, 92, 214, .3), transparent 46%),
    radial-gradient(ellipse at 50% 105%, rgba(201, 106, 123, .16), transparent 48%),
    linear-gradient(180deg, #2b1c4d 0%, #1b1029 64%, #241536 100%);
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .55;
  background-image: radial-gradient(rgba(255, 255, 255, .12) .7px, transparent .7px);
  background-size: 9px 9px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, .5), transparent 70%);
}
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: var(--gold-2); }
p, h1, h2, h3, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; }
[hidden] { display: none !important; }

::selection { background: var(--gold); color: var(--plum); }

.skip-link {
  position: fixed;
  left: 12px;
  top: -100px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: 0 0 12px 12px;
  background: var(--gold-2);
  color: var(--plum);
  font-weight: 800;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--gold-2);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(36, 21, 54, .45);
}

/* ---------- 工具列 ---------- */
.sysbar {
  position: sticky;
  top: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--header-h);
  padding: max(8px, env(safe-area-inset-top)) clamp(10px, 2.6vw, 26px) 8px;
  background: rgba(26, 14, 39, .94);
  border-bottom: 1px solid rgba(233, 196, 106, .34);
  box-shadow: 0 8px 30px rgba(10, 5, 18, .28);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 2px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, .3));
}
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__text strong {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: .08em;
  line-height: 1.15;
  color: var(--cream);
  white-space: nowrap;
}
.brand__text small {
  color: var(--gold-2);
  font-size: 10.5px;
  letter-spacing: .13em;
  line-height: 1.4;
  white-space: nowrap;
}
.sysbar__controls { display: flex; align-items: center; gap: 7px; flex: none; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid rgba(233, 196, 106, .42);
  border-radius: 12px;
  background: rgba(251, 246, 236, .08);
  color: var(--cream);
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.icon-btn:hover { background: var(--gold-2); color: var(--plum); transform: translateY(-1px); }
.icon-btn__label { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.icon-btn--dark {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}
.icon-btn--dark:hover { background: var(--plum); color: var(--cream); border-color: var(--plum); }

/* ---------- 主要版面 ---------- */
.game {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1240px;
  min-height: calc(100dvh - var(--header-h));
  margin: 0 auto;
  padding: clamp(14px, 2.6vw, 30px) clamp(12px, 3vw, 28px) calc(var(--footer-h) + 30px);
  outline: none;
}
.screen { display: none; }
.screen.is-active { display: block; animation: screen-in .35s ease both; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--gold-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.eyebrow__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(233, 196, 106, .16);
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 12px;
  border: 1px solid rgba(233, 196, 106, .4);
  border-radius: 999px;
  background: rgba(233, 196, 106, .1);
  color: var(--gold-2);
  font-size: 13px;
  font-weight: 700;
}
.pill--soft { border-color: rgba(251, 246, 236, .2); background: rgba(251, 246, 236, .08); color: #e9e1f2; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 11px 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, color .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--primary {
  background: linear-gradient(180deg, #f8e5b4, var(--gold));
  color: #2b1c4d;
  box-shadow: 0 8px 22px rgba(233, 196, 106, .25);
}
.btn--primary:hover { background: linear-gradient(180deg, #fff0c9, #f0cf7e); }
.btn--ghost {
  border-color: rgba(233, 196, 106, .42);
  background: rgba(251, 246, 236, .06);
  color: var(--cream);
}
.btn--ghost:hover { background: rgba(251, 246, 236, .14); }
.btn--soft { background: #eee5d5; color: var(--ink); }
.btn--soft:hover { background: #e4d6c1; }
.btn--danger { background: var(--rose); color: #fff9f3; }
.btn--danger:hover { background: #b8586a; }
.btn--lg { min-height: 54px; padding: 14px 28px; font-size: 18px; }
.btn--sm { min-height: 44px; padding: 8px 15px; font-size: 14px; }
.btn--block { width: 100%; }
.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 7px 4px;
  border: 0;
  background: transparent;
  color: #f2e9d8;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.text-btn:hover { color: var(--gold-2); text-decoration: underline; text-underline-offset: 3px; }
.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px 13px;
  border: 1px solid rgba(233, 196, 106, .4);
  border-radius: 999px;
  background: rgba(251, 246, 236, .06);
  color: var(--gold-2);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mini-btn:hover { background: rgba(233, 196, 106, .15); }
.mini-btn:disabled { opacity: .55; cursor: default; }

/* ---------- 頁尾（固定顯示，精確字串） ---------- */
.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--footer-h);
  padding: 6px 14px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(233, 196, 106, .34);
  background: rgba(17, 9, 27, .97);
  color: #d8d0e4;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--gold-2); text-decoration: underline; text-underline-offset: 2px; }
.site-footer a:hover { color: #fff3cf; }

/* ---------- 對話框 ---------- */
body:has(dialog[open])::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(13, 7, 22, .64);
  pointer-events: none;
}
.dialog {
  position: fixed;
  inset: 0 0 calc(var(--footer-h) + 8px) 0;
  width: min(580px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--footer-h) - 22px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(233, 196, 106, .8);
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(10, 5, 18, .55);
  z-index: 100;
}
.dialog::backdrop { background: transparent; }
.dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px 14px;
  background: linear-gradient(135deg, #f7edda, #fbf6ec 65%);
  border-bottom: 1px solid #e5d8c2;
}
.dialog__head h2 { font-family: var(--serif); font-size: 24px; line-height: 1.25; letter-spacing: .03em; }
.dialog__kicker { color: #9a6b2f; font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.dialog__body { max-height: calc(100dvh - var(--footer-h) - 190px); overflow: auto; padding: 16px 18px; overscroll-behavior: contain; }
.dialog__body > p { line-height: 1.75; }
.dialog__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #e5d8c2;
  background: #fbf6ec;
}
.dialog__foot .btn { color: var(--ink); }
.dialog__foot .btn--primary { color: #2b1c4d; }
.dialog__foot .btn--danger { color: #fff9f3; }
.dialog .btn--ghost { border-color: var(--line); background: #fff; color: var(--ink); }
.dialog .btn--ghost:hover { background: #f2eadc; }
.dialog--explain { width: min(620px, calc(100vw - 24px)); }
.dialog--explain .dialog__head { align-items: center; }
.dialog__head--explain { background: linear-gradient(135deg, #f3e5cf, #fbf6ec); }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid #eee5d6;
}
.setting-row strong { display: block; font-size: 15px; }
.setting-row small { display: block; color: var(--ink-2); font-size: 12px; line-height: 1.5; }
.switch { position: relative; display: inline-flex; flex: none; align-items: center; width: 52px; height: 44px; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track { pointer-events: none; width: 52px; height: 30px; border-radius: 999px; background: #cfc6ba; transition: background .18s ease; }
.switch__track::after { content: ""; position: absolute; top: 7px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); transition: transform .18s ease; }
.switch input:checked + .switch__track { background: var(--violet); }
.switch input:checked + .switch__track::after { transform: translateX(22px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--gold-2); outline-offset: 3px; }
.range-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.range-row output { color: var(--violet); font-variant-numeric: tabular-nums; }
.range { width: 100%; height: 44px; margin: 0 0 8px; accent-color: var(--violet); cursor: pointer; }
.settings-more { display: grid; gap: 9px; margin: 18px 0 10px; }
.settings-note { color: var(--ink-2); font-size: 12px; line-height: 1.65; }
.settings-version { margin-top: 10px; color: var(--ink-3); font-size: 11px; }
.install-lead { font-weight: 700; }
.install-steps { margin: 10px 0 12px; padding-left: 22px; }
.install-steps li { margin: 7px 0; line-height: 1.7; }
.install-note { color: var(--ink-2); font-size: 12.5px; line-height: 1.7; }
.install-ok { color: var(--teal); font-size: 20px; font-weight: 800; }
.explain-answer {
  display: inline-block;
  margin-bottom: 12px;
  padding: 7px 13px;
  border: 1px solid #b9d9c0;
  border-radius: 10px;
  background: #edf7ee;
  color: #2f6b48;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.55;
}
.explain-text { color: #403747; font-size: 16px; line-height: 1.85; }
.explain-score { margin-top: 14px; color: #8a5c2b; font-size: 13px; font-weight: 800; }

/* ---------- 提示、吐司、彩帶、密技 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-h) + 16px);
  z-index: 115;
  max-width: calc(100vw - 24px);
  padding: 10px 16px;
  border: 1px solid rgba(233, 196, 106, .5);
  border-radius: 12px;
  background: rgba(24, 13, 37, .97);
  color: var(--cream);
  box-shadow: 0 12px 34px rgba(10, 5, 18, .45);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.toast.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.confetti-layer {
  position: fixed;
  inset: 0 0 var(--footer-h) 0;
  z-index: 85;
  overflow: hidden;
  pointer-events: none;
}
.confetti-piece {
  position: absolute;
  top: -24px;
  border-radius: 2px;
  animation: confetti-fall 2.2s linear forwards;
}
.cheat {
  position: fixed;
  inset: 0 0 var(--footer-h) 0;
  z-index: 96;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 45%, rgba(233, 196, 106, .26), transparent 28%), rgba(14, 8, 23, .82);
  backdrop-filter: blur(5px);
}
.cheat__card {
  width: min(460px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--gold);
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .5);
  animation: cheat-in .45s cubic-bezier(.2, .9, .3, 1.2) both;
}
.cheat__kicker { color: #9a6b2f; font-size: 12px; font-weight: 800; letter-spacing: .2em; }
.cheat__card h2 { margin: 6px 0 8px; font-family: var(--serif); font-size: 34px; letter-spacing: .1em; color: var(--plum); }
.cheat__card p { margin-bottom: 18px; color: var(--ink-2); line-height: 1.8; }

.noscript {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 30px;
  background: var(--plum);
  color: var(--cream);
  text-align: center;
  font-size: 18px;
}

/* ---------- 減少動態 ---------- */
body.is-reduced *,
body.is-reduced *::before,
body.is-reduced *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 窄螢幕 ---------- */
@media (max-width: 760px) {
  :root { --footer-h: 58px; }
  .icon-btn__label { display: none; }
  .icon-btn { padding: 7px; }
  .brand__text strong { font-size: 17px; letter-spacing: .04em; }
  .brand__text small { font-size: 9.5px; letter-spacing: .06em; }
  .site-footer { font-size: 11.5px; padding-left: 10px; padding-right: 10px; }
  .dialog { width: calc(100vw - 16px); max-height: calc(100dvh - var(--footer-h) - 16px); }
  .dialog__body { max-height: calc(100dvh - var(--footer-h) - 178px); }
  .dialog__head { padding: 13px 14px 11px; }
  .dialog__head h2 { font-size: 21px; }
  .dialog__body { padding: 13px 14px; }
  .dialog__foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) {
  .brand__text small { display: none; }
  .brand__mark { width: 34px; height: 34px; }
  .brand__mark svg { width: 34px; height: 34px; }
  .sysbar__controls { gap: 5px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
}
