/* Scanner-specific styling. Reuses design tokens + lab-* / soft-panel classes
   from styles.css.

   Theme: the lab's cream paper from styles.css is the light theme by another
   name, so light needs nothing. Dark repaints the same --lab-* names from the
   shared tokens and every rule below follows without being touched. The camera
   stage and the chips on it stay night in both — the overlay is drawn as light
   marks and would disappear on paper. */

body.scanner-page {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
  /* Pass and fail, dark enough to read as words on paper rather than as tint. */
  --scan-ok: #2d6a3f;
  --scan-bad: #a1394a;
}

:root[data-theme="dark"] body.scanner-page {
  color-scheme: dark;
  --lab-bg: var(--bg);
  --lab-paper: var(--bg-raised);
  --lab-paper-soft: var(--bg-sunken);
  --lab-ink: var(--ink);
  --lab-muted: var(--ink-soft);
  --lab-line: var(--line);
  --lab-blue: var(--a-link);
  --lab-blue-dark: var(--a-brand);
  --lab-olive: var(--a-live);
  --lab-gold: var(--a-warn);
  --lab-coral: #fda4af;
  --lab-shadow: 0 22px 70px rgb(0 0 0 / 45%);
  --lab-panel-shadow: 0 16px 48px rgb(0 0 0 / 40%);
  /* The primary button keeps a light face in both themes, so its label flips. */
  --lab-on-blue: #06121d;
  --scan-ok: var(--a-live);
  --scan-bad: #fda4af;
}

/* styles.css paints the root cream for every lab page; under the dark theme the
   scanner would then show a cream margin below its own background. */
:root[data-theme="dark"]:has(body.scanner-page) {
  background: var(--bg);
}

.scanner-shell {
  width: min(1320px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 20px 0 40px;
  display: grid;
  gap: 16px;
}

.scanner-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.scanner-tools > [data-gab-nav] {
  flex: 1 1 240px;
  min-width: 0;
}

/* The button carries the page's own paper styling: left on the base rules from
   styles.css it would arrive as a dark chip on a cream page. */
.scanner-page .theme-switch {
  border: 1px solid var(--lab-line);
  background: color-mix(in srgb, var(--lab-paper) 72%, transparent);
  color: var(--lab-muted);
}

.scanner-page .theme-switch:hover {
  color: var(--lab-ink);
}

.scanner-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.scanner-status {
  border: 1px solid var(--lab-line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--lab-paper) 72%, transparent);
  padding: 6px 14px;
  color: var(--lab-muted);
  font-size: 12px;
  font-weight: 700;
}

.scanner-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-toggle {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.settings-toggle[aria-expanded="true"] {
  border-color: var(--lab-blue);
  color: var(--lab-blue);
}

/* Settings panel */

.settings-panel {
  display: grid;
  gap: 4px;
  max-height: min(80vh, 720px);
  overflow-y: auto;
  padding: 18px 20px;
}

.settings-panel[hidden] {
  display: none;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-head h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  font-weight: 500;
}

.settings-close {
  min-height: 30px;
  min-width: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Camera / Audio / Tuning sections now reuse the shared dev-mode
   `.section-toggle` / `.controls-section` / `.summary-value` / `.controls` /
   `.section-body` / `.grid.two` / `.grid.three` classes from styles.css, so
   the floating settings panel here only needs light adjustments: the shared
   classes assume a dark sidebar (styles.css `--line`/`--muted`/`--text`
   tokens), while this panel is a light `soft-panel` using `--lab-*` tokens.
   Re-point colors so the dev-mode layout renders legibly inside the floating
   panel without touching styles.css. */
.settings-panel .section-toggle {
  border-top-color: var(--lab-line);
}

.settings-panel .section-toggle summary {
  color: var(--lab-ink);
}

.settings-panel .summary-value {
  color: var(--lab-muted);
}

.settings-panel label {
  color: var(--lab-ink);
  font-size: 12px;
  font-weight: 650;
}

.settings-panel select,
.settings-panel input[type="number"] {
  border: 1px solid var(--lab-line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lab-paper) 90%, transparent);
  padding: 6px 8px;
  font-size: 13px;
  color: var(--lab-ink);
  min-height: 34px;
}

.settings-panel input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--lab-blue);
}

.settings-panel .toggles label {
  color: var(--lab-ink);
}

.auto-status {
  display: block;
  max-width: none;
  margin-top: 4px;
  color: var(--lab-muted);
  font-size: 12px;
  font-weight: 650;
  text-align: left;
  line-height: 1.4;
}

.camera-quick-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.settings-panel .lab-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
  width: 100%;
}

.camera-quick-actions .lab-button {
  width: auto;
}

/* Threshold tuning sliders */

.threshold-sliders {
  display: grid;
  gap: 10px;
}

.threshold-slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 10px;
}

.threshold-slider-row label {
  font-size: 12px;
  font-weight: 650;
  color: var(--lab-ink);
}

.threshold-slider-row .threshold-value {
  font-size: 12px;
  font-weight: 800;
  color: var(--lab-olive);
  min-width: 40px;
  text-align: right;
}

.threshold-slider-row input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--lab-blue);
}

/* Speaker toggle (guidance panel) */

.guidance-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.speaker-toggle {
  min-height: 28px;
  min-width: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.speaker-toggle[aria-pressed="false"] {
  color: var(--lab-muted);
  opacity: 0.55;
}

/* Privacy banner */

.privacy-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--lab-line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--lab-olive) 9%, transparent);
  padding: 14px 16px;
  color: var(--lab-ink);
}

.privacy-banner-icon {
  flex: none;
  margin-top: 2px;
  color: var(--lab-olive);
}

.privacy-banner p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

.privacy-banner strong {
  color: var(--lab-ink);
}

/* Main grid: viewer + guidance panel */

.scanner-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 380px);
  gap: 16px;
  align-items: start;
}

.scanner-viewer {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--lab-line);
  background: var(--stage);
  box-shadow: var(--lab-shadow);
}

.scanner-viewer video,
.scanner-viewer canvas#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#video {
  object-fit: cover;
  /* Mirroring is unified via state.mirror in scanner-app.js (overlay draw +
     guides + capture snapshots). The raw <video> is always covered by the
     opaque overlay canvas, so no CSS transform is needed here. */
  background: var(--stage);
}

#overlay {
  display: block;
  pointer-events: none;
}

#capture {
  display: none;
}

/* Stepper chips */

.scanner-stepper {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}

/* The chips float on the camera stage, which is night in both themes, so they
   keep their own light-on-dark palette instead of following the page. */
.scanner-stepper .step-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  background: rgb(5 5 5 / 52%);
  backdrop-filter: blur(10px);
  color: rgb(244 244 240 / 72%);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.scanner-stepper .step-chip .step-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

.scanner-stepper .step-chip[data-state="done"] {
  color: #86efac;
}

.scanner-stepper .step-chip[data-state="active"] {
  color: #67e8f9;
  background: rgb(103 232 249 / 16%);
}

.scanner-stepper .step-chip[data-state="todo"] {
  color: rgb(244 244 240 / 46%);
}

/* Consent panel */

.consent-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  align-content: center;
  gap: 14px;
  border-radius: 0;
  background: color-mix(in srgb, var(--lab-bg) 96%, transparent);
  padding: clamp(20px, 4vw, 40px);
  overflow: auto;
}

.consent-panel[hidden] {
  display: none;
}

.consent-panel h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 500;
}

.consent-panel p {
  max-width: 520px;
  color: var(--lab-ink);
  font-size: 14px;
  line-height: 1.6;
}

.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 520px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--lab-ink);
}

.consent-check input {
  margin-top: 2px;
  flex: none;
  width: 16px;
  height: 16px;
  accent-color: var(--lab-blue);
}

.consent-check-inline {
  max-width: none;
}

.consent-panel .lab-button {
  width: fit-content;
}

.consent-panel .lab-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Guidance panel */

.guidance-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 0;
}

.guidance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.guidance-head h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 500;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--lab-line);
  background: color-mix(in srgb, var(--lab-olive) 10%, transparent);
  padding: 0 10px;
  color: var(--lab-olive);
  font-size: 12px;
  font-weight: 800;
}

.score-badge[data-state="pass"] {
  border-color: color-mix(in srgb, var(--scan-ok) 40%, transparent);
  background: color-mix(in srgb, var(--scan-ok) 16%, transparent);
  color: var(--scan-ok);
}

.score-badge[data-state="fail"] {
  border-color: color-mix(in srgb, var(--scan-bad) 30%, transparent);
  background: color-mix(in srgb, var(--scan-bad) 12%, transparent);
  color: var(--scan-bad);
}

.guidance-instruction {
  color: var(--lab-ink);
  font-size: 14px;
  line-height: 1.55;
}

.hold-ring-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  margin: 0 auto;
}

.hold-ring {
  width: 88px;
  height: 88px;
  transform: rotate(-90deg);
}

.hold-ring-track {
  fill: none;
  stroke: var(--lab-line);
  stroke-width: 5;
}

.hold-ring-progress {
  fill: none;
  stroke: var(--lab-blue);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 188.5;
  stroke-dashoffset: 188.5;
  transition: stroke-dashoffset 80ms linear;
}

.hold-ring-progress[data-state="pass"] {
  stroke: var(--scan-ok);
}

.hold-ring-label {
  position: absolute;
  color: var(--lab-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hint-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hint-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--lab-paper-soft) 60%, transparent);
  padding: 7px 10px;
  color: var(--lab-ink);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.4;
}

.hint-list li .hint-icon {
  flex: none;
  width: 13px;
  height: 13px;
  color: var(--lab-coral);
}

.hint-list li[data-ok="true"] {
  color: var(--scan-ok);
}

.hint-list li[data-ok="true"] .hint-icon {
  color: var(--scan-ok);
}

.guidance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.guidance-actions .lab-button {
  min-height: 42px;
  padding: 0 16px;
  font-size: 13px;
}

/* Review panel */

.review-panel {
  display: grid;
  gap: 16px;
}

.review-panel[hidden] {
  display: none;
}

.review-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.review-head h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 500;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.review-actions .lab-button {
  min-height: 40px;
  padding: 0 16px;
  font-size: 13px;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.review-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--lab-line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--lab-paper) 72%, transparent);
  padding: 10px;
}

.review-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  object-fit: cover;
  background: var(--stage);
}

.review-card h3 {
  margin: 0;
  color: var(--lab-ink);
  font-size: 13px;
  font-weight: 780;
}

.review-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  font-size: 11.5px;
  color: var(--lab-muted);
}

.review-card dt {
  color: var(--lab-muted);
  font-weight: 700;
}

.review-card dd {
  margin: 0;
}

.review-card[data-pass="true"] {
  border-color: color-mix(in srgb, var(--scan-ok) 40%, transparent);
}

.review-card[data-pass="false"] {
  border-color: color-mix(in srgb, var(--scan-bad) 30%, transparent);
}

#proportionsPanel {
  display: grid;
  gap: 18px;
}

.proportions-section {
  display: grid;
  gap: 8px;
}

.proportions-section-title {
  margin: 0;
  color: var(--lab-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.proportions-note {
  margin: 0;
  color: var(--lab-muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.proportions-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.proportions-panel .proportion-item {
  border-radius: 8px;
  background: color-mix(in srgb, var(--lab-paper-soft) 60%, transparent);
  padding: 10px 12px;
}

.proportions-panel .proportion-item span {
  display: block;
}

.proportions-panel .proportion-label {
  color: var(--lab-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.proportions-panel .proportion-value {
  margin-top: 4px;
  color: var(--lab-ink);
  font-size: 16px;
  font-weight: 780;
}

/* Responsive */

@media (max-width: 960px) {
  .scanner-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .scanner-viewer {
    aspect-ratio: 4 / 3.6;
  }
}

@media (max-width: 640px) {
  .scanner-shell {
    width: calc(100vw - 24px);
    padding: 14px 0 28px;
  }

  .scanner-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .review-actions {
    width: 100%;
    justify-content: space-between;
  }
}
