/* DigitLens: an exercise-book page that a neural network reads. */

:root {
  --paper: #F1F4FA;
  --sheet: #FFFFFF;
  --grid: #DDE6F4;
  --rule: #D3DBE9;
  --ink: #2340B8;
  --ink-wash: rgba(35, 64, 184, 0.10);
  --text: #1A2030;
  --muted: #566075;
  --margin: #D9434A;
  --marker: #FFE164;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0C1220;
    --sheet: #121A2C;
    --grid: #1D2842;
    --rule: #26324D;
    --ink: #92ACFF;
    --ink-wash: rgba(146, 172, 255, 0.12);
    --text: #E4E8F1;
    --muted: #9AA4B9;
    --margin: #F07479;
    --marker: rgba(255, 213, 74, 0.34);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0C1220;
  --sheet: #121A2C;
  --grid: #1D2842;
  --rule: #26324D;
  --ink: #92ACFF;
  --ink-wash: rgba(146, 172, 255, 0.12);
  --text: #E4E8F1;
  --muted: #9AA4B9;
  --margin: #F07479;
  --marker: rgba(255, 213, 74, 0.34);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 16px;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- header ---------- */

.site-header {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.wordmark svg { width: 30px; height: 30px; }
.wordmark rect { fill: var(--ink); }
.wordmark path { fill: none; stroke: var(--sheet); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }

.site-header nav { display: flex; gap: 22px; flex-wrap: wrap; }
.site-header nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.site-header nav a:hover { color: var(--text); }

/* ---------- intro ---------- */

main { max-width: 1120px; margin: 0 auto; }

.intro { padding: 12px 0 32px; }
.intro h1 {
  margin: 0 0 12px;
  max-width: 24ch;
  font-size: clamp(32px, 4.4vw, 50px);
  line-height: 1.04;
  font-weight: 800;
  letter-spacing: -0.025em;
}
.intro p { margin: 0; max-width: 60ch; color: var(--muted); font-size: 19px; }

/* ---------- workbench ---------- */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 540px) minmax(0, 1fr);
  gap: 56px;
  align-items: start;
}

/* keep the page and its buttons on one screen, so the demo works on a projector */
.page-wrap { position: relative; width: min(100%, max(340px, 100svh - 380px)); }

/* the sheet underneath, slightly askew */
.page-wrap::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  aspect-ratio: 1;
  background: var(--sheet);
  border: 1px solid var(--rule);
  transform: rotate(-2.2deg) translate(-6px, 6px);
  border-radius: 3px;
}

.page {
  position: relative;
  aspect-ratio: 1;
  background-color: var(--sheet);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 5% 5%;
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 18px 30px -24px rgba(20, 40, 100, 0.45);
}

/* red margin line of an exercise book */
.page::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 10%;
  width: 2px;
  background: var(--margin);
  opacity: 0.55;
}

#pad {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.pad-hint {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  font-family: var(--hand);
  font-size: clamp(30px, 4.4vw, 44px);
  font-weight: 500;
  color: var(--muted);
  opacity: 0.6;
  transform: rotate(-4deg);
  pointer-events: none;
}

.sample-tag {
  position: absolute;
  top: 10px;
  right: 16px;
  margin: 0;
  font-family: var(--hand);
  font-size: 26px;
  font-weight: 600;
  color: #15803D;
  transform: rotate(-3deg);
  pointer-events: none;
}
.sample-tag.is-wrong { color: var(--margin); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sample-tag:not(.is-wrong) { color: #5EDB8C; }
}
:root[data-theme="dark"] .sample-tag:not(.is-wrong) { color: #5EDB8C; }

.pad-actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--sheet);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; color: var(--ink); }
.btn-quiet:hover { background: var(--ink-wash); filter: none; }
.btn:disabled { opacity: 0.45; cursor: progress; }

/* ---------- reading panel ---------- */

.reading { display: grid; gap: 30px; }

.verdict {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 28px;
  align-items: end;
  isolation: isolate;
}
.verdict p { margin: 0; }
.verdict-label { grid-column: 1 / -1; font-weight: 700; color: var(--muted); margin-bottom: 4px !important; }

.big-digit {
  position: relative;
  min-width: 0.62em;
  text-align: center;
  font-size: clamp(132px, 15vw, 196px);
  font-weight: 800;
  line-height: 0.84;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
/* highlighter swipe behind the answer */
.big-digit::after {
  content: "";
  position: absolute;
  left: -14%;
  right: -14%;
  bottom: 4%;
  height: 30%;
  background: var(--marker);
  border-radius: 3px 10px 4px 12px;
  transform: rotate(-4deg);
  z-index: -1;
}
.big-digit.is-empty { color: var(--rule); }
.big-digit.is-empty::after { display: none; }

.confidence { font-size: 22px; font-weight: 700; line-height: 1.3; padding-bottom: 10px; }
.confidence.is-unsure { font-size: 17px; font-weight: 500; color: var(--margin); }

.models { border: 0; margin: 0; padding: 0; min-width: 0; }
.models legend, .probabilities h2 {
  padding: 0;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}

.model-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.model-option {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 10px 14px 12px;
  border: 1.5px solid var(--rule);
  border-radius: 12px;
  background: var(--sheet);
  cursor: pointer;
}
.model-option input { position: absolute; opacity: 0; pointer-events: none; }
.model-option:has(input:checked) { border-color: var(--ink); background: var(--ink-wash); }
.model-option:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }
.mo-name { font-size: 14px; font-weight: 700; line-height: 1.25; }
.mo-guess { font-size: 34px; font-weight: 800; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; }
.mo-conf { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.bars li {
  display: grid;
  grid-template-columns: 1.6em 1fr 4.2em;
  align-items: center;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}
.bars .d { font-weight: 700; text-align: center; border-radius: 4px; }
.bars .track { height: 12px; background: var(--grid); border-radius: 6px; overflow: hidden; }
.bars .fill { display: block; height: 100%; width: 0; background: var(--ink); opacity: 0.32; transition: width 140ms ease-out; }
.bars .pct { text-align: right; font-size: 15px; color: var(--muted); }
.bars li.top .d { background: var(--marker); }
.bars li.top .fill { opacity: 1; }
.bars li.top .pct { color: var(--text); font-weight: 700; }

.eye { margin: 0; display: grid; grid-template-columns: 132px 1fr; gap: 18px; align-items: center; }
#mosaic {
  width: 132px;
  aspect-ratio: 1;
  background-color: var(--sheet);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: calc(100% / 28) calc(100% / 28);
  border: 1px solid var(--rule);
  image-rendering: pixelated;
}
.eye figcaption { font-size: 15px; color: var(--muted); max-width: 42ch; }

.status { text-align: center; color: var(--muted); margin: 24px 0 0; }
.status.is-error { color: var(--margin); font-weight: 700; }

/* ---------- how it works ---------- */

.how, .results { padding-top: 110px; }
.how h2, .results h2 {
  margin: 0 0 28px;
  font-size: 32px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.015em;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: step;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 32px;
}
.steps li { counter-increment: step; border-top: 2px solid var(--rule); padding-top: 8px; }
.steps li::before {
  content: counter(step);
  display: block;
  font-family: var(--hand);
  font-size: 60px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}
.steps h3 { margin: 8px 0 6px; font-size: 19px; line-height: 1.3; }
.steps p { margin: 0; color: var(--muted); font-size: 16px; }

/* ---------- results ---------- */

.results .lede { margin: -12px 0 28px; max-width: 64ch; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 640px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--rule); }
thead th { font-size: 14px; font-weight: 700; color: var(--muted); }
tbody th { font-weight: 700; white-space: nowrap; }
td { color: var(--muted); }
.num { text-align: right; }
tr.best td.num { color: var(--text); font-weight: 700; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 10px; vertical-align: 1px; }

.figures { display: grid; grid-template-columns: 1.65fr 1fr; gap: 28px; margin-top: 40px; align-items: start; }
.figures figure { margin: 0; }
.figures img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px;
}
.figures figcaption { margin-top: 10px; font-size: 15px; color: var(--muted); }

/* ---------- footer ---------- */

.site-footer {
  max-width: 1120px;
  margin: 110px auto 0;
  padding: 28px 0 48px;
  border-top: 1px solid var(--rule);
  font-size: 15px;
  color: var(--muted);
}
.site-footer p { margin: 0 0 6px; }

/* ---------- responsive ---------- */

@media (max-width: 920px) {
  .workbench { grid-template-columns: minmax(0, 1fr); gap: 44px; }
  .page-wrap { width: min(100%, 540px); margin: 0 auto; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figures { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .intro p { font-size: 17px; }
  .steps { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .model-option { padding: 8px 10px 10px; }
  .mo-name { font-size: 13px; }
  .mo-guess { font-size: 28px; }
  .eye { grid-template-columns: 104px 1fr; }
  #mosaic { width: 104px; }
  .how, .results { padding-top: 80px; }
}

@media (prefers-reduced-motion: reduce) {
  .bars .fill { transition: none; }
}
