:root {
  --bg: #fff8ee;
  --ink: #3b2a1a;
  --muted: #8a6a4e;
  --accent: #b8541f; /* 白字對比 ≥ 4.5 */
  --accent-ink: #fff;
  --card: rgba(255, 250, 242, 0.96);
  --line: #f0d2b4;
  --ok: #2e9d5b;
  --bad: #d64545;
  --gold: #f4b400;
  --r: 16px;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe6ff; }
html { touch-action: manipulation; } /* 快速點選項時不觸發雙擊縮放 */
button, .btn {
  font: inherit; font-size: 1rem; cursor: pointer; border: 2px solid var(--line); background: #fff;
  color: var(--ink); border-radius: 12px; padding: 0.6em 1.1em; min-height: 44px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3em;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:focus-visible, .btn:focus-visible { outline: 3px solid #1e5aa8; outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.big { font-size: 1.2rem; padding: 0.8em 1.6em; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#bg2d { display: none; position: fixed; inset: 0; background: linear-gradient(#bfe6ff 0 55%, #8bc34a 55%); }
.no3d #scene { display: none; }
.no3d #bg2d { display: block; }

.screen { position: fixed; z-index: 2; }
.screen[hidden] { display: none !important; }
.panel {
  inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); overflow: auto; background: var(--card); border-radius: 24px;
  padding: 28px; box-shadow: 0 20px 60px rgba(60, 30, 10, 0.25); border: 3px solid var(--line);
}
.center { text-align: center; }
h1 { font-size: clamp(1.7rem, 5vw, 2.6rem); margin: 0.2em 0; color: #b4501a; }
h2 { margin: 0.2em 0 0.5em; }
.kicker { color: var(--accent); font-weight: 700; margin: 0; letter-spacing: 0.1em; }
.lead { font-size: 1.05rem; line-height: 1.7; }
.tiny { font-size: 0.85rem; color: var(--muted); margin: 0.3em 0; }
.quote { font-style: italic; color: #a14a1b; font-size: 1.1rem; }
.btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 16px 0 6px; }
.btns.col { flex-direction: column; align-items: stretch; max-width: 360px; margin-inline: auto; }
.back { margin-top: 14px; }

.day-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.day-card { flex-direction: column; align-items: stretch; text-align: left; padding: 14px; }
.day-card strong { font-size: 1.2rem; color: #b4501a; }
.day-card ol { margin: 6px 0 0; padding-left: 1.3em; font-size: 0.92rem; line-height: 1.6; }
.day-card .best { font-size: 0.8rem; color: var(--muted); }

/* HUD */
#hud { inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hud-top { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right)); display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.hud-period, .hud-items, .hud-comp { background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 8px 14px; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.hud-period { display: flex; flex-direction: column; }
.hud-period strong { font-size: 1.15rem; color: #b4501a; }
.hud-period span { font-size: 0.85rem; color: var(--muted); }
.hud-items { display: flex; gap: 12px; align-items: center; font-size: 0.95rem; flex-wrap: wrap; }
.hud-comp { position: absolute; top: 96px; left: 12px; display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; }
.hud-comp .on { color: var(--ok); font-weight: 700; }
.hud-bottom { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); left: 12px; right: 12px; display: flex; gap: 10px; justify-content: center; }
.hud-bottom button { box-shadow: 0 4px 14px rgba(0,0,0,.18); white-space: nowrap; }
.dir-arrow { position: absolute; left: 50%; top: 50%; font-size: 2.4rem; color: #ffc107; text-shadow: 0 2px 6px rgba(0,0,0,.45); pointer-events: none;
  transform: translate(-50%, -50%) rotate(var(--a)) translateX(min(42vw, 40vh)); }
.sched { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 12px 16px 12px 36px; margin: 0; line-height: 1.8; min-width: 220px; }
.sched .now { font-weight: 700; color: var(--accent); }
.sched .done { color: var(--muted); text-decoration: line-through; }

/* 戰鬥 */
#battle { inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
#battle > * { pointer-events: auto; }
.mon-bar { margin: calc(12px + env(safe-area-inset-top)) 12px 12px; align-self: center; width: min(720px, calc(100vw - 32px)); background: var(--card); border-radius: var(--r); padding: 10px 16px; border: 2px solid var(--line); display: flex; gap: 14px; align-items: center; justify-content: space-between; }
.mon-bar h2 { margin: 0; font-size: 1.2rem; color: #8e2a0f; }
.hp { width: 40%; min-width: 120px; height: 18px; background: #eee; border-radius: 9px; overflow: hidden; border: 2px solid #8e2a0f; }
#hp-fill { height: 100%; background: linear-gradient(90deg, #e53935, #ff7043); transition: width .35s; }
.mon2d { display: none; justify-content: center; align-items: center; flex: 1; }
.no3d .mon2d { display: flex; }
.blob { width: 150px; height: 160px; border-radius: 50% 50% 46% 46%; background: var(--mon, #7c6cf0); position: relative; box-shadow: inset -12px -16px 0 rgba(0,0,0,.15); animation: bob 2s ease-in-out infinite; }
.blob .e { position: absolute; top: 45px; width: 34px; height: 34px; background: #fff; border-radius: 50%; box-shadow: inset 6px 6px 0 10px #fff, inset 0 0 0 30px #222; }
.blob .e.l { left: 34px; } .blob .e.r { right: 34px; }
.blob .m { position: absolute; bottom: 38px; left: 50%; width: 46px; height: 18px; border-radius: 0 0 30px 30px; background: #3e1a1a; transform: translateX(-50%); }
.mon2d.hit .blob { animation: shake .3s; filter: brightness(1.8); }
@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }

.qpanel { align-self: center; width: min(760px, calc(100vw - 24px)); margin-bottom: calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-radius: 22px; border: 3px solid var(--line); padding: 16px 18px; box-shadow: 0 -6px 30px rgba(0,0,0,.2); max-height: 62dvh; overflow: auto; }
.qmeta { display: flex; justify-content: space-between; font-size: 0.95rem; gap: 8px; flex-wrap: wrap; }
#hearts { color: var(--bad); letter-spacing: 2px; }
#combo { color: #8a5a00; font-weight: 700; }
.qtext { font-size: 1.15rem; font-weight: 700; line-height: 1.6; margin: 8px 0; }
.qhint { background: #fff3cd; border-radius: 10px; padding: 8px 12px; margin: 6px 0; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opts button { justify-content: flex-start; text-align: left; padding: 12px 14px; line-height: 1.45; }
.opts button b { color: var(--accent); min-width: 1.4em; }
.opts button.right { background: #e6f6ec; border-color: var(--ok); }
.opts button.wrong { background: #fde8e8; border-color: var(--bad); }
.opts button:disabled { opacity: 1; cursor: default; }
.opts button.gone { display: none; }
#battle.won .qpanel { display: none; }
.review { text-align: left; max-width: 560px; margin: 10px auto; padding-left: 1.4em; font-size: 0.92rem; line-height: 1.6; }
.review li { margin-bottom: 8px; }
.result .aff { display: block; margin-top: 8px; font-weight: 700; }
.result .up { color: var(--ok); }
.result .down { color: var(--bad); }
.zhuyin { font-size: 0.72em; font-weight: 400; color: var(--muted); letter-spacing: 0.08em; margin-left: 0.5em; }
p.zhuyin { margin: -2px 0 4px; font-size: 0.8rem; }
.tools { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.tools button { font-size: 0.9rem; min-height: 40px; }
.feedback { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: #fff; border: 2px dashed var(--line); }
.fb-head { font-weight: 700; margin: 0 0 4px; }
.fb-head.ok { color: var(--ok); } .fb-head.no { color: var(--bad); }
.flash { position: fixed; inset: 0; background: rgba(214, 69, 69, 0.35); opacity: 0; pointer-events: none !important; transition: opacity .25s; }
.flash.on { opacity: 1; transition: none; }

@media (max-width: 560px) {
  /* 選項維持兩欄、面板壓低，怪獸才露得出來 */
  .opts { gap: 8px; }
  .opts button { padding: 10px; font-size: 0.92rem; }
  .qpanel { max-height: 50dvh; padding: 12px 14px; }
  .feedback { position: sticky; bottom: -12px; box-shadow: 0 -4px 12px rgba(0,0,0,.12); }
  .panel { padding: 20px 16px; }
  .hud-comp { top: auto; bottom: calc(80px + env(safe-area-inset-bottom)); font-size: 0.78rem; padding: 6px 10px; }
  .qtext { font-size: 1.05rem; }
  body #toast { top: auto; bottom: calc(170px + env(safe-area-inset-bottom)); }
  .day-list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .day-card { padding: 10px; }
  .day-card ol { font-size: 0.78rem; line-height: 1.45; padding-left: 1.1em; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .mon-bar { padding: 6px 12px; }
  .mon-bar .tiny { display: none; }
  .qpanel { max-height: 72dvh; }
}

/* 記憶翻牌 */
.mem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0; }
.mem-grid button { min-height: 86px; font-size: 0.95rem; line-height: 1.4; padding: 8px; background: linear-gradient(135deg, #ffcc80, #ffab91); border-color: #e07a3f; color: transparent; }
.mem-grid button.open { background: #fff; color: var(--ink); }
.mem-grid button.unit.open { background: #fff3e0; font-weight: 700; color: #b4501a; }
.mem-grid button.matched { background: #e6f6ec; border-color: var(--ok); color: var(--ink); }
@media (max-width: 560px) { .mem-grid { grid-template-columns: repeat(2, 1fr); } }

.result { background: #fff3e0; border-radius: 12px; padding: 10px 14px; }
#end-card { width: min(280px, 70%); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18); margin: 8px auto; display: block; }
#end-title { font-size: 2rem; color: #c2410c; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile { border: 2px solid var(--line); border-radius: 14px; padding: 12px; background: #fff; }
.tile h3 { margin: 0 0 4px; font-size: 1.05rem; }
.tile p { margin: 4px 0; font-size: 0.88rem; line-height: 1.5; }
.tile.locked { opacity: 0.55; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 6px; }

#toast { position: fixed; z-index: 5; top: 104px; left: 50%; transform: translateX(-50%); background: rgba(59, 42, 26, 0.92); color: #fff; padding: 12px 20px; border-radius: 14px; max-width: calc(100vw - 32px); text-align: center; line-height: 1.6; pointer-events: none; white-space: pre-line; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
