:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #16202c;
  --muted: #5b6878;
  --line: #d8dee7;
  --brand: #0b5cab;
  --brand-ink: #ffffff;
  --good: #1a7f37;
  --good-bg: #dcf5e3;
  --warn: #8a5a00;
  --warn-bg: #fff1cc;
  --bad: #b3261e;
  --bad-bg: #fde4e1;
  --mute-bg: #e8ecf1;
}
:root:not([data-theme="light"]) {
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --card: #19212b;
    --ink: #e8edf3;
    --muted: #9aa8b8;
    --line: #2b3745;
    --brand: #5aa5ee;
    --brand-ink: #08121d;
    --good: #6fd08a;
    --good-bg: #17331f;
    --warn: #f0c35a;
    --warn-bg: #3a2e0e;
    --bad: #ff8b82;
    --bad-bg: #3d1b18;
    --mute-bg: #26313e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-head {
  position: sticky; top: 0; z-index: 5;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(8px + env(safe-area-inset-top)) 16px 0;
}
.app-head h1 { margin: 0 0 6px; font-size: 18px; }
#tabs { display: flex; gap: 4px; }
#tabs button {
  flex: 1; border: 0; background: transparent; color: inherit; opacity: .75;
  padding: 10px 0; font: inherit; font-weight: 600; cursor: pointer;
  border-bottom: 3px solid transparent; min-height: 44px;
}
#tabs button[aria-selected="true"] { opacity: 1; border-bottom-color: currentColor; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 48px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin: 0 0 12px;
}
.card h3 { margin: 0 0 8px; font-size: 16px; }
.card.error { border-color: var(--bad); background: var(--bad-bg); }
.card.warn-card { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.card.reco { border-color: var(--brand); }
.reco-main { font-size: 18px; font-weight: 700; margin: 0 0 6px; }
.card p { margin: 6px 0; }
.card ul { margin: 6px 0; padding-left: 20px; }

.field, .kv, .check { display: block; margin: 0 0 12px; }
.lbl, .k { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.k { font-weight: 500; color: var(--muted); }
.hint, .meta, .sub { color: var(--muted); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: 22px; height: 22px; }

input[type="text"], input[type="number"], input[type="date"], input[type="url"], input[type="password"], textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-height: 44px;
}
input[type="file"] { width: 100%; font: inherit; }
textarea { resize: vertical; }
.preview { display: block; max-width: 100%; max-height: 180px; margin-top: 8px; border-radius: 8px; border: 1px solid var(--line); }

button { font: inherit; }
button.primary, button.secondary {
  width: 100%; min-height: 48px; border-radius: 10px; font-weight: 700; cursor: pointer; margin-top: 4px;
}
button.primary { background: var(--brand); color: var(--brand-ink); border: 0; }
button.secondary { background: transparent; color: var(--brand); border: 1px solid var(--brand); margin-top: 8px; }
button:disabled { opacity: .55; cursor: progress; }
button.link { background: none; border: 0; color: var(--brand); text-decoration: underline; padding: 8px; min-height: 44px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.row2 .field { margin: 0; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  vertical-align: middle; border: 1px solid transparent;
}
.badge.good { color: var(--good); background: var(--good-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.muted { color: var(--muted); background: var(--mute-bg); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--mute-bg); color: var(--muted); margin: 2px 4px 2px 0; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

.option-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 4px; }
.option-head h3 { margin: 0; font-size: 18px; }
.rank { font-size: 13px; color: var(--muted); }
.engines { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .engines { grid-template-columns: 1fr; } }
.engine { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.engine-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
.engine-name { font-size: 13px; color: var(--muted); }
.ev { margin-top: 4px; }
.ev-num { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ev-unit { color: var(--muted); }
.ev.none { font-size: 30px; color: var(--muted); margin-top: 4px; }
.reason, .range, .starter { font-size: 14px; color: var(--muted); }
.sanity { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 14px; }
.error-text { color: var(--bad); font-weight: 600; }
.warn-text { color: var(--warn); }
.status { color: var(--muted); font-size: 14px; min-height: 1.4em; }

details > summary { cursor: pointer; font-weight: 600; padding: 6px 0; min-height: 32px; }
.entry { border-top: 1px solid var(--line); margin-top: 6px; }

.rule-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.rule-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rule-top input[type="checkbox"] { width: 24px; height: 24px; flex: none; }
.marks { margin-top: 6px; }

.table-wrap { overflow-x: auto; }
table.wk { width: 100%; border-collapse: collapse; }
table.wk th, table.wk td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.wk th { font-size: 13px; color: var(--muted); }
table.wk td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.wk tr.dim { opacity: .7; }
.nm { font-weight: 700; }
