/* ============================================================
   Traffic Wand — trafficwand.app
   Minimal-modern with a brutalist edge: stark type, hairline
   structure, monospace accents, grain texture.
   ============================================================ */

:root {
  --sans: "Instrument Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #fafaf7;
  --fg: #16161b;
  --muted: #67676f;
  --line: rgba(22, 22, 27, 0.16);
  --line-soft: rgba(22, 22, 27, 0.08);
  --surface: rgba(22, 22, 27, 0.035);
  --accent: #2e3eb8;
  --on-accent: #fafaf7;

  --maxw: 1060px;
  --radius: 3px;
}

/* Dark tokens apply when the user forces dark, or when the preference is
   "system" and the OS is dark. The block is duplicated (forced + system+media)
   because a media query can't be combined with the attribute selector. */
:root[data-theme="dark"] {
  --bg: #0e0f18;
  --fg: #ececf1;
  --muted: #91919e;
  --line: rgba(236, 236, 241, 0.16);
  --line-soft: rgba(236, 236, 241, 0.07);
  --surface: rgba(236, 236, 241, 0.045);
  --accent: #9aa5f0;
  --on-accent: #0e0f18;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0e0f18;
    --fg: #ececf1;
    --muted: #91919e;
    --line: rgba(236, 236, 241, 0.16);
    --line-soft: rgba(236, 236, 241, 0.07);
    --surface: rgba(236, 236, 241, 0.045);
    --accent: #9aa5f0;
    --on-accent: #0e0f18;
  }
}

/* ---------- reset & base ---------- */

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
}

/* grain overlay — the texture that softens the starkness */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.05;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
p { margin: 0; }
a { color: inherit; }
img { max-width: 100%; display: block; }
code { font-family: var(--mono); font-size: 0.92em; }

::selection { background: var(--accent); color: var(--on-accent); }

.container {
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: 24px;
}

/* ---------- type helpers ---------- */

/* Routing visualization stays mono; rule syntax uses <code> (also mono). */
.route-demo {
  font-family: var(--mono);
}

.fineprint {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.section-title {
  font-size: clamp(1.9rem, 4vw, 2.75rem);
  letter-spacing: -0.03em;
  margin-bottom: 3.5rem;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.875rem 1.5rem;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover {
  background: var(--fg);
  color: var(--bg);
}

.btn-ghost {
  border-color: var(--line);
  color: var(--fg);
}
.btn-ghost:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.btn-small { padding: 0.5rem 0.875rem; font-size: 0.75rem; }

.btn svg {
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
  margin-top: -0.1em;
}

.cta-row {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-block: 2.25rem 1.25rem;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.header-inner {
  max-width: var(--maxw);
  margin-inline: auto;
  padding: 0.75rem 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 650;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand img { border-radius: 6px; }

.site-nav {
  display: flex;
  gap: 2rem;
}
.site-nav a {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-decoration: none;
}
.site-nav a:hover { color: var(--fg); }

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ---------- theme switch ---------- */

.theme-switch {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.theme-opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.theme-opt svg { width: 15px; height: 15px; }

.theme-opt:hover { color: var(--fg); }

.theme-opt[aria-pressed="true"] {
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.theme-opt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- hero ---------- */

.hero {
  text-align: center;
  padding-block: clamp(3.75rem, 9vh, 6.5rem) clamp(3.5rem, 7vh, 5.5rem);
}

.hero h1 {
  font-size: clamp(2.75rem, 7.5vw, 5.25rem);
  line-height: 1.04;
  letter-spacing: -0.035em;
  max-width: 16ch;
  margin-inline: auto;
}

.lede {
  max-width: 56ch;
  margin: 1.75rem auto 0;
  font-size: clamp(1.0625rem, 1.6vw, 1.1875rem);
  color: var(--muted);
}

/* ---------- routing demo ---------- */

/* an open typographic diagram — deliberately no card, no chrome */
.route-demo {
  max-width: 540px;
  margin: 5rem auto 0;
  font-size: 0.875rem;
  text-align: left;
}

.route-incoming {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding-bottom: 1.5rem;
}

.route-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.route-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9375rem;
}

.route-rules {
  list-style: none;
  margin: 0;
  padding: 0 0 1.5rem;
}

.route-rules li {
  display: grid;
  grid-template-columns: 2rem minmax(8rem, 1fr) 1.5rem minmax(8rem, 1fr) 1.5rem;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0;
  color: var(--muted);
  transition: color 200ms ease, opacity 200ms ease;
}

.route-no, .route-arrow { color: var(--muted); }
.route-dest { text-align: right; }
.route-state { text-align: right; }

.route-rules li.checking { color: var(--fg); }
.route-rules li.skip { opacity: 0.45; }
.route-rules li.skip code,
.route-rules li.skip .route-dest { text-decoration: line-through; }
.route-rules li.match { color: var(--accent); }
.route-rules li.match .route-state::after { content: "✓"; }

.route-result {
  color: var(--accent);
  min-height: 1.6em;
  font-size: 0.9375rem;
}
.route-result span { opacity: 0; transition: opacity 300ms ease; }
.route-result span.show { opacity: 1; }

/* ---------- sections ---------- */

.how, .features, .faq, .closing {
  border-top: 1px solid var(--line);
  padding-block: clamp(3.25rem, 6vh, 5rem);
}

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

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3rem;
}

.step-no {
  display: block;
  font-size: 0.8125rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 1rem;
}

.steps h3 {
  font-size: 1.1875rem;
  margin-bottom: 0.75rem;
}

.steps p {
  font-size: 0.9375rem;
  color: var(--muted);
}

.rule-chips {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
  align-items: flex-start;
}

.chip {
  font-size: 0.75rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: nowrap;
}
.chip code { color: var(--accent); }

/* ---------- features ---------- */

.feature {
  display: grid;
  grid-template-columns: 5fr 6fr;
  gap: clamp(2.5rem, 5vw, 5rem);
  align-items: center;
  padding-block: clamp(1.75rem, 3.5vh, 2.75rem);
}
.feature + .feature { border-top: 1px solid var(--line-soft); }

/* Mirror the column ratio so the screenshot keeps the wider (6fr) column on
   flipped rows too — every .shot frame stays the same physical width. */
.feature-flip { grid-template-columns: 6fr 5fr; }
.feature-flip .feature-text { order: 2; }
.feature-flip .shot { order: 1; }

.feature h3 {
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  letter-spacing: -0.025em;
  margin-bottom: 1rem;
}

.feature-text p { color: var(--muted); }
.feature-text code {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.0625rem 0.3125rem;
  font-size: 0.85em;
}

/* screenshot frame */
.shot {
  margin: 0;
  position: relative;
  aspect-ratio: 4 / 3;
}
.shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* placeholder state until real screenshots land (aspect-ratio inherited from .shot) */
.shot.missing img { display: none; }
.shot.missing::after {
  content: attr(data-shot);
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  background: url("../assets/icon-512.png") center calc(50% - 3.25rem) / 72px no-repeat;
  padding-top: 5.5rem;
}
@supports (filter: grayscale(1)) {
  .shot.missing::after {
    filter: grayscale(1);
    opacity: 0.55;
  }
}

/* secondary features */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: clamp(1.75rem, 3.5vh, 2.75rem);
}

.mini {
  background: var(--bg);
  padding: 1.375rem 1.25rem;
}
.mini h4 { font-size: 1rem; margin-bottom: 0.625rem; }
.mini p { font-size: 0.875rem; color: var(--muted); }

/* ---------- faq ---------- */

.faq-list { max-width: 760px; }

.faq-list .qa {
  border-top: 1px solid var(--line);
  padding-block: 1.5rem;
}
.faq-list .qa:last-child { border-bottom: 1px solid var(--line); }

.faq-list h3 {
  font-weight: 600;
  font-size: 1.0625rem;
  margin-bottom: 0.625rem;
}

.faq-list p {
  color: var(--muted);
  max-width: 64ch;
}
.faq-list a {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, var(--accent) 50%, transparent);
  transition: text-decoration-color 0.15s ease;
}
.faq-list a:hover {
  text-decoration-color: var(--accent);
}

/* ---------- closing cta ---------- */

.closing { text-align: center; }

.closing h2 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  letter-spacing: -0.035em;
}

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

.site-footer {
  border-top: 1px solid var(--line);
  padding-block: 2.5rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--muted);
}

.footer-inner nav { display: flex; gap: 1.75rem; }
.footer-inner a {
  color: var(--muted);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.footer-inner a:hover { color: var(--fg); }
.footer-inner p a { text-transform: none; letter-spacing: 0.04em; }

/* ---------- scroll reveals ---------- */

@media (prefers-reduced-motion: no-preference) {
  html.js .reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 600ms ease, transform 600ms ease;
  }
  html.js .reveal.in {
    opacity: 1;
    transform: none;
  }
}

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

@media (max-width: 880px) {
  .steps { grid-template-columns: 1fr; gap: 2.5rem; }

  .feature,
  .feature-flip { grid-template-columns: 1fr; gap: 2rem; }
  .feature-flip .feature-text { order: 1; }
  .feature-flip .shot { order: 2; }

  .feature-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .site-nav { display: none; }
  .header-inner { grid-template-columns: auto 1fr; }

  .route-rules li {
    grid-template-columns: 1.5rem minmax(6rem, 1fr) 1rem minmax(6rem, 1fr) 1.25rem;
    font-size: 0.71875rem;
    gap: 0.375rem;
  }
  .route-incoming { gap: 0.625rem; }

  .footer-inner { flex-direction: column; }
}
