:root {
  color-scheme: dark;
  --bg: #0d1f1a;
  --panel: #12332a;
  --ink: #f2f6f3;
  --muted: #9fb5ab;
  --accent: #e8b923;
  --good: #48b06a;
  --bad: #d4574a;
  --line: #26564733;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header { text-align: center; }
h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; }
.sub { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }
main { flex: 1; display: flex; flex-direction: column; gap: 0.75rem; }

.stage {
  position: relative;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  aspect-ratio: 3 / 4;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.stage video, .stage img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: none;
}
.stage.live video, .stage.photo img { display: block; }
.stage.live .placeholder, .stage.photo .placeholder { display: none; }
.placeholder { color: var(--muted); padding: 1rem; text-align: center; font-size: 0.9rem; }

.guide { position: absolute; border: 2px dashed rgba(255,255,255,0.65); border-radius: 0.3rem; pointer-events: none; }
.guide[hidden] { display: none; }
.corner { position: absolute; width: 1.1rem; height: 1.1rem; border: 3px solid var(--accent); }
.corner.tl { top: -3px; left: -3px; border-right: 0; border-bottom: 0; }
.corner.tr { top: -3px; right: -3px; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: -3px; left: -3px; border-right: 0; border-top: 0; }
.corner.br { bottom: -3px; right: -3px; border-left: 0; border-top: 0; }
.guide.hit { border-color: var(--good); }

.status { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.8rem; min-height: 1.1em; }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }

.controls { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
button, .filebtn {
  font: inherit;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button.primary, .filebtn.primary { background: var(--accent); color: #221c00; border-color: transparent; font-weight: 600; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0.3rem; }
button[hidden] { display: none; }




.meta { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.85rem; }








footer { display: flex; align-items: center; justify-content: center; gap: 0.6rem; }
.count { color: var(--muted); font-size: 0.8rem; }
#exportOut {
  max-width: 30rem; margin: 0 auto; width: 100%; white-space: pre-wrap; word-break: break-all;
  background: #0b1a16; border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.75rem;
  font-size: 0.75rem; color: var(--muted); max-height: 14rem; overflow: auto;
}
#exportOut[hidden] { display: none; }

.build {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  opacity: 0.75;
}
.updatebar {
  position: fixed;
  left: 50%;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--accent);
  color: #221c00;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.6rem 0.5rem 0.9rem;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.updatebar[hidden] { display: none; }
.updatebar button {
  font: inherit;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 0;
  background: #221c00;
  color: var(--accent);
}

/* Live readout: always on screen, never in the way of the camera. */
.readout {
  max-width: 30rem;
  width: 100%;
  margin: 0 auto;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 0.6rem;
  background: var(--panel);
}
.readout.idle { border-left-color: #3a5a4e; }
.readout.reading { border-left-color: var(--accent); }
.readout.good { border-left-color: var(--good); }
.readout.newcard { border-left-color: #4f9bd9; }

.rowtop { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; }
.rname {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.rstate { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
.readout.good .rstate { color: var(--good); }

.rowsub { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; margin-top: 0.2rem; min-height: 1.1rem; }
.rid { color: var(--muted); font-size: 0.8rem; }
.rpattern {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.enrol { margin-top: 0.6rem; }
.enrol label { display: block; color: var(--muted); font-size: 0.8rem; margin-bottom: 0.3rem; }
.enrolrow { display: flex; gap: 0.4rem; }
.enrolrow input {
  flex: 1; min-width: 0; font: inherit; padding: 0.5rem 0.6rem;
  border-radius: 0.45rem; border: 1px solid var(--line); background: #0b1a16; color: var(--ink);
}
.enrol[hidden] { display: none; }

/* A desktop webcam is landscape; letterboxing it into a portrait stage
   wastes most of the preview when building the card database at a desk. */
@media (min-width: 56rem) {
  .stage { aspect-ratio: 4 / 3; max-width: 44rem; }
}
