@layer reset, tokens, base, layout, components, motion;

@font-face {
  font-family: "Hartford Mono";
  src: url("./hartford-mono.ttf") format("truetype-variations");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { color-scheme: dark; scroll-behavior: smooth; }
  body, h1, h2, h3, p, figure, ul, ol { margin: 0; }
  img { display: block; max-width: 100%; }
  button, input { font: inherit; }
}

@layer tokens {
  :root {
    --board: #0f3b2c;
    --board-raised: #124936;
    --trace-panel: #165b45;
    --cream: #ead0ac;
    --copper-hot: #d98c53;
    --copper: #b87333;
    --silver: #c0c0c0;
    --gold: #ffd700;
    --ink: #09271d;
    --line: color-mix(in srgb, var(--copper) 78%, transparent);
    --measure: 72ch;
    --page: min(1280px, calc(100% - 3rem));
    --section-gap: clamp(4rem, 8vw, 8rem);
    --radius: 8px;
    --shadow: 0 2px 12px rgba(1, 18, 12, .34);
  }
}

@layer base {
  body {
    min-width: 0;
    overflow-x: hidden;
    color: var(--cream);
    background: var(--board);
    font-family: "Hartford Mono", "Courier New", Courier, monospace;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.6;
  }

  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
      radial-gradient(circle at 16px 16px, rgba(234, 208, 172, .035) 1px, transparent 1.4px) 0 0 / 32px 32px,
      linear-gradient(115deg, rgba(255,255,255,.018), transparent 28%, rgba(0,0,0,.035) 72%, transparent);
  }

  a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    color: var(--cream);
    text-decoration-color: var(--copper-hot);
    text-decoration-thickness: 2px;
    text-underline-offset: .22em;
    overflow-wrap: anywhere;
  }

  a:hover { color: var(--gold); }
  a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
    outline: 2px solid var(--copper-hot);
    outline-offset: 2px;
  }

  h1, h2, h3, strong, summary, button { font-weight: 700; }
  h1, h2, h3 { line-height: 1.14; letter-spacing: -.035em; text-wrap: balance; }
  h1 { font-size: clamp(2.5rem, 5vw, 4rem); }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.125rem; }
  p, li, td, th, label, figcaption { font-size: 1rem; }
  p { max-width: var(--measure); }
  button, input { min-height: 48px; border-radius: var(--radius); }
  button {
    border: 1px solid var(--copper-hot);
    padding: .7rem 1rem;
    color: var(--ink);
    background: var(--copper-hot);
    font-weight: 700;
    cursor: pointer;
  }
  button:hover { background: var(--gold); border-color: var(--gold); }
}

@layer layout {
  [data-site-header], main, footer { width: var(--page); margin-inline: auto; }

  [data-site-header] {
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    position: relative;
    z-index: 20;
    border-bottom: 1px solid var(--line);
  }

  main { padding-block: clamp(2.5rem, 6vw, 5rem) var(--section-gap); }

  [data-hero] {
    min-height: min(680px, 76vh);
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(280px, .92fr);
    align-items: center;
    gap: clamp(2rem, 6vw, 6rem);
    padding-block: 2rem var(--section-gap);
    position: relative;
  }

  [data-hero]::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: calc(var(--section-gap) / 2);
    width: min(26rem, 62%);
    height: 2px;
    background: linear-gradient(90deg, var(--copper-hot), var(--copper), transparent);
  }

  [data-hero]::before {
    content: "";
    position: absolute;
    left: min(26rem, 62%);
    bottom: calc(var(--section-gap) / 2 - 5px);
    width: 12px;
    height: 12px;
    border: 2px solid var(--gold);
    border-radius: 50%;
    background: var(--board);
  }

  [data-hero] > div { min-width: 0; }
  [data-lede] { margin-top: 1.5rem; font-size: clamp(1.05rem, 2vw, 1.25rem); color: var(--silver); }

  article {
    display: grid;
    gap: var(--section-gap);
  }

  article > section {
    width: min(100%, 780px);
    min-width: 0;
    position: relative;
  }

  article > section:nth-of-type(odd) { justify-self: start; }
  article > section:nth-of-type(even) { justify-self: end; }

  article > section[data-route]:not(:last-child)::after {
    content: "";
    position: absolute;
    width: min(44vw, 28rem);
    height: calc(var(--section-gap) - 1rem);
    left: 12%;
    top: calc(100% + .5rem);
    border-left: 2px solid var(--copper);
    border-bottom: 2px solid var(--copper);
    border-radius: 0 0 0 var(--radius);
    opacity: .78;
    pointer-events: none;
  }

  article > section:nth-of-type(even)[data-route]:not(:last-child)::after {
    left: auto;
    right: 12%;
    border-left: 0;
    border-right: 2px solid var(--copper);
    border-radius: 0 0 var(--radius) 0;
  }

  footer {
    padding-block: 2rem 3rem;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 1.5rem;
  }

  footer nav { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; }
  footer p { color: var(--silver); }
}

@layer components {
  [data-skip] {
    position: fixed;
    top: .5rem;
    left: .5rem;
    z-index: 100;
    padding: .5rem .75rem;
    background: var(--gold);
    color: var(--ink);
    transform: translateY(-140%);
  }
  [data-skip]:focus { transform: translateY(0); }

  [data-home] {
    flex: 0 1 auto;
    font-weight: 800;
    text-decoration: none;
    letter-spacing: -.04em;
  }
  [data-home] span { color: var(--copper-hot); }

  [data-menu] { position: relative; }
  [data-menu] summary {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .45rem .8rem;
    border: 1px solid var(--copper);
    border-radius: var(--radius);
    background: var(--board-raised);
    cursor: pointer;
    list-style: none;
  }
  [data-menu] summary::-webkit-details-marker { display: none; }
  [data-menu] summary::before { content: "+"; color: var(--gold); font-size: 1.3rem; }
  [data-menu][open] summary::before { content: "−"; }
  [data-menu] nav {
    position: absolute;
    right: 0;
    top: calc(100% + .75rem);
    width: min(720px, calc(100vw - 3rem));
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    border: 1px solid var(--copper);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--copper);
    box-shadow: var(--shadow);
  }
  [data-menu] section {
    min-width: 0;
    padding: .75rem;
    background: #103f2f;
  }
  [data-menu] a { width: 100%; padding: .35rem .5rem; }
  [data-menu] a[aria-current="page"] { color: var(--gold); }
  [data-nav-label], [data-kicker] {
    color: var(--copper-hot);
    font-size: .875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
  }
  [data-nav-label] { color: var(--silver); padding-inline: .5rem; }
  article [data-kicker] { color: #eeaa76; }

  [data-hero-media], [data-signal] {
    position: relative;
    border: 1px solid var(--copper);
    border-radius: var(--radius);
    background: var(--board-raised);
    box-shadow: var(--shadow);
  }
  [data-hero-media]::before, [data-signal]::before, article > section::before {
    content: "";
    position: absolute;
    top: 12px;
    bottom: 12px;
    left: -5px;
    width: 8px;
    background: radial-gradient(circle, var(--silver) 0 2px, transparent 2.5px) 0 0 / 8px 20px;
  }
  [data-hero-media]::after, [data-signal]::after, article > section > header::after {
    content: "";
    position: absolute;
    top: 12px;
    bottom: 12px;
    right: -5px;
    width: 8px;
    background: radial-gradient(circle, var(--silver) 0 2px, transparent 2.5px) 0 0 / 8px 20px;
  }
  [data-hero-media] { overflow: visible; }
  [data-hero-media] img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: calc(var(--radius) - 1px); }
  [data-hero-media] figcaption { padding: .75rem 1rem; color: var(--silver); }

  [data-signal] {
    min-height: 290px;
    display: grid;
    place-items: center;
    overflow: hidden;
  }
  [data-signal] span {
    width: 60%;
    height: 44%;
    position: absolute;
    border-left: 3px solid var(--copper-hot);
    border-bottom: 3px solid var(--copper-hot);
  }
  [data-signal] span::before, [data-signal] span::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid var(--silver);
    background: var(--board);
  }
  [data-signal] span::before { left: -10px; top: -10px; }
  [data-signal] span::after { right: -10px; bottom: -10px; border-color: var(--gold); }
  [data-signal] p { position: relative; z-index: 2; padding: 1rem; background: var(--board-raised); }

  article > section {
    padding: clamp(1.25rem, 3vw, 2.5rem);
    border: 1px solid var(--copper);
    border-radius: var(--radius);
    background: #134d39;
    box-shadow: var(--shadow);
  }
  article > section > header { position: relative; padding-right: .5rem; }
  article > section > header::after { top: 0; bottom: auto; height: 34px; right: -2.85rem; }
  article > section > * + * { margin-top: 1rem; }
  article > section > header + * { margin-top: 1.5rem; }
  article > section[data-alert] { border-color: var(--gold); }

  [data-source] {
    margin-top: 1.5rem;
    padding: 1rem 1rem 1rem 1.35rem;
    border-left: 3px solid var(--silver);
    background: rgba(15,59,44,.72);
  }
  [data-source] strong { color: var(--silver); font-size: .875rem; letter-spacing: .04em; text-transform: uppercase; }
  [data-source] p { margin-top: .35rem; }

  [data-card-grid] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
  [data-card] {
    min-height: 150px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.2rem;
    border: 1px solid var(--copper);
    border-radius: var(--radius);
    background: #104532;
    box-shadow: var(--shadow);
    text-decoration: none;
  }
  [data-card] span { color: var(--silver); }
  [data-card]:hover { border-color: var(--gold); background: var(--trace-panel); }

  [data-nodes] { padding: 0; list-style: none; display: grid; gap: .9rem; }
  [data-nodes] li {
    min-height: 48px;
    position: relative;
    padding: .7rem .75rem .7rem 2.6rem;
    border-bottom: 1px solid color-mix(in srgb, var(--copper) 60%, transparent);
  }
  [data-nodes] li::before {
    content: "";
    position: absolute;
    left: .4rem;
    top: 1rem;
    width: 14px;
    height: 14px;
    border: 3px solid var(--copper-hot);
    border-radius: 50%;
    background: var(--board);
    box-shadow: 20px 0 0 -6px var(--copper);
  }
  [data-nodes] strong, [data-nodes] span { display: block; }
  [data-nodes] span { color: var(--silver); }

  [data-action] {
    padding: .7rem 1rem;
    border: 1px solid var(--copper-hot);
    border-radius: var(--radius);
    background: var(--copper-hot);
    color: var(--ink);
    font-weight: 700;
    text-decoration: none;
  }
  [data-action]:hover { background: var(--gold); border-color: var(--gold); color: var(--ink); }

  [data-worksheet] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
  [data-worksheet] > p, [data-button-row] { grid-column: 1 / -1; }
  [data-worksheet] label { display: grid; gap: .35rem; color: var(--silver); }
  [data-worksheet] input {
    width: 100%;
    min-width: 0;
    padding: .65rem .75rem;
    border: 1px solid var(--copper);
    color: var(--cream);
    background: var(--board);
  }
  [data-button-row] { display: flex; flex-wrap: wrap; gap: .75rem; }
  [data-quiet] { color: var(--cream); background: transparent; }
  [data-cost-output] {
    display: block;
    min-height: 88px;
    margin-top: 1rem;
    padding: 1rem;
    border: 1px dashed var(--silver);
    border-radius: var(--radius);
  }
  [data-cost-output] ul { margin: .5rem 0 0; padding-left: 1.5rem; }

  [data-table-wrap] { max-width: 100%; overflow-x: auto; border: 1px solid var(--copper); border-radius: var(--radius); }
  table { width: 100%; min-width: 620px; border-collapse: collapse; }
  th, td { padding: .8rem; text-align: left; border-bottom: 1px solid var(--copper); }
  thead { color: var(--gold); background: var(--board); }

  [data-next] {
    margin-top: var(--section-gap);
    padding-top: 1.5rem;
    border-top: 1px solid var(--copper);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 2rem;
  }
}

@layer motion {
  body { animation: page-in 200ms ease-out both; }
  [data-reveal] { animation: rise-in 420ms ease-out both; }
  article [data-reveal]:nth-child(2) { animation-delay: 80ms; }
  article [data-reveal]:nth-child(3) { animation-delay: 160ms; }
  article [data-reveal]:nth-child(4) { animation-delay: 240ms; }
  a, button, summary { transition: color 200ms ease, background-color 200ms ease, border-color 200ms ease, transform 200ms ease; }
  [data-card]:hover, [data-action]:hover, button:hover { transform: translateY(-2px); }
  @keyframes page-in { from { opacity: .84; } to { opacity: 1; } }
  @keyframes rise-in { from { opacity: .82; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
}

@media (max-width: 767px) {
  :root { --page: min(100% - 2rem, 1280px); --section-gap: 4rem; }
  [data-site-header] { min-height: 72px; gap: .75rem; }
  [data-home] span { display: block; }
  [data-menu] summary { max-width: 11.5rem; }
  [data-menu] nav { grid-template-columns: 1fr; max-height: min(72vh, 620px); overflow-y: auto; }
  [data-hero] { min-height: 0; grid-template-columns: 1fr; gap: 2.5rem; padding-top: 3.5rem; }
  [data-signal] { min-height: 220px; }
  article > section { justify-self: stretch !important; width: 100%; }
  article > section[data-route]:not(:last-child)::after,
  article > section:nth-of-type(even)[data-route]:not(:last-child)::after { left: 2rem; right: auto; width: 2px; border-right: 0; }
  [data-card-grid], [data-worksheet] { grid-template-columns: 1fr; }
  [data-worksheet] > p, [data-button-row] { grid-column: auto; }
  table { min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  table, tbody, tr, th, td { display: block; width: 100%; }
  tbody th { padding-bottom: .25rem; border-bottom: 0; color: var(--gold); }
  tbody td { display: flex; gap: 1rem; justify-content: space-between; padding-top: .35rem; padding-bottom: .35rem; border-bottom: 0; }
  tbody td::before { content: attr(data-label); color: var(--silver); }
  tbody tr { border-bottom: 1px solid var(--copper); padding-bottom: .5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0ms !important; transition-duration: .001ms !important; }
}

@media print {
  [data-menu], [data-next], footer nav, [data-print], [data-hero-media], [data-signal] { display: none !important; }
  body { color: #111; background: #fff; }
  [data-site-header], main, footer { width: 100%; }
  [data-hero] { min-height: 0; display: block; padding: 1rem 0; }
  article { gap: 1.5rem; }
  article > section { width: 100%; color: #111; background: #fff; border-color: #555; box-shadow: none; break-inside: avoid; }
  article > section::before, article > section header::after, article > section::after { display: none; }
  a { color: #111; }
}
