:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #0f172a;
  --muted: #5b6678;
  --border: #dde3ea;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --good: #16a34a;
  --warn: #d97706;
  --poor: #dc2626;
  --unknown: #94a3b8;
  --ideal: #0ea5e9;
  --stage: #0b1220;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1017;
    --surface: #131a23;
    --surface-2: #1b2430;
    --text: #e6ebf2;
    --muted: #93a0b3;
    --border: #273241;
    --accent: #2dd4bf;
    --accent-text: #04201d;
    --good: #22c55e;
    --warn: #f59e0b;
    --poor: #f87171;
    --ideal: #38bdf8;
  }
}

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

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

h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 1.4rem 0 0.6rem; }

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  justify-content: space-between;
  align-items: flex-end;
  padding: 1.25rem 1.5rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
}
.sub, .privacy { margin: 0.2rem 0 0; color: var(--muted); }
.privacy { font-size: 0.85rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1.25rem;
  padding: 0 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---- Controls ---- */
button, .button, select {
  font: inherit;
  font-weight: 550;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
button:hover:not(:disabled), .button:hover { background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button[aria-pressed="true"] { outline: 2px solid var(--ideal); outline-offset: 1px; }
button.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding-inline: 0.3rem; }
:focus-visible { outline: 2px solid var(--ideal); outline-offset: 2px; }

.toolbar, .view-opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.toolbar { margin-bottom: 0.75rem; }
.view-opts { margin-top: 0.75rem; font-size: 0.9rem; color: var(--muted); }
.view-opts label { display: inline-flex; gap: 0.35rem; align-items: center; margin-right: 0.5rem; }
.spacer { flex: 1; }

.legend { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; margin-left: 0.4rem; }
.legend i.good { background: var(--good); }
.legend i.warn { background: var(--warn); }
.legend i.poor { background: var(--poor); }
.legend i.ideal { background: repeating-linear-gradient(90deg, var(--ideal) 0 4px, transparent 4px 7px); }

/* ---- Stage ---- */
.stage-wrap {
  position: relative;
  background: var(--stage);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 420px;
  display: grid;
  place-items: center;
  border: 2px dashed transparent;
}
.stage-wrap.drag { border-color: var(--ideal); }
#stage { display: block; width: 100%; height: auto; max-height: 78vh; object-fit: contain; }
#stage.marking { cursor: crosshair; }
#video { display: none; }

.placeholder { color: #cbd5e1; max-width: 520px; padding: 2rem 1.5rem; }
.placeholder h2 { color: #f1f5f9; text-transform: none; letter-spacing: 0; font-size: 1.15rem; margin-top: 1rem; }
.placeholder ol { padding-left: 1.2rem; margin: 0.75rem 0; }
.placeholder svg { width: 220px; max-width: 100%; display: block; margin: 0 auto; }
.ph-screen { fill: #a78bfa; }
.ph-line { stroke: #64748b; stroke-width: 3; }
.ph-body { fill: #e2e8f0; }
.ph-body-line { fill: none; stroke: #e2e8f0; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.ph-guide { stroke: #38bdf8; stroke-width: 2; stroke-dasharray: 6 5; }

.stage-hint {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.status { margin: 0.6rem 0 0; color: var(--muted); }
.status.error { color: var(--poor); }

/* ---- Panel ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  align-self: start;
}
.summary { display: flex; gap: 1rem; align-items: center; }
.ring {
  --p: 0;
  --c: var(--unknown);
  width: 76px;
  height: 76px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(closest-side, var(--surface) 78%, transparent 80%),
    conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-2) 0);
  font-size: 1.5rem;
  font-weight: 700;
}
.ring[data-status="good"] { --c: var(--good); }
.ring[data-status="warn"] { --c: var(--warn); }
.ring[data-status="poor"] { --c: var(--poor); }
.verdict strong { display: block; font-size: 1.1rem; }
.verdict span { color: var(--muted); font-size: 0.9rem; }
.side-info { color: var(--muted); font-size: 0.8rem; margin: 0.6rem 0 0; }

.actions { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.actions li { display: flex; gap: 0.6rem; align-items: flex-start; }
.actions li.none { color: var(--muted); }
.actions .num {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  background: var(--warn);
  margin-top: 1px;
}
.actions li[data-status="poor"] .num { background: var(--poor); }

.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 0.55rem 0; border-top: 1px solid var(--border); }
.checks li:first-child { border-top: 0; }
.checks .row { display: flex; align-items: center; gap: 0.5rem; }
.checks .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--unknown); flex: none; }
.checks li[data-status="good"] .dot { background: var(--good); }
.checks li[data-status="warn"] .dot { background: var(--warn); }
.checks li[data-status="poor"] .dot { background: var(--poor); }
.checks .name { font-weight: 600; flex: 1; }
.checks .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; }
.checks p { margin: 0.15rem 0 0 18px; font-size: 0.88rem; color: var(--muted); }
.checks em { font-style: normal; opacity: 0.8; }

.manual-wrap summary { cursor: pointer; list-style: revert; }
.manual-wrap summary h2 { display: inline; }
.manual { list-style: none; padding: 0; margin: 0.4rem 0 0; display: grid; gap: 0.4rem; font-size: 0.9rem; }
.manual label { display: flex; gap: 0.5rem; align-items: flex-start; }
.manual input { margin-top: 0.25rem; }

.disclaimer { font-size: 0.78rem; color: var(--muted); margin: 1.4rem 0 0; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 0 1rem 1.5rem; }
  .top { padding: 1rem; }
  .stage-wrap { min-height: 300px; }
}

@media print {
  body { background: #fff; color: #000; }
  .toolbar, .view-opts, .privacy, .stage-hint, .status { display: none !important; }
  .layout { display: block; padding: 0; }
  .stage-wrap { background: none; min-height: 0; }
  #stage { max-height: none; width: 100%; }
  .panel { border: 0; padding: 1rem 0 0; }
  .manual-wrap { display: block; }
  .manual-wrap > * { display: block; }
}
