/* 小遊戲盒共用樣式：同一套圓角、字型、按鈕；每款遊戲用 body[data-game] 換主色。 */
:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --ink: #1b2420;
  --ink-soft: #5c6a64;
  --line: #d9e1dd;
  --shadow: 0 1px 2px rgba(20, 35, 28, .08), 0 4px 14px rgba(20, 35, 28, .07);
  --solitaire: #2f7a49;
  --find: #13806a;
  --color: #d9711f;
  --apple: #d23f3a;
  --maze: #3461d1;
  --accent: #2f7a49;
  --on-accent: #ffffff;
  --good: #1f9254;
  --bad: #d23f3a;
  --font-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-num: "Fredoka", "Noto Sans TC", system-ui, sans-serif;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121816; --surface: #1c2421; --surface-2: #232d29; --ink: #ecf2ef; --ink-soft: #9badA5;
    --line: #2e3a35; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    --solitaire: #4fae72; --find: #2fb393; --color: #f0913f; --apple: #f0645e; --maze: #6b8ff0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121816; --surface: #1c2421; --surface-2: #232d29; --ink: #ecf2ef; --ink-soft: #9badA5;
  --line: #2e3a35; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  --solitaire: #4fae72; --find: #2fb393; --color: #f0913f; --apple: #f0645e; --maze: #6b8ff0;
  color-scheme: dark;
}
body[data-game="find"] { --accent: var(--find); }
body[data-game="color"] { --accent: var(--color); }
body[data-game="apple"] { --accent: var(--apple); }
body[data-game="maze"] { --accent: var(--maze); }

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.page {
  max-width: 480px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px 28px;
  display: flex; flex-direction: column; gap: 14px;
}

/* 頂部列：返回遊戲盒、遊戲名、右側按鈕 */
.bar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; min-height: 44px; }
.back {
  display: inline-flex; align-items: center; gap: 2px; padding: 6px 12px 6px 8px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); color: var(--ink); text-decoration: none; font-weight: 700; font-size: 14px;
}
.back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.bar h1 { margin: 0; font-size: 19px; font-weight: 900; letter-spacing: .04em; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar h1 small { font: 500 12px var(--font-num); color: var(--ink-soft); margin-left: 4px; letter-spacing: 0; }
.chip {
  border: 0; border-radius: 999px; padding: 7px 14px; background: var(--surface); box-shadow: var(--shadow);
  font-weight: 700; font-size: 14px; cursor: pointer;
}

/* 數據列 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; align-items: center; gap: 0; box-shadow: var(--shadow); min-width: 0; }
.stat .lbl { font-size: 12px; font-weight: 700; color: var(--ink-soft); letter-spacing: .06em; white-space: nowrap; }
.stat .val { font: 600 22px/1.2 var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .val.warn { color: var(--bad); }

/* 按鈕 */
.btn {
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; font-size: 16px; cursor: pointer;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:not(:disabled):active, .chip:active, .back:active { transform: scale(.97); }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }

.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.muted { color: var(--ink-soft); }

/* 彈窗與提示 */
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(8, 16, 12, .55);
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet {
  background: var(--surface); color: var(--ink); border-radius: 20px; width: 100%; max-width: 380px;
  max-height: 100%; overflow-y: auto; padding: 22px 20px 18px; display: flex; flex-direction: column; gap: 12px;
}
.sheet h2 { margin: 0; font-size: 20px; font-weight: 900; text-wrap: balance; }
.sheet p, .sheet li { margin: 0; font-size: 14px; line-height: 1.7; color: var(--ink-soft); }
.sheet ol, .sheet ul { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }
.sheet strong { color: var(--ink); }
.sheet .big { font: 700 44px/1 var(--font-num); color: var(--accent); }
.sheet .meta { font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--line); padding-top: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 70;
  font-size: 14px; font-weight: 700; max-width: calc(100% - 32px); text-align: center; pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }
