/* CHAIN — original palette, rounded shapes and type.
 *
 * Colour means exactly one thing here: a rule type. Every other state (active,
 * rejected, dead) is carried by weight, border and fill instead.
 *
 * Rule chips are always filled, so a chip looks identical whether or not its
 * link has been made. In light mode that puts white text on the fills, which
 * is why compound and sounds-like run a shade deeper than their dark-mode
 * counterparts — a legibility floor, not a style choice.
 */

:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --sunk: #E9EBEF;
  --fg: #101114;
  --fg-2: #4A4E57;
  --fg-3: #7B818C;
  --hair: #D4D8DE;
  --hair-2: #BFC5CE;

  --anchor-bg: #101114;
  --anchor-fg: #F4F5F7;
  --anchor-fg-2: #767C87;
  --anchor-shadow: rgba(16, 17, 20, .3);

  --compound: #1668C4;
  --phrase: #0B7A53;
  --rhyme: #7B3FD4;
  --anagram: #C62828;
  --sounds: #E0A800;
  --chip-fg: #FFFFFF;

  --accent: #101114;
  --accent-glow: rgba(16, 17, 20, .09);
  --good: #158B45;
  --dead: #9098A2;

  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --round: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;

  --r-card: 14px;
  --r-pill: 999px;
  --r-swatch: 6px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06);
  --col: 460px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114; --surface: #191B20; --sunk: #232730;
    --fg: #EDEFF2; --fg-2: #A8AEB8; --fg-3: #767C87;
    --hair: #2C2F36; --hair-2: #3D414A;
    --anchor-bg: #EDEFF2; --anchor-fg: #101114; --anchor-fg-2: #6B7280;
    --anchor-shadow: rgba(0, 0, 0, .5);
    --compound: #4FA3F0; --phrase: #2FBE85; --rhyme: #A97BF0;
    --anagram: #FF6B6B; --sounds: #E8C22A;
    --chip-fg: #101114;
    --accent: #EDEFF2; --accent-glow: rgba(237, 239, 242, .12);
    --good: #3ECF74; --dead: #6A707A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .34);
  }
}
:root[data-theme="dark"] {
  --bg: #101114; --surface: #191B20; --sunk: #232730;
  --fg: #EDEFF2; --fg-2: #A8AEB8; --fg-3: #767C87;
  --hair: #2C2F36; --hair-2: #3D414A;
  --anchor-bg: #EDEFF2; --anchor-fg: #101114; --anchor-fg-2: #6B7280;
  --anchor-shadow: rgba(0, 0, 0, .5);
  --compound: #4FA3F0; --phrase: #2FBE85; --rhyme: #A97BF0;
  --anagram: #FF6B6B; --sounds: #E8C22A;
  --chip-fg: #101114;
  --accent: #EDEFF2; --accent-glow: rgba(237, 239, 242, .12);
  --good: #3ECF74; --dead: #6A707A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .34);
}
:root[data-theme="light"] {
  --bg: #F4F5F7; --surface: #FFFFFF; --sunk: #E9EBEF;
  --fg: #101114; --fg-2: #4A4E57; --fg-3: #7B818C;
  --hair: #D4D8DE; --hair-2: #BFC5CE;
  --anchor-bg: #101114; --anchor-fg: #F4F5F7; --anchor-fg-2: #767C87;
  --anchor-shadow: rgba(16, 17, 20, .3);
  --compound: #1668C4; --phrase: #0B7A53; --rhyme: #7B3FD4;
  --anagram: #C62828; --sounds: #E0A800;
  --chip-fg: #FFFFFF;
  --accent: #101114; --accent-glow: rgba(16, 17, 20, .09);
  --good: #158B45; --dead: #9098A2;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06);
}

* { box-sizing: border-box; }

/* Any class that sets `display` outbeats the browser's [hidden] rule, which
   silently leaves hidden elements on screen. One global override instead of
   remembering it per component. */
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sounds-like is a bright yellow: no shade of it carries white text, so that
   one chip flips to dark text rather than being darkened into a muddy olive. */
.rule-compound { --rc: var(--compound); }
.rule-phrase   { --rc: var(--phrase); }
.rule-rhyme    { --rc: var(--rhyme); }
.rule-anagram  { --rc: var(--anagram); }
.rule-sounds   { --rc: var(--sounds); --rc-fg: #101114; }

/* ------------------------------------------------------------------ shell */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--col);
  margin: 0 auto;
  background: var(--bg);
}

.appbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 15px 16px;
  border-bottom: 1px solid var(--hair);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 20;
}

.appbar__title { font: 700 17px/1 var(--round); letter-spacing: .2em; text-indent: .2em; }
.appbar__side { display: flex; gap: 4px; }
.appbar__side--right { justify-content: flex-end; }

.iconbtn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  font-size: 14px;
  color: var(--fg-3);
}
.iconbtn:hover { background: var(--sunk); color: var(--fg); }
#btn-back { font-size: 22px; line-height: 1; }

.view { flex: 1; display: flex; flex-direction: column; padding: 16px 18px 24px; }

/* ------------------------------------------------------------------- meta */

.meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; gap: 12px; }
.meta__label { font-size: 11.5px; font-weight: 600; color: var(--fg-3); }

.badge {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: capitalize;
  background: var(--anchor-bg);
  color: var(--anchor-fg);
  padding: 6px 13px;
  border-radius: var(--r-pill);
}

/* -------------------------------------------------------------------- hub */

.hub { display: flex; flex-direction: column; gap: 12px; }

.hubcard {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--hair);
  border-radius: var(--r-card);
  padding: 15px 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color .14s ease, transform .14s ease;
}
.hubcard:hover { border-color: var(--hair-2); }
.hubcard:active { transform: scale(.994); }
.hubcard--solved { background: transparent; box-shadow: none; border-color: var(--hair); }
.hubcard--solved .hubcard__name { color: var(--fg-3); }

.hubcard__top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hubcard__name { font: 700 18px/1 var(--round); letter-spacing: -.01em; }
.hubcard__name em {
  font-style: normal;
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--fg-3);
  margin-left: 9px;
}

.hubcard__state { font-size: 10.5px; font-weight: 700; letter-spacing: .03em; color: var(--fg-3); white-space: nowrap; }
.hubcard__state--ok { color: var(--good); }

.strip { display: flex; gap: 5px; }
.strip span { width: 19px; height: 19px; border-radius: var(--r-swatch); background: var(--rc); display: block; }

/* ------------------------------------------------------------------ board */

/* The spine.
 *
 * One continuous thread down the left gutter, but it is not a divider — it is
 * the chain. It runs solid in a rule's colour as it passes that rule's pill,
 * and blends from one colour to the next as it crosses a word, so a word is
 * visibly where two rules meet.
 *
 * Drawn per row rather than as one long gradient: each node and joint paints
 * its own segment from its top colour to its bottom colour. Rows are flush in
 * the flex column, so the segments abut and read as one line, and it works at
 * any chain length without measuring anything.
 */
.board { display: flex; flex-direction: column; padding-left: 22px; }

/* Offsets on an absolutely positioned child resolve against the PADDING box,
   which sits inside the border. Word cards have a 1px border and pills have
   none, so one flat set of offsets put every card's segment 1px right of every
   pill's — a jagged line — and 1px short at each end — hairline gaps at every
   junction. Each row declares its own border, so the segments align on the
   border box and meet exactly. */
/* The extra half-pixel makes neighbours overlap rather than merely touch. On a
   2x or 3x screen a row can land on a fractional pixel and a seam reappears
   even when the arithmetic says zero; both sides of every junction are the same
   colour, so the overlap can't be seen. */
.node, .joint { position: relative; --spine-gap: 15px; --spine-bleed: 0.5px; }
.node { --spine-gap: 16px; --spine-bleed: 1.5px; }   /* its 1px border, plus the same half */

.node::before, .joint::before {
  content: "";
  position: absolute;
  left: calc(var(--spine-gap) * -1);
  top: calc(var(--spine-bleed) * -1);
  bottom: calc(var(--spine-bleed) * -1);
  width: 3px;
  background: linear-gradient(to bottom, var(--sp-up, transparent), var(--sp-down, transparent));
}
/* Only the ends are capped — rounding every segment would read as dashes. */
.board > :first-child::before { border-radius: 3px 3px 0 0; }
.board > :last-child::before  { border-radius: 0 0 3px 3px; }

.node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--hair);
  border-radius: var(--r-card);
  padding: 14px 17px;
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: 52px;
  scroll-margin-block: 90px;
}

.node__word { font: 700 21px/1 var(--round); letter-spacing: .02em; }
.node__role { font-size: 10.5px; font-weight: 600; color: var(--fg-3); white-space: nowrap; }

.node--anchor { background: var(--anchor-bg); border-color: var(--anchor-bg); box-shadow: 0 2px 9px -4px var(--anchor-shadow); }
.node--anchor .node__word { color: var(--anchor-fg); }
.node--anchor .node__role { color: var(--anchor-fg-2); }

/* Waiting, not disabled — a quiet filled panel rather than an empty outline. */
.node--empty { background: var(--sunk); border-color: transparent; box-shadow: none; cursor: pointer; }
.node--empty:hover { background: var(--hair); }


.node--dead { border-color: var(--hair); background: transparent; box-shadow: none; cursor: pointer; }
.node--dead .node__word { color: var(--dead); text-decoration: line-through; text-decoration-thickness: 2px; }

/* Every slot is a live input. Only the focused one is highlighted, and the
   border width never changes so nothing shifts as focus moves. */
.node--slot { cursor: text; }
.node--slot:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.node--bad { border-color: var(--fg-2); }
.node--done { background: var(--sunk); }

.node__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  padding: 0;
  font: 700 21px/1.15 var(--round);
  letter-spacing: .02em;
  color: var(--fg);
  text-transform: uppercase;
  caret-color: var(--accent);
}
.node__input:focus { outline: none; }
.node__input::placeholder {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 13.5px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg-3);
}

.shake { animation: shake .34s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.pop { animation: pop .22s ease-out; }
@keyframes pop {
  0% { transform: scale(.95); opacity: .4; }
  100% { transform: scale(1); opacity: 1; }
}

/* Pill and template sit left, hard against the spine, in one normal-flow row.
   They used to be centred with the template absolutely positioned off the
   chip's right edge, which pushed the longest joins off a 320px screen. */
.joint { display: flex; padding: 11px 0; }
.joint__body { display: flex; align-items: center; gap: 11px; min-width: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--rc-fg, var(--chip-fg));
  background: var(--rc);
  padding: 6px 13px;
  border-radius: var(--r-pill);
  white-space: nowrap;
}

.joint__tmpl {
  display: flex;
  align-items: baseline;
  white-space: nowrap;
  font: 700 13px/1 var(--round);
  letter-spacing: .02em;
}
.joint__tmpl--spaced { column-gap: 7px; }   /* a phrase is two words — show it */
.joint__word { color: var(--fg); }
.joint__sep   { color: var(--fg-3); font-weight: 500; white-space: pre; }
.joint__gap {
  display: inline-block;
  width: 30px;
  height: 13px;
  border-bottom: 2px dashed var(--rc);
}
.joint__gap--wide { width: 66px; }

/* The longest join is an 11-character rule name beside two long words. In
   normal flow that now fits, but the narrowest phones have no margin to spare. */
@media (max-width: 359px) {
  .board { padding-left: 18px; }
  .joint { --spine-gap: 13px; }
  .node  { --spine-gap: 14px; }
  .joint__body { gap: 8px; }
  .joint__tmpl { font-size: 12px; }
  .chip { padding: 6px 10px; letter-spacing: .03em; }
}

.board--long .node { padding: 11px 16px; min-height: 46px; }
.board--long .node__word, .board--long .node__input { font-size: 19px; }
.board--long .joint { padding: 8px 0; }

/* ---------------------------------------------------------------- message */

.message { margin-top: 14px; font-size: 12.5px; line-height: 1.5; font-weight: 500; padding: 11px 14px; border-radius: var(--r-card); }
.message--reject { background: var(--sunk); color: var(--fg); font-weight: 600; }
.message--info { background: var(--sunk); color: var(--fg-2); }
.message--win {
  background: color-mix(in srgb, var(--good) 14%, transparent);
  color: var(--good);
  font-weight: 700;
  text-align: center;
}


/* ---------------------------------------------------------------- buttons */

.btnrow { display: flex; gap: 9px; margin-top: auto; padding-top: 20px; }

.btn {
  flex: 1;
  text-align: center;
  padding: 14px 12px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
}
.btn--primary { background: var(--good); color: #fff; }
.btn--dark { background: var(--anchor-bg); color: var(--anchor-fg); }
.btn--secondary { background: var(--surface); color: var(--fg); border: 1px solid var(--hair); }
.btn--ghost { background: transparent; color: var(--fg-3); border: 1px solid var(--hair); }
/* Reset, once it's actually armed. Flipping to the solid dark treatment makes
   the second press feel deliberate rather than like a repeat of the first. */
.btn--armed { background: var(--anchor-bg); color: var(--anchor-fg); border-color: var(--anchor-bg); }

.btn--secondary:hover { border-color: var(--hair-2); }
.btn--ghost:hover { border-color: var(--fg-3); color: var(--fg-2); }

/* ----------------------------------------------------------------- modals */

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; background: rgba(8, 10, 14, .5); }

.modal__panel {
  width: 100%;
  max-width: var(--col);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 14px 20px 24px;
  display: flex;
  flex-direction: column;
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }

@media (min-width: 520px) {
  .modal { place-items: center; }
  .modal__panel { border-radius: 18px; max-height: 88dvh; }
  @keyframes rise { from { transform: scale(.98); opacity: 0; } }
}

.modal__close { align-self: flex-end; font-size: 15px; color: var(--fg-3); width: 32px; height: 32px; border-radius: var(--r-pill); }
.modal__close:hover { color: var(--fg); background: var(--sunk); }
.modal h2 { margin: 2px 0 8px; font: 700 26px/1.15 var(--round); letter-spacing: -.02em; }
.modal p { margin: 0 0 15px; font-size: 14.5px; line-height: 1.55; color: var(--fg-2); }
.modal p b { color: var(--fg); font-weight: 600; }

.helpsection { border-top: 1px solid var(--hair); padding-top: 16px; margin-top: 18px; }
.modal p + .helpsection { margin-top: 2px; }

.rulelist { display: flex; flex-direction: column; gap: 15px; }
.rulelist__row { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.rulelist__row p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--fg-2); }
.rulelist__row p b { color: var(--fg); font-weight: 700; }

/* The worked example. Same rounded face as the board so the help and the game
   look like the same object. */
.eg {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 7px;
  font: 700 14px/1.35 var(--round);
  letter-spacing: .02em;
  color: var(--fg);
}
.eg__op { color: var(--fg-3); font-weight: 600; }
.eg__result { color: var(--fg-2); font-weight: 600; }

.fineprint { font-size: 12.5px; line-height: 1.6; color: var(--fg-3); border-top: 1px solid var(--hair); padding-top: 14px; margin-top: 18px; }

.subhead { font-size: 11px; font-weight: 700; letter-spacing: .03em; color: var(--fg-3); margin-bottom: 11px; }

/* stats */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 24px; }
.stats > div { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-card); padding: 13px 4px; box-shadow: var(--shadow); }
.stats b { display: block; font: 700 25px/1 var(--round); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stats span { display: block; font-size: 9.5px; font-weight: 600; color: var(--fg-3); margin-top: 7px; line-height: 1.3; }

.bars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.bars__row { display: flex; align-items: center; gap: 10px; font-size: 11.5px; font-weight: 600; }
.bars__row em { font-style: normal; width: 56px; color: var(--fg-3); text-transform: capitalize; }
.bars__bar {
  height: 22px;
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  min-width: 34px;
  font-variant-numeric: tabular-nums;
}

/* share */

.sharecard {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r-card);
  padding: 17px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.sharecard__head { font-size: 11.5px; font-weight: 700; color: var(--fg-3); }
.sharecard__foot { font-size: 11.5px; color: var(--fg-3); margin-top: 2px; }

.stack { display: flex; flex-direction: column; gap: 9px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--anchor-bg);
  color: var(--anchor-fg);
  padding: 12px 20px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  z-index: 60;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, .45);
  animation: rise .18s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------ prose pages */

.prose { max-width: var(--col); padding-bottom: 40px; }
.prose h1 { font: 700 30px/1.15 var(--round); letter-spacing: -.02em; margin: 6px 0 4px; }
.prose h2 { font: 700 15px/1.3 var(--round); letter-spacing: -.01em; margin: 26px 0 8px; }
.prose p { margin: 0 0 13px; font-size: 14.5px; line-height: 1.6; color: var(--fg-2); }
.prose p b { color: var(--fg); font-weight: 600; }
.prose__date { font-size: 11.5px !important; font-weight: 600; color: var(--fg-3) !important; margin-bottom: 22px !important; }
.prose ul { margin: 0 0 13px; padding-left: 20px; }
.prose li { font-size: 14px; line-height: 1.6; color: var(--fg-2); margin-bottom: 7px; }
.prose a { color: var(--fg); text-decoration-color: var(--hair-2); text-underline-offset: 2px; word-break: break-word; }
.prose a:hover { text-decoration-color: var(--fg); }
.appbar__side .iconbtn { text-decoration: none; }

.sitefoot { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--hair); text-align: center; }
.sitefoot a { font-size: 11.5px; font-weight: 600; color: var(--fg-3); text-decoration: none; }
.sitefoot a:hover { color: var(--fg-2); }

/* -------------------------------------------------------------------- ads */

/* Space is reserved up front so a slow-filling ad never pushes the board
   around — layout shift on a puzzle you're mid-way through is unforgivable.
   Collapses to nothing if no ad script is wired up. */
.adslot {
  margin-top: 20px;
  min-height: 250px;
  border-radius: var(--r-card);
  background: var(--sunk);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.adslot > span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fg-3);
  opacity: .55;
}
/* :empty would never match — the label itself is a child — so the placeholder
   hides once the network injects anything alongside it. */
.adslot > span:not(:only-child) { display: none; }

@media (min-width: 520px) {
  .adslot { min-height: 90px; }
}
