/* ============================================================
   基礎樣式、色彩、系統列、頁尾、按鈕、對話框
   ============================================================ */
:root {
  --paper: #fff8e9;
  --paper-2: #ffefd0;
  --paper-3: #fbe4bd;
  --cream: #fffdf7;
  --ink: #3c2a1e;
  --ink-soft: #634b39;
  --muted: #826a56;
  --wood: #a86a3b;
  --wood-dark: #71451f;
  --orange: #e98b3f;
  --orange-2: #f6c95c;
  --nori: #315d47;
  --nori-2: #4f8a69;
  --mint: #8fd2b2;
  --plum: #ba4b56;
  --blue: #3f86c6;
  --line: #e7d4b5;
  --line-strong: #d3b88f;
  --shadow-sm: 0 3px 0 rgba(104, 66, 33, .12), 0 8px 18px rgba(104, 66, 33, .1);
  --shadow: 0 6px 0 rgba(104, 66, 33, .14), 0 18px 38px rgba(104, 66, 33, .16);
  --shadow-lg: 0 10px 0 rgba(104, 66, 33, .14), 0 28px 60px rgba(104, 66, 33, .2);
  --radius: 24px;
  --radius-lg: 34px;
  --font-body: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, sans-serif;
  --font-display: "Yuanti TC", "YuanTi TC", "PingFang TC", "Heiti TC", var(--font-body);
  --zone-color: #e98b3f;
  --zone-color2: #f6c95c;
  --zone-ink: #5a3218;
  --sysbar-h: 58px;
  --footer-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.65;
  background: #f7e7c9;
  overflow-x: hidden;
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}

body[data-screen="home"] { --footer-h: 52px; }

h1, h2, h3, p, dl, dd, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img { max-width: 100%; height: auto; display: block; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--nori); text-underline-offset: 3px; }
:focus-visible { outline: 4px solid #2f7bbf; outline-offset: 3px; }

.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;
}

.skip-link {
  position: fixed;
  left: 12px; top: -80px;
  z-index: 200;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  transition: top .2s;
}
.skip-link:focus { top: 12px; }

/* ---------- 背景 ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 8%, #fff4d8 0 18%, transparent 42%),
    linear-gradient(160deg, #fbe7c1 0%, #f5d7a8 46%, #ecd0a0 100%);
}
.bg__img {
  position: absolute;
  inset: -4%;
  background-position: center;
  background-size: cover;
  filter: blur(3px) saturate(.92);
  opacity: 0;
  transform: scale(1.04);
  transition: opacity .6s ease;
}
.bg__img[data-src] { opacity: .34; }
.bg__wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 251, 236, .5), transparent 60%),
    linear-gradient(180deg, rgba(255, 248, 233, .22), rgba(255, 238, 204, .8));
}

/* ---------- 系統列 ---------- */
.sysbar {
  position: fixed;
  z-index: 70;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: 14px;
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 18px;
  background: rgba(255, 253, 247, .78);
  border: 1px solid rgba(255, 255, 255, .8);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  background: #fffaf0;
  color: var(--wood-dark);
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 2px 0 rgba(104, 66, 33, .16), inset 0 0 0 1px rgba(168, 106, 59, .16);
  transition: transform .15s, background .15s, box-shadow .15s;
}
.icon-btn:hover { background: #fff3dc; transform: translateY(-1px); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 0 0 rgba(0, 0, 0, 0); }
.icon-btn svg { width: 25px; height: 25px; fill: currentColor; }
.icon-btn--gear { background: #fff3dc; }
.icon-btn--sm { width: 44px; height: 44px; min-width: 44px; min-height: 44px; border-radius: 12px; font-size: 18px; }
.icon-btn--sm svg { width: 22px; height: 22px; }

/* ---------- 頁尾 ---------- */
.site-footer {
  position: fixed;
  z-index: 60;
  left: 0; right: 0; bottom: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 12.5px;
  line-height: 1.5;
  color: #5d4635;
  background: rgba(255, 249, 236, .9);
  border-top: 1px solid rgba(168, 106, 59, .18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.site-footer a { color: #6b3c17; font-weight: 700; display: inline-block; padding: 9px 6px; margin: -9px -6px; }
.site-footer p { max-width: 980px; margin: 0 auto; }

/* ---------- 通用按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 22px;
  border: 0;
  border-radius: 16px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .02em;
  text-decoration: none;
  box-shadow: 0 4px 0 rgba(104, 66, 33, .22);
  transition: transform .14s, box-shadow .14s, filter .14s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.03); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(104, 66, 33, .2); }
.btn:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.btn--primary {
  color: #fffdf5;
  background: linear-gradient(180deg, #c4701f, #b25c14 55%, #9c4c0d);
  border: 1px solid #8f4409;
  text-shadow: 0 1px 0 rgba(96, 47, 9, .25);
}
.btn--soft { color: var(--wood-dark); background: #fff3d8; border: 1px solid #e5c99b; }
.btn--ghost { color: var(--ink-soft); background: rgba(255, 253, 247, .7); border: 1px solid rgba(168, 106, 59, .24); }
.btn--danger { color: #fff; background: linear-gradient(180deg, #d56a71, var(--plum)); border: 1px solid #9c3842; }
.btn--xl { min-height: 64px; padding: 16px 30px; font-size: 24px; border-radius: 20px; }
.btn--sm { min-height: 44px; padding: 8px 16px; font-size: 17px; border-radius: 12px; }
.btn__icon { font-size: 1.18em; }

/* ---------- 對話框 ---------- */
.dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 80px);
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: transparent;
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(48, 30, 16, .5); backdrop-filter: blur(3px); }
.dialog__form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  background: var(--cream);
  border: 2px solid #f1ddba;
  border-radius: 26px;
  overflow: hidden;
}
.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  background: linear-gradient(180deg, #fff5df, #ffebc8);
  border-bottom: 1px solid var(--line);
}
.dialog__head h2 { font-family: var(--font-display); font-size: 24px; }
.dialog__body { padding: 20px; overflow-y: auto; overscroll-behavior: contain; }
.dialog__foot { padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); text-align: right; }
.dialog__foot--two { display: flex; justify-content: flex-end; gap: 10px; }
.dialog__hr { border: 0; border-top: 1px dashed var(--line-strong); margin: 18px 0; }
.dialog__note { margin-top: 16px; font-size: 14px; color: var(--muted); line-height: 1.7; }
.dialog__version { margin-top: 8px; font-size: 12px; color: #a18a73; }
.dialog--small { width: min(430px, calc(100vw - 32px)); }

.setting { margin-bottom: 18px; }
.setting__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.setting__row label { font-weight: 700; font-size: 18px; }
.switch {
  position: relative;
  width: 64px; height: 44px;
  min-width: 64px; min-height: 44px;
  border: 1px solid #d9c19b;
  border-radius: 999px;
  background: #eadbc3;
  transition: background .2s;
}
.switch span {
  position: absolute;
  top: 4px; left: 4px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #fffdf7;
  box-shadow: 0 2px 4px rgba(80, 50, 20, .2);
  transition: transform .2s;
}
.switch[aria-checked="true"] { background: var(--nori-2); border-color: var(--nori); }
.switch[aria-checked="true"] span { transform: translateX(22px); }
.range { width: 100%; height: 44px; accent-color: var(--orange); cursor: pointer; }
.setting-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 54px;
  margin-top: 10px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff8e8;
  text-align: left;
  font-weight: 700;
  font-size: 17px;
  transition: background .15s;
}
.setting-btn:hover { background: #fff1d4; }
.setting-btn--danger { color: var(--plum); border-color: #ecc7c7; background: #fff6f4; }
.setting-btn__state { font-size: 14px; color: var(--muted); font-weight: 500; }

.steps-list { margin: 14px 0 0; padding-left: 1.5em; }
.steps-list li { margin-bottom: 9px; }
.kbd {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  border: 1px solid #cbb28b;
  border-bottom-width: 3px;
  background: #fff9e9;
  font-family: ui-monospace, monospace;
}

/* ---------- 吐司、彩帶、密技 ---------- */
.toast {
  position: fixed;
  z-index: 150;
  left: 50%;
  bottom: calc(var(--footer-h) + 24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 18px);
  max-width: min(92vw, 520px);
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(60, 42, 30, .92);
  color: #fff9ea;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; z-index: 140; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 9px; height: 16px;
  border-radius: 2px;
  animation: confetti-fall 1.8s cubic-bezier(.2, .7, .3, 1) forwards;
}

.cheat-overlay {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(50, 31, 16, .62);
  backdrop-filter: blur(4px);
}
.cheat-overlay[hidden] { display: none; }
.cheat-overlay__card {
  width: min(420px, 90vw);
  padding: 32px 24px;
  border-radius: 28px;
  background: var(--cream);
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop-in .35s cubic-bezier(.2, 1.3, .4, 1);
}
.cheat-overlay__big { font-size: 64px; line-height: 1; }
.cheat-overlay__card h2 { font-family: var(--font-display); font-size: 28px; margin-top: 8px; }
.cheat-overlay__card p { color: var(--muted); margin-top: 6px; }

.noscript {
  position: fixed;
  z-index: 300;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--paper);
  font-size: 20px;
  text-align: center;
}

/* ---------- 共用 ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #fff6e2;
  border: 1px solid var(--line);
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}
.pill b { font-size: 18px; }
.pill--star { color: #8a5a0d; background: #fff1c4; border-color: #ecd18a; }
.pill--score { color: #7a4c10; }
.pill--combo { color: #fff; background: linear-gradient(135deg, #e46f49, var(--plum)); border-color: #a33b44; }

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--zone-color) 16%, #fff);
  color: var(--zone-ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .02em;
}

.stars-line { color: #dfa41f; letter-spacing: 2px; font-size: 20px; }
.stars-line .is-off { color: #d9cbb5; }

@media (max-width: 620px) {
  body { font-size: 17px; }
  .sysbar { top: max(6px, env(safe-area-inset-top, 0px)); right: 8px; gap: 5px; padding: 5px; border-radius: 16px; }
  .icon-btn { width: 46px; height: 46px; min-width: 46px; min-height: 46px; }
  .site-footer { font-size: 11px; padding: 7px 10px calc(7px + env(safe-area-inset-bottom, 0px)); }
  .dialog__body { padding: 16px; }
  .btn { min-height: 50px; font-size: 18px; }
  .btn--xl { min-height: 58px; font-size: 21px; }
}

/* fallback for older browsers without color-mix */
.dialog { background: #fffdf7; }
