/* Laundry Color Scanner — mobile-first styles. No remote fonts or assets. */

:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #e8ecf1;
  --text: #121820;
  --text-muted: #46505e;
  --border: #cbd3dd;
  --accent: #0b5f86;
  --accent-strong: #084a69;
  --accent-contrast: #ffffff;
  --accent-soft: #dcecf5;
  --ok: #1d6b3a;
  --ok-soft: #e1f2e7;
  --warn: #8a4b00;
  --warn-soft: #fcefdc;
  --danger: #a3262d;
  --danger-soft: #fbe3e4;
  --focus: #1a73e8;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 6px 20px rgb(0 0 0 / 8%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1116;
    --surface: #161b22;
    --surface-2: #202833;
    --text: #eef2f6;
    --text-muted: #aab4c0;
    --border: #334050;
    --accent: #62bde9;
    --accent-strong: #9ad6f3;
    --accent-contrast: #062231;
    --accent-soft: #123447;
    --ok: #7fd49a;
    --ok-soft: #14301f;
    --warn: #f5b862;
    --warn-soft: #3a2a12;
    --danger: #ff9a9f;
    --danger-soft: #3d1a1c;
    --focus: #8ab4f8;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 20px rgb(0 0 0 / 35%);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* App-like taps: no double-tap-to-zoom delay or swallowed taps on iOS;
     pinch-zoom stays available for accessibility. */
  touch-action: manipulation;
}

button,
a,
label,
input,
select,
textarea,
summary,
.picker-option {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

main {
  outline: none;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0;
}

p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Headings and <main> receive focus programmatically for screen readers only. */
h1[tabindex="-1"]:focus,
h2[tabindex="-1"]:focus,
main[tabindex="-1"]:focus {
  outline: none;
}

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -100px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  top: calc(8px + var(--safe-top));
}

.noscript {
  padding: 24px;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.5rem 1.25rem;
  border: 2px solid transparent;
  border-radius: 12px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 120ms ease, transform 80ms ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn--secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn--ghost {
  background: transparent;
  color: var(--accent);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .btn--danger {
    color: #2a0a0c;
  }
}

.btn--small {
  min-height: 44px;
  padding: 0.25rem 0.875rem;
  font-size: 0.9375rem;
}

.btn--xl {
  min-height: 60px;
  font-size: 1.125rem;
  border-radius: 16px;
}

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 45%);
  color: #fff;
  cursor: pointer;
}

.btn-icon[aria-pressed="true"] {
  background: #ffd84d;
  color: #1a1400;
}

.btn-icon .icon {
  width: 24px;
  height: 24px;
}

/* ---------- Screens ---------- */

.screen {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 640px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
}

.topbar > :first-child {
  justify-self: start;
}

.topbar > :last-child {
  justify-self: end;
}

.topbar h2 {
  font-size: 1.125rem;
  text-align: center;
}

.hint {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.inline-error {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.actionbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: auto;
}

.actionbar--sticky {
  position: sticky;
  bottom: 0;
  padding: 0.75rem 0 calc(0.25rem + var(--safe-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}

.actionbar > :only-child {
  grid-column: 1 / -1;
}

.actionbar .btn {
  padding-inline: 0.75rem;
  white-space: nowrap;
}

@media (max-width: 360px) {
  .actionbar .btn .icon {
    display: none;
  }
}

/* ---------- Home ---------- */

.screen--home {
  justify-content: center;
  gap: 1.5rem;
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.home-logo {
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.home-hero h1 {
  font-size: clamp(1.75rem, 7vw, 2.25rem);
  letter-spacing: -0.01em;
}

.lede {
  max-width: 28em;
  color: var(--text-muted);
  font-size: 1.0625rem;
}

.home-actions {
  display: grid;
  gap: 0.75rem;
}

.privacy-note {
  color: var(--text-muted);
  font-size: 0.9375rem;
  text-align: center;
  text-wrap: balance;
}

.privacy-note .icon {
  margin-right: 0.35em;
  vertical-align: -0.2em;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
}

.banner--info {
  background: var(--accent-soft);
}

.banner--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.home-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 1rem;
}

.home-footer-actions {
  display: flex;
  gap: 0.25rem;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.status-chip[data-state="ready"] {
  background: var(--ok-soft);
  color: var(--ok);
}

/* ---------- Camera ---------- */

.screen--camera {
  max-width: none;
  padding: 0;
  gap: 0;
  background: #000;
  color: #fff;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.camera-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.camera-stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.camera-target {
  position: absolute;
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 42%);
  pointer-events: none;
}

.camera-target::before,
.camera-target::after,
.camera-target span::before,
.camera-target span::after {
  content: "";
  position: absolute;
  width: 28px;
  height: 28px;
  border: 4px solid #fff;
}

.camera-target::before {
  top: -2px;
  left: -2px;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 18px;
}

.camera-target::after {
  top: -2px;
  right: -2px;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 18px;
}

.camera-target span::before {
  bottom: -2px;
  left: -2px;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 18px;
}

.camera-target span::after {
  bottom: -2px;
  right: -2px;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 18px;
}

.camera-target[data-mode="calibrate"]::before,
.camera-target[data-mode="calibrate"]::after,
.camera-target[data-mode="calibrate"] span::before,
.camera-target[data-mode="calibrate"] span::after {
  border-color: #ffd84d;
}

.camera-topbar {
  position: absolute;
  z-index: 2;
  top: calc(12px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.camera-chip {
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  background: rgb(0 0 0 / 60%);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
}

.camera-guidance {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}

.camera-instruction,
.camera-feedback {
  max-width: 30em;
  padding: 0.5rem 0.875rem;
  border-radius: 12px;
  background: rgb(0 0 0 / 60%);
  text-align: center;
  font-weight: 600;
}

.camera-feedback:empty {
  display: none;
}

.camera-message {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 24px;
  background: #0d1116;
  text-align: center;
}

.camera-message p {
  max-width: 28em;
  color: #cfd6df;
}

.camera-message-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.camera-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 16px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: #000;
}

.camera-side-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-self: center;
  gap: 0.25rem;
  min-width: 72px;
  min-height: 56px;
  padding: 0.25rem 0.5rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.camera-side-btn .icon {
  width: 26px;
  height: 26px;
}

.camera-side-btn[aria-pressed="true"] {
  color: #ffd84d;
}

.camera-side-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.shutter {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  padding: 0;
  border: 4px solid #fff;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.shutter span {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  transition: transform 100ms ease;
}

.shutter:active span {
  transform: scale(0.9);
}

.shutter:disabled {
  opacity: 0.5;
}

.shutter[data-mode="calibrate"] span {
  background: #ffd84d;
}

/* ---------- Crop ---------- */

.screen--crop {
  max-width: 900px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow-y: auto;
}

/* The stage takes the leftover height; the image box is sized from it in JS
   and positioned absolutely so it never feeds back into the stage's size. */
.crop-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 240px;
  border-radius: var(--radius);
  background: #111;
  overflow: hidden;
  touch-action: none;
}

.crop-image {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.crop-image canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.region {
  position: absolute;
  border: 3px solid #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 70%), 0 0 0 100vmax rgb(0 0 0 / 35%);
  cursor: move;
  touch-action: none;
}

.region--patch {
  border-style: dashed;
  border-color: #ffd84d;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 70%);
}

.region:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.region-label {
  position: absolute;
  top: -1.9em;
  left: -3px;
  padding: 0.125rem 0.5rem;
  border-radius: 6px;
  background: rgb(0 0 0 / 70%);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

.region-handle {
  position: absolute;
  right: -16px;
  bottom: -16px;
  width: 32px;
  height: 32px;
  cursor: nwse-resize;
  touch-action: none;
}

.region-handle::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgb(0 0 0 / 60%);
}

.region--patch .region-handle::after {
  background: #ffd84d;
}

.crop-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem;
}

.numeric-crop summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.numeric-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem 0.75rem;
  padding: 0.5rem 0;
}

.numeric-fields fieldset {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.numeric-fields legend {
  font-weight: 600;
  font-size: 0.875rem;
}

/* ---------- Forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-label {
  font-weight: 650;
}

.optional {
  color: var(--text-muted);
  font-weight: 400;
}

input[type="text"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

textarea {
  resize: vertical;
}

.small-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.small-label input {
  min-height: 44px;
  /* iOS Safari zooms the page when a field under 16px gets focus. */
  font-size: 1rem;
}

.choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.25rem 0;
  cursor: pointer;
}

.choice input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

/* Color picker */

.picker {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.picker-list {
  display: grid;
  gap: 0.25rem;
  max-height: min(46vh, 420px);
  overflow-y: auto;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overscroll-behavior: contain;
}

.picker-option {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}

.picker-option:has(input:checked) {
  background: var(--accent-soft);
}

.picker-option input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.picker-option small {
  display: block;
  color: var(--text-muted);
}

.picker-empty {
  padding: 1rem;
  color: var(--text-muted);
}

/* ---------- Swatches ---------- */

.swatch {
  display: inline-block;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 18%);
}

@media (prefers-color-scheme: dark) {
  .swatch {
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 22%);
  }
}

.swatch--sm {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

/* ---------- Results ---------- */

.result-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.result-hero {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hero-swatch {
  display: flex;
  height: clamp(140px, 30vh, 240px);
  overflow: hidden;
  border-radius: 22px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgb(0 0 0 / 12%);
}

.hero-swatch > span {
  display: block;
  height: 100%;
}

.eyebrow {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-name {
  font-size: clamp(2rem, 9vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  outline: none;
}

.result-summary {
  display: grid;
  gap: 0.75rem;
}

.group-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.group-row .icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.group-row strong {
  display: block;
  font-size: 1.375rem;
}

.group-row span {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.confidence {
  display: grid;
  gap: 0.375rem;
}

.confidence-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  font-weight: 650;
}

.confidence-meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.confidence-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.confidence[data-level="Low"] .confidence-meter span {
  background: var(--warn);
}

.info-btn {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.confidence-note {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.messages {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-size: 0.9375rem;
}

.message .icon {
  margin-top: 0.125rem;
}

.message--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.message--ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.message-action {
  margin-left: auto;
}

.section-title {
  font-size: 1rem;
  font-weight: 750;
}

.list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
}

.list-item .grow {
  flex: 1;
  min-width: 0;
}

.list-item .meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.values {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.values dt {
  color: var(--text-muted);
}

.values dd {
  margin: 0;
  font-family: var(--mono);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented button {
  min-height: 40px;
  padding: 0 0.875rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: var(--shadow);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.disclaimer {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.correction-note {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 600;
}

/* ---------- Settings ---------- */

.settings-section {
  display: grid;
  gap: 0.75rem;
}

.settings-section h3 {
  font-size: 1.0625rem;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.override-grid {
  display: grid;
  gap: 0.5rem;
}

.override-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(11.5rem, 55%);
  align-items: center;
  gap: 0.625rem;
}

.override-row select {
  min-height: 44px;
  padding: 0.25rem 0.5rem;
}

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.75rem;
  font-weight: 700;
}

.badge--ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.gates {
  display: grid;
  gap: 0.375rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9375rem;
}

.gates li {
  display: flex;
  gap: 0.5rem;
}

.gate-fail {
  color: var(--warn);
}

/* ---------- Debug ---------- */

.debug {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.debug summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  font-weight: 700;
  cursor: pointer;
}

.debug-body {
  display: grid;
  gap: 1rem;
  padding: 0 1rem 1rem;
  font-size: 0.8125rem;
}

.debug-canvases {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.debug-canvases figure {
  margin: 0;
}

.debug-canvases canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  image-rendering: pixelated;
  background: #111;
}

.debug-canvases figcaption {
  color: var(--text-muted);
}

.debug table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.debug th,
.debug td {
  padding: 0.25rem 0.375rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.debug pre {
  margin: 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Overlay, dialog, toast ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(0 0 0 / 55%);
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-width: 220px;
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 650;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.dialog {
  width: min(92vw, 460px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 55%);
}

.dialog-form {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

.dialog-body {
  display: grid;
  gap: 0.75rem;
  color: var(--text-muted);
}

.dialog-body img {
  max-width: 100%;
  max-height: 40vh;
  border-radius: var(--radius-sm);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 60;
  width: max-content;
  max-width: min(92vw, 520px);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  font-weight: 600;
  transform: translateX(-50%);
}

@media (min-width: 720px) {
  .screen {
    padding-top: calc(24px + var(--safe-top));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .camera-target,
  .region {
    forced-color-adjust: none;
  }
}
