/* diviZible — GCD landing page
   Palette, fonts and components matched to the live game's actual tokens. */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500;600;700&family=Space+Grotesk:wght@700&display=swap');

:root {
  --bg: #14231c;
  --surface: #355542;
  --surface-2: #47694f;
  --chalk: #ffffff;
  --chalk-dim: #d3ddd7;
  --divisor: #ffa688;
  --divisor-ink: #241109;
  --correct: #2ee673;
  --present: #ff9f45;
  --absent: #74887a;
  --rule: #b0bab4;
  --mono: 'JetBrains Mono', monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --wordmark-font: 'Space Grotesk', var(--sans);
  --z-chalk: #f2f0e6; /* exact color from the live wordmark/app-icon mark, not the page's --chalk */
  --z-coral: #e8846b; /* exact color from the live wordmark/app-icon mark, not the page's --divisor */
  --max: 42rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--chalk);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--divisor); text-underline-offset: 0.15em; }
a:hover { filter: brightness(1.1); }

:focus-visible {
  outline: 2px solid var(--divisor);
  outline-offset: 3px;
}

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 1.5rem; }

/* ---------- nav ---------- */
.nav {
  display: flex;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--rule);
}
.nav .wrap { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 0.75rem; flex-wrap: nowrap; }

/* Matches the live game's own wordmark treatment exactly: Space
   Grotesk at the game's real 30px/1em-mark sizing, with the "Z"
   replaced by its actual logo mark (two chalk bars + a coral
   diagonal) rather than rendered as a letter. */
.wordmark {
  font-family: var(--wordmark-font);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--chalk);
  text-decoration: none;
}
.z-mark {
  display: inline-block;
  width: 1em;
  height: 1em;
  margin: 0 0.11em;
  vertical-align: baseline;
}
.z-mark svg { width: 100%; height: 100%; display: block; }
.z-mark .zbar,
.z-mark .zdiag {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
}
.z-mark .zbar { stroke: var(--z-chalk); }
.z-mark .zdiag { stroke: var(--z-coral); }
.wordmark {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
/* Mirrors the game's .splash-eyebrow: JetBrains Mono 11px, .22em tracking,
   uppercase, coral (--divisor), centred under the wordmark. */
.wordmark-tagline {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--divisor);
  line-height: 1;
  white-space: nowrap;
}
.nav-play {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--divisor-ink);
  background: var(--divisor);
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}
.nav-play:hover { filter: brightness(1.06); }

/* ---------- hero ---------- */
.hero { padding: 3.5rem 0 2.5rem; }
.hero h1 {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(1.3rem, 3.6vw, 1.75rem);
  line-height: 1.25;
  letter-spacing: -0.005em;
  margin: 0 0 1.1rem;
}
.hero .mechanic {
  font-size: 1.1rem;
  color: var(--chalk-dim);
  margin: 0 0 1rem;
}
.hero-meta {
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--divisor);
  margin: 0 0 2.25rem;
}

/* ---------- demo ---------- */
.demo {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.5rem;
  overflow: hidden;
}
/* Left cluster (digit count + toggle button) stacks; the mode name
   sits on the right, deliberately large and wrapped onto two lines
   so switching between "Easier mode" and "Harder mode" reads as an
   actual change, not a small label flicker. */
.demo-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 1.1rem;
}
.demo-top-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
}
.demo-digits {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: var(--chalk-dim);
  margin: 0;
}
.demo-toggle {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--chalk-dim);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.demo-toggle:hover { color: var(--chalk); border-color: var(--chalk-dim); }

.demo-mode {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.2;
  color: var(--divisor);
  text-align: right;
  max-width: 6.6rem;
  margin: 0;
}
.demo-mode.mode-flash { animation: modeFlash 0.5s ease both; }
@keyframes modeFlash {
  from { opacity: 0.25; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .demo-mode.mode-flash { animation: none; }
}

/* readout: the hidden-number strip, styled as a distinct dark panel
   nearly as wide as the surrounding surface, with tiles aligned to
   the same x-position as the guess rows below. Title (with the range
   folded into it) sits above the tiles; the factorization sits below. */
.readout {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.75rem;
}
.readout-title {
  display: block;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--chalk-dim);
  margin-bottom: 0.45rem;
  font-variant-numeric: tabular-nums;
}
.readout-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.readout-factorization .fz-match { color: var(--divisor); font-weight: 700; }
.readout-factorization {
  margin-top: 0.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--chalk-dim);
  font-variant-numeric: tabular-nums;
}

/* Board, row, tile and GCD values below are copied from the live
   game's own CSS (its .board/.row/.tile/.ground rules), not
   re-invented for the landing page, so this demo matches what a
   player actually sees — including how it behaves on a phone. */
.board {
  display: flex;
  flex-direction: column;
  gap: 0.3125rem; /* 5px, matches live .board */
  margin-bottom: 0.75rem;
}

.row {
  border-radius: 0.625rem; /* 10px, matches live .row */
  padding: 0.1875rem 0.625rem; /* 3px 10px, matches live .row */
}

.row-main {
  display: flex;
  align-items: center;
  gap: 0.875rem; /* 14px, matches live .row gap */
  flex-wrap: nowrap;
  min-height: 3.375rem;
}

/* Reserved, always-present line under every row so an occasional
   explanatory note never changes the board's height mid-playback.
   (Landing-page addition — the live game doesn't need this since its
   rows aren't scripted.) */
.row-note {
  min-height: 1.35em;
  margin-top: 0.3rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--chalk-dim);
}
.row-note .note-factor { color: var(--divisor); font-weight: 700; }

.tiles { display: flex; gap: 0.5rem; } /* 8px, matches live .tiles */

.tile {
  width: 3.375rem;  /* 54px, matches live .tile */
  height: 3.375rem;
  border: 2px solid var(--rule);
  border-radius: 0.5rem; /* 8px, matches live .tile */
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 1.625rem; /* 26px, matches live .tile */
  font-weight: 700;
  background: var(--surface);
  color: var(--chalk);
  flex: none;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.tile.static { background: var(--surface-2); }
.tile.empty { background: transparent; border-style: dashed; border-color: var(--rule); opacity: 0.55; }
.tile.correct { background: var(--correct); border-color: var(--correct); color: #0e1a14; }
.tile.present { background: var(--present); border-color: var(--present); color: #2a2107; }
.tile.absent { background: var(--absent); border-color: var(--absent); color: var(--chalk-dim); }

/* GCD readout — label above value, same as the live game's own
   "rule example" component (the mini-board it uses for its own
   how-to-play walkthrough, which is the real-game analog closest to
   this demo). Fixed-ish width so it doesn't jitter as digits change. */
.ground {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.0625rem; /* 1px, matches live .rule-example-gcd */
  min-width: 3.4rem;
  font-family: var(--mono);
  color: var(--chalk-dim);
  flex: none;
}
.ground .gcd-label {
  font-size: 0.5rem; /* 8px, matches live .rule-example-gcd-label */
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--chalk-dim);
}
.ground .gcd-val {
  font-size: 1.375rem; /* 22px, matches live main-board .gcd-val */
  font-weight: 800;
  color: var(--divisor);
  line-height: 1.1;
}
.ground .gcd-val.pending { color: var(--rule); font-weight: 600; }

/* Pegs always sit on a single line, right after the GCD block rather
   than pushed to the far edge of the row. Dot size/shape matches the
   live game's .peg-swatch. */
.pegs {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.375rem; /* 6px, matches live .peg-swatch spacing */
  flex: none;
}
.peg {
  width: 0.625rem;  /* 10px, matches live .peg-swatch */
  height: 0.625rem;
  flex: none;
  border-radius: 50%;
  background: var(--rule);
  opacity: 0.35;
}
.peg.peg-correct { background: var(--correct); opacity: 1; }
.peg.peg-present { background: var(--present); opacity: 1; }
.peg.peg-absent { background: var(--absent); opacity: 1; }

.row.guess-row.filled { animation: rowReveal 0.3s ease both; }
@keyframes rowReveal {
  from { background: var(--surface-2); }
  to { background: transparent; }
}

.modes-key {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--chalk-dim);
  text-align: left;
}
.mode-card { border-top: 1px solid var(--rule); padding-top: 0.9rem; }
.mode-card p { margin: 0; }
.mode-card .mode-title { color: var(--chalk); font-weight: 700; font-size: 1rem; margin-bottom: 0.4rem; }
.mode-title .hint-realname { display: block; color: var(--chalk-dim); font-weight: 400; font-size: 0.85rem; }
.modes-gcd { grid-column: 1 / -1; margin: 0; }
@media (max-width: 36rem) {
  .modes-key { grid-template-columns: 1fr; }
}

/* Mirrors the game's post-solve .fun-fact-card */
.fact-card {
  margin: 1.5rem 0 0.5rem;
  background: var(--surface);
  border-radius: 14px;
  padding: 20px 18px;
  text-align: center;
  max-width: 22.5rem;
}
.fact-hero { font-size: 34px; font-weight: 800; color: var(--chalk); letter-spacing: 0.02em; line-height: 1; }
.fact-label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  line-height: 1.6;
  margin: 8px 0;
  color: var(--divisor);
}
.fact-sentence { font-size: 14px; color: var(--chalk-dim); line-height: 1.5; }
.fact-figure { margin-top: 14px; color: var(--chalk); display: flex; justify-content: center; }
.fact-figure svg { display: block; width: 100%; height: auto; max-height: 260px; }
.fact-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--rule);
  padding-top: 12px;
  margin-top: 18px;
  font-size: 11px;
  color: var(--chalk-dim);
  font-family: var(--mono);
}

@media (prefers-reduced-motion: reduce) {
  .row.guess-row.filled { animation: none; }
}

/* ---------- copy section kept after demo ---------- */
section.copy {
  padding: 2.5rem 0;
  border-top: 1px solid var(--rule);
}
section.copy p { margin: 0 0 1em; max-width: 68ch; color: var(--chalk); }
.copy h2 {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--divisor);
  margin: 2.4em 0 .6em;
  line-height: 1.2;
  text-wrap: balance;
}
.copy h3 {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--chalk);
  margin: 1.6em 0 .35em;
  line-height: 1.3;
}
.copy strong { color: var(--divisor); font-weight: 700; }
.copy table.algo {
  border-collapse: collapse;
  margin: 1.4em 0 1.6em;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  width: 100%;
  max-width: 36rem;
  display: block;
  overflow-x: auto;
}
.copy table.algo caption {
  text-align: left;
  font-size: .82rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--chalk-dim);
  padding-bottom: .6em;
}
.copy table.algo th,
.copy table.algo td {
  text-align: left;
  padding: .5em .9em .5em 0;
  border-bottom: 1px solid var(--rule);
  color: var(--chalk);
}
.copy table.algo th {
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--chalk-dim);
  font-weight: 500;
}

/* hero sub (content review addition) */
.hero-sub {
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--chalk-dim);
  line-height: 1.35;
  margin: .3em 0 .8em;
}

/* ---------- inline mid-page CTA ---------- */
.inline-cta {
  background: var(--surface);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 1.4rem 0;
  text-align: center;
}
.inline-cta p {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--chalk-dim);
}
.inline-cta-link {
  color: var(--divisor);
  font-weight: 700;
  text-decoration: none;
}
.inline-cta-link:hover { filter: brightness(1.1); }

/* ---------- CTA band ---------- */
.cta-band {
  background: var(--surface);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 2.5rem 0;
}
.cta-band .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; }
.cta-band h2 {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--chalk);
  margin: 0;
  max-width: 22ch;
}
.cta-button {
  display: inline-block;
  background: var(--divisor);
  color: var(--divisor-ink);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.8rem 1.6rem;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}
.cta-button:hover { filter: brightness(1.06); }

/* ---------- footer ---------- */
footer { padding: 2.5rem 0 3.5rem; color: var(--chalk-dim); font-size: 0.9rem; }
footer .wrap {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
  border-top: 1px solid var(--rule);
  padding-top: 1.5rem;
}
footer a { color: var(--chalk-dim); }
footer a:hover { color: var(--divisor); }

/* Matches the live game's own @media (max-width: 480px) rule: only
   the GCD column shrinks, tiles stay full-size (4 tiles at 54px
   always fits a phone width — that's the live game's own logic). */
@media (max-width: 30rem) {
  .cta-band .wrap { flex-direction: column; align-items: flex-start; }
  .cta-button { white-space: normal; max-width: 100%; }
  /* On phones the demo board is sized with min(rem, vw) so it fits the
     screen even when the reader's browser text size is larger than
     default (rem-only sizes grew with the text and the demo card,
     which clips its overflow, cut off the last peg and the mode name). */
  .wrap { padding: 0 min(1.5rem, 5vw); }
  .demo { padding: min(1.1rem, 3.5vw); }
  .row-main { gap: min(0.3rem, 1.2vw); }
  .row { padding: 0.1875rem min(0.4rem, 1.5vw); }
  .tiles { gap: min(0.2rem, 0.8vw); }
  .tile { width: min(2.3rem, 9.2vw); height: min(2.3rem, 9.2vw); font-size: min(1.1rem, 4.4vw); }
  .readout { padding: 0.5rem 0.5rem; }
  .ground { min-width: min(2.3rem, 9vw); }
  .ground .gcd-val { font-size: min(0.85rem, 3.6vw); }
  .ground .gcd-label { font-size: min(0.5rem, 2.4vw); }
  .pegs { gap: min(0.2rem, 0.8vw); }
  .peg { width: min(0.4rem, 1.7vw); height: min(0.4rem, 1.7vw); }
  .demo-toggle { font-size: min(0.66rem, 2.9vw); padding: 0.3rem min(0.6rem, 2.4vw); }
  .demo-mode { font-size: min(1rem, 4.6vw); }
  .demo-digits { font-size: min(0.78rem, 3.4vw); }
}

/* Narrow screens: the nav stays one row with the tagline visible, by
   shrinking the icon, the tagline's tracking and the controls. */
@media (max-width: 28rem) {
  .wordmark { font-size: 1.75rem; gap: 0.3rem; }
  .wordmark-tagline { font-size: 10px; letter-spacing: 0.14em; }
  .nav-play { font-size: 0.8rem; padding: 0.5rem 0.85rem; }
}
@media (max-width: 22.5rem) {
  .wordmark { font-size: 1.5rem; }
  .wordmark-tagline { font-size: 9px; letter-spacing: 0.1em; }
  .nav-play { font-size: 0.74rem; padding: 0.45rem 0.7rem; }
}

/* ---------- collapsible algorithm walkthrough ---------- */
.algo-detail { margin: 1.5rem 0 0.5rem; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.algo-detail summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 0.25rem;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--chalk-dim);
}
.algo-detail summary::-webkit-details-marker { display: none; }
.algo-detail summary::before {
  content: "";
  flex: none;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--divisor);
  border-bottom: 2px solid var(--divisor);
  transform: rotate(-45deg);
  transition: transform 0.18s ease;
  margin: 0 0.25rem 0 0.1rem;
}
.algo-detail[open] summary::before { transform: rotate(45deg); }
.algo-detail summary:hover { color: var(--chalk); }
.algo-detail summary:focus-visible {
  outline: 2px solid var(--divisor);
  outline-offset: 2px;
  border-radius: 4px;
  color: var(--chalk);
}
.algo-detail .algo-body { padding: 0.25rem 0.25rem 0.75rem; }
@media (prefers-reduced-motion: reduce) {
  .algo-detail summary::before { transition: none; }
}

/* Separates the Q&A reference block from the narrative sections above it */
.copy h2.faq-title {
  margin-top: 3.25rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
