:root {
  --bg: #f6f2ef;
  --surface: #ffffff;
  --text: #241f26;
  --muted: #6d6570;
  --line: #e2dad4;
  --accent: #8a3b5c;
  --accent-text: #ffffff;
  --danger: #a3261f;
  --guide: rgba(255, 255, 255, 0.9);
  --radius: 14px;
  --gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a1f;
    --surface: #2a252c;
    --text: #f2ece9;
    --muted: #a99fa6;
    --line: #3d363f;
    --accent: #c76d93;
    --accent-text: #1d1a1f;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.25rem; letter-spacing: 0.02em; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }

.muted { color: var(--muted); font-size: 0.9rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar form { margin: 0; }

.privacy {
  margin: 12px var(--gutter);
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 8px;
  font-size: 0.85rem;
}

main { max-width: 900px; margin: 0 auto; padding: 0 var(--gutter) 32px; }

.step {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gutter);
  margin-top: 16px;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}
.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.stage.mirrored video { transform: scaleX(-1); }

.guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.guide-hair { fill: none; stroke: var(--guide); stroke-width: 2; stroke-dasharray: 8 6; }
.guide-face { fill: none; stroke: rgba(255, 255, 255, 0.45); stroke-width: 1.5; }
.guide-card { fill: rgba(200, 200, 200, 0.18); stroke: var(--guide); stroke-width: 2; }
.guide-label {
  fill: #fff;
  font-size: 13px;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.6);
  stroke-width: 3px;
}

.stage-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.85rem; }
.btn.block { width: 100%; }

.shutter {
  width: 68px;
  height: 68px;
  padding: 0;
  border-radius: 50%;
  border: 4px solid var(--surface);
  box-shadow: 0 0 0 3px var(--accent);
}

.tips { margin: 14px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.9rem; }

#preview { display: block; width: 100%; max-width: 520px; margin: 0 auto; border-radius: 12px; }
#preview-info { text-align: center; }

.alert {
  color: var(--danger);
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 8px 12px;
}

body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: var(--gutter); }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.login-card label { display: block; margin: 16px 0 6px; font-weight: 600; }
.login-card input[type=password] {
  width: 100%;
  padding: 12px;
  font: inherit;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  #step-capture { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 0 24px; align-items: start; }
  #step-capture h2 { grid-column: 1 / -1; }
  #step-capture .stage { grid-row: 2 / 4; }
  #step-capture .controls { flex-direction: column; margin-top: 0; }
}

.small { font-size: 0.8rem; }

.status { text-align: center; margin: 12px 0 0; }
.status.error { color: var(--danger); }

.warn {
  border: 1px solid #c98a1b;
  background: rgba(201, 138, 27, 0.1);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.warn ul { margin: 6px 0; padding-left: 20px; }
.warn p { margin: 8px 0 0; }

.diag-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0;
}
.diag-grid dt {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.diag-grid dt:first-child { border-top: 0; padding-top: 0; }
.diag-grid dd { margin: 2px 0 10px; font-weight: 600; }
.diag-grid dd small { display: block; font-weight: 400; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

@media (min-width: 600px) {
  .diag-grid { grid-template-columns: 200px 1fr; }
  .diag-grid dt, .diag-grid dd { padding: 10px 0; margin: 0; border-top: 1px solid var(--line); }
  .diag-grid dt:first-child, .diag-grid dt:first-child + dd { border-top: 0; }
}

.confidence { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; font-weight: 600; }
.confidence meter { flex: 1; height: 14px; }

.diag-grid.unreliable { opacity: 0.5; }
