/* ==========================================================
   維也納練習室 — 全域樣式
   外殼（首頁、紀錄、設定）走「駕駛艙儀表」風格；
   測驗畫面本身刻意樸素，接近 VTS 實機的灰白螢幕與操作盤。
   ========================================================== */

:root {
  --bg: #F2F3EF;
  --surface: #FFFFFF;
  --surface-2: #F7F8F5;
  --ink: #15202B;
  --ink-2: #3A4652;
  --muted: #66717C;
  --line: #DCE0E2;
  --primary: #1D3B5A;
  --primary-ink: #FFFFFF;
  --accent: #D9820B;
  --good: #1E8A4C;
  --bad: #C43B32;
  --focus: #2F7FD1;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 4px 16px rgba(20, 30, 40, .06);
  --radius: 14px;
  --chart-line: #1D3B5A;
  --chart-grid: #E3E6E8;

  /* 測驗畫面（不跟深色模式，實機就是灰白螢幕） */
  --vts-bg: #E6E6E3;
  --vts-screen: #F4F4F2;
  --vts-ink: #1B1B1B;
  --panel: #2A2D30;
  --panel-2: #1D1F22;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1318;
    --surface: #151D24;
    --surface-2: #1A232B;
    --ink: #E5EAEE;
    --ink-2: #C1CAD2;
    --muted: #8D99A5;
    --line: #26313A;
    --primary: #7DB3E6;
    --primary-ink: #0B1520;
    --accent: #F0A53A;
    --good: #4CC27F;
    --bad: #EF6A5F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --chart-line: #7DB3E6;
    --chart-grid: #26313A;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--bad); }

/* ---------------- 按鈕 ---------------- */

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: .72em 1.35em;
  min-height: 46px;
  font-weight: 650;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, background-color .15s ease, opacity .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
}
a.btn { text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--primary); color: var(--primary-ink); }
.btn--ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn--danger { background: var(--bad); color: #fff; }
.btn--accent { background: var(--accent); color: #1A1204; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.link-btn {
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: .5em;
  font-size: .9rem;
}

/* ==========================================================
   外殼
   ========================================================== */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: 1.08rem;
  letter-spacing: .01em;
}
.brand svg { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.brand small { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); letter-spacing: .04em; }

.main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px calc(96px + var(--safe-bottom));
}

/* 底部分頁列：浮動膠囊（與 TeaTracker 一致） */
.tabdock {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 10px);   /* Home Indicator 讓位 */
  z-index: 6;
  display: flex;
  justify-content: center;
  pointer-events: none;                      /* 只有膠囊本身可以點 */
}
.tabdock__pill {
  pointer-events: auto;
  display: flex;
  gap: 2px;
  padding: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border: 1px solid var(--line);
  box-shadow: 0 2px 6px rgba(20, 30, 40, .08), 0 10px 30px rgba(20, 30, 40, .14);
}
.tab {
  min-width: 72px;
  min-height: 50px;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .05em;
  text-decoration: none;
  cursor: pointer;
  transition: color .18s, background .18s;
  -webkit-tap-highlight-color: transparent;
}
.tab-ic, .tab svg { width: 22px; height: 22px; display: block; }
.tab[aria-current="page"] {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(20, 30, 40, .08), 0 2px 8px rgba(20, 30, 40, .08);
}
@media (prefers-color-scheme: dark) {
  .tab[aria-current="page"] { background: #243039; }
}
.tab:active { transform: scale(.96); }

.main > .section-title:first-child { margin-top: 4px; }
.section-title {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 26px 2px 10px;
}

/* ---------------- 首頁：模擬考主卡 ---------------- */

.hero {
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius) + 4px);
  padding: 22px 20px;
  background: #13283D;
  color: #EAF1F7;
  box-shadow: var(--shadow);
}
.hero::after {
  content: "";
  position: absolute;
  right: -90px; top: -90px;
  width: 220px; height: 220px;
  opacity: .8;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, transparent 58%, rgba(255,255,255,.07) 59%, transparent 61%),
    radial-gradient(circle at center, transparent 38%, rgba(255,255,255,.06) 39%, transparent 41%),
    linear-gradient(180deg, rgba(79,149,214,.35) 50%, rgba(160,105,52,.32) 50%);
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero h2 { margin: 0 0 4px; font-size: 1.3rem; }
.hero p { margin: 0 0 16px; color: #B8C7D4; max-width: 34em; font-size: .95rem; }
.hero .hero-actions { display: flex; flex-wrap: wrap; gap: 10px; position: relative; z-index: 1; }
.hero .btn--ghost { color: #EAF1F7; box-shadow: inset 0 0 0 1.5px rgba(234,241,247,.35); }
.hero-kicker { font-size: .72rem; font-weight: 700; letter-spacing: .12em; color: #F0A53A; margin-bottom: 6px; }

/* ---------------- 首頁：測驗卡片 ---------------- */

.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}

.test-card {
  position: relative;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 4px 14px;
  align-items: start;
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .1s ease, border-color .15s;
}
.test-card:active { transform: scale(.985); }
.test-card:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.test-icon {
  grid-row: span 3;
  width: 56px; height: 56px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}
.test-icon svg { width: 40px; height: 40px; }
.test-card-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.test-nick { font-size: 1.12rem; font-weight: 750; }
.test-code {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.test-name { font-size: .85rem; color: var(--ink-2); }
.test-foot { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .78rem; color: var(--muted); margin-top: 4px; }
.test-foot b { color: var(--ink); font-weight: 700; }

/* ---------------- 測驗詳情（開始前） ---------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 14, 20, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .15s ease;
}
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } }
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  animation: rise .2s ease;
}
@media (min-width: 700px) { .sheet { border-radius: 20px; } }
.sheet h2 { margin: 2px 0 2px; font-size: 1.35rem; }
.sheet .test-code { font-size: .8rem; }
.sheet-desc { color: var(--ink-2); margin: 10px 0 14px; }
.sheet-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .9rem; margin: 0 0 16px; }
.sheet-facts dt { color: var(--muted); }
.sheet-facts dd { margin: 0; }
.opt-group { margin: 14px 0; }
.opt-label { font-size: .85rem; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: .45em 1em;
  font-size: .9rem;
  cursor: pointer;
  min-height: 40px;
}
.seg button[aria-pressed="true"] { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 700; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { width: 100%; }
.mode-hint { font-size: .78rem; color: var(--muted); text-align: center; margin-top: 4px; }

/* ---------------- 紀錄 ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.hist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.hist-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.hist-head h3 { margin: 0; font-size: 1.05rem; }
.hist-stats { display: flex; gap: 16px; font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.hist-stats b { color: var(--ink); font-size: 1rem; }
.hist-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: .85rem; }
.hist-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.hist-list .idx { font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------------- 設定 ---------------- */

.settings-list { display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}
.setting:first-child { border-top: 0; }
.setting-text b { display: block; font-weight: 650; }
.setting-text span { font-size: .82rem; color: var(--muted); }
.switch {
  appearance: none;
  width: 52px; height: 32px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background .15s;
  border: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .15s;
}
.switch:checked { background: var(--good); }
.switch:checked::after { transform: translateX(20px); }
input[type="range"] { width: 140px; accent-color: var(--primary); }

.about { font-size: .88rem; color: var(--ink-2); }
.about p { margin: 0 0 10px; }

/* ---------------- 圖表 ---------------- */

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 12px; }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--surface); stroke: var(--chart-line); stroke-width: 2; }
.chart-dot--last { fill: var(--accent); stroke: var(--accent); }

/* ==========================================================
   測驗 Session（全螢幕）
   ========================================================== */

html.in-session, html.in-session body { overflow: hidden; }

.session {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--vts-bg);
  color: var(--vts-ink);
  color-scheme: light;
  /*
   * 這裡「不能」寫 touch-action: none。
   * touch-action 是沿祖先鏈取交集的：祖先關掉之後，子孫再寫 pan-y 也救不回來，
   * 結果測驗裡所有捲動都失效（行事曆／電話簿滑不動就是這樣來的）。
   * 需要吃掉手勢的元素自己宣告：.stage-canvas、.js（搖桿）、.pk（操作盤按鍵）。
   */
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.session-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(var(--safe-top) + 4px) calc(10px + var(--safe-right)) 4px calc(12px + var(--safe-left));
  min-height: 44px;
  background: #CFCFCB;
  border-bottom: 1px solid #B9B9B4;
  font-size: .86rem;
}
.session-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.session-code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-weight: 800; letter-spacing: .04em; color: #1D3B5A; }
.session-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.session-battery { font-size: .75rem; color: #555; background: #E4E4E0; border-radius: 99px; padding: 0 8px; }
.session-right { display: flex; align-items: center; gap: 8px; }
.session-status { font-size: .8rem; color: #444; font-variant-numeric: tabular-nums; white-space: nowrap; }
.session-phase { font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: #BDBDB8; color: #333; white-space: nowrap; }
.session-phase--practice { background: #F6D78B; color: #5A3E00; }
.session-phase--test { background: #1D3B5A; color: #fff; }
.session-phase--result { background: #BFE0CB; color: #0E4D2A; }
.session-exit {
  appearance: none;
  border: 0;
  background: transparent;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #333;
  cursor: pointer;
}
.session-exit span, .session-exit svg { width: 22px; height: 22px; display: block; }
.session-exit:active { background: rgba(0,0,0,.08); }

.session-body {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.test-host {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.session-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(20, 20, 20, .45);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fade .12s ease;
  touch-action: auto;
}

.dialog {
  width: 100%;
  max-width: 420px;
  background: #fff;
  color: #1B1B1B;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
.dialog p { margin: 0 0 16px; color: #444; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.session .btn--primary { background: #1D3B5A; color: #fff; }
.session .btn--ghost { color: #1B1B1B; box-shadow: inset 0 0 0 1.5px #BDBDB8; }

/* ---------------- 說明頁（仿 VTS 指導語畫面） ---------------- */

.intro {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: auto;
  padding: 16px calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.intro-card {
  width: 100%;
  max-width: 760px;
  background: var(--vts-screen);
  border: 1px solid #C9C9C4;
  border-radius: 6px;
  padding: 22px 22px 18px;
  box-shadow: 0 1px 0 #fff inset, 0 2px 10px rgba(0,0,0,.06);
}
.intro-kicker { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .75rem; letter-spacing: .08em; color: #6A6A66; margin-bottom: 4px; }
.intro-title { margin: 0 0 12px; font-size: 1.35rem; line-height: 1.3; }
.intro-text { font-size: 1.02rem; line-height: 1.75; color: #262626; }
.intro-text p { margin: 0 0 .8em; }
.intro-text ul, .intro-text ol { margin: 0 0 .8em; padding-left: 1.3em; }
.intro-text li { margin: .2em 0; }
.intro-text b, .intro-text strong { color: #000; }
.intro-text .key {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 .45em;
  border-radius: 5px;
  font-size: .9em;
  font-weight: 700;
  text-align: center;
  border: 1px solid rgba(0,0,0,.25);
  box-shadow: 0 2px 0 rgba(0,0,0,.18);
  vertical-align: .05em;
}
.intro-text .tip { background: #FFF6DA; border-left: 4px solid #E0B040; padding: 10px 12px; border-radius: 4px; margin: .6em 0 1em; font-size: .95rem; }
.intro-figure {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 42vh;
  margin: 4px 0 14px;
  background: #fff;
  border: 1px solid #D5D5D0;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.intro-note { margin: 10px 0 0; font-size: .85rem; color: #7A5A00; background: #FFF3C9; padding: 8px 10px; border-radius: 6px; }
.intro-nav {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 14px;
}
.intro-dots { display: flex; gap: 6px; }
.intro-dots i { width: 7px; height: 7px; border-radius: 50%; background: #B8B8B3; }
.intro-dots i.on { background: #1D3B5A; }
.intro-buttons { display: flex; gap: 10px; margin-left: auto; }
.intro-skip { width: 100%; text-align: right; color: #666; }

/* ---------------- 轉場、倒數 ---------------- */

.between, .countdown {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 16px;
}
.between-card {
  max-width: 480px;
  width: 100%;
  background: var(--vts-screen);
  border: 1px solid #C9C9C4;
  border-radius: 8px;
  padding: 24px;
  text-align: left;
}
.between-card h1 { margin: 0 0 8px; font-size: 1.4rem; }
.between-card p { margin: 0 0 10px; }
.between-card .muted { color: #666; }
.between-card .dialog-actions { margin-top: 18px; }
.error-pre { font-size: .72rem; white-space: pre-wrap; background: #eee; padding: 8px; border-radius: 6px; max-height: 30vh; overflow: auto; }

.countdown { align-content: center; gap: 4px; }
.countdown-label { font-size: 1rem; color: #555; text-align: center; font-weight: 600; letter-spacing: .1em; }
.countdown-num { font-size: 5.5rem; font-weight: 800; color: #1D3B5A; text-align: center; font-variant-numeric: tabular-nums; animation: pop .7s ease infinite; }

/* ---------------- 成績頁 ---------------- */

.result-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.result {
  max-width: 720px;
  margin: 0 auto;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid #D5D5D0;
  --chart-line: #1D3B5A;
  --chart-grid: #E6E6E2;
  --surface: #fff;
  --muted: #6A6A66;
  --accent: #D9820B;
  --ink-2: #333;
  --line: #EAEAE6;
}
.result-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.result-index { display: flex; align-items: baseline; gap: 4px; }
.result-num { font-size: 3.6rem; font-weight: 800; line-height: 1; color: #1D3B5A; font-variant-numeric: tabular-nums; }
.result-of { color: #888; font-weight: 600; }
.result-label { font-weight: 700; }
.result-delta { font-size: .9rem; color: #666; }
.result-delta.up { color: #1E8A4C; }
.result-delta.down { color: #C43B32; }
.result-summary { margin: 14px 0 6px; font-size: 1.02rem; }
.result-section { margin-top: 18px; }
.result-section h3 { font-size: .9rem; margin: 0 0 6px; color: #444; }
.metrics { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .93rem; font-variant-numeric: tabular-nums; }
.metrics th, .metrics td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.metrics thead th { font-size: .75rem; color: var(--muted); font-weight: 600; }
.metrics tbody th { font-weight: 500; color: var(--ink-2); }
.metrics td small { color: var(--muted); }
.trend { font-size: .8rem; font-weight: 700; }
.trend--up { color: #1E8A4C; }
.trend--down { color: #C43B32; }
.disclaimer { margin-top: 16px; }
.result-actions { margin-top: 18px; }

/* ==========================================================
   測驗版面工具（給 js/tests/* 使用）
   ========================================================== */

/* 上：刺激畫面，下：操作盤 */
.tl { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tl-stim { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.tl-panel {
  flex: none;
  position: relative;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-top: 1px solid #0F1011;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  padding: 12px calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  color: #CFD3D6;
}
/* 橫向且高度不足時，操作盤移到右側 */
@media (orientation: landscape) and (max-height: 620px) {
  .tl.tl--side { flex-direction: row; }
  .tl.tl--side > .tl-panel {
    border-top: 0;
    border-left: 1px solid #0F1011;
    padding: 10px calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* VTS 螢幕感：淺灰白底 + 細框 */
.vts-screen { background: var(--vts-screen); }
.vts-black { background: #000; }

/* 階段中的浮動提示（練習回饋） */
.fb-toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 99px;
  font-weight: 700;
  font-size: .9rem;
  pointer-events: none;
  z-index: 5;
  animation: toast .9s ease forwards;
}
.fb-toast.ok { background: #1E8A4C; color: #fff; }
.fb-toast.err { background: #C43B32; color: #fff; }

/* ---------------- 操作盤按鍵 ---------------- */

.pk {
  --cap: #9A9FA5;
  --cap-hi: #C2C6CA;
  --cap-lo: #6B7075;
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  position: relative;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: inline-grid;
  place-items: center;
  flex: none;
}
.pk-cap {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background: radial-gradient(120% 90% at 35% 25%, var(--cap-hi) 0%, var(--cap) 45%, var(--cap-lo) 100%);
  box-shadow:
    0 5px 0 #0B0C0D,
    0 6px 10px rgba(0,0,0,.55),
    inset 0 1px 1px rgba(255,255,255,.45),
    inset 0 -3px 5px rgba(0,0,0,.25);
  transform: translateY(0);
  transition: transform .04s ease, box-shadow .04s ease, filter .1s;
}
.pk.is-down .pk-cap {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #0B0C0D, 0 2px 4px rgba(0,0,0,.5), inset 0 1px 1px rgba(255,255,255,.3), inset 0 -1px 3px rgba(0,0,0,.3);
  filter: brightness(.92);
}
.pk.is-disabled { opacity: .5; }
.pk--round { width: var(--pk-size, 64px); height: var(--pk-size, 64px); border-radius: 50%; }
.pk--rect { width: var(--pk-w, 78px); height: var(--pk-h, 52px); border-radius: 10px; }
.pk--wide { width: var(--pk-w, 100%); height: var(--pk-h, 58px); border-radius: 12px; }
.pk--pedal { width: var(--pk-w, 120px); height: var(--pk-h, 70px); border-radius: 14px 14px 18px 18px; }
.pk--pedal .pk-cap {
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.07) 0 3px, transparent 3px 9px),
    linear-gradient(180deg, #3A3D40, #1B1C1E);
  box-shadow: 0 6px 0 #070808, 0 8px 12px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.15);
}
.pk--pedal.is-down .pk-cap { transform: translateY(5px) scaleY(.97); box-shadow: 0 1px 0 #070808, inset 0 2px 6px rgba(0,0,0,.6); }

.pk--red    { --cap: #D3302C; --cap-hi: #F06A5E; --cap-lo: #8E1C18; }
.pk--yellow { --cap: #F0C419; --cap-hi: #FFE37A; --cap-lo: #B08900; }
.pk--green  { --cap: #2BA24C; --cap-hi: #6BD98A; --cap-lo: #177030; }
.pk--blue   { --cap: #2A67CF; --cap-hi: #6E9EF0; --cap-lo: #173F8A; }
.pk--white  { --cap: #E9EAE6; --cap-hi: #FFFFFF; --cap-lo: #A9ABA6; }
.pk--grey   { --cap: #8E9398; --cap-hi: #BFC3C7; --cap-lo: #5D6166; }
.pk--black  { --cap: #2A2C2F; --cap-hi: #55595D; --cap-lo: #111214; }

.pk-label { font-weight: 800; font-size: .85rem; color: rgba(0,0,0,.65); letter-spacing: .02em; pointer-events: none; }
.pk--black .pk-label, .pk--pedal .pk-label, .pk--blue .pk-label, .pk--red .pk-label, .pk--green .pk-label { color: rgba(255,255,255,.85); }
.pk-hint {
  position: absolute;
  right: -4px; top: -8px;
  font: 700 10px/1 ui-monospace, Consolas, monospace;
  background: #fff;
  color: #000;
  border-radius: 4px;
  padding: 2px 4px;
  pointer-events: none;
  z-index: 2;
}
.pk-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: 8px; }
.pk-caption { font-size: .72rem; color: #AEB3B8; letter-spacing: .04em; white-space: nowrap; }

.pk.flash-ok .pk-cap { animation: flashOk .35s ease; }
.pk.flash-err .pk-cap { animation: flashErr .35s ease; }

/* ---------------- 虛擬搖桿 ---------------- */

.js { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; touch-action: none; }
.js-base {
  position: relative;
  width: var(--js-size, 150px);
  height: var(--js-size, 150px);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #3B3F43 0%, #232629 60%, #15171A 100%);
  box-shadow: inset 0 2px 8px rgba(0,0,0,.7), 0 1px 0 rgba(255,255,255,.08), 0 0 0 5px #141618, 0 0 0 6px #33373B;
  touch-action: none;
  cursor: grab;
}
.js-guides { position: absolute; inset: 14%; border-radius: 50%; pointer-events: none; }
.js-guides::before, .js-guides::after { content: ""; position: absolute; background: rgba(255,255,255,.1); }
.js-guides::before { left: 50%; top: 0; bottom: 0; width: 2px; transform: translateX(-50%); }
.js-guides::after { top: 50%; left: 0; right: 0; height: 2px; transform: translateY(-50%); }
.js-guides--x::before { display: none; }
.js-guides--y::after { display: none; }
.js-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #6C7176 0%, #3B3F43 55%, #1F2225 100%);
  box-shadow: 0 6px 12px rgba(0,0,0,.6), inset 0 1px 2px rgba(255,255,255,.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.js-knob::after { content: ""; position: absolute; inset: 30%; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #2B2E31, #151719); box-shadow: inset 0 1px 2px rgba(0,0,0,.6); }
.js.is-active .js-base { cursor: grabbing; }
.js-label { font-size: .72rem; color: #AEB3B8; letter-spacing: .04em; text-align: center; }

/* ---------------- 動畫 ---------------- */

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes pop { 0% { transform: scale(1.15); opacity: .4; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -6px); } 15% { opacity: 1; transform: translate(-50%, 0); } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flashOk { 0%, 100% { filter: none; } 30% { filter: drop-shadow(0 0 10px #6BFF9A) brightness(1.2); } }
@keyframes flashErr { 0%, 100% { filter: none; } 30% { filter: drop-shadow(0 0 10px #FF5A4E) brightness(1.2); } }

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

/* ---------------- 只支援橫向 ---------------- */

/* 直向／橫向都可以，由使用者自己決定（原本的「請橫放」遮罩已移除） */
