/* ArcSim web UI: the desktop app's light-green / off-white palette (see theme.py). */
:root {
  --page: #F4F2E8;
  --card: #FFFDF7;
  --field: #F8F7F0;
  --tint: #E7F4E0;
  --green: #AEDDA5;
  --green-hover: #9DD493;
  --green-strong: #76B96D;
  --green-text: #467F40;
  --line: #E1EBD9;
  --ink: #1F3327;
  --ink-soft: #64786A;
  --ink-faint: #9AAA9E;
  --warn: #C9826B;
  --warn-tint: #F7E6DE;
  --warn-text: #9A4F38;
  --stage: #E9EDE2;
  --shadow: 0 1px 2px rgb(31 51 39 / 6%), 0 8px 24px rgb(31 51 39 / 6%);
  --radius: 18px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Ubuntu, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #141A16;
    --card: #1B231D;
    --field: #222B24;
    --tint: #24342A;
    --green: #8FCB86;
    --green-hover: #A2D69A;
    --green-strong: #76B96D;
    --green-text: #A6D99E;
    --line: #2C392F;
    --ink: #E8EFE6;
    --ink-soft: #A3B3A7;
    --ink-faint: #6F8073;
    --warn: #D9967F;
    --warn-tint: #3A2621;
    --warn-text: #EBB09C;
    --stage: #0F1411;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
a { color: var(--green-text); }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px max(16px, calc((100vw - 1180px) / 2));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; letter-spacing: -0.01em; }
.brand p { font-size: 12px; color: var(--ink-soft); }
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); }
.status[data-state="ready"] .dot { background: var(--green-strong); box-shadow: 0 0 0 3px var(--tint); }
.status[data-state="loading"] .dot { animation: pulse 1.2s ease-in-out infinite; background: var(--green); }
.status[data-state="error"] .dot { background: var(--warn); }
@keyframes pulse { 50% { opacity: .3; } }

/* ------------------------------------------------------------------ layout */
.layout {
  flex: 1;
  width: 100%;
  max-width: 1212px;
  margin: 0 auto;
  padding: 0 16px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
.panel { display: grid; gap: 20px; min-width: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

/* ------------------------------------------------------------------ stage */
.stage-card { padding: 10px; position: sticky; top: 16px; }
@media (max-width: 900px) { .stage-card { position: static; } }
.stage {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: var(--stage);
}
.stage video, .stage img, .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* Selfie view: only the video is mirrored; the overlay mirrors its own coordinates
   so labels stay readable. */
.stage.mirror video { transform: scaleX(-1); }
.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 16px;
  color: var(--green-text);
}
.stage-empty p:first-of-type { color: var(--ink); font-weight: 600; }
.scan {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 30%;
  background: linear-gradient(to bottom, transparent, rgb(174 221 165 / 45%), transparent);
  animation: sweep 1.1s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes sweep { from { transform: translateY(-40%); } to { transform: translateY(270%); } }
.stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 4px 2px;
}

/* ------------------------------------------------------------------ controls */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  font: 600 14px/1 var(--font);
  padding: 11px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  min-height: 42px;
}
.btn:hover { background: var(--tint); border-color: var(--green); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .tab:focus-visible, input:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.btn.primary { background: var(--green); border-color: var(--green-strong); color: #1F3327; }
.btn.primary:hover { background: var(--green-hover); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.busy { position: relative; color: transparent; }
.btn.busy::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid #1F3327;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toggle { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; font-size: 14px; cursor: pointer; }
.toggle input { accent-color: var(--green-strong); width: 18px; height: 18px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 14px/1 var(--font);
  padding: 10px;
  border-radius: 999px;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.field input {
  font: 15px var(--font);
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  width: 100%;
}
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; font-size: 13px; color: var(--ink-soft); }
.check input { accent-color: var(--green-strong); margin-top: 3px; width: 16px; height: 16px; flex: none; }
#register-hint { margin-top: 10px; }

/* ------------------------------------------------------------------ result */
.result-head { display: flex; justify-content: space-between; gap: 14px; }
.result-head > div { min-width: 0; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--green-text); }
.result h2 { font-size: 26px; margin: 4px 0; overflow-wrap: anywhere; }
.result[data-tone="match"] { border-color: var(--green-strong); }
.result[data-tone="match"] h2 { color: var(--green-text); }
.result[data-tone="warn"] { border-color: var(--warn); }
.result[data-tone="warn"] .eyebrow, .result[data-tone="warn"] h2 { color: var(--warn-text); }
.crop { margin: 0; display: grid; justify-items: center; gap: 4px; flex: none; }
.crop img {
  width: 84px; height: 84px;
  border-radius: 12px;
  border: 1px solid var(--line);
  image-rendering: auto;
  background: #000;
}
.crop figcaption { font-size: 11px; color: var(--ink-faint); }
.crop:has(img[hidden]) { display: none; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.metric {
  background: var(--tint);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 4px;
  min-width: 0;
}
.metric .label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.metric .value { font: 700 24px/1.1 var(--mono); font-variant-numeric: tabular-nums; }
.metric .hint { font-size: 11px; color: var(--ink-soft); }
.meter { position: relative; height: 6px; border-radius: 3px; background: var(--card); margin-top: 4px; }
.meter span {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0;
  border-radius: 3px;
  background: var(--green-strong);
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}
.meter i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-soft); left: 40%; }
.result[data-tone="warn"] .meter span { background: var(--warn); }

.candidates { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.candidates li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--field);
}
.candidates .rank { color: var(--ink-faint); font: 600 12px var(--mono); }
.candidates .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.candidates .score { font: 600 13px var(--mono); color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.details { margin-top: 10px; }

/* ------------------------------------------------------------------ people */
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
h3 { font-size: 16px; }
.pill { background: var(--tint); color: var(--green-text); font: 700 12px var(--mono); padding: 3px 9px; border-radius: 999px; }
.people { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px; max-height: 220px; overflow: auto; }
.people li {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.people li small { color: var(--ink-faint); margin-left: 4px; }
.people .empty { background: none; border: 0; color: var(--ink-soft); padding: 0; }

/* ------------------------------------------------------------------ footer, dialog, toast */
.footer {
  max-width: 1212px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px 28px;
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  padding: 20px;
  max-width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(20 26 22 / 40%); }
dialog p { margin-top: 8px; color: var(--ink-soft); }
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--page);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.toast[data-tone="warn"] { background: var(--warn-text); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
