:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1c1d1f;
  --muted: #5b5f66;
  --line: #d9dad6;
  --accent: #1f5f8b;
  --accent-text: #ffffff;
  --ok: #1d6b3a;
  --ok-bg: #e3f1e7;
  --bad: #9b2c22;
  --bad-bg: #f8e4e1;
  --stage: #111214;
  --readout-bg: rgba(0, 0, 0, 0.62);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --surface: #1d1f22;
    --text: #ececea;
    --muted: #a5a9b0;
    --line: #34373c;
    --accent: #6fb0de;
    --accent-text: #0d1014;
    --ok: #7fd09a;
    --ok-bg: #1c3324;
    --bad: #f19a90;
    --bad-bg: #3a2020;
    --stage: #000000;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 8px; }

.top { padding: 16px 16px 8px; }
.sub { margin: 4px 0 0; color: var(--muted); }

.layout {
  display: grid;
  gap: 12px;
  padding: 8px 16px 32px;
  max-width: 1280px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr);
    align-items: start;
  }
  .stage-panel { grid-row: span 2; position: sticky; top: 8px; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}

.stage-panel { padding: 0; overflow: hidden; }

.stage {
  position: relative;
  background: var(--stage);
  aspect-ratio: 3 / 4;
  max-height: 78vh;
  width: 100%;
  overflow: hidden;
}

@media (min-width: 900px) {
  .stage { aspect-ratio: 4 / 3; }
}

.media {
  position: absolute;
  inset: 0;
}

.media video,
.media canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Mirror only the picture. Angles come from the unmirrored frame. */
.media.mirror { transform: scaleX(-1); }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: #c9ccd1;
}

.readout {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: var(--readout-bg);
  color: #ffffff;
  border-radius: 8px;
  padding: 0 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(64px, 20vw, 150px);
  line-height: 1.05;
}

.readout .deg { font-size: 0.6em; vertical-align: top; }

.big {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 800;
  font-size: clamp(96px, 34vw, 260px);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.big.word { font-size: clamp(48px, 14vw, 120px); }

.fps {
  position: absolute;
  right: 8px;
  top: 8px;
  color: #ffffff;
  background: var(--readout-bg);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 13px;
}

.fps:empty { display: none; }

.status {
  margin: 0;
  padding: 12px;
  font-size: 1.15rem;
  font-weight: 600;
  min-height: 3.2em;
}

.status.bad { color: var(--bad); }
.status.ok { color: var(--ok); }

.group + .group { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.hint { color: var(--muted); margin: 8px 0; font-size: 0.95rem; }
.hint:empty { display: none; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.space { justify-content: space-between; margin-top: 0; flex-wrap: wrap; }
.label { color: var(--muted); }

button,
.button {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

button:hover, .button:hover { border-color: var(--muted); }
button:focus-visible, .button:focus-visible, select:focus-visible, input:focus-visible + .button {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 1.15rem;
  flex: 1;
  min-height: 56px;
}

button.danger { color: var(--bad); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.seg button { flex: 1 1 auto; }
.seg button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.seg.small { margin-top: 0; }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; color: var(--muted); }
select {
  min-height: 44px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
}

.check { display: inline-flex; gap: 8px; align-items: center; min-height: 44px; }
.check input { width: 20px; height: 20px; }

.dev { margin-top: 12px; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 8px; }
.dev-title { margin: 0; color: var(--muted); font-size: 0.9rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.last { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--bg); }
.last .value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.last.bad { background: var(--bad-bg); color: var(--bad); }

.result-group { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.result-group h3 { font-size: 1rem; margin: 0 0 6px; }
.result-group.current h3::after { content: " (current)"; color: var(--muted); font-weight: 400; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0;
}

@media (min-width: 520px) {
  .stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

.stat { background: var(--bg); border-radius: 6px; padding: 6px 8px; }
.stat b { display: block; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.stat span { color: var(--muted); font-size: 0.85rem; }

.verdict { font-weight: 700; padding: 8px 10px; border-radius: 6px; background: var(--bg); }
.verdict.pass { background: var(--ok-bg); color: var(--ok); }
.verdict.fail { background: var(--bad-bg); color: var(--bad); }

.trials { list-style: none; margin: 8px 0 0; padding: 0; }
.trials li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.trials .main { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.5em; }
.trials .meta { color: var(--muted); font-size: 0.88rem; flex: 1 1 12em; }
.trials .invalid .main { color: var(--bad); }
.trials .confirm { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
