@import url("tokens.css");

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.72;
  word-break: keep-all;
  overflow-wrap: normal;
  letter-spacing: 0.002em;
}

img { max-width: 100%; height: auto; display: block; }

a { color: var(--color-accent-deep); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--color-accent); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.24;
  letter-spacing: -0.012em;
  margin: 0 0 var(--space-4);
  text-wrap: balance;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-lg); }
p { margin: 0 0 var(--space-4); }
small { font-size: var(--text-xs); color: var(--color-muted); }

.wrap { width: min(100% - clamp(56px, 9.4vw, 130px), var(--maxw)); margin-inline: auto; }
.prose { max-width: var(--maxw-prose); }
.muted { color: var(--color-muted); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin: 0 0 var(--space-3);
}
.lead { font-size: var(--text-lg); color: var(--color-muted); max-width: 44ch; }
hr.rule { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-8) 0; opacity: 0.6; }

/* ---------- header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-5); min-height: 60px;
}
.brand {
  display: inline-flex; align-items: baseline; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  color: var(--color-fg); text-decoration: none; white-space: nowrap;
}
.brand b { color: var(--color-accent); font-weight: 700; }
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--color-accent); transform: translateY(-2px);
}
.tabs { display: flex; gap: var(--space-5); list-style: none; margin: 0; padding: 0; }
.tabs a {
  display: inline-block; padding: 18px 0 16px;
  font-size: var(--text-sm); color: var(--color-muted); text-decoration: none;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--color-fg); }
.tabs a[aria-current="page"] { color: var(--color-fg); border-bottom-color: var(--color-accent); }

/* ---------- hero ---------- */
.hero { position: relative; overflow: hidden; padding: var(--space-9) 0 var(--space-8); }
.hero::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(0deg, var(--color-grid) 0 1px, transparent 1px 8px),
    repeating-linear-gradient(90deg, var(--color-grid) 0 1px, transparent 1px 8px),
    repeating-linear-gradient(0deg, var(--color-grid-strong) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, var(--color-grid-strong) 0 1px, transparent 1px 40px);
  opacity: 0.42;
  -webkit-mask-image: linear-gradient(to right, #000 0%, #000 55%, transparent 92%);
  mask-image: linear-gradient(to right, #000 0%, #000 55%, transparent 92%);
  pointer-events: none;
}
.hero .wrap { position: relative; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); gap: var(--space-7); align-items: center; }
.hero h1 { margin-bottom: var(--space-5); }
.hero h1 span { color: var(--color-accent-deep); }
.hero .cta-row { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-5); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: var(--radius-md);
  font-size: var(--text-sm); text-decoration: none; border: 1px solid transparent;
}
.btn-primary { background: var(--color-accent); color: var(--color-on-accent); box-shadow: var(--shadow-soft); }
.btn-primary:hover { background: var(--color-accent-deep); color: var(--color-on-accent); }
.btn-ghost { border-color: var(--color-border); color: var(--color-fg); background: var(--color-surface); }
.btn-ghost:hover { border-color: var(--color-accent); color: var(--color-accent-deep); }

.printout {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: 10px; box-shadow: var(--shadow-deep);
  transform: rotate(-1.4deg);
}
.printout img { border-radius: 2px; }
.printout figcaption { margin-top: 8px; font-size: var(--text-xs); color: var(--color-muted); text-align: right; }

/* ---------- stat strip ---------- */
.stats { border-block: 1px solid var(--color-border); }
.stats .wrap { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat {
  padding: var(--space-5) var(--space-4);
  border-left: 1px solid var(--color-border);
}
.stat:first-child { border-left: 0; padding-left: 0; }
.stat .v { font-family: var(--font-mono); font-size: 1.5rem; font-variant-numeric: tabular-nums; color: var(--color-accent-deep); }
.stat .k { font-size: var(--text-xs); color: var(--color-muted); margin-top: 2px; }

/* ---------- sections ---------- */
.section { padding: var(--space-8) 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-5); border-bottom: 1px solid var(--color-border); padding-bottom: var(--space-3); margin-bottom: var(--space-6); }
.section-head h2 { margin: 0; }
.section-head .idx { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-muted); }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-5); }
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-soft);
}
.card h3 { margin-bottom: var(--space-2); }
.card p:last-child { margin-bottom: 0; }
.card .n { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-accent); }

.figure { margin: var(--space-5) 0 var(--space-7); }
.figure img { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.figure figcaption { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--color-muted); max-width: 78ch; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-6); align-items: start; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: var(--space-4) 0 var(--space-6); }
table.data caption { text-align: left; font-size: var(--text-xs); color: var(--color-muted); padding-bottom: var(--space-2); }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--color-border); }
table.data th { font-weight: 700; font-size: var(--text-xs); letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-muted); }
table.data td.num { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table.data { min-width: 520px; }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-cell .track { flex: 1; height: 6px; background: var(--color-surface-alt); border-radius: 3px; overflow: hidden; }
.bar-cell .fill { height: 100%; background: var(--color-accent); }

.callout {
  background: #FBEDE4; border: 1px solid var(--color-accent-soft);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5); margin: var(--space-6) 0; box-shadow: var(--shadow-soft);
}
.callout h3 { color: var(--color-accent-deep); }
.callout h3 { font-size: var(--text-base); margin-bottom: var(--space-2); }
.callout p:last-child { margin-bottom: 0; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--color-border); background: var(--color-surface-alt);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-muted);
}
.tag.warn { border-color: var(--color-accent-soft); color: var(--color-accent-deep); background: #FBEDE4; }

/* ---------- demo ---------- */
.demo-shell { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); gap: var(--space-6); align-items: start; }
.dropzone {
  border: 1.5px dashed var(--color-border); border-radius: var(--radius-lg);
  background: var(--color-surface); padding: var(--space-7) var(--space-5);
  text-align: center; box-shadow: var(--shadow-soft);
}
.dropzone.is-dragover { border-color: var(--color-accent); background: #FBEDE4; }
.dropzone h3 { margin-bottom: var(--space-2); }
.dropzone .hint { font-size: var(--text-sm); color: var(--color-muted); margin-bottom: var(--space-4); }
.samples { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); margin-top: var(--space-4); }
.samples button {
  padding: 0; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); cursor: pointer; overflow: hidden; box-shadow: var(--shadow-soft);
}
.samples button img { width: 100%; }
.samples button:hover { border-color: var(--color-accent); }

.result-panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-soft); }
.result-panel h3 { font-size: var(--text-base); }
.result-list { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; gap: 10px; }
.result-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; font-size: var(--text-sm); }
.result-list .track { grid-column: 1 / -1; height: 6px; background: var(--color-surface-alt); border-radius: 3px; position: relative; }
.result-list .track .cutoff { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--color-muted); opacity: 0.6; border-radius: 1px; pointer-events: none; }
.result-list li.is-positive .mono { font-weight: 700; color: var(--color-accent-deep); }
.cutoff-legend { font-size: var(--text-xs); color: var(--color-muted); margin: var(--space-3) 0 var(--space-4); }
.fineprint { margin-top: var(--space-7); border-top: 1px solid var(--color-border); padding-top: var(--space-4);
  font-size: var(--text-xs); color: var(--color-muted); }
.fineprint summary { cursor: pointer; color: var(--color-muted); font-weight: 600; }
.fineprint summary:hover { color: var(--color-fg); }
.fineprint p { margin: var(--space-3) 0 0; line-height: 1.7; }
.fineprint code { font-size: 0.95em; }
.result-list .fill { height: 100%; background: var(--color-accent-soft); transition: width 180ms ease; }
.result-list li { cursor: pointer; border-radius: var(--radius-sm); padding: 2px 4px; margin: -2px -4px; }
.result-list li:hover { background: var(--color-surface-alt); }
.result-list li.is-top { font-weight: 700; }
.result-list li.is-top .fill { background: var(--color-accent); }
.cam-figure { margin-top: var(--space-5); border-top: 1px solid var(--color-border); padding-top: var(--space-4); }
.cam-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: var(--text-xs); color: var(--color-muted); margin-bottom: var(--space-2); }
.cam-controls select { font: inherit; padding: 4px 6px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-fg); max-width: 100%; }
.cam-check { display: inline-flex; align-items: center; gap: 5px; }
#cam { width: 100%; max-width: 420px; height: auto; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface-alt); display: block; }
.status-note { font-size: var(--text-sm); color: var(--color-muted); }
.preview { margin-top: var(--space-4); }
.preview img { border: 1px solid var(--color-border); border-radius: var(--radius-sm); }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--color-border); padding: var(--space-7) 0 var(--space-8); font-size: var(--text-sm); color: var(--color-muted); }
.site-footer .wrap { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--space-6); }
.site-footer a { color: var(--color-muted); }
.site-footer a:hover { color: var(--color-accent-deep); }
.footer-meta { font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.9; }
.footer-note { max-width: 52ch; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .hero { padding: var(--space-7) 0 var(--space-6); }
  .hero .wrap { grid-template-columns: 1fr; }
  .printout { transform: none; }
  .stats .wrap { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards { grid-template-columns: 1fr; }
  .grid-2, .demo-shell { grid-template-columns: 1fr; }
  .tabs { gap: var(--space-4); }
  .tabs a { font-size: var(--text-xs); }
  .site-footer .wrap { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .brand span.full { display: none; }
  .samples { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  table.data { font-size: 0.9rem; }
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; top: 8px; z-index: 60;
  background: var(--color-surface); border: 1px solid var(--color-accent);
  padding: 8px 14px; border-radius: var(--radius-md); font-size: var(--text-sm);
}
.skip-link:focus {
  width: auto; height: auto; clip-path: none; overflow: visible; left: 16px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
