:root {
  color-scheme: dark;
  --ink: #f4f1e8;
  --muted: #a5aa9f;
  --surface: #171a16;
  --surface-raised: #20241e;
  --line: rgba(244, 241, 232, 0.12);
  --acid: #c9ff59;
  --acid-dark: #182205;
  --warning: #ffc85a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 75% 12%, rgba(201, 255, 89, 0.08), transparent 30rem),
    #10120f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }

.shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 56px;
}

.topbar {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 34px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #10120f;
  background: var(--acid);
  border-radius: 4px 10px 4px 4px;
  font-family: Georgia, serif;
  font-size: 23px;
  font-weight: 800;
  transform: rotate(-3deg);
}

.model-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #dce3d5;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.model-chip > span:last-child {
  color: var(--muted);
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--acid);
  box-shadow: 0 0 12px var(--acid);
}

.hero {
  display: grid;
  grid-template-columns: 0.82fr 1.18fr;
  gap: clamp(36px, 6vw, 92px);
  align-items: center;
  padding: 72px 0 58px;
}

.eyebrow {
  margin: 0 0 18px;
  color: var(--acid);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(49px, 6vw, 84px);
  font-weight: 500;
  line-height: 0.94;
  letter-spacing: -0.055em;
}

h1 em {
  color: var(--acid);
  font-weight: 500;
}

.lede {
  max-width: 520px;
  margin: 26px 0 30px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.result-card {
  max-width: 465px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.result-card > div:first-child {
  display: flex;
  align-items: center;
  gap: 16px;
}

.result-label {
  width: 62px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.11em;
}

#resultDigit {
  min-width: 46px;
  color: var(--acid);
  font-family: Georgia, serif;
  font-size: 57px;
  line-height: 0.8;
  text-align: center;
}

.confidence-block {
  width: min(185px, 45%);
  color: var(--muted);
  font-size: 12px;
}

.confidence-track {
  height: 4px;
  margin-top: 9px;
  overflow: hidden;
  background: #30362d;
  border-radius: 10px;
}

#confidenceBar {
  width: 0;
  height: 100%;
  display: block;
  background: var(--acid);
  border-radius: inherit;
  transition: width 180ms ease;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.actions button {
  min-height: 48px;
  padding: 0 21px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 750;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease;
}

.actions button:hover:not(:disabled) { transform: translateY(-2px); }
.actions button:disabled { cursor: not-allowed; opacity: 0.38; }

.primary-button { color: #10120f; background: var(--acid); }
.secondary-button { color: var(--ink); background: transparent; border-color: var(--line) !important; }

.privacy-note { margin: 12px 0 0; color: #747a70; font-size: 11px; }

.camera-panel {
  padding: 12px 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 35px 80px rgba(0, 0, 0, 0.35);
}

.camera-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #0b0c0a;
  border-radius: 13px;
}

#camera, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#camera { object-fit: cover; }
#overlay { pointer-events: none; }

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  color: #70766d;
  font-size: 13px;
  background: linear-gradient(145deg, #131512, #0b0c0a);
  transition: opacity 200ms ease;
}

.camera-placeholder.hidden { opacity: 0; pointer-events: none; }

.paper-icon {
  width: 82px;
  height: 108px;
  display: grid;
  place-items: center;
  color: #20231e;
  background: #dadbd4;
  border-radius: 4px;
  box-shadow: 10px 12px 0 rgba(201, 255, 89, 0.12);
  transform: rotate(5deg);
}

.paper-icon span { font-family: Georgia, serif; font-size: 60px; transform: rotate(-5deg); }

.viewfinder { position: absolute; inset: 25px; pointer-events: none; }
.viewfinder i { position: absolute; width: 34px; height: 34px; opacity: 0.55; }
.viewfinder i:nth-child(1) { top: 0; left: 0; border-top: 2px solid white; border-left: 2px solid white; }
.viewfinder i:nth-child(2) { top: 0; right: 0; border-top: 2px solid white; border-right: 2px solid white; }
.viewfinder i:nth-child(3) { bottom: 0; right: 0; border-bottom: 2px solid white; border-right: 2px solid white; }
.viewfinder i:nth-child(4) { bottom: 0; left: 0; border-bottom: 2px solid white; border-left: 2px solid white; }

.live-badge {
  position: absolute;
  top: 18px;
  left: 18px;
  padding: 6px 9px;
  color: #d8ddd3;
  background: rgba(12, 14, 11, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.live-badge.active { color: var(--acid); }

.camera-result {
  position: absolute;
  right: 18px;
  bottom: 18px;
  min-width: 112px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: end;
  column-gap: 10px;
  padding: 11px 13px;
  opacity: 0;
  color: var(--ink);
  background: rgba(12, 14, 11, 0.84);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(201, 255, 89, 0.55);
  border-radius: 10px;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.camera-result.visible { opacity: 1; transform: translateY(0); }
.camera-result span { align-self: center; color: var(--acid); font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: 0.12em; }
.camera-result strong { grid-row: 1 / 3; grid-column: 2; color: var(--acid); font-family: Georgia, serif; font-size: 52px; line-height: 0.85; }
.camera-result small { color: #c2c8bd; font-size: 10px; }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 7px 0;
  font-size: 13px;
}

.status-row > div { display: flex; align-items: center; gap: 9px; }
.status-row > span { color: #747a70; font-variant-numeric: tabular-nums; }

.status-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  background: #656a61;
  border-radius: 50%;
}

.status-dot.active { background: var(--acid); box-shadow: 0 0 9px rgba(201, 255, 89, 0.7); }
.status-dot.warning { background: var(--warning); }
.status-message { margin: 7px 7px 0; color: var(--muted); font-size: 12px; }

.debug-panel {
  margin-bottom: 58px;
  padding: clamp(20px, 3vw, 34px);
  background: #141713;
  border: 1px solid var(--line);
  border-radius: 20px;
}

.debug-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.debug-header .eyebrow { margin-bottom: 8px; }

.debug-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(27px, 3vw, 40px);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.debug-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.debug-toggle input { position: absolute; opacity: 0; }

.debug-toggle > span {
  position: relative;
  width: 38px;
  height: 22px;
  background: #30352d;
  border-radius: 20px;
  transition: background 160ms ease;
}

.debug-toggle > span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #91978c;
  border-radius: 50%;
  transition: transform 160ms ease, background 160ms ease;
}

.debug-toggle input:checked + span { background: var(--acid-dark); }
.debug-toggle input:checked + span::after { transform: translateX(16px); background: var(--acid); }

.debug-capture {
  min-height: 40px;
  padding: 0 15px;
  color: var(--acid);
  background: var(--acid-dark);
  border: 1px solid rgba(201, 255, 89, 0.3);
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.debug-capture:disabled { cursor: wait; opacity: 0.5; }

.pipeline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.pipeline-step {
  position: relative;
  min-height: 112px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: start;
  gap: 12px;
  padding: 18px;
  background: #191c18;
  border-right: 1px solid var(--line);
}

.pipeline-step:last-child { border-right: 0; }
.pipeline-step.pass { background: linear-gradient(145deg, rgba(201, 255, 89, 0.08), #191c18 60%); }
.pipeline-step.fail { background: linear-gradient(145deg, rgba(255, 200, 90, 0.08), #191c18 60%); }

.stage-number {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: #8b9187;
  border: 1px solid #444a40;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
}

.pipeline-step.pass .stage-number { color: #10120f; background: var(--acid); border-color: var(--acid); }
.pipeline-step.fail .stage-number { color: #10120f; background: var(--warning); border-color: var(--warning); }
.pipeline-step strong { display: block; margin-top: 4px; font-size: 13px; }
.pipeline-step p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }

.stage-state {
  position: absolute;
  top: 13px;
  right: 13px;
  color: #666c62;
  font-size: 9px;
  font-style: normal;
  font-weight: 850;
  letter-spacing: 0.1em;
}

.pipeline-step.pass .stage-state { color: var(--acid); }
.pipeline-step.fail .stage-state { color: var(--warning); }

.debug-images {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.debug-images figure {
  min-width: 0;
  margin: 0;
  padding: 8px;
  background: #0d0f0c;
  border: 1px solid var(--line);
  border-radius: 11px;
}

.debug-image-wrap {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(45deg, #161914 25%, transparent 25%),
    linear-gradient(-45deg, #161914 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #161914 75%),
    linear-gradient(-45deg, transparent 75%, #161914 75%),
    #10120f;
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border-radius: 7px;
}

.debug-image-wrap img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.debug-image-wrap img.available { display: block; }
.debug-image-wrap.pixelated img { image-rendering: pixelated; }

.debug-images figcaption {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 4px 3px;
}

.debug-images figcaption strong { font-size: 12px; }
.debug-images figcaption span { overflow: hidden; color: #747a70; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.debug-footer {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.diagnostic-message, .debug-footer details {
  padding: 16px 18px;
  background: #191c18;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.diagnostic-message span {
  display: block;
  margin-bottom: 6px;
  color: var(--acid);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

.diagnostic-message strong { font-size: 12px; font-weight: 550; line-height: 1.5; }
.debug-footer summary { color: var(--muted); font-size: 12px; cursor: pointer; }

#rawDebug {
  max-height: 220px;
  overflow: auto;
  margin: 14px 0 0;
  color: #bac3b3;
  font-size: 10px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.tips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.tips article {
  display: flex;
  gap: 16px;
  padding: 24px;
  border-right: 1px solid var(--line);
}

.tips article:last-child { border-right: 0; }
.tips article > span { color: var(--acid); font-family: Georgia, serif; font-size: 24px; }
.tips strong { display: block; margin-bottom: 5px; font-size: 13px; }
.tips p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; padding-top: 50px; }
  .intro { text-align: center; }
  .lede, .result-card { margin-left: auto; margin-right: auto; }
  .actions { justify-content: center; }
  .tips { grid-template-columns: 1fr; }
  .pipeline, .debug-images { grid-template-columns: repeat(2, 1fr); }
  .pipeline-step:nth-child(2) { border-right: 0; }
  .pipeline-step:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .debug-footer { grid-template-columns: 1fr; }
  .tips article { border-right: 0; border-bottom: 1px solid var(--line); }
  .tips article:last-child { border-bottom: 0; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 24px, 1180px); }
  .topbar { min-height: 70px; }
  .model-chip > span:last-child { display: none; }
  .hero { gap: 36px; padding: 42px 0; }
  h1 { font-size: clamp(44px, 14vw, 66px); }
  .result-card { align-items: center; }
  .camera-panel { padding: 7px 7px 13px; border-radius: 16px; }
  .viewfinder { inset: 15px; }
  .debug-header { align-items: start; flex-direction: column; }
  .pipeline, .debug-images { grid-template-columns: 1fr; }
  .pipeline-step { border-right: 0; border-bottom: 1px solid var(--line); }
  .pipeline-step:last-child { border-bottom: 0; }
}
