/* ============================================================
   基礎：變數、重置、背景、按鈕、對話框、頁尾、系統按鈕
   ============================================================ */
:root {
  --ink: #243055;
  --ink-soft: #46527d;
  --cream: #fffaf0;
  --paper: #ffffff;
  --sun: #ffd166;
  --sun-d: #f2a93b;
  --coral: #ff7a6b;
  --sky: #3fb2f5;
  --mint: #46d6c8;
  --green: #58c26b;
  --purple: #a77bf5;
  --accent: #ff7a6b;
  --accent2: #ffb36b;
  --footer-h: 46px;
  --sys-w: 176px;
  --gutter: 16px;
  --radius: 18px;
  font-family: system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  color-scheme: light;
}

#game[data-zone="1"] { --accent: #ff7a6b; --accent2: #ffb36b; --accent-soft: #ffe3dc; }
#game[data-zone="2"] { --accent: #3fb2f5; --accent2: #46d6c8; --accent-soft: #dff2ff; }
#game[data-zone="3"] { --accent: #58c26b; --accent2: #f2b84b; --accent-soft: #e3f6dc; }
#game[data-zone="4"] { --accent: #a77bf5; --accent2: #f2c14b; --accent-soft: #eee4ff; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #ffe9c7;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; height: auto; }
button { font: inherit; color: inherit; }
b, strong { font-weight: 800; }

:focus-visible { outline: 4px solid #1d6cff; outline-offset: 3px; border-radius: 8px; }

/* ---------- 背景 ---------- */
.bg { position: fixed; inset: 0; z-index: -1; background: #ffe9c7; overflow: hidden; }
.bg__img { position: absolute; inset: 0; background-size: cover; background-position: center; }
.bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 250, 240, .55), rgba(255, 238, 210, .8)); }

.game { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom)); }
.screen { display: none; min-height: calc(100dvh - var(--footer-h)); }
.screen.is-active { display: block; }

/* ---------- 系統按鈕 ---------- */
.sysbar {
  position: fixed; z-index: 55;
  top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right));
  display: flex; gap: 6px;
}

.icon-btn {
  width: 48px; height: 48px; min-width: 48px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink); cursor: pointer; font-size: 22px; font-weight: 800; line-height: 1;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.icon-btn svg { width: 26px; height: 26px; fill: var(--ink); }
.icon-btn:hover { background: #fff3cf; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.icon-btn--sm { width: 44px; height: 44px; min-width: 44px; font-size: 20px; }
#btn-settings:hover svg { animation: spin 1.2s linear infinite; }

/* ---------- 按鈕 ---------- */
.btn {
  min-height: 48px; padding: 0 20px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--sun); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink);
  font-size: 18px; font-weight: 800; cursor: pointer; text-align: center;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: linear-gradient(180deg, #ffe08a, var(--sun-d)); }
.btn--soft { background: #fff; }
.btn--ghost { background: rgba(255, 255, 255, .8); }
.btn--danger { background: var(--coral); }
.btn--xl { min-height: 60px; padding: 0 34px; font-size: 22px; border-radius: 20px; }
.btn--sm { min-height: 44px; padding: 0 14px; font-size: 16px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 12px;
  background: #fff; border: 3px solid var(--ink); border-radius: 999px; font-weight: 800; font-size: 17px;
}
.badge { display: inline-block; padding: 2px 14px; background: var(--accent); color: var(--ink); border: 3px solid var(--ink); border-radius: 999px; font-weight: 800; font-size: 15px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; font-weight: 700; font-size: 15px; }
.chip--best { background: #fff3cf; }

/* ---------- 對話框 ---------- */
dialog.dialog {
  width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - var(--footer-h) - env(safe-area-inset-bottom) - 24px); padding: 0; margin: auto;
  /* 對話框只置中在頁尾上方，不壓住頁尾 */
  bottom: calc(var(--footer-h) + env(safe-area-inset-bottom));
  background: var(--cream); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 10px 0 rgba(36, 48, 85, .35);
}
dialog.dialog--small { width: min(420px, calc(100vw - 24px)); }
/* 模態對話框在 top layer，::backdrop 會蓋住整個視窗（含頁尾）。
   改成透明 backdrop，另用 z-index 比頁尾低的 body::before 變暗，頁尾永遠清楚可見。 */
dialog.dialog::backdrop { background: transparent; }
html:has(dialog.dialog[open]) body::before {
  content: ""; position: fixed; inset: 0; z-index: 89; background: rgba(36, 48, 85, .6);
}
/* 確認框疊在設定框上時，把下層的設定框壓暗，凸顯確認框 */
html:has(dialog.dialog--small[open]) dialog.dialog:not(.dialog--small)[open] { filter: brightness(.62); }
.dialog__form { display: flex; flex-direction: column; max-height: calc(100dvh - var(--footer-h) - env(safe-area-inset-bottom) - 30px); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px 20px; }
.dialog__head h2 { font-size: 22px; }
.dialog__body { padding: 8px 20px 12px; overflow: auto; }
.dialog__foot { padding: 10px 20px 18px; display: flex; justify-content: center; gap: 12px; }
.dialog__foot--two .btn { flex: 1; }
.dialog__hr { border: 0; border-top: 2px dashed rgba(36, 48, 85, .3); margin: 14px 0; }
.dialog__note { font-size: 14px; color: var(--ink-soft); margin-top: 10px; }
.dialog__version { font-size: 13px; color: var(--ink-soft); margin-top: 4px; text-align: right; }
.dialog__lead { background: #fff3cf; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-weight: 700; }
.steps-list { padding-left: 24px; margin: 10px 0 0; }
.steps-list li { margin-bottom: 8px; }
.kbd { display: inline-block; min-width: 26px; padding: 0 6px; text-align: center; border: 2px solid var(--ink); border-radius: 6px; background: #fff; font-weight: 800; }

.setting { margin-bottom: 14px; }
.setting__row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font-weight: 800; font-size: 18px; }
.range { width: 100%; height: 32px; accent-color: var(--accent); }
.switch {
  position: relative; width: 72px; height: 44px; padding: 0; flex: none;
  background: #cfd6ea; border: 3px solid var(--ink); border-radius: 999px; cursor: pointer; transition: background .15s;
}
.switch span { position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; background: #fff; border: 3px solid var(--ink); border-radius: 50%; transition: transform .18s; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"] span { transform: translateX(28px); }
.setting-btn {
  display: flex; width: 100%; min-height: 48px; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; padding: 0 14px;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink); font-size: 17px; font-weight: 800; cursor: pointer; text-align: left;
}
.setting-btn:active { transform: translateY(3px); box-shadow: none; }
.setting-btn--danger { background: #ffe3dc; }
.setting-btn__state { font-size: 14px; font-weight: 700; color: var(--ink-soft); }

/* ---------- 頁尾（所有畫面都看得到） ---------- */
.site-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: rgba(30, 40, 75, .96); color: #f4f6ff; text-align: center; font-size: 13px; line-height: 1.45;
}
.site-footer a { color: #ffd166; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.site-footer a:hover { color: #fff; }

/* ---------- 提示、彩帶、密技 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--footer-h) + 18px + env(safe-area-inset-bottom)); z-index: 95;
  max-width: min(520px, calc(100vw - 32px)); padding: 12px 18px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; border-radius: 16px; font-weight: 700; text-align: center; transition: opacity .25s, transform .25s;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; z-index: 85; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 10px; height: 16px; border-radius: 3px; animation: confetti-fall 1.6s ease-in forwards; }

.cheat-overlay { position: fixed; inset: 0; z-index: 88; padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; background: rgba(36, 48, 85, .65); }
.cheat-overlay__card { padding: 28px 40px; text-align: center; background: var(--cream); border: 4px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--ink); }
.cheat-overlay__big { font-size: 72px; line-height: 1.1; }
.cheat-overlay h2 { font-size: 34px; margin: 6px 0; }
.noscript { position: fixed; inset: auto 16px 60px; z-index: 99; background: #fff; padding: 16px; border-radius: 12px; }

@media (max-width: 720px) {
  :root { --footer-h: 52px; --sys-w: 168px; }
  body { font-size: 16px; }
  .site-footer { font-size: 12.5px; }
}

h1:focus, h2:focus { outline: none; }
