/* 梨山雲端的AI冒險群島：三組底色主題＋RWD */
:root,
:root[data-theme="dawn"] {
  --bg: #f6f0e4; --surface: #fffaf1; --surface2: #efe6d4; --ink: #3b3226; --muted: #6b5d48; --line: #e2d5bd;
  --primary: #2f7a6b; --primary-ink: #ffffff; --accent: #b8611f; --gold: #c99400; --ok: #2f7a4a; --bad: #b4452f;
  --shadow: 0 12px 34px rgba(70, 50, 20, .16); color-scheme: light;
}
:root[data-theme="mist"] {
  --bg: #dcebee; --surface: #f6fbfc; --surface2: #e3eff2; --ink: #22343b; --muted: #4c6670; --line: #c4dbe1;
  --primary: #1f6f7b; --primary-ink: #ffffff; --accent: #b25a1c; --gold: #a87c00; --ok: #2a7346; --bad: #ad3f2b;
  --shadow: 0 12px 34px rgba(20, 50, 60, .16); color-scheme: light;
}
:root[data-theme="night"] {
  --bg: #16222e; --surface: #1f2f3d; --surface2: #253847; --ink: #eef3f6; --muted: #b3c3cd; --line: #34495a;
  --primary: #5cc8b0; --primary-ink: #0f1d26; --accent: #f0a050; --gold: #f2c230; --ok: #6fd39a; --bad: #ff8f7a;
  --shadow: 0 12px 34px rgba(0, 0, 0, .45); color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif; background: var(--bg); color: var(--ink);
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; font-size: 16px; line-height: 1.6;
}
a { color: var(--primary); }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--primary); color: var(--primary-ink); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- 上方工具列 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 20; flex-wrap: wrap; }
.brand { flex: 1 1 260px; min-width: 0; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 900; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tagline { margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.themes { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--surface2); }
.themes button { border: 0; background: none; border-radius: 999px; padding: 6px 12px; cursor: pointer; display: flex; align-items: center; gap: 6px; min-height: 36px; font-size: 14px; }
.themes i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
.themes button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); font-weight: 700; }
.tools { display: flex; gap: 4px; flex-wrap: wrap; }
.tools button { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 5px 9px; min-height: 40px; cursor: pointer; display: flex; align-items: center; gap: 4px; font-size: 14px; }
.tools button:hover { border-color: var(--primary); }
.tools button[aria-pressed="true"], .tools button[aria-expanded="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.tools b { font-weight: 500; }

/* ---------- 3D 世界 ---------- */
.world { position: relative; overflow: hidden; min-height: 0; }
.world canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.isle-label { position: absolute; left: 0; top: 0; pointer-events: auto; border: 2px solid var(--primary); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 3px 12px; font-size: 14px; font-weight: 700; white-space: nowrap; cursor: pointer; box-shadow: 0 3px 10px rgba(0,0,0,.18); min-height: 32px; }
.isle-label.center { border-color: var(--accent); font-size: 15px; }
.isle-label.cleared::after { content: " ⭐"; }
.isle-label:hover, .isle-label.on { background: var(--primary); color: var(--primary-ink); }
.zone-label { position: absolute; left: 0; top: 0; font-size: 13px; font-weight: 700; color: var(--ink); opacity: .7; white-space: nowrap; pointer-events: none; letter-spacing: 1px; }
.hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); margin: 0; font-size: 13px; color: var(--muted); background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 4px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; }
.fallback { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; max-width: 560px; margin: auto; }

/* ---------- HUD ---------- */
.hud { position: fixed; left: 12px; top: 84px; z-index: 15; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px 12px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 24px); }
.hud-name { font-weight: 900; }
.hud-lv { background: var(--accent); color: #fff; font-weight: 900; border-radius: 8px; padding: 0 8px; }
:root[data-theme="night"] .hud-lv { color: #1b1408; }
.hud-bar { width: 110px; height: 10px; border-radius: 999px; background: var(--surface2); overflow: hidden; border: 1px solid var(--line); }
.hud-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .5s; }
.hud-stamp { color: var(--gold); font-weight: 700; }
:root[data-theme="dawn"] .hud-stamp, :root[data-theme="mist"] .hud-stamp { color: #8a6400; }

/* ---------- 面板 ---------- */
.panel, .list-panel { position: fixed; z-index: 25; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; border: 1px solid var(--line); }
.panel { right: 12px; top: 72px; bottom: 44px; width: min(460px, calc(100vw - 24px)); border-radius: 18px; }
.list-panel { left: 12px; top: 130px; bottom: 44px; width: min(330px, calc(100vw - 24px)); border-radius: 18px; padding-bottom: 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 21px; line-height: 1.3; }
.panel-kicker { margin: 0; font-size: 13px; color: var(--muted); font-weight: 700; }
.x { border: 0; background: var(--surface2); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; flex: none; font-size: 16px; }
.panel-body { overflow-y: auto; padding: 12px 16px 18px; overscroll-behavior: contain; }
.search { display: block; padding: 10px 14px 4px; }
.search input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; background: var(--bg); color: var(--ink); font: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 14px; }
.chips button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 12px; min-height: 36px; cursor: pointer; font-size: 14px; }
.chips button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.isle-list { list-style: none; margin: 0; padding: 4px 10px; overflow-y: auto; display: grid; gap: 6px; }
.isle-list li { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--bg); }
.isle-list .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.isle-list strong { font-size: 15px; }
.isle-list small { display: block; color: var(--muted); font-size: 13px; }
.isle-list .acts { display: flex; gap: 6px; margin-top: 6px; }
.isle-list mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 3px; }
.search-empty { padding: 0 16px; color: var(--muted); }

/* ---------- 按鈕 ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 14px; min-height: 44px; cursor: pointer; font-weight: 700; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- NPC 對話 ---------- */
.npc { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: start; margin: 4px 0 12px; }
.npc-face { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; color: #fff; font-weight: 900; box-shadow: inset 0 -6px 0 rgba(0,0,0,.15); }
.npc-name { font-weight: 900; font-size: 15px; }
.npc-name small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.bubble { position: relative; background: var(--surface2); border-radius: 14px; padding: 10px 12px; margin-top: 4px; min-height: 52px; }
.npc-acts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.stamp-state { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; border-radius: 999px; padding: 2px 10px; background: var(--surface2); }
.stamp-state.got { background: color-mix(in srgb, var(--gold) 25%, transparent); }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin: 14px 0 10px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 8px 12px; min-height: 44px; cursor: pointer; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; flex: none; }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.lesson p { margin: 0 0 10px; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 0 6px; background: var(--surface2); color: var(--muted); margin-left: 4px; }
.tip { border-left: 4px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); padding: 8px 12px; border-radius: 8px; }
.points { margin: 0 0 10px; padding-left: 20px; }
.sheet label { display: block; font-weight: 700; margin: 10px 0 4px; }
.sheet textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); color: var(--ink); font: inherit; resize: vertical; }
.row-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- 挑戰 ---------- */
.quiz-q { font-weight: 700; font-size: 17px; margin: 6px 0 10px; }
.quiz-progress { font-size: 13px; color: var(--muted); font-weight: 700; }
.opts { display: grid; gap: 8px; }
.opts button { text-align: left; border: 2px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; min-height: 48px; cursor: pointer; }
.opts button:hover:not(:disabled) { border-color: var(--primary); }
.opts button.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--bg)); }
.opts button.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--bg)); }
.opts button:disabled { cursor: default; }
.explain { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface2); }
.explain b.ok { color: var(--ok); }
.explain b.bad { color: var(--bad); }
.gain { display: inline-block; font-weight: 900; color: var(--accent); margin-left: 6px; }
.result { text-align: center; padding: 10px 0; }
.result .big { font-size: 40px; font-weight: 900; color: var(--primary); }

/* ---------- 對話框 ---------- */
dialog { border: 0; border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(10, 20, 30, .5); }
dialog form, .dlg-wrap { padding: 0 0 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
#startForm { padding: 18px 20px; }
#startForm h2 { margin: 0 0 6px; }
.mascot-line { background: var(--surface2); border-radius: 12px; padding: 10px 12px; margin: 0 0 10px; }
.field { display: block; font-weight: 700; margin: 10px 0 2px; }
.field input { display: block; width: 100%; margin-top: 4px; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; font: inherit; background: var(--bg); color: var(--ink); }
.err { color: var(--bad); min-height: 1.4em; margin: 2px 0; font-size: 14px; }
.looks { border: 0; padding: 0; margin: 4px 0 8px; }
.looks legend { font-weight: 700; margin-bottom: 6px; }
.look-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.look-list label { border: 2px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; cursor: pointer; font-size: 14px; }
.look-list label:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, var(--surface)); }
.look-list input { position: absolute; opacity: 0; }
.look-list svg { width: 54px; height: 64px; display: block; margin: 0 auto 4px; }
.existing h3 { margin: 4px 0; font-size: 16px; }
.existing-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.dlg-wrap > :not(.panel-head) { margin-left: 18px; margin-right: 18px; }
.help { padding-left: 20px; }
.help li { margin-bottom: 6px; }
.note { font-size: 13px; color: var(--muted); }
.stamps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stamp-card { border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; background: var(--bg); }
.stamp-card .seal { font-size: 34px; line-height: 1.2; filter: grayscale(1); opacity: .35; }
.stamp-card.got .seal { filter: none; opacity: 1; }
.stamp-card b { display: block; font-size: 14px; }
.stamp-card small { color: var(--muted); font-size: 12px; display: block; }
textarea.code { width: 100%; min-height: 84px; font-family: Consolas, monospace; font-size: 13px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); color: var(--ink); word-break: break-all; }
.cert-canvas { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); display: block; margin: 8px 0; }

/* ---------- 回饋 ---------- */
.toast { position: fixed; left: 50%; bottom: 56px; transform: translate(-50%, 20px); background: #2b241c; color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 60; max-width: calc(100vw - 24px); text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.levelup { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; z-index: 70; pointer-events: none; opacity: 0; }
.levelup b { font-size: clamp(42px, 9vw, 86px); font-weight: 900; color: var(--gold); text-shadow: 0 4px 0 #8a5a00, 0 10px 30px rgba(0,0,0,.35); }
.levelup span { font-size: 20px; font-weight: 700; background: var(--surface); padding: 4px 14px; border-radius: 999px; margin-top: 6px; }
.levelup.on { animation: lvl 2.2s ease forwards; }
@keyframes lvl { 0% { opacity: 0; transform: scale(.6); } 15% { opacity: 1; transform: scale(1.08); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
.foot { font-size: 12px; color: var(--muted); padding: 4px 14px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: var(--surface); border-top: 1px solid var(--line); z-index: 20; }
.noscript { padding: 20px; }

/* ---------- 手機與平板 ---------- */
.themes button, .tools button { min-height: 44px; }
@media (max-width: 1100px) {
  .tools b { display: none; }
  .tools button { width: 44px; justify-content: center; }
}
@media (max-width: 760px) {
  .topbar { padding: 6px 10px; gap: 6px; }
  .brand { flex-basis: 100%; }
  .brand h1 { font-size: 17px; }
  .tagline { display: none; }
  .themes button { padding: 4px 9px; font-size: 13px; min-height: 44px; }
  .tools { gap: 4px; }
  .tools button { width: 44px; min-height: 44px; padding: 0; }
  .isle-label { font-size: 13px; padding: 2px 10px; }
  .hud { top: auto; bottom: 44px; left: 8px; font-size: 13px; padding: 4px 10px; gap: 6px; }
  .hud-bar { width: 70px; }
  .panel, .list-panel { left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-height: 74vh; border-radius: 18px 18px 0 0; }
  .list-panel { height: 70vh; }
  .hint { display: none; }
  .foot { display: none; }
  .toast { bottom: auto; top: 12px; }
  .tabs button { padding: 8px 9px; font-size: 15px; }
  .look-list { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .levelup.on { animation: none; opacity: 1; }
  .toast, .hud-bar i { transition: none; }
}
body.reduce .levelup.on { animation: none; opacity: 1; }

/* ---------- 列印證書 ---------- */
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea img { width: 100%; }
  body { overflow: visible; display: block; background: #fff; }
}
#printArea { display: none; }
