:root {
  --bg: #0b0f14; --surface: #141a22; --surface2: #1c2430; --line: #2a3442;
  --text: #eef2f7; --muted: #9aa8b9; --accent: #ffb000; --accent-ink: #1a1200;
  --danger: #ff5a52; --danger-bg: #3a1514; --ok: #35d07f; --ok-bg: #11301f;
  --warn: #ffb000; --warn-bg: #3a2a05; --info: #5aa9ff; --info-bg: #11263d;
  --r: 14px; --tap: 56px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}
:root[data-theme="light"] {
  --bg: #f3f5f8; --surface: #ffffff; --surface2: #eaeef3; --line: #cfd7e1;
  --text: #0f1822; --muted: #4a5868; --accent: #8f5200; --accent-ink: #ffffff;
  --danger: #c4261d; --danger-bg: #fde8e6; --ok: #137a43; --ok-bg: #e0f4e9;
  --warn: #9a5b00; --warn-bg: #fff1d6; --info: #1b64b8; --info-bg: #e3effc;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.5 var(--font); }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); min-height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--info); }
h1, h2, h3, p { margin: 0; }

/* shell */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 19px; font-weight: 700; flex: 1; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: var(--surface); border-radius: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.chip.off i { background: var(--danger); }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.page { padding: 16px; max-width: 720px; margin: 0 auto; display: grid; gap: 14px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: grid; justify-items: center; gap: 2px; padding: 9px 0 8px; color: var(--muted); text-decoration: none; font-size: 13px; min-height: 64px; }
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.on { color: var(--accent); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: var(--tap); padding: 0 20px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface2); font-weight: 600; text-decoration: none; cursor: pointer; width: 100%; }
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
:root[data-theme="light"] .btn.primary { background: #a85f00; border-color: #a85f00; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; font-size: 15px; padding: 0 14px; width: auto; }
.btn svg { width: 24px; height: 24px; flex: none; }
.btn.hero { min-height: 128px; font-size: 26px; flex-direction: column; gap: 8px; }
.btn.hero svg { width: 44px; height: 44px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 10px; }
.card h2 { font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }

/* banners */
.banner { border-radius: var(--r); padding: 12px 14px; display: grid; gap: 4px; border: 1px solid; }
.banner b { font-size: 17px; }
.banner.ok { background: var(--ok-bg); border-color: var(--ok); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); }
.banner.danger { background: var(--danger-bg); border-color: var(--danger); }
.banner.info { background: var(--info-bg); border-color: var(--info); }

/* inputs */
.field { width: 100%; min-height: var(--tap); padding: 0 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); outline: none; }
.field:focus { border-color: var(--accent); }
textarea.field { padding: 12px 16px; min-height: 90px; }
label.l { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }

/* class diamond */
.dia { --c: #888; width: 40px; height: 40px; position: relative; flex: none; margin: 4px; }
.dia::before { content: ""; position: absolute; inset: 4px; background: var(--c); transform: rotate(45deg); border-radius: 3px; border: 2px solid rgba(0,0,0,.35); }
.dia span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.dia.light span { color: #111; text-shadow: none; }
.dia.big { width: 56px; height: 56px; } .dia.big span { font-size: 18px; }

/* candidates */
.cand { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.mini { min-height: 44px; min-width: 56px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); font-size: 13px; cursor: pointer; margin-top: 2px; }
.cand:first-of-type { border-top: 0; }
.cand .nm { font-weight: 700; font-size: 17px; line-height: 1.25; }
.cand .sub { font-size: 13.5px; color: var(--muted); }
.cand .pc { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 6px; background: var(--surface2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.cand.top .pc { color: var(--accent); }

/* big distance */
.dist { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dist > div { background: var(--surface2); border-radius: 12px; padding: 10px 8px; text-align: center; }
.dist b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dist small { color: var(--muted); font-size: 12.5px; display: block; margin-top: 2px; }
.dist .k { font-size: 14px; font-weight: 600; margin-bottom: 4px; display: block; }

/* lists */
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .s { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 13px; padding: 3px 10px; border-radius: 8px; background: var(--surface2); border: 1px solid var(--line); }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.tag.danger { color: var(--danger); border-color: var(--danger); }

/* guide text */
.sec h3 { font-size: 14px; letter-spacing: .06em; color: var(--accent); margin-bottom: 4px; }
.sec ul { margin: 0; padding-left: 18px; display: grid; gap: 5px; }
.sec .mh { font-weight: 700; margin-top: 8px; list-style: none; margin-left: -18px; }
.sec .cau { font-weight: 700; list-style: none; margin-left: -18px; background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }
details.acc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
details.acc > summary { list-style: none; padding: 14px 16px; font-weight: 700; cursor: pointer; display: flex; justify-content: space-between; align-items: center; min-height: 52px; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: "＋"; color: var(--muted); }
details.acc[open] > summary::after { content: "－"; }
details.acc > .in { padding: 0 16px 14px; display: grid; gap: 12px; }

/* keypad */
.udisp { display: flex; gap: 10px; justify-content: center; }
.udisp b { width: 62px; height: 78px; display: grid; place-items: center; border-radius: 12px; background: var(--surface); border: 2px solid var(--line); font-size: 40px; font-variant-numeric: tabular-nums; }
.udisp b.cur { border-color: var(--accent); }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keys button { min-height: 68px; font-size: 30px; font-weight: 700; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface2); cursor: pointer; }
.keys button:active { background: var(--accent); color: var(--accent-ink); }
.keys button.fn { font-size: 18px; }

/* photo grid */
.shots { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.shot { position: relative; border-radius: 12px; overflow: hidden; background: var(--surface2); aspect-ratio: 4/3; }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot button { position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 20px; }
.spin { width: 56px; height: 56px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--accent); animation: sp 0.9s linear infinite; margin: 20px auto; }
@keyframes sp { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #000d; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99; max-width: 88vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.refimg { width: 100%; height: auto; border-radius: 10px; background: #fff; display: block; }
.hr { height: 1px; background: var(--line); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; }
table.t1 { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.t1 th, table.t1 td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
table.t1 th:first-child, table.t1 td:first-child { text-align: left; }
table.t1 th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
@media (min-width: 720px) { body { font-size: 18px; } }
@media print { .tabbar, .top .back { display: none; } }

.card, .page > *, .card > * { min-width: 0; }
details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
a.lk { display: inline-flex; align-items: center; min-height: 44px; }
.item .s { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sec li { overflow-wrap: anywhere; }
.refimg { touch-action: pinch-zoom; }

a.gl { display: inline-flex; align-items: center; justify-content: center; min-width: 48px; min-height: 44px; margin-left: 6px; padding: 0 12px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--line); text-decoration: none; font-weight: 700; }

.t3c { background: var(--surface2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.t3c .hd { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.t3c .g { display: grid; grid-template-columns: 3.2em repeat(3, 1fr); gap: 4px 6px; text-align: center; align-items: center; font-variant-numeric: tabular-nums; }
.t3c .g i { font-style: normal; color: var(--muted); font-size: 13px; }
.t3c .g b { font-size: 21px; }
.t3c .g b.n { color: var(--accent); }
