:root {
  --ink: #1b2238;
  --ink-soft: #4a5068;
  --paper: #fbf6ec;
  --paper-2: #f1e8d8;
  --line: #e2d6c1;
  --dawn: #f0803c;
  --dawn-deep: #d9622a;
  --forest: #2f5a45;
  --t0: #8b8f9c;
  --t1: #a9805a;
  --t2: #4f8f5f;
  --t3: #3f7fb5;
  --t4: #7a5bb5;
  --t5: #d9a514;
  --radius: 18px;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: #1b2238;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 天空與場景 ---------- */
#sky {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, #1b2238 0%, #3b3a66 26%, #a86a78 48%, #ef9a63 66%, #f7cf9a 100%);
}
.sun {
  position: absolute; right: 12%; top: 40%;
  width: 46vmin; height: 46vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 236, 196, .95) 0%, rgba(255, 196, 128, .45) 28%, rgba(255, 170, 110, 0) 68%);
}
/* 山景一路延伸到面板後方,面板高度變化時不會露出空白 */
#scene { position: fixed; inset: 0 0 200px 0; }
#scene canvas { display: block; width: 100%; height: 100%; }
/* 背景載入完成、換上較精細的山景時淡入 */
#scene > canvas, #scene > svg { animation: scene-in .9s ease both; }
@keyframes scene-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #scene > canvas, #scene > svg { animation: none; } }
#scene svg.profile { width: 100%; height: 100%; display: block; }
.profile-sky-0 { fill: rgba(238, 182, 164, .42); }
.profile-sky-1 { fill: rgba(186, 126, 134, .45); }
.profile-sky-2 { fill: rgba(92, 88, 104, .5); }
.profile-fill { fill: rgba(47, 90, 69, .78); }
.profile-line { fill: none; stroke: rgba(255, 244, 228, .7); stroke-width: 2; }
.profile-done { fill: none; stroke: #ff9a4d; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.profile-dot { fill: #fff7ea; }
.profile-label { fill: #fff7ea; font: 600 10px var(--sans); }
.profile-me { fill: #ff7a2f; stroke: #fff; stroke-width: 2; }

/* ---------- 頂部資訊 ---------- */
.hud {
  position: fixed; inset: 0 0 auto 0; z-index: 3;
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  color: #fff8ee;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.brand { background: none; border: 0; padding: 4px 2px; cursor: pointer; white-space: nowrap; }
.brand-mode { font: 700 12px var(--sans); letter-spacing: .12em; color: #ffd9b0; border: 1px solid rgba(255, 217, 176, .5); border-radius: 999px; padding: 2px 7px; }
.brand-mark { font: 900 26px/1 var(--serif); letter-spacing: .08em; color: #fff8ee; text-shadow: 0 2px 12px rgba(0, 0, 0, .35); }
.altitude { justify-self: center; text-align: center; text-shadow: 0 2px 12px rgba(0, 0, 0, .45); }
.altitude-value { display: block; font: 900 34px/1 var(--serif); font-variant-numeric: tabular-nums; }
.altitude-value small { font: 700 14px var(--sans); margin-left: 3px; opacity: .85; }
.altitude-place { display: block; margin-top: 4px; font-size: 13px; font-weight: 500; opacity: .92; }
.route-progress { white-space: nowrap; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 5px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; opacity: .95; }
.bar { display: block; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--dawn); transform-origin: left; transform: scaleX(0); transition: transform 1.2s cubic-bezier(.2, .7, .2, 1); }
.route-progress .bar { width: 64px; height: 5px; background: rgba(255, 248, 238, .3); }
.hud-actions { display: flex; gap: 4px; }
.icon-btn[aria-pressed="true"] { background: var(--dawn); border-color: var(--dawn); color: #fff; }

/* 山峰標籤(3D):由 JS 投影定位 */
.peak-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.peak-label { position: absolute; left: 0; top: 0; white-space: nowrap; font: 700 11px var(--sans); color: #fff8ee; text-shadow: 0 1px 6px rgba(0, 0, 0, .7); padding: 2px 7px; border-radius: 999px; background: rgba(27, 34, 56, .45); }
.peak-label.goal { background: var(--dawn-deep); }
.peak-label.done::before { content: "🚩 "; }
.peak-label.far { font-weight: 600; font-size: 10px; color: rgba(255, 248, 238, .78); background: rgba(27, 34, 56, .28); }
.peak-label.trailhead { background: rgba(138, 90, 60, .85); font-size: 10px; }
.icon-btn {
  background: rgba(27, 34, 56, .42); border: 1px solid rgba(255, 248, 238, .28); color: #fff8ee;
  border-radius: 999px; padding: 7px 9px; font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap;
  backdrop-filter: blur(6px);
}

/* ---------- 底部面板 ---------- */
#panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  margin: 0 auto; width: min(100%, 560px);
  background: var(--paper);
  border-radius: 26px 26px 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -18px 50px rgba(20, 16, 30, .35);
  max-height: 72dvh; overflow-y: auto;
}
.view { animation: rise .32s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.modes { display: flex; gap: 6px; margin: -4px 0 14px; overflow-x: auto; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.mode { flex: none; border: 1.5px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700; color: var(--ink-soft); cursor: pointer; }
.mode.active { background: var(--ink); border-color: var(--ink); color: #fff8ee; cursor: default; }
.route-card { display: grid; gap: 7px; width: 100%; text-align: left; margin: 0 0 14px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--paper-2); cursor: pointer; font-size: 13.5px; color: var(--ink-soft); }
.route-card.static { cursor: default; }
.route-card b { font-size: 15px; color: var(--ink); }
.route-card .bar { background: #fff; }
.eyebrow { margin: 0 0 6px; font-size: 13px; font-weight: 700; letter-spacing: .14em; color: var(--dawn-deep); }
h1 { margin: 0 0 10px; font: 900 30px/1.25 var(--serif); letter-spacing: .02em; }
.lede { margin: 0 0 18px; font-size: 15px; line-height: 1.7; color: var(--ink-soft); }
.fineprint { margin: 12px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--ink-soft); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1.5px solid transparent;
  font-weight: 700; font-size: 16px; cursor: pointer; transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); color: #fff8ee; flex: 1 1 auto; }
.btn.primary:hover { background: #2a3352; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--paper-2); }
.btn.line { background: #06c755; color: #fff; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--dawn); outline-offset: 2px; }

/* ---------- 作答 ---------- */
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.steps { display: flex; gap: 5px; list-style: none; margin: 0; padding: 0; }
.steps li { width: 22px; height: 8px; border-radius: 4px; background: var(--line); }
.steps li.now { background: var(--ink); }
.steps li[data-tier="0"] { background: var(--t0); }
.steps li[data-tier="1"] { background: var(--t1); }
.steps li[data-tier="2"] { background: var(--t2); }
.steps li[data-tier="3"] { background: var(--t3); }
.steps li[data-tier="4"] { background: var(--t4); }
.steps li[data-tier="5"] { background: var(--t5); }
.chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--paper-2); color: var(--ink-soft); white-space: nowrap; }
.prompt { margin: 0 0 6px; font: 900 25px/1.35 var(--serif); }
.prompt.small { font-size: 22px; }
.note { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-soft); min-height: 1em; }

.timer { position: relative; height: 10px; border-radius: 5px; background: var(--line); margin: 4px 44px 14px 0; }
.timer-bar { height: 100%; width: 100%; border-radius: 5px; background: var(--forest); transform-origin: left; }
.timer.low .timer-bar { background: var(--dawn-deep); }
.timer-num { position: absolute; right: -44px; top: -7px; width: 36px; text-align: right; font: 700 18px var(--sans); font-variant-numeric: tabular-nums; }
.timer.low .timer-num { color: var(--dawn-deep); }

#answer-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
#answer {
  min-width: 0; height: 52px; padding: 0 16px; border-radius: 14px;
  border: 2px solid var(--ink); background: #fff; font-size: 18px; font-weight: 500;
}
#answer::placeholder { color: #a9a39a; font-weight: 400; }
#answer.shake { animation: shake .3s; border-color: var(--dawn-deep); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#answer-form .btn { flex: none; min-height: 52px; }
.hint { margin: 10px 0 0; min-height: 1.4em; font-size: 14px; font-weight: 500; color: var(--dawn-deep); }

/* ---------- 單題結果 ---------- */
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tier-badge { display: inline-block; padding: 6px 14px; border-radius: 999px; color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .08em; background: var(--t0); }
.tier-badge[data-tier="1"] { background: var(--t1); }
.tier-badge[data-tier="2"] { background: var(--t2); }
.tier-badge[data-tier="3"] { background: var(--t3); }
.tier-badge[data-tier="4"] { background: var(--t4); }
.tier-badge[data-tier="5"] { background: var(--t5); color: var(--ink); }
.gain { font: 900 22px var(--serif); font-variant-numeric: tabular-nums; }
.reveal { margin: 0 0 16px; display: grid; gap: 8px; }
.reveal div { display: grid; grid-template-columns: 96px 1fr; gap: 10px; padding: 10px 12px; background: var(--paper-2); border-radius: 12px; font-size: 14px; }
.reveal dt { color: var(--ink-soft); }
.reveal dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }

/* ---------- 總結 ---------- */
.tiles { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 0 0 18px; }
.tile { aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; background: var(--t0); }
.tile[data-tier="1"] { background: var(--t1); }
.tile[data-tier="2"] { background: var(--t2); }
.tile[data-tier="3"] { background: var(--t3); }
.tile[data-tier="4"] { background: var(--t4); }
.tile[data-tier="5"] { background: var(--t5); color: var(--ink); }

/* ---------- 勳章 ---------- */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 0 0 14px; }
.badge { display: grid; justify-items: center; gap: 3px; padding: 10px 6px; border-radius: 14px; border: 1.5px solid var(--line); background: transparent; text-align: center; color: var(--ink-soft); }
.badge.owned { background: var(--paper-2); border-color: var(--t5); color: var(--ink); cursor: pointer; }
.badge-icon { font-size: 26px; line-height: 1.2; }
.badge:not(.owned) .badge-icon { filter: grayscale(1); opacity: .45; }
.badge-name { font-size: 13px; font-weight: 700; }
.badge-desc { font-size: 11px; line-height: 1.35; color: var(--ink-soft); }
.badge-grid.fresh { margin: 14px 0 4px; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.badge-grid.fresh .badge-desc { display: none; }
.badge-grid.fresh::before { content: "今日解鎖"; grid-column: 1 / -1; font-size: 13px; font-weight: 700; letter-spacing: .1em; color: var(--dawn-deep); }
#badge-wall h3 { margin: 16px 0 8px; font-size: 14px; letter-spacing: .08em; color: var(--dawn-deep); }

.actions.second { margin-top: 10px; }
.actions.second .btn { flex: 1 1 0; }
.answers-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.answers-list li { display: grid; gap: 3px; padding: 10px 12px; border-radius: 12px; background: var(--paper-2); font-size: 13.5px; color: var(--ink-soft); }
.answers-list b { color: var(--ink); font-size: 14.5px; }
.answers-list li.plain { background: transparent; padding: 4px 0; }
.answers-list summary { display: grid; gap: 3px; cursor: pointer; list-style: none; }
.answers-list summary::-webkit-details-marker { display: none; }
.answers-list summary span::after { content: " ▾"; }
.answers-list details[open] summary span::after { content: " ▴"; }
.tier-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 0; align-items: center; }
.tier-row .tier-badge { font-size: 11.5px; padding: 3px 9px; }
.ans { font-size: 12.5px; padding: 3px 8px; border-radius: 999px; background: #fff; color: var(--ink); }
.ans.mine { background: var(--dawn); color: #fff; font-weight: 700; }
.ans.more { background: transparent; color: var(--ink-soft); }
.section-title { margin: 20px 0 10px; font: 900 18px var(--serif); }
.flavor { margin: 0 0 18px; font-size: 15px; color: var(--ink-soft); }
.histogram { display: flex; align-items: flex-end; gap: 5px; height: 72px; margin: 0 0 18px; padding: 8px 10px 0; border-radius: 12px; background: var(--paper-2); }
.histogram i { flex: 1; border-radius: 5px 5px 0 0; background: var(--line); }
.histogram i.me { background: var(--dawn); }
#feedback-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#rating { grid-column: 1 / -1; display: flex; gap: 6px; }
#rating button { flex: 1; height: 40px; border-radius: 10px; border: 1.5px solid var(--line); background: transparent; font-weight: 700; cursor: pointer; }
#rating button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff8ee; }
#feedback-text { min-width: 0; height: 48px; padding: 0 12px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-size: 14px; }

/* ---------- 路線列表與登頂 ---------- */
.route-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.route-list li { display: grid; gap: 6px; padding: 11px 13px; border-radius: 14px; border: 1.5px solid var(--line); font-size: 14px; }
.route-list li.current { border-color: var(--dawn); background: var(--paper-2); }
.route-list li.locked { opacity: .55; }
.route-row { display: flex; justify-content: space-between; gap: 10px; }
.route-row span { color: var(--ink-soft); font-size: 13px; }
.route-list small { color: var(--ink-soft); font-size: 12px; }
dialog.peak { text-align: center; }
dialog.peak .peak-flag { font-size: 56px; line-height: 1.1; margin: 0 0 6px; animation: plant .6s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes plant { from { transform: translateY(-30px) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
dialog.peak p { font-size: 15px; line-height: 1.7; color: var(--ink-soft); margin: 0 0 16px; }

/* ---------- 對話框 ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 22px 20px; width: min(92vw, 440px); max-height: 86dvh;
  background: var(--paper); color: var(--ink); box-shadow: 0 30px 80px rgba(10, 8, 20, .5);
}
dialog::backdrop { background: rgba(20, 20, 36, .55); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 12px; font: 900 22px var(--serif); }
dialog ol { margin: 0 0 14px; padding-left: 20px; font-size: 14.5px; line-height: 1.75; }
dialog form { margin-top: 16px; display: flex; }
dialog.peak form { margin-top: 0; }
#scene { touch-action: none; }
fieldset { border: 0; padding: 0; margin: 0 0 6px; display: grid; gap: 4px; }
legend { font-weight: 700; margin-bottom: 6px; }
fieldset label { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: 15px; }
fieldset input { width: 18px; height: 18px; accent-color: var(--ink); }
.tier-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tier-table td { padding: 7px 4px; border-top: 1px solid var(--line); }
.tier-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.tier-table i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--paper-2); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font: 900 24px var(--serif); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--ink-soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff8ee; padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 鍵盤彈出或螢幕很矮時,壓縮山景讓題目與輸入框留在畫面內 */
@media (max-height: 560px) {
  #scene { bottom: 150px; }
  .altitude-value { font-size: 26px; }
  .prompt { font-size: 21px; }
  #panel { padding-top: 14px; max-height: 80dvh; }
}
@media (min-width: 900px) {
  #scene { bottom: 0; }
  /* 寬螢幕:面板靠左,把畫面右側留給山景 */
  #panel { bottom: 28px; left: 28px; right: auto; margin: 0; width: 480px; border-radius: 26px; }
  .brand-mark { font-size: 32px; }
  .altitude-value { font-size: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .view, #answer.shake, .peak-flag { animation: none; }
  .bar i { transition: none; }
  .btn { transition: none; }
}

.noscript { position: relative; z-index: 5; max-width: 560px; margin: 0 auto; padding: 24px 20px; color: #fff8ee; line-height: 1.8; }
.noscript h1 { font-size: 24px; }

.footer-links { margin-top: 8px; }
.footer-links a { color: var(--ink-soft); text-underline-offset: 3px; }
