/* Ivy 的 AI 夢想學院：明亮、溫暖、療癒的科技教育風 */

:root {
  --font: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --serif: "Noto Serif TC", "PMingLiU", serif;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(60, 50, 40, 0.14), 0 2px 6px rgba(60, 50, 40, 0.08);
  --shadow-sm: 0 4px 14px rgba(60, 50, 40, 0.1);
  --gold: #e8b33a;
  --gold-ink: #5a3e00;
  --navy: #2c3e66;
  --ok: #2f9e6e;
  --ok-bg: #e6f6ee;
  --bad: #d9534f;
  --bad-bg: #fdecea;
  --warn-bg: #fff4dc;
}

/* 五種主題：奶油白、天空藍、薄荷綠、薰衣草紫、暖杏桃 */
:root, [data-theme="cream"] {
  --bg: #f6efe3; --bg2: #efe4d2; --panel: #fffdf8; --panel2: #f8f2e8; --line: #e6dccb;
  --ink: #2c2a33; --ink2: #625c6a; --accent: #2fa596; --accent2: #5aa7d8; --accent3: #9b87d8; --accent-ink: #ffffff;
}
[data-theme="sky"] {
  --bg: #e5f0fa; --bg2: #d4e6f6; --panel: #fbfdff; --panel2: #eef5fc; --line: #cfe0ef;
  --ink: #1f2a3a; --ink2: #536379; --accent: #2f86c8; --accent2: #3fb6a8; --accent3: #8f7fd6; --accent-ink: #ffffff;
}
[data-theme="mint"] {
  --bg: #e3f4ec; --bg2: #d0ecdf; --panel: #fbfffd; --panel2: #eef8f3; --line: #cde6da;
  --ink: #1f312a; --ink2: #4f6a5f; --accent: #23917a; --accent2: #4f9fd0; --accent3: #9b87d8; --accent-ink: #ffffff;
}
[data-theme="lavender"] {
  --bg: #efeaf8; --bg2: #e3dbf3; --panel: #fdfbff; --panel2: #f4f0fb; --line: #e0d7f0;
  --ink: #2b2638; --ink2: #625a75; --accent: #7a62c9; --accent2: #3fa4b6; --accent3: #d27fae; --accent-ink: #ffffff;
}
[data-theme="apricot"] {
  --bg: #fcece0; --bg2: #f7dcc8; --panel: #fffcf9; --panel2: #fbf1e9; --line: #f0dccb;
  --ink: #33281f; --ink2: #6e5a4b; --accent: #d8743f; --accent2: #3fa596; --accent3: #a37fd0; --accent-ink: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; overflow: hidden; }
button { font-family: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--ink2); }
.small { font-size: 13px; }
kbd { font-family: inherit; background: var(--navy); color: #fff; border-radius: 6px; padding: 1px 7px; font-weight: 700; font-size: 12px; }

/* ------------------------------------------------------------ 舞台 */
#stage { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 30%, var(--panel2), var(--bg2)); touch-action: none; }
#stage .webgl { display: block; width: 100%; height: 100%; outline: none; }
#stage .label-layer { position: absolute; inset: 0; pointer-events: none; }
.label-layer * { pointer-events: none !important; }

.tag {
  font-size: 13px; font-weight: 700; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px;
  background: rgba(255, 253, 248, 0.94); color: var(--ink);
  border: 2px solid var(--line); box-shadow: 0 3px 8px rgba(0,0,0,0.12);
  transform: translateY(-4px);
}
.tag-player { background: #fff3c4; border-color: #f0c84a; }
.tag-robot { font-size: 11px; padding: 1px 8px; background: #e3faf7; border-color: #9ee0d6; }
.tag-npc { background: #ffffff; border-color: var(--accent); }
.tag-npc.pending { animation: bob 1.4s ease-in-out infinite; }
.tag-npc .tag-state { margin-right: 4px; }
.tag-monster { background: #fff0f3; border-color: #ef6f8f; color: #8a2140; }
.tag-monster.friendly { background: #fff5fb; border-color: #f7a8c8; color: #9b3a6a; }
.tag-card { font-size: 12px; background: #fffbe6; border-color: #f2cf5b; }
.tag-card.done { opacity: 0.7; }
.tag-podium { background: #eaf6ff; border-color: #6bb7e8; }
.tag-podium.pending { animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-9px); } }

.interact-prompt {
  font-size: 13px; font-weight: 700; color: #fff; background: var(--navy);
  padding: 4px 10px 4px 5px; border-radius: 999px; box-shadow: var(--shadow-sm);
  display: flex; gap: 6px; align-items: center; animation: pulse 1.2s ease-in-out infinite;
}
.interact-prompt kbd { background: var(--gold); color: var(--gold-ink); }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ------------------------------------------------------------ 按鈕與表單 */
.btn {
  appearance: none; border: 0; cursor: pointer; font-weight: 700; font-size: 15px;
  padding: 10px 18px; border-radius: 12px; color: var(--ink); background: var(--panel2);
  border: 2px solid var(--line); transition: transform .12s, box-shadow .12s, background .12s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, .opt:focus-visible, .ib:focus-visible, .zone-card:focus-visible, .w2d-obj:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.gold { background: var(--gold); border-color: #d9a12a; color: var(--gold-ink); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.ghost { background: var(--panel); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.big { font-size: 18px; padding: 14px 26px; }
.btn.tiny { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.btn.hint { background: var(--panel); border-style: dashed; font-size: 14px; flex: 1; }
.row { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.row.wrap { flex-wrap: wrap; }
.field { display: block; margin: 12px 0; }
.field > span, .field-inline > span { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; color: var(--ink2); }
.field-inline { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.field-inline > span { margin: 0; min-width: 72px; }
input[type="text"], input:not([type]), select {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--line);
  background: #fff; color: var(--ink); width: 100%; max-width: 360px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="range"] { flex: 1; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.swatch { width: 36px; height: 36px; border-radius: 10px; background: var(--sw); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--accent); transform: scale(1.08); }
.chips-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 700; font-size: 14px; color: var(--ink); min-height: 40px; }
.chip-btn.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.dot[data-t="cream"] { background: #f6efe3; } .dot[data-t="sky"] { background: #b9d9f3; } .dot[data-t="mint"] { background: #b5e3cf; }
.dot[data-t="lavender"] { background: #d6c8f0; } .dot[data-t="apricot"] { background: #f7c9a8; }
.mode-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { text-align: left; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; color: var(--ink); display: flex; flex-direction: column; gap: 2px; }
.mode b { font-size: 15px; } .mode small { color: var(--ink2); }
.mode.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.file-btn { position: relative; }

/* ------------------------------------------------------------ 載入、錯誤與開始畫面 */
.screen { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.loading { background: var(--bg); z-index: 80; }
.loading-card { text-align: center; max-width: 420px; }
.loading-logo { font-size: 54px; color: var(--accent); animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-bar { height: 8px; border-radius: 99px; background: var(--bg2); overflow: hidden; margin-top: 12px; }
.loading-bar span { display: block; height: 100%; width: 40%; border-radius: 99px; background: var(--accent); animation: load 1.2s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
#fatal { background: var(--bg); z-index: 90; }
.fatal-card { background: var(--panel); border-radius: var(--radius); padding: 28px; max-width: 560px; box-shadow: var(--shadow); text-align: center; }
.fatal-ico { font-size: 48px; }
.fineprint { font-size: 12.5px; color: var(--ink2); line-height: 1.6; margin-top: 14px; }

#screenTitle { background: radial-gradient(circle at 20% 10%, var(--panel2), transparent 50%), linear-gradient(160deg, var(--bg), var(--bg2)); align-items: safe center; }
.title-wrap { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr); gap: 20px; width: min(1080px, 100%); }
.title-card, .title-preview { background: var(--panel); border-radius: 22px; box-shadow: var(--shadow); padding: 26px 28px; border: 2px solid var(--line); }
.brand { display: flex; gap: 14px; align-items: center; }
.brand-logo { width: 58px; height: 58px; border-radius: 16px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; display: grid; place-items: center; font-size: 30px; box-shadow: var(--shadow-sm); flex: none; }
.brand small { color: var(--accent); font-weight: 900; letter-spacing: .14em; font-size: 12px; }
.brand h1 { margin: 2px 0 0; font-size: clamp(24px, 3.6vw, 36px); font-weight: 900; }
.brand .sub { margin: 4px 0 0; color: var(--ink2); font-weight: 500; }
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 18px 0 6px; counter-reset: st; }
.steps li { counter-increment: st; flex: 1; font-size: 13px; font-weight: 700; color: var(--ink2); border-bottom: 3px solid var(--line); padding-bottom: 6px; }
.steps li::before { content: counter(st); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--line); margin-right: 6px; font-size: 12px; }
.steps li.on { color: var(--ink); border-color: var(--gold); }
.steps li.on::before { background: var(--gold); color: var(--gold-ink); }
.save-note { background: var(--panel2); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.title-preview { display: flex; flex-direction: column; align-items: center; text-align: center; }
.title-preview canvas { width: min(240px, 60vw); height: auto; aspect-ratio: 1; }
.preview-name { font-size: 24px; font-weight: 900; margin-top: 10px; word-break: break-all; }
.mini-list { list-style: none; padding: 0; margin: 12px 0 0; text-align: left; display: grid; gap: 6px; font-weight: 500; }

/* ------------------------------------------------------------ HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.hud-tl { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; display: flex; flex-direction: column; gap: 8px; }
.hud-zone { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 7px 14px 7px 8px; box-shadow: var(--shadow-sm); }
.hz-ico { width: 36px; height: 36px; display: grid; place-items: center; font-size: 22px; background: var(--panel2); border-radius: 10px; }
.hud-zone small { display: block; font-size: 11px; color: var(--ink2); font-weight: 700; }
.hud-zone b { font-size: 16px; }
.hud-stats { display: flex; gap: 6px; }
.hud-stats span { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 4px 10px; font-size: 14px; box-shadow: var(--shadow-sm); }
.hud-stats i { font-style: normal; color: var(--ink2); font-size: 12px; }
.hud-tr { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
.ib { width: 54px; height: 54px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; color: var(--ink); padding: 0; }
.ib span { font-size: 20px; line-height: 1.1; }
.ib small { font-size: 10.5px; font-weight: 700; color: var(--ink2); }
.ib:hover { border-color: var(--accent); }

.task-panel { position: absolute; left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); width: 330px; background: var(--navy); color: #fff; border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; border: 2px solid rgba(255,255,255,.15); }
.tp-head { width: 100%; display: flex; gap: 10px; align-items: center; padding: 12px 14px 8px; background: none; border: 0; color: inherit; cursor: pointer; text-align: left; }
.tp-ico { width: 40px; height: 40px; border-radius: 12px; background: #f06d8e; display: grid; place-items: center; font-size: 22px; flex: none; }
.tp-head small { display: block; font-size: 11px; color: #8fe0d2; font-weight: 700; letter-spacing: .05em; }
.tp-head b { font-size: 17px; }
.tp-caret { margin-left: auto; font-style: normal; transition: transform .2s; }
.task-panel.collapsed .tp-caret { transform: rotate(-90deg); }
.task-panel.collapsed .tp-list, .task-panel.collapsed .tp-btns { display: none; }
.tp-list { list-style: none; margin: 0; padding: 0 14px; }
.tp-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-size: 14px; border-bottom: 1px dashed rgba(255,255,255,.15); line-height: 1.45; }
.tp-list li i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); flex: none; margin-top: 3px; }
.tp-list li.done { opacity: .7; }
.tp-list li.done i { background: #3fd1b5; border-color: #3fd1b5; }
.tp-list li.done span { text-decoration: line-through; text-decoration-color: rgba(255,255,255,.4); }
.tp-list li.current { color: #ffe08a; font-weight: 700; }
.tp-list li.current i { border-color: #ffe08a; box-shadow: 0 0 0 3px rgba(255,224,138,.25); }
.tp-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px 14px; }
.tp-btns .btn.navy { background: #3a4d7a; border-color: #4d6195; }
.task-panel, .help-box { transition: opacity .2s; }
html.panel-open .task-panel, html.panel-open .help-box { opacity: 0; pointer-events: none; }
.help-box { position: absolute; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); background: var(--navy); color: #e8ecf6; border-radius: 12px; padding: 8px 14px; font-size: 13px; line-height: 1.6; box-shadow: var(--shadow-sm); }

/* 小光提示 */
#robotTip { position: fixed; top: 80px; left: 50%; transform: translate(-50%, -12px); opacity: 0; z-index: 30; display: flex; gap: 10px; align-items: center; background: var(--panel); border: 2px solid var(--accent); border-radius: 16px; padding: 10px 16px 10px 10px; box-shadow: var(--shadow); max-width: min(560px, calc(100vw - 32px)); transition: opacity .25s, transform .25s; pointer-events: none; }
#robotTip.show { opacity: 1; transform: translate(-50%, 0); }
.robot-face { font-size: 30px; background: #e3faf7; border-radius: 12px; width: 44px; height: 44px; display: grid; place-items: center; flex: none; }
#robotTip b { font-size: 13px; color: var(--accent); }
#robotTip p { margin: 2px 0 0; font-size: 15px; line-height: 1.5; }

/* 提示訊息 */
#toastRoot { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(520px, calc(100vw - 32px)); }
.toast { background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 500; font-size: 14px; animation: tin .25s ease-out; transition: opacity .35s, transform .35s; text-align: center; }
.toast-ok { background: var(--ok); } .toast-warn { background: #b4632a; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }

/* ------------------------------------------------------------ 觸控 */
#touchControls { display: none; }
html.touch #touchControls:not([hidden]) { display: block; }
#joystick { position: fixed; left: 24px; bottom: calc(24px + env(safe-area-inset-bottom)); width: 128px; height: 128px; border-radius: 50%; background: rgba(255,255,255,.55); border: 3px solid rgba(44,62,102,.25); z-index: 12; touch-action: none; backdrop-filter: blur(4px); }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: var(--navy); box-shadow: var(--shadow-sm); pointer-events: none; }
#actBtn { position: fixed; right: 24px; bottom: calc(30px + env(safe-area-inset-bottom)); width: 88px; height: 88px; border-radius: 50%; border: 4px solid #fff; background: #8a93a8; color: #fff; font-weight: 900; font-size: 18px; z-index: 12; box-shadow: var(--shadow); touch-action: manipulation; }
#actBtn.ready { background: var(--gold); color: var(--gold-ink); animation: pulse 1.2s infinite; }
#touchControls.locked { opacity: 0; pointer-events: none; }
html.touch .task-panel { bottom: auto; top: 128px; width: min(300px, calc(100vw - 24px)); }
html.touch .help-box { display: none; }

/* ------------------------------------------------------------ 面板通用 */
#panelRoot, #modalRoot { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
#modalRoot { z-index: 45; }
.backdrop { position: absolute; inset: 0; background: rgba(40, 34, 50, 0.38); display: flex; align-items: center; justify-content: center; padding: 16px; pointer-events: auto; animation: fade .2s; backdrop-filter: blur(2px); }
.dock { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); pointer-events: auto; background: linear-gradient(transparent 40%, rgba(40,34,50,.18)); }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); padding: 22px 24px; width: min(620px, 100%); max-height: calc(100dvh - 32px); overflow: auto; border: 2px solid var(--line); animation: pop .22s ease-out; overscroll-behavior: contain; }
.modal.small { width: min(440px, 100%); }
.modal.wide { width: min(940px, 100%); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal h2 { margin: 0 0 8px; font-size: 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; position: sticky; top: -22px; background: var(--panel); padding: 4px 0 8px; z-index: 2; }
.modal-head h2 { margin: 0; }

/* 對話 */
.dlg { width: min(720px, 100%); background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; border: 3px solid var(--navy); animation: up .25s ease-out; max-height: min(78dvh, 640px); display: flex; flex-direction: column; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.dlg-head { display: flex; gap: 12px; align-items: center; padding: 12px 16px; background: var(--c); color: #fff; flex: none; }
.dlg-head .avatar { width: 50px; height: 50px; border-radius: 14px; background: rgba(255,255,255,.85); display: grid; place-items: center; font-size: 30px; }
.dlg-head b { font-size: 19px; display: block; text-shadow: 0 1px 2px rgba(0,0,0,.2); }
.dlg-head small { opacity: .95; font-weight: 500; }
.dlg-body { padding: 16px; overflow: auto; flex: 1; }
.line { display: flex; gap: 10px; align-items: flex-start; animation: fade .2s; }
.lavatar { width: 44px; height: 44px; flex: none; border-radius: 12px; background: var(--panel2); display: grid; place-items: center; font-size: 26px; border: 2px solid var(--line); }
.bubble { background: var(--panel2); border-radius: 14px; padding: 10px 14px; border: 2px solid var(--line); flex: 1; }
.bubble small { font-weight: 700; color: var(--ink2); }
.bubble p { margin: 4px 0 0; font-size: 17px; line-height: 1.65; }
.who-player .bubble { background: #fff4e0; border-color: #f2d29b; }
.who-robot .bubble { background: #e6faf6; border-color: #a6e3d8; }
.who-monster .bubble { background: #fff0f4; border-color: #f4b6c8; }
.who-narrator .bubble { background: #f6f3ff; border-color: #d9cff5; }
.dlg-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 14px; gap: 10px; flex: none; }
.kbd-hint { font-size: 13px; }
.choice-q { font-weight: 700; font-size: 16px; line-height: 1.6; margin: 0 0 10px; }
.choice-opts { display: grid; gap: 8px; }
.choice-fb { margin-top: 12px; border-radius: 12px; padding: 10px 14px; }
.choice-fb.ok { background: var(--ok-bg); border: 2px solid #9fd8bd; }
.choice-fb.bad { background: var(--warn-bg); border: 2px solid #f0cd84; }
.choice-fb p { margin: 4px 0 8px; line-height: 1.6; }

/* 選項 */
.opt { display: flex; gap: 10px; align-items: center; text-align: left; padding: 11px 14px; border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer; font-size: 16px; line-height: 1.5; color: var(--ink); width: 100%; min-height: 50px; transition: border-color .12s, background .12s; }
.opt:hover:not(:disabled) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, #fff); }
.opt .num { width: 28px; height: 28px; flex: none; border-radius: 8px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 14px; }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .num { background: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .num { background: var(--bad); }
.opt.eliminated { opacity: .35; text-decoration: line-through; }
.opt.picked-ok { border-color: var(--ok); background: var(--ok-bg); }
.opt.picked-bad { border-color: #e2a03f; background: var(--warn-bg); }

/* 答題 */
.quiz { width: min(820px, 100%); background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); border: 3px solid var(--navy); padding: 16px 18px; max-height: calc(100dvh - 24px); overflow: auto; animation: up .25s ease-out; overscroll-behavior: contain; }
.quiz-top { display: flex; align-items: center; gap: 12px; }
.qno { font-weight: 900; color: var(--ink2); }
.progress { flex: 1; height: 10px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 99px; transition: width .3s; }
.qscore { font-weight: 900; font-size: 14px; }
.timerbar { height: 6px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.timerbar span { display: block; height: 100%; background: var(--accent2); transition: width .25s linear; }
.timerbar.low span { background: var(--bad); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 6px; }
.chip { font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 8px; background: var(--panel2); border: 1.5px solid var(--line); color: var(--ink2); }
.chip.self { background: #fff3c4; border-color: #f0c84a; color: #6b4e00; }
.chip.zone { background: color-mix(in srgb, var(--c, var(--accent)) 14%, #fff); border-color: var(--c, var(--accent)); color: var(--ink); }
.stem { font-size: 19px; line-height: 1.6; margin: 6px 0 12px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint-box { margin-top: 10px; background: #eef7ff; border: 2px solid #b8d8f2; border-radius: 12px; padding: 10px 14px; }
.hint-box p { margin: 4px 0; line-height: 1.6; }
.hint-box small { color: var(--ink2); }
.hint-row { display: flex; gap: 10px; margin-top: 12px; }
.feedback { margin-top: 12px; border-radius: 14px; padding: 12px 16px; }
.feedback.ok { background: var(--ok-bg); border: 2px solid #9fd8bd; }
.feedback.bad { background: var(--bad-bg); border: 2px solid #f1b4b1; }
.fb-title { font-weight: 900; font-size: 18px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.fb-title small { font-weight: 500; font-size: 13px; color: var(--ink2); }
.fb-answer, .fb-reason { margin: 6px 0; line-height: 1.6; }
.fb-more { margin-top: 8px; background: rgba(255,255,255,.7); border-radius: 10px; padding: 8px 12px; line-height: 1.6; }
.expl-list { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 8px; }
.expl-list li { padding: 8px 10px; border-radius: 8px; background: #fff; border: 1.5px solid var(--line); }
.expl-list li.right { border-color: var(--ok); }
.expl-list li.wrong { border-color: var(--bad); }
.expl-list p { margin: 4px 0 0; font-size: 14.5px; }

/* 知識卡 */
.card-modal { border-top: 8px solid var(--c); }
.kc-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.kc-ico { font-size: 40px; width: 64px; height: 64px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 14%, #fff); border-radius: 16px; flex: none; }
.kc-head small { color: var(--ink2); font-weight: 700; }
.kc-head h2 { margin: 2px 0 0; }
.new-badge { margin-left: auto; background: var(--gold); color: var(--gold-ink); font-weight: 900; padding: 3px 10px; border-radius: 99px; font-size: 13px; }
.kc-sec { background: var(--panel2); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.kc-sec h4 { margin: 0 0 4px; font-size: 14px; color: var(--ink2); }
.kc-sec p { margin: 0; line-height: 1.7; font-size: 15.5px; }
.kc-sec.warn { background: var(--warn-bg); }

/* 結果與徽章 */
.result { text-align: center; border-top: 8px solid var(--c); }
.res-stars { font-size: 64px; letter-spacing: 6px; }
.res-stars span { color: #ddd5c8; display: inline-block; }
.res-stars span.on { color: #f2b521; animation: starIn .5s var(--d) both cubic-bezier(.3,1.6,.5,1); text-shadow: 0 3px 0 #d89a10; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } }
.res-score { font-size: 68px; font-weight: 900; color: var(--bad); }
.res-score.ok { color: var(--ok); }
.res-score small { font-size: 28px; color: var(--ink2); }
.rule { font-size: 12.5px; color: var(--ink2); background: var(--panel2); border-radius: 10px; padding: 8px 12px; }
.review { text-align: left; background: var(--panel2); border-radius: 12px; padding: 8px 12px; margin-top: 10px; }
.review summary { cursor: pointer; font-weight: 700; }
.rv-item { border-top: 1px dashed var(--line); padding: 8px 0; }
.rv-item p { margin: 3px 0; line-height: 1.55; }
.rv-ans { color: var(--ok); font-weight: 700; }
.badge-modal { text-align: center; position: relative; overflow: hidden; }
.badge-big { width: 150px; height: 150px; margin: 10px auto; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, color-mix(in srgb, var(--c) 30%, #fff)); border: 10px solid var(--c); display: grid; place-items: center; font-size: 70px; box-shadow: 0 0 0 8px color-mix(in srgb, var(--c) 25%, transparent), var(--shadow); animation: badgeIn .8s cubic-bezier(.3,1.5,.5,1); }
@keyframes badgeIn { from { transform: scale(0) rotate(-200deg); } }
.badge-modal h2 { font-size: 28px; }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -10px; left: calc(var(--i) * 4.2%); width: 8px; height: 14px; background: hsl(calc(var(--i) * 37), 80%, 60%); animation: fall 2.4s calc(var(--i) * 0.06s) ease-in infinite; border-radius: 2px; }
@keyframes fall { to { transform: translateY(520px) rotate(540deg); } }

/* 地圖 */
.zone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 12px; }
.zone-card { position: relative; text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 14px; border-radius: 16px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; color: var(--ink); border-left: 8px solid var(--c, var(--accent)); min-height: 120px; }
.zone-card:hover:not(:disabled) { box-shadow: var(--shadow-sm); transform: translateY(-2px); }
.zone-card:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.4); }
.zone-card.here { box-shadow: 0 0 0 3px var(--gold); }
.zc-ico { font-size: 28px; }
.zone-card small { color: var(--ink2); font-weight: 700; font-size: 12px; }
.zone-card b { font-size: 17px; }
.zc-stars { color: #d99a10; font-weight: 700; font-size: 14px; }
.zc-badge { position: absolute; top: 10px; right: 12px; font-size: 24px; }
.zone-card.final { --c: #2f9fd0; background: linear-gradient(135deg, #eef7ff, var(--panel)); }
.dev-note { background: #fff0f0; border: 1px dashed var(--bad); border-radius: 10px; padding: 8px 12px; font-size: 13px; }

/* 圖鑑 */
.tabs { display: flex; gap: 6px; margin: 8px 0 12px; border-bottom: 2px solid var(--line); }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 700; font-size: 15px; color: var(--ink2); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }
.grp { margin: 14px 0 8px; border-left: 5px solid var(--c); padding-left: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.kc-mini { text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 12px; border-radius: 14px; border: 2px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); border-top: 5px solid var(--c, var(--line)); }
.kc-mini span { font-size: 26px; }
.kc-mini small { color: var(--ink2); line-height: 1.45; }
.kc-mini.locked { background: var(--panel2); cursor: default; opacity: .7; }
.mon-grid, .badge-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.mon-card { padding: 12px; border-radius: 14px; border: 2px solid var(--line); background: #fff; border-top: 6px solid var(--c); }
.mon-card.ok { background: #fff7fb; }
.mon-ico { font-size: 30px; display: block; }
.mon-card small { color: var(--ink2); display: block; }
.mon-card p { margin: 6px 0 0; font-size: 14px; }
.badge-item { text-align: center; padding: 14px; border-radius: 14px; background: var(--panel2); border: 2px solid var(--line); display: flex; flex-direction: column; gap: 3px; }
.badge-item span { font-size: 34px; width: 64px; height: 64px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; background: #fff; border: 5px solid #d8d2c8; }
.badge-item.on span { border-color: var(--c); }
.badge-item small { color: #d99a10; font-weight: 700; }

/* 錯題本與總覽 */
.wb-list { display: grid; gap: 8px; margin-top: 12px; }
.wb-item { border: 2px solid var(--line); border-left: 6px solid var(--c); border-radius: 12px; padding: 8px 12px; background: #fff; }
.wb-item summary { cursor: pointer; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.wb-stem { flex: 1 1 240px; font-weight: 500; line-height: 1.5; }
.wb-rv { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--bad-bg); color: var(--bad); }
.wb-rv.ok { background: var(--ok-bg); color: var(--ok); }
.wb-item p { margin: 6px 0; line-height: 1.6; }
.empty { text-align: center; padding: 40px; color: var(--ink2); font-size: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 10px 0 16px; }
.stat { background: var(--panel2); border-radius: 14px; padding: 12px 14px; border: 2px solid var(--line); }
.stat small { color: var(--ink2); font-weight: 700; display: block; }
.stat b { font-size: 26px; display: block; margin: 2px 0; }
.stat span { font-size: 12.5px; color: var(--ink2); }
.ov-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.ov-table th, .ov-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.ov-table th { color: var(--ink2); font-size: 13px; }
.ov-table .stars { color: #d99a10; letter-spacing: 1px; }
.final-row { background: #eef7ff; font-weight: 700; }

/* 設定 */
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.set-grid section { background: var(--panel2); border-radius: 14px; padding: 12px 16px; border: 2px solid var(--line); }
.set-grid h4 { margin: 0 0 8px; }
.set-grid .span2 { grid-column: 1 / -1; }
.pause { text-align: center; }
.menu-list { display: grid; gap: 8px; margin-top: 10px; }
.help-list { line-height: 1.8; padding-left: 20px; }
.tutorial { text-align: center; }
.tut-robot { font-size: 60px; animation: bob 1.6s ease-in-out infinite; }
.tutorial p { font-size: 16px; line-height: 1.7; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); width: 22px; border-radius: 99px; }

/* 證書與拍照 */
.cert-modal { width: min(1080px, 100%); }
.cert-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; }
.cert-preview { background: var(--panel2); border-radius: 12px; padding: 10px; display: grid; place-items: center; min-height: 200px; }
.cert-preview img { width: 100%; height: auto; border-radius: 6px; box-shadow: var(--shadow-sm); }
.cert-side h4 { margin: 4px 0 6px; }
.pdf-tip { margin-top: 12px; background: var(--panel2); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.pdf-tip summary { cursor: pointer; font-weight: 700; }
.pdf-tip ol { padding-left: 18px; line-height: 1.7; margin: 8px 0 0; }
.note { font-size: 12.5px; color: var(--ink2); border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 12px; }
.req-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.req-list li { padding: 10px 14px; border-radius: 12px; background: var(--panel2); border: 2px solid var(--line); }
.req-list li::before { content: '⬜ '; }
.req-list li.ok { background: var(--ok-bg); border-color: #9fd8bd; }
.req-list li.ok::before { content: '✅ '; }
.cam-stage { position: relative; background: #1d2230; border-radius: 14px; overflow: hidden; aspect-ratio: 4 / 3; display: grid; place-items: center; }
.cam-stage video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam-stage canvas { max-width: 100%; max-height: 100%; aspect-ratio: 1; }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; padding: 20px; text-align: center; line-height: 1.6; }

/* ------------------------------------------------------------ 2D 降級場域 */
#stage2d { position: absolute; inset: 0; overflow: auto; background: linear-gradient(160deg, var(--bg), var(--bg2)); padding: 150px 16px 30px; }
.w2d { width: min(980px, 100%); margin: 0 auto; }
.w2d-room { background: var(--panel); border-radius: 22px; border: 2px solid var(--line); box-shadow: var(--shadow); padding: 20px; border-top: 10px solid var(--c); }
.w2d-head { display: flex; gap: 14px; align-items: center; }
.w2d-zico { font-size: 40px; width: 70px; height: 70px; display: grid; place-items: center; background: var(--panel2); border-radius: 18px; }
.w2d-head h2 { margin: 2px 0 0; font-size: 26px; }
.w2d-head small { color: var(--ink2); font-weight: 700; }
.w2d-board { background: #2f5d50; color: #f7f4ea; border-radius: 14px; padding: 12px 18px; margin: 14px 0; border: 6px solid #8a6a4a; }
.w2d-board ul { margin: 6px 0 0; padding-left: 20px; line-height: 1.7; }
.w2d-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.w2d-obj { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px; border-radius: 16px; border: 2px solid var(--line); background: #fff; cursor: pointer; text-align: left; color: var(--ink); min-height: 120px; transition: transform .12s; }
.w2d-obj:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.w2d-ico { font-size: 36px; }
.w2d-obj small { color: var(--ink2); }
.w2d-obj.pending { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.w2d-obj.card { background: #fffbe6; border-color: #f2cf5b; }
.w2d-obj.card.done { background: #fff; border-color: var(--line); }
.w2d-obj.monster { background: #fff0f4; border-color: #ef8fa8; }
.w2d-obj.monster.done { background: #fff8fc; }
.w2d-obj.podium { background: #eef7ff; border-color: #6bb7e8; }
.w2d-obj.flash { animation: flash 1s 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 6px var(--gold); } }
.w2d-obj.hit { animation: shake .35s; }
.w2d-obj.laugh { animation: hop .5s; }
.w2d-obj.heal { animation: heal .9s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes hop { 30% { transform: translateY(-10px); } 60% { transform: translateY(0); } 80% { transform: translateY(-5px); } }
@keyframes heal { 50% { transform: scale(1.06) rotate(-2deg); box-shadow: 0 0 0 8px #ffc2d6; } }
html.mode-2d .help-box { display: none; }
html.mode-2d .task-panel { position: fixed; }
/* 2D 模式：任務清單放在左側欄，不蓋住場域物件 */
html.mode-2d #stage2d { padding: 100px 16px 30px 360px; }
@media (max-width: 900px) {
  html.mode-2d #stage2d { padding: 196px 12px 30px; }
  html.mode-2d .task-panel { top: 118px; bottom: auto; width: min(300px, calc(100vw - 24px)); z-index: 11; }
}

/* ------------------------------------------------------------ 響應式 */
@media (max-width: 860px) {
  .title-wrap { grid-template-columns: 1fr; }
  .title-preview { order: -1; padding: 16px; }
  .title-preview canvas { width: 130px; }
  .mini-list { display: none; }
  .cert-layout { grid-template-columns: 1fr; }
  .set-grid { grid-template-columns: 1fr; }
  .hud-tr { max-width: 52vw; }
}
@media (max-width: 640px) {
  .hide-sm { display: none !important; }
  .hide-xs { display: none !important; }
  .ib { width: 46px; height: 46px; }
  .ib small { display: none; }
  .ib span { font-size: 21px; }
  .hud-zone { padding: 5px 10px 5px 6px; }
  .hud-zone b { font-size: 14px; }
  .hz-ico { width: 30px; height: 30px; font-size: 18px; }
  .hud-stats span { font-size: 13px; padding: 3px 8px; }
  .task-panel { top: 118px; bottom: auto; width: min(300px, calc(100vw - 24px)); }
  html.touch .task-panel { top: 118px; }
  .help-box { display: none; }
  .opts { grid-template-columns: 1fr; }
  .stem { font-size: 17px; }
  .opt { font-size: 15px; }
  .bubble p { font-size: 16px; }
  .modal { padding: 18px 16px; }
  .modal-head { top: -18px; }
  .mode-pick { grid-template-columns: 1fr; }
  .title-card { padding: 18px 16px; }
  .hint-row { flex-direction: column; }
  #robotTip { top: 192px; }
  #joystick { width: 112px; height: 112px; left: 16px; }
  #actBtn { width: 78px; height: 78px; right: 16px; }
  #stage2d { padding-top: 170px; }
  .res-stars { font-size: 52px; }
  .dock { padding: 8px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .task-panel { width: 260px; }
  .dlg, .quiz { max-height: calc(100dvh - 16px); }
  #robotTip { top: 10px; }
}

/* 減少動態效果（系統設定或遊戲設定） */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }

/* ------------------------------------------------------------ 列印：A4 橫式證書 */
#printArea { display: none; }
@media print {
  @page { size: A4 landscape; margin: 0; }
  html, body { width: 297mm; height: 210mm; overflow: visible; background: #fff; }
  #app, .noscript { display: none !important; }
  #printArea { display: block !important; width: 297mm; height: 210mm; }
  #printImg { display: block; width: 297mm; height: 210mm; object-fit: contain; }
}
.noscript { padding: 40px; text-align: center; font-size: 18px; }
