:root {
  --bg: #0a0e13;
  --panel: #111821;
  --panel-2: #0e141c;
  --line: #1f2a37;
  --line-2: #2b3847;
  --text: #e6edf3;
  --muted: #8b98a5;
  --gold: #d4b26a;
  --gold-dim: #8a7444;
  --red: #e5484d;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --blue: #58a6ff;
  --radius: 14px;
  --tabs-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; min-height: 100dvh; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

[hidden] { display: none !important; }

/* ── 上方標題列 ── */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 8px;
}
.brand { font-weight: 700; letter-spacing: 0.08em; color: var(--gold); font-size: 17px; }
.rule-chip {
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 5px 10px;
  touch-action: manipulation;
}
.rule-chip.pending { color: var(--warn); border-color: #5a4613; }
.rule-chip.bad { color: var(--bad); border-color: #6b2020; }

.main {
  flex: 1;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}

h2 { font-size: 20px; margin: 8px 0 12px; }
h3 { font-size: 15px; margin: 20px 0 8px; color: var(--gold); }
p { line-height: 1.6; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.lead { font-size: 17px; font-weight: 600; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* ── 使用說明 ── */
.guide {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  font-size: 14px;
  color: var(--gold);
  background: linear-gradient(180deg, #1a1609, #13110a);
  border: 1px solid #3a2f14;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
}

/* ── 羅盤 ── */
.dial-wrap { display: flex; justify-content: center; padding: 4px 0; }
.dial { width: min(78vw, 320px); height: auto; aspect-ratio: 424 / 436; display: block; }
.d-bezel { fill: #06090d; stroke: #2a3440; stroke-width: 2; }
.d-face { fill: #0f151d; stroke: var(--gold-dim); stroke-width: 1.5; }
.d-ring { fill: none; stroke: var(--line-2); stroke-width: 1; }
.d-tick { stroke: #56616d; stroke-width: 1; }
.d-tick.major { stroke: #a9b4bf; stroke-width: 1.4; }
.d-degnum { fill: #7d8894; font-size: 10px; font-family: var(--mono); }
.d-divider { stroke: #2f3b49; stroke-width: 1; }
.d-divider.strong { stroke: #45525f; }
.d-mt { fill: #cfd6dd; font-size: 19px; font-weight: 600; }
.d-mt.active { fill: var(--gold); font-size: 22px; }
.d-tr { fill: #8f9ba7; font-size: 14px; }
.d-card { fill: #6f7b87; font-size: 15px; font-weight: 700; }
.d-card.north { fill: var(--red); }
.d-lubber { stroke: var(--red); stroke-width: 1.5; opacity: 0.8; }
.d-lubber.back { stroke: #6d7782; stroke-dasharray: 3 4; opacity: 0.8; }
.d-pointer { fill: var(--red); }
.d-pointer.back { fill: #6d7782; }
.d-level { fill: #0a0f15; stroke: #2b3847; stroke-width: 1; }
.d-level-target { fill: none; stroke: #3b4a5a; stroke-width: 1; }
.d-cross { stroke: #1c2733; stroke-width: 1; }
.d-bubble { stroke: none; }
.d-bubble.ok { fill: var(--ok); }
.d-bubble.bad { fill: var(--warn); }
.d-bubble.unknown { fill: #3b4652; }

/* ── 讀數 ── */
.readout { text-align: center; margin-top: 2px; }
.deg-row, .final { display: flex; align-items: baseline; justify-content: center; gap: 2px; }
.deg, .final-deg {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.deg-unit { font-size: 26px; color: var(--muted); }
.dir8 { margin-left: 12px; font-size: 18px; color: var(--muted); }
.facing-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.facing-label { font-size: 28px; font-weight: 700; color: var(--gold); letter-spacing: 0.06em; }

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
  text-align: left;
}
.facts > div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-size: 15px; }

.tag {
  display: inline-block;
  font-size: 11px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 999px;
  vertical-align: middle;
  white-space: nowrap;
}
.tag.pending { color: #f0c05a; background: #2b220c; border: 1px solid #5a4613; }
.tag.warn { color: #ffb86b; background: #2e1d0c; border: 1px solid #6a4017; }

.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.meter { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.meter.wide { grid-column: 1 / -1; }
.meter .k { font-size: 12px; color: var(--muted); }
.meter .v { font-size: 14px; }

.state-line {
  margin: 12px 0 4px;
  text-align: center;
  font-size: 15px;
  min-height: 1.5em;
  color: var(--muted);
}
.state-line.ok { color: var(--ok); font-weight: 700; font-size: 17px; }
.state-line.warn { color: var(--warn); }

/* ── 固定在下方的操作列（測量頁） ── */
.has-dock { padding-bottom: 132px; }
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 16px 10px;
  background: linear-gradient(to top, var(--bg) 78%, rgba(10, 14, 19, 0));
  z-index: 9;
}
.dock .state-line { margin: 0 0 8px; }
.dock-buttons { display: flex; gap: 10px; }
.dock-buttons .btn.big { flex: 1; }
.dock-buttons #stopBtn { flex: 0 0 auto; padding-left: 18px; padding-right: 18px; }

/* ── 按鈕 ── */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #d9b870, #b8954b); color: #1a1406; border-color: #c8a458; font-weight: 700; }
.btn.primary:disabled { background: #2a2f36; color: #6f7a85; border-color: #2f3843; }
.btn.big { font-size: 18px; padding: 15px 16px; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 13px; padding: 7px 10px; }
.btn:disabled { cursor: not-allowed; }

/* ── 提示框 ── */
.alert {
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.55;
  border: 1px solid var(--line-2);
  background: var(--panel);
}
.alert p { margin: 4px 0 0; }
.alert.ok { border-color: #1f5a2a; background: #0d1f12; color: #b6f0c0; }
.alert.warn { border-color: #5a4613; background: #1d170a; color: #f3d38a; }
.alert.bad { border-color: #6b2020; background: #1f0d0d; color: #ffc1bd; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* ── 確認頁 ── */
.method-line { text-align: center; font-size: 14px; color: var(--muted); }
.method-line.manual { color: var(--blue); }
.adjust-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-top: 12px; }
.adjust-box .k { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.adjust { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.btn.adj { font-family: var(--mono); font-size: 17px; padding: 12px 0; }
.kv { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.kv th { text-align: left; color: var(--muted); font-weight: 400; padding: 7px 8px 7px 0; white-space: nowrap; vertical-align: top; width: 7.5em; }
.kv td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.kv tr th { border-bottom: 1px solid var(--line); }

/* ── 手動輸入 ── */
.form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.input-row { display: flex; align-items: baseline; gap: 6px; }
.input-row input {
  flex: 1;
  font-family: var(--mono);
  font-size: 32px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
}
.input-row input:focus { outline: 2px solid var(--gold-dim); }
.form .btn { width: 100%; margin-top: 14px; }

/* ── 校準 ── */
.fig8 { display: flex; justify-content: center; margin: 4px 0 8px; }
.fig8 svg { width: min(70vw, 260px); }
.fig8-path { fill: none; stroke: var(--gold-dim); stroke-width: 2; stroke-dasharray: 4 5; }
.fig8-phone rect { fill: #1b2430; stroke: var(--gold); stroke-width: 1.5; }
.steps { padding-left: 22px; line-height: 1.7; }

/* ── 紀錄 ── */
.count { font-size: 14px; color: var(--muted); font-weight: 400; }
.rec-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.rec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.rec-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.rec-method.manual { color: var(--blue); }
.rec-main { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 4px 0; }
.rec-label { font-size: 20px; font-weight: 700; color: var(--gold); }
.rec-final { font-family: var(--mono); font-size: 18px; }
.rec-detail { font-size: 13px; color: #b5c0cb; font-family: var(--mono); }
.rec-id { font-size: 11px; color: var(--muted); margin-top: 4px; font-family: var(--mono); }
.fallback { width: 100%; height: 160px; margin-top: 10px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; font-family: var(--mono); font-size: 11px; }

/* ── 規則頁 ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-top: 8px; }
.card p { margin: 6px 0 0; }
.version { font-family: var(--mono); font-size: 24px; color: var(--gold); font-weight: 700; }
.file-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.path { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.confirmed { color: #b6f0c0; background: #0d1f12; border: 1px solid #1f5a2a; }
.badge.draft { color: #f0c05a; background: #2b220c; border: 1px solid #5a4613; }
.badge.pending { color: #ffb86b; background: #2e1d0c; border: 1px solid #6a4017; }
.pending-list { padding-left: 20px; }
.pending-list li { margin-bottom: 10px; }
.pending-list p { margin: 4px 0 0; color: #c3ccd5; }
.settings { padding-left: 18px; line-height: 1.7; color: #c3ccd5; }

/* ── 下方選單 ── */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(8, 11, 15, 0.96);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.tab {
  font: inherit;
  font-size: 11px;
  color: var(--muted);
  background: none;
  border: 0;
  height: var(--tabs-h);
  padding: 0;
  justify-content: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  touch-action: manipulation;
}
.tab span { font-size: 18px; line-height: 1.2; }
.tab.active { color: var(--gold); }

.noscript { padding: 20px; }
.panel { padding: 16px 0; }

@media (min-width: 560px) {
  .tabs { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
