:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1b2430;
  --muted: #5d6673;
  --line: #e3ddd3;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ec;
  --amber: #b7791f;
  --amber-soft: #fbf1df;
  --red: #b42318;
  --red-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.06), 0 6px 24px rgba(20, 30, 40, 0.06);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --surface: #1a2027;
    --ink: #e8ecf0;
    --muted: #9aa4af;
    --line: #2a323b;
    --accent: #4fb6a1;
    --accent-ink: #08201b;
    --accent-soft: #17302b;
    --amber: #e0a648;
    --amber-soft: #2c2415;
    --red: #f07167;
    --red-soft: #321a19;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 var(--sans);
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.15; margin: 0.2em 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; margin-top: 1.4em; }
a { color: var(--accent); }
p { margin: 0.5em 0 0.9em; }
small { color: var(--muted); }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; max-width: 1040px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-size: 1.35rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav[hidden] { display: none; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.nav a.active, .nav a:hover { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 8px 16px 64px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin: 12px 0; }
.panel.narrow { max-width: 720px; margin-inline: auto; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; color: var(--accent); font-weight: 600; margin: 0; }
.lead { font-size: 1.15rem; color: var(--muted); }
.fine { font-size: 0.86rem; color: var(--muted); }
.note, .warn, .danger { padding: 10px 14px; border-radius: 10px; font-size: 0.95rem; }
.note { background: var(--accent-soft); }
.warn { background: var(--amber-soft); border-left: 3px solid var(--amber); }
.danger { background: var(--red-soft); border-left: 3px solid var(--red); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 1rem var(--sans); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { min-height: 54px; padding: 12px 26px; font-size: 1.1rem; }
.btn.sm { min-height: 40px; width: 44px; padding: 0; font-size: 1.3rem; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.file { position: relative; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 18px 0; }
.facts div { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; }
.facts b { display: block; font-family: var(--serif); font-size: 1.6rem; }
.facts span { color: var(--muted); font-size: 0.92rem; }
.checks { padding-left: 0; list-style: none; }
.checks li { padding-left: 28px; position: relative; margin: 6px 0; }
.checks li::before { content: '✓'; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.checks.big li { font-size: 1.05rem; }
.steps li { margin: 8px 0; }

/* forms */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: 0.97rem; }
.form input:not([type=checkbox]):not([type=radio]), .form select {
  font: 1rem var(--sans); padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); min-height: 44px; width: 100%;
}
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 12px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.form .cb { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.cb input { width: 20px; height: 20px; margin-top: 3px; flex: none; accent-color: var(--accent); }
.ack { background: var(--bg); padding: 12px; border-radius: 10px; }
.likert { display: flex; flex-wrap: wrap; gap: 6px; }
.likert label { display: block; font-weight: 400; }
.likert input { position: absolute; opacity: 0; pointer-events: none; }
.likert span { display: inline-block; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 0.92rem; }
.likert input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.likert input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* calibration */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 6px 0 12px; }
.seg button { border: 0; background: transparent; padding: 9px 16px; font: 600 0.95rem var(--sans); color: var(--muted); cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.calib-stage { min-height: 200px; display: flex; align-items: center; justify-content: center; padding: 16px 0; overflow: hidden; }
.card-shape { border: 2px solid var(--ink); border-radius: 3.2mm; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 0.85rem; padding: 6px; background: repeating-linear-gradient(135deg, transparent 0 10px, var(--accent-soft) 10px 20px); }
.ruler-shape { position: relative; height: 70px; border-bottom: 2px solid var(--ink); align-self: center; }
.ruler-shape i { position: absolute; bottom: 0; width: 2px; height: 30px; background: var(--ink); margin-left: -1px; }
.ruler-shape em { position: absolute; top: -22px; left: -4px; font-style: normal; font-size: 0.8rem; }
.ruler-shape span { position: absolute; bottom: -26px; left: 0; white-space: nowrap; font-size: 0.85rem; color: var(--muted); }
.slider-row { display: flex; align-items: center; gap: 10px; max-width: 560px; margin: 8px auto 4px; }
.slider-row input { flex: 1; accent-color: var(--accent); height: 36px; }
.calgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 28px; }

/* dashboard */
.hero-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin: 12px 0; border-top: 4px solid var(--accent); }
.hero-card.done { border-top-color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 4px; align-content: start; }
.stat > span { color: var(--muted); font-size: 0.88rem; }
.stat b { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; }
.stat b.va { font-size: 1.15rem; font-family: var(--sans); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.delta { font-size: 0.85rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.delta.up { background: var(--accent-soft); color: var(--accent); }
.delta.down { background: var(--red-soft); color: var(--red); }
.links { gap: 18px; }
.key { font: 600 1.25rem ui-monospace, 'SF Mono', Consolas, monospace; letter-spacing: 0.06em; background: var(--bg); padding: 12px; border-radius: 10px; word-break: break-all; user-select: all; }
.chart { width: 100%; height: auto; }
.chart path { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart circle { fill: var(--accent); }
.chart text { font-size: 11px; fill: var(--muted); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.panel.narrow td { white-space: normal; }
.panel.narrow td .delta { display: inline-block; margin-top: 4px; }

/* ===== Stage (full-screen test area) ===== */
body.staging { overflow: hidden; }
.stage { position: fixed; inset: 0; z-index: 50; background: rgb(188, 188, 188); color: #111; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.stage[hidden] { display: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: max(8px, env(safe-area-inset-top)) 14px 8px; font: 600 0.85rem var(--sans); color: rgba(0, 0, 0, 0.55); }
.hud .bar { flex: 1; background: rgba(0, 0, 0, 0.1); height: 4px; }
.hud .bar i { background: rgba(0, 0, 0, 0.35); }
.hud button { background: rgba(0, 0, 0, 0.08); border: 0; border-radius: 8px; padding: 8px 14px; font: 600 0.85rem var(--sans); color: rgba(0, 0, 0, 0.65); cursor: pointer; min-height: 36px; }
#hudLabel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
.resp { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 16px; padding: 12px 16px max(16px, env(safe-area-inset-bottom)); }
.rbtn { min-width: 120px; min-height: 64px; border-radius: 14px; border: 1px solid rgba(0, 0, 0, 0.15); background: rgba(255, 255, 255, 0.35); color: #222; font: 700 1.15rem var(--sans); cursor: pointer; display: grid; place-items: center; padding: 6px 16px; }
.rbtn small { display: block; font-weight: 500; font-size: 0.72rem; color: rgba(0, 0, 0, 0.5); }
.rbtn:disabled { opacity: 0.35; }
.rbtn:active:not(:disabled) { background: rgba(255, 255, 255, 0.65); }
.rbtn.wide { min-width: 220px; }
.dpad { display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 60px); gap: 8px; }
.dpad .rbtn { min-width: 0; min-height: 0; font-size: 1.4rem; }
.dpad [data-v=up] { grid-column: 2; grid-row: 1; }
.dpad [data-v=left] { grid-column: 1; grid-row: 2; }
.dpad .ns { grid-column: 2; grid-row: 2; font-size: 0.72rem; }
.dpad [data-v=right] { grid-column: 3; grid-row: 2; }
.dpad [data-v=down] { grid-column: 2; grid-row: 3; }
.stage .msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(188, 188, 188, 0.96); overflow-y: auto; }
.stage .msg[hidden] { display: none; }
.smsg { background: #fff; color: #1b2430; border-radius: 16px; padding: 24px; max-width: 520px; width: 100%; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15); }
.smsg .eyebrow { color: #0f6b5c; }
.smsg .fine { color: #5d6673; }
.smsg .btn { background: #fff; color: #1b2430; border-color: #d8d2c8; }
.smsg .btn.primary { background: #0f6b5c; color: #fff; border-color: #0f6b5c; }
table.mini { margin: 8px 0; }
.smsg th, .smsg td { border-color: #e3ddd3; color: #1b2430; }

@media (max-width: 560px) {
  .panel, .hero-card { padding: 18px; }
  .rbtn { min-width: 0; flex: 1; }
  .dpad { grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 54px); }
}
