:root {
  color-scheme: dark;
  font: 100%/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  --page: #0f0d0e;
  --surface: #191618;
  --raised: #221e21;
  --tint: #2a2428;
  --ink: #f5edf0;
  --muted: #c2b7bb;
  --line: #393136;
  --line-strong: #83757c;
  --accent: #ff9eab;
  --accent-soft: #3b1e28;
  --accent-fill: #c62843;
  --accent-hover: #cc2b47;
  --danger: #ffb7c1;
  --danger-surface: #381b23;
  --shadow: 0 2px 10px #0004;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #f7f4f3;
  --surface: #fff;
  --raised: #fcf9f9;
  --tint: #f2ecec;
  --ink: #211c1e;
  --muted: #655c5e;
  --line: #e6dcde;
  --line-strong: #9b878d;
  --accent: #a8172f;
  --accent-soft: #f8e7eb;
  --accent-fill: #a8172f;
  --accent-hover: #891328;
  --danger: #941a30;
  --danger-surface: #fcecef;
  --shadow: 0 1px 3px #21181b0a, 0 4px 14px #21181b08;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--page); color: var(--ink); }
[hidden] { display: none !important; }
::selection { color: var(--ink); background: var(--accent-soft); }
.wrap { width: min(100% - 2rem, 66rem); margin-inline: auto; }

.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-inner {
  display: flex;
  min-height: 69px;
  padding-block: .65rem;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: var(--ink);
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -.05em;
  line-height: 1;
  text-decoration: none;
}
.brand img { display: block; flex-shrink: 0; border-radius: .4rem; }
.brand-accent { color: var(--accent); }

main.wrap { padding-block: clamp(1.65rem, 5vw, 3.25rem) 2rem; }
.intro { margin-bottom: clamp(1.25rem, 3vw, 1.85rem); }
h1 { margin: 0; font-size: clamp(2rem, 5vw, 2.85rem); font-weight: 760; letter-spacing: -.058em; line-height: 1.1; }
.intro p { color: var(--muted); line-height: 1.55; margin: .55rem 0 0; }
.scanner-layout { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); align-items: start; gap: 1rem; }
.scanner-side { display: grid; gap: .8rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); padding: clamp(.85rem, 2.5vw, 1.25rem); }
.camera-panel h2, .manual label, .choices h2 { font-size: 1.05rem; font-weight: 730; letter-spacing: -.02em; }
.camera-panel h2, .choices h2 { margin: 0 0 .75rem; }

.preview {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 10.5rem;
  aspect-ratio: 16 / 9;
  background: #160f13;
  border: 1px solid #55404a;
  border-radius: 11px;
  isolation: isolate;
}
.preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, #37212e 0%, #160f1370 69%),
    repeating-linear-gradient(90deg, transparent 0 27px, #eab2c014 27px 28px),
    repeating-linear-gradient(0deg, transparent 0 27px, #eab2c014 27px 28px);
}
.preview video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.preview.has-camera::before, .preview.has-camera .symbol { display: none; }
.viewfinder {
  position: absolute;
  inset: 21% 13%;
  z-index: 1;
  border: 1px solid #ffb6bf52;
  border-radius: 13px;
  color: #ffb6bf;
  pointer-events: none;
}
.viewfinder::before, .viewfinder::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 2px solid currentColor;
  border-radius: inherit;
  clip-path: polygon(0 0, 24px 0, 24px 2px, 2px 2px, 2px 24px, 0 24px);
  filter: drop-shadow(0 1px 2px #0f0d0e);
}
.viewfinder::after { transform: rotate(180deg); }
.preview.has-camera .viewfinder {
  background: linear-gradient(transparent calc(50% - 1px), #ff9eabc7 50%, transparent calc(50% + 1px));
  box-shadow: 0 0 0 100vmax #100d1175;
}
.symbol {
  position: relative;
  width: min(30%, 6.1rem);
  height: clamp(1.55rem, 4vw, 2.3rem);
  background: repeating-linear-gradient(90deg, #ffc5ce 0 2px, transparent 2px 5px, #ffc5ce 5px 6px, transparent 6px 9px, #ffc5ce 9px 13px, transparent 13px 15px, #ffc5ce 15px 17px, transparent 17px 21px);
  opacity: .84;
}

.controls { position: relative; display: flex; flex-wrap: wrap; gap: .65rem; margin-top: .8rem; }
.controls > :is(button, label) { flex: 1 1 11rem; }
button, .file-button, .workbook {
  appearance: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  min-height: 45px;
  padding: .6rem .85rem;
  border: 1px solid transparent;
  border-radius: 9px;
  font: inherit;
  font-size: .91rem;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.primary { color: #fff; background: var(--accent-fill); border-color: var(--accent-fill); box-shadow: 0 2px 6px #3b0a1940; }
.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary, .workbook { color: var(--ink); background: var(--raised); border-color: var(--line-strong); }
.secondary:hover:not(:disabled):not([aria-disabled="true"]), .workbook:hover { background: var(--tint); border-color: var(--accent); }
.workbook { min-height: 40px; white-space: nowrap; }
.workbook span { color: var(--accent); }
button:disabled, [aria-disabled="true"] { opacity: .62; cursor: default; }
#photo-file { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
.controls:has(#photo-file:focus-visible) .file-button,
:is(a, button, input, select, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.manual-controls { display: grid; gap: .65rem; margin-top: .7rem; }
.manual-controls input, .footer select { font: inherit; color: var(--ink); background: var(--raised); border: 1px solid var(--line-strong); border-radius: 9px; }
.manual-controls input { width: 100%; min-width: 0; min-height: 45px; font-variant-numeric: tabular-nums; padding: .6rem .7rem; }
.manual-controls input::placeholder { color: var(--muted); opacity: 1; }
.manual-controls input[aria-invalid="true"] { border-color: var(--danger); }
.access-note { margin: 0; padding: .8rem .9rem; color: var(--muted); background: var(--raised); border: 1px solid var(--line); border-radius: 11px; font-size: .9rem; }
.feedback { margin: .85rem 0 0; color: var(--muted); overflow-wrap: anywhere; }
.feedback:empty { margin: 0; }
.feedback[data-level="error"]:not(:empty) { padding: .65rem .8rem; border-radius: 9px; background: var(--danger-surface); color: var(--danger); }
.choices { margin-top: .85rem; }
.choices ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .55rem; }
.choices button { width: 100%; justify-content: flex-start; text-align: left; line-height: 1.4; overflow-wrap: anywhere; }
.footer { display: flex; align-items: center; justify-content: flex-end; gap: .55rem; margin-top: 1.15rem; color: var(--muted); font-size: .85rem; }
.footer select { min-height: 38px; padding: .35rem .5rem; }

@media (max-width: 44rem) {
  .scanner-layout { grid-template-columns: 1fr; }
}

@media (max-width: 29rem) {
  .controls > :is(button, label) { flex-basis: 100%; }
  .preview { min-height: 9.5rem; }
}
