/* ============================================================
   joincraft-explained — an animated explainer for the join-ribbon idea.
   Same identity as joincraft: graphite-slate + electric chartreuse.
   Dark is default; light is a full parallel scheme. Motion is opt-in
   and degrades to legible static states under prefers-reduced-motion.
   ============================================================ */

:root {
  color-scheme: dark;

  --bg:      #1D2126;
  --panel:   #262C33;
  --panel2:  #2E353D;
  --line:    #3A424B;
  --ink:     #E9EDF0;
  --muted:   #9AA7B0;   /* 6.6:1 on bg */
  --accent:  #D7F84B;   /* electric chartreuse — large fills / accents */
  --accent-ink: #161A10;/* ink that sits ON chartreuse */
  --accent-text: #D7F84B; /* chartreuse as text on dark (13.4:1) */
  --orphan:  #6B7680;   /* NULL / orphan grey — ALWAYS with dash pattern */
  --orphan-text: #9AA7B0;
  --orphan-solid: #586069;
  --danger:  #FF8A5B;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --wrap: 1100px;
  --shadow: 0 16px 40px -26px rgba(0,0,0,0.75);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg:      #F3F5F2;
    --panel:   #FFFFFF;
    --panel2:  #EEF1EC;
    --line:    #D3D9CF;
    --ink:     #22282E;
    --muted:   #566068;   /* 5.9:1 on bg */
    --accent:  #D7F84B;
    --accent-ink: #161A10;
    --accent-text: #526600; /* olive-chartreuse text/lines, 5.9:1 */
    --orphan:  #8A949C;
    --orphan-text: #566068;
    --orphan-solid: #647079;
    --danger:  #B23A12;
    --shadow: 0 16px 40px -30px rgba(30,40,20,0.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1100px 560px at 84% -10%, rgba(215,248,75,0.07), transparent 60%),
    radial-gradient(760px 460px at 4% 2%, rgba(215,248,75,0.04), transparent 55%);
}

h1, h2, h3 { margin: 0; font-weight: 750; letter-spacing: -0.02em; line-height: 1.12; }
p { margin: 0; }
em { font-style: normal; color: var(--ink); }
code { font-family: var(--mono); font-size: 0.9em; color: var(--accent-text); }
a { color: var(--accent-text); }

.tok { font-family: var(--mono); font-size: 0.86em; padding: 0 5px; border-radius: 4px; }
.tok--null {
  color: var(--orphan-text);
  border: 1px dashed var(--orphan);
  background: transparent;
  font-style: italic;
}

.counter__val, .tt, .demo__count { font-variant-numeric: tabular-nums; }

/* --- skip link + focus --- */
.skip-link {
  position: absolute; left: 12px; top: -60px;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 10px; font-weight: 700;
  z-index: 60; transition: top 0.18s var(--ease); text-decoration: none;
}
.skip-link:focus { top: 12px; }

a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* --- scroll progress rail --- */
.scrollrail {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 55;
  background: transparent; pointer-events: none;
}
.scrollrail__fill {
  display: block; height: 100%; width: 0%;
  background: var(--accent); transform-origin: left;
}

.eyebrow, .kicker {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--muted); font-weight: 700;
}
.kicker { color: var(--accent-text); margin-bottom: 12px; }

/* ============================================================ HERO */
.hero {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(215,248,75,0.05), transparent 72%);
}
.hero__inner {
  max-width: var(--wrap); margin: 0 auto;
  padding: clamp(44px, 8vw, 96px) clamp(18px, 5vw, 48px) clamp(40px, 6vw, 68px);
  text-align: center;
}
.hero__title {
  font-size: clamp(2rem, 5.2vw, 3.4rem); font-weight: 800; margin: 16px auto 0;
  max-width: 20ch; letter-spacing: -0.025em;
}
.hero__accent { color: var(--accent-text); }
.hero__strike { position: relative; white-space: nowrap; color: var(--muted); }
.hero__strike::after {
  content: ""; position: absolute; left: -2%; right: -2%; top: 54%; height: 3px;
  background: var(--danger); transform: rotate(-4deg); border-radius: 2px;
}
.hero__lede {
  margin: 22px auto 0; max-width: 60ch; font-size: clamp(1.02rem, 1.6vw, 1.2rem);
  color: var(--muted); line-height: 1.55;
}
.hero__lede strong { color: var(--ink); font-weight: 650; }

.hero__stage { margin: clamp(28px, 5vw, 48px) auto 0; max-width: 560px; }
.herofig { width: 100%; height: auto; }
.herofig__venn circle { fill: rgba(154,167,176,0.08); stroke: var(--muted); stroke-width: 1.6; }
.herofig__cross { stroke: var(--danger); stroke-width: 4; stroke-linecap: round; }
.hf-row, .tm-row { fill: var(--panel2); stroke: var(--line); stroke-width: 1.4; }
.hf-rib {
  fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; opacity: 0.92;
}

.hero__cta { margin-top: clamp(30px, 5vw, 44px); display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ============================================================ BUTTONS */
.btn {
  font-family: var(--sans); font-size: 0.95rem; font-weight: 700;
  border-radius: var(--radius-sm); padding: 11px 20px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  text-decoration: none; display: inline-block;
  transition: transform 0.08s var(--ease), background 0.15s var(--ease), border-color 0.15s, filter 0.15s;
}
.btn:hover { border-color: var(--accent-text); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--primary:hover { filter: brightness(1.05); }
.btn--ghost { background: transparent; }
.btn--lg { padding: 14px 26px; font-size: 1.02rem; }

/* ============================================================ BANDS / SCROLL REVEAL */
main { max-width: var(--wrap); margin: 0 auto; padding: 0 clamp(18px, 5vw, 48px); }
.band { margin-top: clamp(56px, 9vw, 108px); scroll-margin-top: 24px; }
.band__inner { max-width: 760px; }
.band--feature .band__inner, .band--privacy .band__inner { max-width: 860px; }
.band__title {
  font-size: clamp(1.5rem, 3.4vw, 2.3rem); font-weight: 800; letter-spacing: -0.022em;
  max-width: 24ch;
}
.band__title em { font-style: italic; color: var(--accent-text); }
.band__body {
  margin-top: 18px; color: var(--muted); font-size: clamp(1rem, 1.5vw, 1.12rem); line-height: 1.6; max-width: 64ch;
}
.band__body strong { color: var(--ink); font-weight: 650; }
.band__body--sm { font-size: 0.98rem; margin-top: 20px; }

.reveal { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .reveal { opacity: 0; transform: translateY(28px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
  .reveal.is-in { opacity: 1; transform: none; }
}

.painlist { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 10px; }
.painlist__q {
  display: block; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent-text);
  border-radius: var(--radius-sm); padding: 12px 16px; color: var(--ink); font-size: 0.98rem;
}
.painlist code { color: var(--accent-text); }

/* ============================================================ BLOWUP DEMO */
.demo {
  margin-top: 28px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(14px, 3vw, 26px); box-shadow: var(--shadow);
}
.demo__stage { overflow-x: auto; }
.joinfig { display: block; width: 100%; min-width: 460px; height: auto; }
.stack__cap { font-family: var(--mono); font-size: 13px; fill: var(--muted); text-anchor: middle; letter-spacing: 0.06em; }
.jrow rect { fill: var(--panel2); stroke: var(--line); stroke-width: 1.4; }
.jrow__k { font-family: var(--mono); font-size: 15px; font-weight: 700; fill: var(--accent-text); }
.jrow__v { font-family: var(--mono); font-size: 13px; fill: var(--muted); }
.jrib { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; opacity: 0.9; }

.demo__count {
  margin-top: 20px; display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
}
.demo__op { font-family: var(--mono); font-size: 1.5rem; color: var(--accent-text); font-weight: 700; }
.counter {
  background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; text-align: center; min-width: 108px;
}
.counter__val { display: block; font-size: 1.9rem; font-weight: 800; line-height: 1; }
.counter__label { display: block; font-size: 0.72rem; color: var(--muted); margin-top: 7px; text-transform: uppercase; letter-spacing: 0.04em; }
.counter--out { border-color: var(--accent-text); }
.counter--out .counter__val { color: var(--accent-text); }

.blowup {
  margin-top: 22px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(215,248,75,0.09); border: 1px solid var(--accent-text);
  border-radius: var(--radius); padding: 14px 18px; font-size: 0.98rem; color: var(--ink);
}
.blowup em { color: var(--ink); font-style: italic; }
.blowup__badge {
  font-family: var(--mono); font-weight: 800; font-size: 0.78rem; letter-spacing: 0.04em;
  background: var(--accent); color: var(--accent-ink); padding: 3px 9px; border-radius: 6px; white-space: nowrap;
}

/* ============================================================ NULL FIGURE */
.v-unknown, .v-UNKNOWN { color: var(--orphan-text); font-style: italic; }
.v-true, .v-TRUE { color: var(--accent-text); font-weight: 700; }
.v-false, .v-FALSE { color: var(--muted); }

.nullfig {
  margin-top: 26px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(16px, 3vw, 26px); box-shadow: var(--shadow);
}
.nullfig__eq { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; font-family: var(--mono); font-size: 1.2rem; }
.nf-cell {
  border: 1px dashed var(--orphan); color: var(--orphan-text); font-style: italic;
  padding: 6px 14px; border-radius: 6px;
}
.nf-op { color: var(--accent-text); font-weight: 700; }
.nf-arrow { color: var(--muted); }
.nf-result { font-weight: 700; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); }

.tt { border-collapse: collapse; width: 100%; max-width: 460px; margin: 22px auto 0; font-family: var(--mono); font-size: 0.9rem; }
.tt__cap { caption-side: top; color: var(--muted); font-family: var(--sans); font-size: 0.85rem; text-align: left; margin-bottom: 8px; }
.tt th, .tt td { padding: 7px 10px; text-align: center; border: 1px solid var(--line); }
.tt th { color: var(--muted); font-weight: 600; }
.tt td.null { color: var(--orphan-text); font-style: italic; }
.nullfig__note { margin-top: 18px; color: var(--muted); font-size: 0.92rem; text-align: center; }

/* ============================================================ GROUP-BY BINS */
.binfig {
  margin-top: 26px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(16px, 3vw, 26px); box-shadow: var(--shadow); text-align: center;
}
.binfig__loose { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.chip {
  font-family: var(--mono); font-size: 0.86rem; padding: 6px 12px; border-radius: 999px;
  border: 1px dashed var(--orphan); color: var(--orphan-text); font-style: italic;
}
.chip--k { border-style: solid; border-color: var(--line); color: var(--ink); font-style: normal; background: var(--panel2); }
.binfig__arrow { margin: 16px 0; color: var(--accent-text); font-family: var(--mono); font-size: 0.9rem; }
.binfig__bins { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.bin {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 22px; background: var(--panel2); min-width: 130px;
}
.bin--null { border-style: dashed; border-color: var(--orphan); }
.bin__label { display: block; font-family: var(--mono); font-weight: 700; color: var(--ink); }
.bin--null .bin__label { color: var(--orphan-text); font-style: italic; }
.bin__n { display: block; margin-top: 6px; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.binfig__note { margin-top: 18px; color: var(--muted); font-size: 0.92rem; }

/* ============================================================ PRIVACY / CSP */
.band--privacy .band__inner { }
.csp {
  margin-top: 26px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(18px, 3vw, 30px); box-shadow: var(--shadow); text-align: center;
}
.csp__code { display: inline-block; font-family: var(--mono); font-size: 1.15rem; color: var(--ink); background: var(--panel2); padding: 10px 18px; border-radius: 8px; border: 1px solid var(--line); }
.csp__none { color: var(--accent-text); font-weight: 700; }
.csp__packets {
  position: relative; margin: 26px auto 20px; height: 40px; max-width: 420px;
  border-bottom: 1px dashed var(--line);
}
.pkt {
  position: absolute; left: 4px; top: 12px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--danger); opacity: 0.9;
}
.csp__wall {
  position: absolute; right: 8px; top: -4px; bottom: -4px; width: 5px; border-radius: 3px;
  background: repeating-linear-gradient(45deg, var(--accent-text) 0 6px, transparent 6px 12px);
}
.csp__verdict { display: block; font-family: var(--mono); font-size: 0.92rem; color: var(--accent-text); font-weight: 700; }

/* ============================================================ FEATURE TOUR */
.tour { margin-top: 30px; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tour__card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 20px 22px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.tour__card:hover { border-color: var(--accent-text); transform: translateY(-3px); }
.tour__mark { width: 46px; height: 46px; border-radius: 11px; background: var(--panel2); border: 1px solid var(--line); display: grid; place-items: center; }
.tour__mark svg { width: 30px; height: 30px; }
.tm-rib { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.tm-txt { font-family: var(--mono); font-size: 12px; font-weight: 800; fill: var(--ink); }
.tm-txt--out { fill: var(--accent-text); }
.tm-txt--sm { font-size: 9px; fill: var(--muted); }
.tm-txt--u { font-size: 11px; fill: var(--orphan-text); font-style: italic; font-weight: 700; }
.tm-bin { fill: var(--panel); stroke: var(--accent-text); stroke-width: 2; }
.tm-card { fill: none; stroke: var(--line); stroke-width: 2; }
.tm-tick { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.tm-dl { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tm-tray { fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round; }
.tour__h { font-size: 1.08rem; font-weight: 750; }
.tour__p { color: var(--muted); font-size: 0.94rem; line-height: 1.5; }
.tour__p code { color: var(--accent-text); }

/* ============================================================ CTA */
.cta { margin-top: clamp(64px, 10vw, 120px); text-align: center; }
.cta__inner {
  max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--accent-text);
  border-radius: var(--radius); padding: clamp(32px, 6vw, 60px) clamp(20px, 5vw, 48px);
  box-shadow: var(--shadow);
}
.cta__fan { width: clamp(150px, 30vw, 200px); height: auto; margin-bottom: 8px; }
.cta__title { font-size: clamp(1.6rem, 3.6vw, 2.4rem); font-weight: 800; }
.cta__lede { margin: 18px auto 26px; max-width: 52ch; color: var(--muted); font-size: 1.05rem; }
.cta__sub { margin-top: 18px; color: var(--muted); font-size: 0.85rem; }

/* ============================================================ FOOTER */
.foot { margin-top: clamp(56px, 8vw, 96px); border-top: 1px solid var(--line); }
.foot__inner { max-width: var(--wrap); margin: 0 auto; padding: 28px clamp(18px,5vw,48px) 52px; }
.foot__disclaimer { color: var(--muted); font-size: 0.9rem; max-width: 90ch; }
.foot__disclaimer strong { color: var(--ink); }
.foot__meta { margin-top: 16px; color: var(--muted); font-size: 0.82rem; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.foot__dot { opacity: 0.5; }
.foot__link { color: var(--accent-text); }

/* ============================================================ ANIMATIONS (opt-in only) */
@media (prefers-reduced-motion: no-preference) {
  /* hero: draw the ribbon fan on load */
  .hf-rib, .cta__fan .hf-rib {
    stroke-dasharray: 120; stroke-dashoffset: 120;
    animation: draw 1s var(--ease) forwards;
    animation-delay: calc(0.35s + var(--i) * 0.22s);
  }
  .herofig__cross { stroke-dasharray: 210; stroke-dashoffset: 210; animation: draw 0.6s var(--ease) 1.2s forwards; }
  @keyframes draw { to { stroke-dashoffset: 0; } }

  /* blowup demo ribbons draw when the section reveals */
  .band--feature.is-in .jrib {
    stroke-dasharray: 260; stroke-dashoffset: 260;
    animation: draw 0.85s var(--ease) forwards;
    animation-delay: calc(var(--i) * 0.16s);
  }
  .band--feature:not(.is-in) .jrib { opacity: 0.28; }

  /* blowup rows pop in */
  .band--feature.is-in .jrow { animation: pop 0.5s var(--ease) both; animation-delay: calc(var(--i) * 0.06s); }
  @keyframes pop { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

  /* privacy: packets fly toward the wall and get stopped, on a loop */
  .band--privacy.is-in .pkt {
    animation: fly 2.6s var(--ease) infinite;
    animation-delay: calc(var(--i) * 0.7s);
  }
  @keyframes fly {
    0%   { left: 4px; opacity: 0; }
    15%  { opacity: 0.95; }
    72%  { left: calc(100% - 34px); opacity: 0.95; }
    80%  { left: calc(100% - 34px); opacity: 0.2; transform: scale(0.5); }
    100% { left: calc(100% - 34px); opacity: 0; transform: scale(0.4); }
  }
}

/* reduced-motion: everything is drawn, visible, legible, no looping */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hf-rib, .jrib, .herofig__cross { stroke-dashoffset: 0; }
  .pkt { opacity: 0.5; }
  .pkt:nth-child(2) { left: 40%; }
  .pkt:nth-child(3) { left: 66%; }
}

/* ============================================================ PRINT */
@media print {
  :root { --bg: #fff; --ink: #111; --muted: #444; --panel: #fff; --panel2: #f4f4f4; --line: #bbb; --accent-text: #333; }
  body::before, .scrollrail, .hero__cta, .cta .btn { display: none !important; }
  .band { margin-top: 20px; page-break-inside: avoid; }
  .cta__inner, .demo, .nullfig, .binfig, .csp { box-shadow: none; }
  a { color: inherit; text-decoration: underline; }
}
