/* ===== 米寶島 樣式 ===== */

/* 三組底色主題：用 <html data-theme="..."> 切換 */
:root { --badge-space: 0px; --badge-space-m: 0px; }
/* 平台徽章：桌機在右下角（約 36px 高），手機是底部整條 */
html.host-badge { --badge-space: 52px; --badge-space-m: 52px; }

:root,
:root[data-theme="sky"] {
  --bg: #eaf4fb;
  --surface: #ffffff;
  --surface-2: #f3f8fc;
  --ink: #14263d;
  --muted: #4a5d73;
  --line: #cddfee;
  --primary: #2c6db5;
  --on-primary: #ffffff;
  --primary-soft: #dcebf9;
  --accent: #f2b33d;
  --on-accent: #3a2700;
  --accent-soft: #fdf0d3;
  --ok: #1f7a4d;
  --bad: #b3261e;
  --warn: #8a5a00;
  --shadow: 0 10px 30px rgba(20, 38, 61, .14);
  --overlay: rgba(255, 255, 255, .86);
  color-scheme: light;
}
:root[data-theme="cloud"] {
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-2: #f1f4f7;
  --ink: #1d2733;
  --muted: #4d5a68;
  --line: #dbe2e9;
  --primary: #2c6db5;
  --on-primary: #ffffff;
  --primary-soft: #e3edf8;
  --accent: #f2b33d;
  --on-accent: #3a2700;
  --accent-soft: #fdf2db;
  --overlay: rgba(255, 255, 255, .88);
  --shadow: 0 10px 30px rgba(29, 39, 51, .12);
  color-scheme: light;
}
:root[data-theme="night"] {
  --bg: #121c2e;
  --surface: #1b2840;
  --surface-2: #22314d;
  --ink: #eef3fb;
  --muted: #b7c4d8;
  --line: #36496d;
  --primary: #8cbcf2;
  --on-primary: #0b1626;
  --primary-soft: #253a5c;
  --accent: #f2b33d;
  --on-accent: #2a1c00;
  --accent-soft: #3a3220;
  --ok: #7fd6a4;
  --bad: #ff9a8f;
  --warn: #ffd27a;
  --overlay: rgba(18, 28, 46, .86);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-x: hidden;
}
h1, h2, h3, .brand-title, .panel-title, .label-name, .round {
  font-family: "Huninn", "Noto Sans TC", sans-serif;
  font-weight: 400;
}
a { color: var(--primary); }
img { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--primary); color: var(--on-primary); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { top: 8px; }

/* ===== 按鈕 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; font-weight: 500; text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 15px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { border-color: var(--primary); }

/* ===== 上方工具列 ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--overlay); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mascot { width: 40px; height: auto; flex: none; }
.brand-text { min-width: 0; }
.brand-title { margin: 0; font-size: 26px; line-height: 1.1; color: var(--primary); }
.brand-tagline { margin: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; align-items: center; gap: 6px; position: relative; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; min-width: 44px; padding: 6px 12px;
  border-radius: 12px; border: 2px solid transparent; background: transparent; color: var(--ink);
  cursor: pointer; font-size: 15px; white-space: nowrap;
}
.tb-btn:hover { background: var(--primary-soft); }
.tb-btn[aria-pressed="true"], .tb-btn[aria-expanded="true"] { background: var(--primary-soft); border-color: var(--primary); }
.tb-ico { font-size: 18px; line-height: 1; }
.tb-extra { display: flex; gap: 6px; }
.tb-more { display: none; }

/* ===== 3D 舞台 ===== */
.stage {
  position: relative;
  height: calc(100svh - 64px);
  min-height: 420px;
  overflow: hidden;
  background: linear-gradient(var(--bg), var(--surface-2));
}
.scene { position: absolute; inset: 0; touch-action: none; }
.scene canvas { display: block; width: 100%; height: 100%; }
.scene-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--surface); color: var(--ink); padding: 14px 20px; border-radius: 16px;
  box-shadow: var(--shadow); text-align: center; max-width: calc(100% - 32px);
}
.scene-msg:empty { display: none; }
.hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: var(--overlay); color: var(--ink); padding: 6px 14px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); pointer-events: none; white-space: nowrap;
  transition: opacity .6s;
}
.hint.hide { opacity: 0; }

.theme-switch {
  position: absolute; left: 16px; bottom: 16px; z-index: 5;
  display: flex; gap: 6px; padding: 6px; border-radius: 999px;
  background: var(--overlay); box-shadow: var(--shadow);
}
.swatch {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 12px;
  border-radius: 999px; border: 2px solid transparent; background: transparent; color: var(--ink);
  cursor: pointer; font-size: 15px;
}
.swatch .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); }
.swatch[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }

/* 3D 島名標籤：放在島外海面，細引線指向島岸 */
.label-layer, .leader-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; transition: opacity .15s; }
.label-layer.flying, .leader-layer.flying { opacity: 0; }
.label-layer.flying .island-label { pointer-events: none; }
.leader-layer line { stroke: rgba(70, 60, 40, .55); stroke-width: 1.2; }
:root[data-theme="night"] .leader-layer line { stroke: rgba(240, 230, 210, .6); }
.island-label {
  position: absolute; left: 0; top: 0;
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 3px 10px 3px 4px; border-radius: 10px;
  background: #fffaf0; color: #3a3020; border: 1px solid rgba(90, 70, 40, .18);
  box-shadow: 0 3px 10px rgba(60, 50, 30, .16); cursor: pointer; white-space: nowrap;
  font-size: 14px; transition: opacity .2s, box-shadow .2s;
}
.island-label:hover, .island-label:focus-visible { box-shadow: 0 0 0 3px var(--accent), 0 3px 10px rgba(60, 50, 30, .2); }
.island-label .num {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 4px; border-radius: 7px;
  background: var(--sea, var(--primary)); color: #1b1b1b; font-weight: 700; font-size: 12px;
}
.island-label .label-name { font-size: 15px; }
.island-label .state { font-size: 11px; padding: 0 6px; border-radius: 6px; background: #f1ead8; color: #5a4d33; }
.island-label .state.done { background: var(--accent); color: var(--on-accent); }
.island-label.center { padding-left: 10px; border-color: var(--accent); }
.island-label.center .label-name { font-size: 17px; color: #2c5e9e; }
.island-label.squeezed .label-name, .island-label.squeezed .state { display: none; }
.island-label.squeezed { padding-right: 4px; }
.island-label.hidden-behind, .sea-tag.hidden-behind { opacity: 0; pointer-events: none; transition: none; }
.sea-tag {
  position: absolute; left: 0; top: 0;
  pointer-events: none; font-size: 13px; padding: 2px 10px; border-radius: 999px;
  background: rgba(255, 250, 240, .72); color: #3a3020; border: 1px dashed rgba(90, 70, 40, .3); white-space: nowrap;
}

/* 配色預覽面板（網址加 ?palette=edit 才出現，只給製作者用） */
.palette-editor {
  position: fixed; z-index: 55; left: 16px; top: 80px; width: min(340px, calc(100vw - 32px)); max-height: calc(100svh - 100px); overflow-y: auto;
  background: var(--surface); color: var(--ink); border: 2px solid var(--accent); border-radius: 18px; box-shadow: var(--shadow); padding: 12px 14px;
}
.pe-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pe-head h2 { margin: 0; font-size: 19px; }
.pe-sets { display: grid; gap: 8px; margin: 8px 0; }
.pe-set { text-align: left; border: 2px solid var(--line); border-radius: 14px; padding: 8px 10px; background: var(--surface-2); cursor: pointer; min-height: 44px; display: grid; gap: 4px; }
.pe-set[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.pe-name { font-weight: 700; }
.pe-sw { display: flex; gap: 4px; }
.pe-sw i { width: 24px; height: 24px; border-radius: 6px; border: 1px solid rgba(0,0,0,.15); }
.pe-intent { font-size: 13px; color: var(--muted); }
.pe-custom { border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 6px; }
.pe-custom label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.pe-custom span { display: flex; gap: 6px; }
.pe-custom input[type="color"] { width: 44px; height: 44px; border: 0; padding: 0; background: none; }
.pe-custom input[type="text"] { width: 92px; min-height: 44px; border-radius: 10px; border: 2px solid var(--line); padding: 0 8px; background: var(--surface-2); }
.pe-msg { color: var(--bad); font-size: 14px; min-height: 1em; margin: 4px 0; }
.guardian-btn { width: 100%; }

/* ===== 文字版清單 ===== */
.text-list { padding: 40px 0 24px; }
.text-list h2 { font-size: 28px; margin: 0 0 4px; }
.sea-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.island-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.island-list.compact { grid-template-columns: 1fr; gap: 8px; }
.island-card {
  width: 100%; text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start;
  padding: 14px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; min-height: 44px;
}
.island-card:hover { border-color: var(--primary); }
.island-card .num {
  grid-row: span 2; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--sea, var(--accent)); color: #1b1b1b; font-weight: 700;
}
.island-card .name { font-family: "Huninn", sans-serif; font-size: 20px; line-height: 1.3; }
.island-card .meta { font-size: 14px; color: var(--muted); }
.island-card .sub { grid-column: 2; font-size: 15px; }
.island-list.compact .island-card { padding: 10px 12px; }
.island-list.compact .island-card .sub { display: none; }
.status-pill { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.status-pill.done { background: var(--accent); color: var(--on-accent); }

/* ===== 頁尾 ===== */
.site-footer { border-top: 1px solid var(--line); padding: 28px 0 calc(120px + var(--badge-space)); background: var(--surface-2); }
.site-footer h2 { margin: 0 0 6px; font-size: 22px; }
.source-sites { padding-left: 20px; margin: 8px 0; }
.source-sites li { margin: 4px 0; overflow-wrap: anywhere; }
.disclaimer { font-weight: 700; }
.credit { font-size: 14px; color: var(--muted); }

/* ===== 內容面板 ===== */
.panel {
  position: fixed; z-index: 40; top: 72px; right: 16px; bottom: calc(16px + var(--badge-space));
  width: min(460px, calc(100vw - 32px));
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border-radius: 20px; box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden;
}
.panel[hidden], .drawer[hidden], .guide[hidden] { display: none; }
.panel-grip { display: none; }
.panel-head { position: relative; padding: 16px 64px 10px 18px; border-bottom: 1px solid var(--line); }
.panel-kicker { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.panel-title { margin: 2px 0 0; font-size: 30px; line-height: 1.2; outline: none; }
.panel-close { position: absolute; top: 14px; right: 14px; }
.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 18px 24px; }
.sea-chip { display: inline-flex; align-items: center; gap: 4px; padding: 0 10px; border-radius: 999px; background: var(--sea, var(--accent)); color: #1b1b1b; font-size: 13px; }
.intro { font-size: 17px; margin: 0 0 10px; }
.tag-sample { display: inline-block; font-size: 12px; font-weight: 700; padding: 0 8px; border-radius: 6px; background: var(--accent-soft); color: var(--warn); border: 1px solid var(--accent); vertical-align: middle; margin-left: 4px; white-space: nowrap; }
.tag-self { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 6px; background: var(--primary-soft); color: var(--ink); border: 1px solid var(--line); vertical-align: middle; margin-left: 4px; }
.box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin: 10px 0; }
.box h3 { margin: 0 0 4px; font-size: 18px; }
.box ul { margin: 0; padding-left: 20px; }
.points { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.points li { padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); border: 1px solid var(--accent); font-size: 14px; }

.tabs { display: flex; gap: 6px; margin: 14px 0 10px; position: sticky; top: -14px; background: var(--surface); padding: 8px 0; z-index: 2; }
.tab {
  flex: 1; min-height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface-2); color: var(--ink);
  cursor: pointer; font-size: 16px;
}
.tab[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.tabpanel:focus-visible { outline-offset: 4px; }
.lesson-card { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 10px 0; background: var(--surface); }
.lesson-card h3 { margin: 0 0 4px; font-size: 19px; }
.lesson-card p { margin: 0; }
.lesson-card .src { margin-top: 6px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.lesson-card .src a { color: var(--primary); }
.lesson-card.is-sample { border-style: dashed; }

.ws-item { margin: 14px 0; }
.ws-item label { display: block; font-weight: 700; }
.ws-item .hint-txt { font-size: 14px; color: var(--muted); margin: 2px 0 6px; }
.ws-item textarea {
  width: 100%; min-height: 96px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface-2); color: var(--ink); resize: vertical; font-size: 16px; line-height: 1.6;
}
.ws-item textarea:focus { border-color: var(--primary); outline: none; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.save-state { font-size: 14px; color: var(--muted); }

.q { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.q legend { font-weight: 700; padding: 0 4px; }
.q .from { font-size: 13px; color: var(--muted); }
.opt { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; margin: 6px 0; border-radius: 10px; border: 2px solid var(--line); cursor: pointer; background: var(--surface-2); }
.opt:hover { border-color: var(--primary); }
.opt input { width: 22px; height: 22px; flex: none; accent-color: var(--primary); }
.opt.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.q .explain { margin-top: 6px; font-size: 15px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.q.unanswered { border-color: var(--warn); border-width: 2px; }
.q .verdict { font-weight: 700; }
.q .verdict.ok { color: var(--ok); }
.q .verdict.no { color: var(--bad); }
.q .verdict.miss { color: var(--warn); }
.score-box { text-align: center; padding: 14px; border-radius: 16px; background: var(--accent-soft); border: 2px solid var(--accent); margin: 12px 0; }
.score-box .big { font-family: "Huninn", sans-serif; font-size: 40px; line-height: 1.1; }

/* 數學米工具 */
.tool { border: 2px solid var(--accent); border-radius: 16px; padding: 12px 14px; margin: 14px 0; background: var(--accent-soft); }
.tool h3 { margin: 0 0 6px; font-size: 19px; }
.tool .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tool label { font-size: 15px; display: block; }
.tool input, .tool select { width: 100%; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); }
.tool output { display: block; margin-top: 8px; font-size: 18px; font-weight: 700; }
.bars { display: grid; gap: 8px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: 76px 1fr; gap: 8px; align-items: center; font-size: 15px; }
.bar { height: 30px; border-radius: 8px; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; font-weight: 700; min-width: 48px; }
.paddy-grid { display: grid; gap: 2px; margin: 8px 0; touch-action: none; max-width: 360px; }
.paddy-grid button { aspect-ratio: 1; border: 1px solid rgba(0,0,0,.15); padding: 0; cursor: pointer; min-width: 0; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.palette button { width: 44px; height: 44px; border-radius: 10px; border: 3px solid transparent; cursor: pointer; }
.palette button[aria-pressed="true"] { border-color: var(--ink); }

/* 謠言翻牌 */
.rumor-grid { display: grid; gap: 10px; margin: 12px 0; }
.rumor {
  border-radius: 16px; border: 2px solid var(--line); padding: 12px 14px; background: var(--surface-2);
}
.rumor .claim { font-weight: 700; font-size: 17px; }
.rumor .guess { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.rumor .reveal { margin-top: 8px; }
.verdict-tag { display: inline-block; font-weight: 700; padding: 0 10px; border-radius: 999px; font-size: 14px; }
.verdict-tag.false { background: var(--bad); color: #fff; }
.verdict-tag.mislead { background: var(--accent); color: var(--on-accent); }
.verdict-tag.true { background: var(--ok); color: #fff; }

/* 進度與圖鑑 */
.progress-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.progress-table th, .progress-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.progress-table td.c, .progress-table th.c { text-align: center; }
.meter { height: 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.cardx {
  border-radius: 16px; border: 2px solid var(--line); padding: 10px; text-align: center; min-height: 150px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; background: var(--surface-2);
}
.cardx.got { border-color: var(--accent); background: var(--accent-soft); }
.cardx .ico { font-size: 34px; line-height: 1.2; }
.cardx.locked .ico { filter: grayscale(1); opacity: .45; }
.cardx .nm { font-family: "Huninn", sans-serif; font-size: 18px; }
.cardx .bd { font-size: 13px; color: var(--muted); }
.cardx.got .bd { color: var(--ink); }

/* ===== 抽屜 ===== */
.drawer {
  position: fixed; z-index: 45; top: 72px; left: 16px; bottom: calc(16px + var(--badge-space)); width: min(380px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 8px; padding: 14px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0; font-size: 22px; }
.search-box input {
  width: 100%; min-height: 48px; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--surface-2); font-size: 16px;
}
.search-box input:focus { border-color: var(--primary); outline: none; }
.search-results:empty { display: none; }
.search-results { display: grid; gap: 6px; }
.result {
  width: 100%; text-align: left; border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px;
  background: var(--surface-2); cursor: pointer; min-height: 44px;
}
.result:hover { border-color: var(--primary); }
.result b { color: var(--primary); }
.result mark { background: var(--accent); color: var(--on-accent); border-radius: 3px; padding: 0 2px; }
.result small { display: block; color: var(--muted); }

/* ===== 對話框 ===== */
.modal {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100svh - 48px);
  border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(10, 20, 35, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 24px; }
.modal-body { padding: 14px 18px 20px; }
.modal-body h3 { margin: 16px 0 6px; }

/* ===== 米寶問答 ===== */
.guide-fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--badge-space)); z-index: 35;
  display: inline-flex; align-items: center; gap: 4px; min-height: 56px; padding: 4px 16px 4px 6px;
  border-radius: 999px; border: 2px solid var(--accent); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer; font-family: "Huninn", sans-serif; font-size: 17px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
}
.guide-fab img { width: 44px; height: auto; }
.guide {
  position: fixed; right: 16px; bottom: calc(84px + var(--badge-space)); z-index: 50; width: min(380px, calc(100vw - 32px)); max-height: min(560px, calc(100svh - 120px));
  display: flex; flex-direction: column; background: var(--surface); color: var(--ink); border-radius: 20px; box-shadow: var(--shadow); border: 2px solid var(--accent);
}
.guide-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.guide-head h2 { margin: 0; font-size: 19px; flex: 1; }
.guide-head img { width: 36px; height: auto; }
.guide-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-height: 160px; }
.msg { max-width: 92%; padding: 8px 12px; border-radius: 14px; font-size: 15px; }
.msg.me { align-self: flex-end; background: var(--primary); color: var(--on-primary); }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); }
.msg.bot .cite { display: block; margin-top: 4px; font-size: 13px; }
.msg.bot .go { margin-top: 6px; }
.guide-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.guide-form input { flex: 1; min-width: 0; min-height: 44px; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface-2); font-size: 16px; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest button { min-height: 44px; font-size: 14px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--badge-space)); transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.noscript { padding: 16px; background: #fff3cd; color: #3a2700; text-align: center; }

/* WebGL 無法使用時：直接顯示文字清單 */
body.no-3d .stage { height: auto; min-height: 0; padding: 72px 16px 72px; }
body.no-3d .scene, body.no-3d .hint { display: none; }
body.no-3d .scene-msg { position: static; transform: none; margin: 0 auto; }
body.no-3d .theme-switch { position: static; margin: 12px auto 0; width: max-content; max-width: 100%; }

/* ===== 減少動態 ===== */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important;
}

/* ===== 平板 ===== */
@media (max-width: 1100px) {
  .tb-txt { display: none; }
  .tb-btn { padding: 6px 10px; }
  .tb-btn .tb-ico { font-size: 20px; }
}

/* ===== 手機：工具列收合、面板變底部抽屜 ===== */
@media (max-width: 720px) {
  .topbar { padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); gap: 8px; }
  .brand-mascot { width: 32px; }
  .brand-title { font-size: 22px; }
  .brand-tagline { font-size: 12px; }
  .toolbar { gap: 2px; }
  .tb-more { display: inline-flex; }
  .tb-extra {
    display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 40;
    flex-direction: column; align-items: stretch; gap: 4px; padding: 8px; min-width: 200px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  }
  .tb-extra.open { display: flex; }
  .tb-extra .tb-txt { display: inline; }
  .stage { height: calc(100svh - 58px); }
  .hint { top: 8px; font-size: 13px; white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 32px); }
  .theme-switch { left: 12px; bottom: calc(12px + var(--badge-space-m)); gap: 2px; padding: 4px; }
  .swatch { padding: 4px 8px; font-size: 14px; }
  .guide-fab { right: 12px; bottom: calc(12px + var(--badge-space-m)); padding-right: 12px; }
  .guide-fab span { display: none; }
  .guide-fab { padding-left: 6px; }
  .island-label { min-height: 30px; font-size: 13px; padding-right: 7px; }
  .island-label .num { min-width: 22px; height: 22px; font-size: 12px; }
  .island-label .label-name { font-size: 13px; }
  .island-label .state { display: none; }
  .island-label.center .label-name { font-size: 15px; }
  .sea-tag { font-size: 12px; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 64svh;
    border-radius: 20px 20px 0 0; border-bottom: 0;
  }
  .panel-grip { display: block; width: 48px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
  .panel-head { padding: 8px 64px 8px 16px; }
  .panel-title { font-size: 26px; }
  .panel-close { top: 10px; }
  .panel-body { padding: 10px 16px calc(24px + env(safe-area-inset-bottom) + var(--badge-space-m)); }
  .drawer { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 82svh; border-radius: 20px 20px 0 0; padding-bottom: calc(14px + var(--badge-space-m)); }
  .guide { right: 8px; left: 8px; width: auto; bottom: calc(80px + var(--badge-space-m)); }
  .tool .fields { grid-template-columns: 1fr; }
  .modal { width: calc(100vw - 16px); max-height: calc(100svh - 16px); }
  .text-list h2 { font-size: 24px; }
}
@media (max-width: 380px) {
  .swatch .dot { width: 16px; height: 16px; }
  .brand-tagline { display: none; }
}
