:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --fg: #1b1c1e;
  --muted: #6a6d72;
  --line: #dcdcd8;
  --accent: #2f5d50;
  --accent-fg: #ffffff;
  --ok: #2e7d4f;
  --bad: #b23a2e;
  --warn: #b7791f;
  --band: rgba(47, 93, 80, 0.14);
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #151617;
    --surface: #1e2022;
    --fg: #e8e8e6;
    --muted: #9a9da2;
    --line: #33363a;
    --accent: #7fb8a6;
    --accent-fg: #0f1a17;
    --ok: #6cc193;
    --bad: #ef7d70;
    --warn: #e0a64a;
    --band: rgba(127, 184, 166, 0.16);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #151617;
  --surface: #1e2022;
  --fg: #e8e8e6;
  --muted: #9a9da2;
  --line: #33363a;
  --accent: #7fb8a6;
  --accent-fg: #0f1a17;
  --ok: #6cc193;
  --bad: #ef7d70;
  --warn: #e0a64a;
  --band: rgba(127, 184, 166, 0.16);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.testing { overflow: hidden; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 0.8em; }
a { color: var(--accent); }
small { color: var(--muted); font-weight: 400; }
kbd {
  font: 12px var(--mono);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  background: var(--surface);
}

/* ---------- header ---------- */
.top {
  max-width: 1040px;
  margin: 0 auto;
  padding: 22px 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  align-items: end;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.top .brand { padding-bottom: 14px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand strong { font-size: 16px; letter-spacing: -0.01em; }
.tag {
  font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: 0.08em;
  border: 1px solid var(--line); color: var(--muted); border-radius: 4px; padding: 1px 5px; margin-left: 8px; vertical-align: 2px;
}
.mark {
  width: 30px; height: 30px; border-radius: 6px; flex: none;
  background:
    linear-gradient(45deg, transparent 38%, #c77a6a 38% 62%, transparent 62%),
    repeating-conic-gradient(#8d8f8c 0 25%, #a7a9a5 0 50%) 0 0 / 8px 8px;
}
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-right: auto; }
.tabs button {
  border: 0; background: none; color: var(--muted);
  font-size: 14px; padding: 10px 12px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--fg); }
.tabs button.active { color: var(--fg); border-bottom-color: var(--fg); }

.profile-menu { position: relative; padding-bottom: 10px; }
.profile-menu summary {
  list-style: none; cursor: pointer; display: flex; gap: 8px; align-items: center;
  font-size: 14px; padding: 4px 10px 4px 4px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
}
.profile-menu summary::-webkit-details-marker { display: none; }
.profile-menu summary::after { content: '▾'; color: var(--muted); font-size: 11px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--fg); color: var(--bg); font: 600 12px var(--mono);
}
.menu {
  position: absolute; right: 0; top: calc(100% - 4px); z-index: 20; width: 260px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); padding: 8px; display: grid; gap: 2px;
}
.menu button { text-align: left; border: 0; background: none; color: var(--fg); padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.menu button:hover { background: var(--bg); }
.menu .danger { color: var(--bad); }
.menu-meta { font-size: 12px; color: var(--muted); padding: 4px 10px 8px; margin: 0; border-bottom: 1px solid var(--line); }

main { max-width: 1040px; margin: 0 auto; padding: 28px 16px 64px; }

/* ---------- buttons ---------- */
button { font: inherit; color: inherit; }
.panel button:not(.link), .actions button, .intro button, .new-profile button, .banner button, .pin-form button {
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
button.primary {
  background: var(--accent) !important; color: var(--accent-fg) !important; border-color: var(--accent) !important; font-weight: 600;
}
button.primary:disabled { opacity: 0.4; cursor: not-allowed; }
button.big { padding: 12px 22px !important; font-size: 15px !important; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 14px; }
.muted { color: var(--muted); }

/* ---------- intro ---------- */
.intro, .login { max-width: 760px; margin: 0 auto; padding: 40px 16px 72px; }
.intro h1 { font-size: clamp(26px, 4.5vw, 36px); margin: 36px 0 14px; letter-spacing: -0.02em; line-height: 1.15; }
.lead { font-size: 17px; color: var(--muted); max-width: 64ch; }
.callout {
  border: 1px solid var(--line); border-left: 4px solid var(--warn); background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 18px 22px; margin: 26px 0;
}
.callout h2 { font-size: 15px; margin-bottom: 10px; }
.callout ul { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 14.5px; }
.intro-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; margin: 8px 0 28px; }
.intro-grid h2 { font-size: 15px; margin-bottom: 8px; }
.intro-grid ol { padding-left: 18px; margin: 0; display: grid; gap: 6px; font-size: 14.5px; }
.intro-grid p { font-size: 14.5px; color: var(--muted); }
.ack { display: flex; gap: 10px; align-items: baseline; font-size: 14.5px; margin-bottom: 16px; cursor: pointer; }
.ack input, .new-profile input[type='checkbox'] { accent-color: var(--accent); }

/* ---------- login ---------- */
.login h1 { font-size: 28px; margin: 36px 0 8px; }
.profile-list { display: grid; gap: 8px; margin: 24px 0; }
.profile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.profile-open {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  border: 0; background: none; padding: 12px 14px; cursor: pointer; border-radius: var(--radius);
}
.profile-open:hover { background: var(--bg); }
.profile-open .avatar { width: 34px; height: 34px; font-size: 14px; }
.profile-text { display: grid; flex: 1; }
.profile-text small { font-size: 12.5px; }
.lock { font: 600 10px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.pin-form { display: flex; gap: 8px; padding: 0 14px 14px 60px; }
.pin-form input, .new-profile input {
  font: 15px var(--mono); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
.pin-form input { width: 140px; }
.new-profile {
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; max-width: 420px;
}
.new-profile.first { border-style: solid; border-color: var(--accent); }
.new-profile h2 { font-size: 15px; }
.new-profile label { display: grid; gap: 4px; font-size: 14px; }
.new-profile button { justify-self: start; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.login-foot { display: flex; gap: 20px; flex-wrap: wrap; align-items: center; margin-top: 22px; }
.file-btn { color: var(--accent); cursor: pointer; font-size: 14px; }
.error { color: var(--bad); font-size: 14px; min-height: 1.4em; margin-top: 12px; }

/* ---------- screen banner ---------- */
.banner {
  max-width: 1040px; margin: 16px auto 0; padding: 14px 16px; display: flex; gap: 14px 24px; flex-wrap: wrap;
  align-items: center; justify-content: space-between; border: 1px solid var(--warn); border-radius: var(--radius);
  background: var(--surface); font-size: 14px;
}
.banner > div:first-child { display: grid; gap: 2px; max-width: 70ch; }
.banner span { color: var(--muted); }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 1072px) { .banner { margin-left: 16px; margin-right: 16px; } }

/* ---------- test tab ---------- */
.notice {
  border: 1px solid var(--bad); color: var(--fg); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 20px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
}
.status {
  display: flex; flex-wrap: wrap; gap: 8px 28px; align-items: center;
  padding: 14px 0 22px; border-bottom: 1px solid var(--line); margin-bottom: 24px;
}
.status div { display: flex; flex-direction: column; }
.status span { font-size: 12px; color: var(--muted); }
.status strong { font: 600 15px var(--mono); }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.mode {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column;
}
.mode.feature { border-color: var(--accent); }
.mode header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.mode h2 { font-size: 17px; }
.dur { font: 12px var(--mono); color: var(--muted); }
.mode p { color: var(--muted); font-size: 14px; flex: 1; }
.mode button { align-self: flex-start; }

.howto { margin-top: 36px; display: grid; gap: 8px; }
.howto h3 { font-size: 15px; }
.howto ol { margin: 0; padding-left: 20px; max-width: 70ch; }
.howto li { margin-bottom: 4px; }
.keys { display: flex; gap: 20px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.keys p { margin: 0; font-size: 14px; color: var(--muted); max-width: 60ch; line-height: 1.9; }
.keypad { display: grid; grid-template-columns: repeat(3, 28px); gap: 4px; }
.keypad span {
  height: 28px; display: grid; place-items: center; font: 600 13px var(--mono);
  border-radius: 5px; border: 1px solid var(--line); background: var(--surface);
}
.keypad span:empty { border-color: transparent; background: none; }
.keypad .dim { color: var(--muted); opacity: 0.5; }

/* ---------- setup ---------- */
.step { padding: 0 0 26px; margin-bottom: 26px; border-bottom: 1px solid var(--line); max-width: 760px; }
.step h2 { font-size: 17px; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; }
.step h2 span {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--fg); color: var(--bg); font: 600 12px var(--mono);
}
.step > p { color: var(--muted); max-width: 64ch; }
.card-cal { padding: 12px 0; overflow-x: auto; }
.card-shape {
  aspect-ratio: 85.6 / 53.98; border-radius: 3.2% / 5.1%;
  border: 2px solid var(--fg);
  background: repeating-linear-gradient(135deg, transparent 0 12px, var(--band) 12px 24px);
  display: grid; place-items: end start; padding: 10px 12px;
}
.card-shape span { font: 12px var(--mono); color: var(--muted); }
input[type='range'] { width: min(100%, 700px); accent-color: var(--accent); }
.meta { font: 13px var(--mono); color: var(--muted); margin-top: 8px; }
.field { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; }
.field input, .field select {
  font: 15px var(--mono); padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
}
.field input { width: 90px; }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checklist label { display: flex; gap: 10px; align-items: baseline; font-size: 14px; }
.checklist input { accent-color: var(--accent); }

/* ---------- results ---------- */
.result-head { max-width: 760px; margin-bottom: 28px; }
.eyebrow { font: 12px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.result-head h2 { font-size: 28px; margin-bottom: 12px; }
.warn { color: var(--warn); font-size: 14px; }
.demo-note { color: var(--muted); font-size: 14px; max-width: 70ch; border-left: 3px solid var(--warn); padding-left: 12px; }

.result-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 400px); gap: 32px; align-items: start; }
@media (max-width: 820px) { .result-grid { grid-template-columns: 1fr; } }

.bar { margin-bottom: 26px; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.bar-head strong { font: 600 22px var(--mono); }
.bar-head small { font-size: 13px; }
.bar-track { position: relative; height: 30px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.bar-mark { position: absolute; top: -1px; bottom: -1px; border-left: 1px dashed var(--muted); }
.bar-mark span { position: absolute; top: 32px; transform: translateX(-50%); font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.bar-err { position: absolute; top: 12px; height: 6px; background: var(--fg); opacity: 0.25; border-radius: 3px; }
.bar-value { position: absolute; top: 4px; bottom: 4px; width: 3px; margin-left: -1.5px; background: var(--fg); border-radius: 2px; }
.bar-scale { display: flex; justify-content: space-between; font: 11px var(--mono); color: var(--muted); margin-top: 20px; }
.theory {
  border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface); padding: 14px 16px; margin: 4px 0 18px;
}
.theory h3 { font-size: 14px; margin-bottom: 6px; }
.theory p { font-size: 14px; margin-bottom: 6px; }
.theory p:last-child { margin-bottom: 0; font-size: 12.5px; }
.legend { font-size: 13px; color: var(--muted); }
.idx { margin: 18px 0 0; display: grid; gap: 6px; }
.idx div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 6px; font-size: 14px; }
.idx dt { color: var(--muted); }
.idx dd { margin: 0; font-family: var(--mono); }

.plot { margin: 0; }
.plot figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; }
.cie { width: 100%; height: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.cie .frame { fill: none; stroke: var(--line); }
.cie .grid { stroke: var(--line); stroke-width: 0.5; }
.cie .tick, .trend .tick { font: 9px var(--mono); fill: var(--muted); }
.cie .axis { font: italic 12px system-ui; fill: var(--muted); }
.cie .confusion { stroke: var(--muted); stroke-width: 0.6; stroke-dasharray: 2 3; }
.cie .conf-label { font: 9px var(--mono); fill: var(--muted); }
.cie .sn { fill: none; stroke: var(--fg); stroke-width: 1; stroke-dasharray: 4 3; }
.cie .contour { fill: none; stroke: var(--fg); stroke-width: 1; opacity: 0.35; }
.cie .origin { fill: var(--fg); }

.table-wrap { margin: 28px 0; }
.table-wrap summary { cursor: pointer; font-size: 14px; color: var(--muted); }
table { border-collapse: collapse; width: 100%; font-size: 14px; margin-top: 12px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; font-size: 12px; color: var(--muted); }
td { font-family: var(--mono); font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.fine { font-size: 12px; color: var(--muted); margin-top: 18px; }

/* ---------- history ---------- */
.trend { width: 100%; max-width: 680px; height: auto; margin: 16px 0; }
.trend polyline { fill: none; stroke: var(--fg); stroke-width: 1.5; }
.trend circle { fill: var(--fg); }
.trend .ref { stroke: var(--line); stroke-dasharray: 3 3; }
.scroll { overflow-x: auto; max-width: 100%; }
.scroll td { white-space: nowrap; }
.empty { color: var(--muted); }
.empty h2 { color: var(--fg); margin-bottom: 8px; }

/* ---------- about ---------- */
.prose { max-width: 780px; }
.prose h2 { font-size: 18px; margin: 28px 0 10px; }
.prose h2:first-child { margin-top: 0; }
.spec td { font-family: inherit; font-size: 13.5px; vertical-align: top; }
.spec td:first-child { font-weight: 600; white-space: nowrap; }
.sources li { margin-bottom: 4px; font-size: 14px; }

/* ---------- test stage ---------- */
#stage { position: fixed; inset: 0; z-index: 100; cursor: none; background: #777; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud {
  position: absolute; left: 16px; bottom: 12px;
  font: 12px var(--mono); color: rgba(0, 0, 0, 0.32); pointer-events: none; user-select: none;
}
#msg {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  font: 500 16px system-ui; color: rgba(0, 0, 0, 0.6); pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
}
#msg.show { opacity: 1; }

@media (max-width: 600px) {
  .top { padding-top: 18px; }
  .result-head h2 { font-size: 23px; }
  .spec td:first-child { white-space: normal; }
}
