@font-face {
  font-family: "Literata";
  src: url("font/literata-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0100-024F, U+0300-036F, U+1E00-1EFF, U+2000-206F, U+2122, U+2190-21FF, U+25CC;
}

:root {
  color-scheme: light;
  --bg: #f8f4ec;
  --bg-surface: #f1e9d9;
  --bg-inset: #e9dfcb;
  --text-primary: #1a1815;
  --text-secondary: #38322a;
  --text-muted: #4c453a;
  --accent: #872e0f;
  --accent-soft: #f3ddce;
  --done: #2f5d33;
  --rule: #ddd0b7;
  --rule-strong: #b9a884;
  --focus: #872e0f;
  --shadow: 0 1px 2px rgba(26, 24, 21, .05), 0 10px 30px rgba(26, 24, 21, .06);

  --serif: "Literata", "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --measure: 33rem;
  --wide: 60rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131519;
    --bg-surface: #1b1e24;
    --bg-inset: #22262e;
    --text-primary: #f4f0e7;
    --text-secondary: #cdc5b7;
    --text-muted: #bcb3a4;
    --accent: #f0a86a;
    --accent-soft: #33251b;
    --done: #8fcf8a;
    --rule: #333944;
    --rule-strong: #4d5462;
    --focus: #f0a86a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .28);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131519;
  --bg-surface: #1b1e24;
  --bg-inset: #22262e;
  --text-primary: #f4f0e7;
  --text-secondary: #cdc5b7;
  --text-muted: #bcb3a4;
  --accent: #f0a86a;
  --accent-soft: #33251b;
  --done: #8fcf8a;
  --rule: #333944;
  --rule-strong: #4d5462;
  --focus: #f0a86a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .28);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  overflow-wrap: break-word;
}

a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: from-font; }
a:hover { text-decoration-thickness: .1em; }

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

h1, h2, h3 { font-weight: 700; line-height: 1.2; letter-spacing: -.012em; }

.is-hidden { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.wrap { width: 100%; max-width: var(--wide); margin: 0 auto; padding: 0 1.15rem; }
.measure { max-width: var(--measure); }

/* ---------- masthead ---------- */

.masthead { padding: 2.25rem 0 .5rem; }
.masthead h1 {
  margin: 0 0 .6rem;
  font-size: clamp(2.1rem, 8.2vw, 3.4rem);
}
.masthead h1 i { font-style: italic; color: var(--accent); }
.deck {
  margin: 0;
  max-width: var(--measure);
  font-size: clamp(1.02rem, 3.4vw, 1.2rem);
  color: var(--text-secondary);
}
.jump {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1.1rem;
  margin: .9rem 0 0;
  font-size: .84rem;
}
.jump a { color: var(--text-muted); text-decoration-color: var(--rule-strong); }
.jump a:hover { color: var(--accent); }

.utility {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  margin-bottom: 1.5rem;
  font-size: .82rem;
}
.utility a, .utility button {
  font: inherit;
  font-family: var(--serif);
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: .3rem .8rem;
  cursor: pointer;
  text-decoration: none;
}
.utility a:hover, .utility button:hover { border-color: var(--rule-strong); color: var(--text-primary); }

/* ---------- game ---------- */

.game { margin: 1.4rem 0 1rem; }

.stage {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: .9rem 0 .85rem;
  border-bottom: 1px solid var(--rule);
}

.meta {
  display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
  margin: 0 0 .5rem;
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.meta .count { font-variant-numeric: tabular-nums; white-space: nowrap; }

.goal { margin: 0 0 .8rem; font-size: .95rem; color: var(--text-secondary); }
.goal b { color: var(--text-primary); }

.derivation { list-style: none; margin: 0; padding: 0; }
.derivation li {
  display: grid;
  grid-template-columns: 1fr;
  gap: .05rem;
  padding: .1rem 0;
}
.derivation .form {
  font-size: 1.55rem;
  line-height: 1.25;
  color: var(--text-muted);
  letter-spacing: .005em;
}
.derivation li:first-child .form {
  font-variant-caps: small-caps;
  letter-spacing: .1em;
  color: var(--text-secondary);
}
.derivation li:last-child .form {
  font-size: clamp(2rem, 9vw, 2.9rem);
  color: var(--text-primary);
  font-weight: 700;
}
.derivation li.solved:last-child .form { color: var(--done); }
.derivation .via {
  font-size: .78rem;
  color: var(--text-muted);
  padding-left: .1rem;
  margin-top: .15rem;
}
.derivation .via::before { content: "↓ "; color: var(--rule-strong); }
.derivation .form .hit { color: var(--accent); }
.derivation .form .gone { color: var(--accent); text-decoration: line-through; opacity: .55; }

/* On a short screen the sticky derivation column must leave room for the rules. */
@media (max-height: 720px) and (max-width: 62rem) {
  .derivation .form { font-size: 1.25rem; }
  .derivation li:last-child .form { font-size: 2.1rem; }
  .derivation .via { font-size: .72rem; }
  .goal { margin-bottom: .5rem; }
}

@media (min-width: 46rem) {
  .derivation .form { font-size: 1.85rem; }
}

@media (min-width: 62rem) {
  [data-game] {
    display: grid;
    grid-template-columns: minmax(0, 25rem) minmax(0, 1fr);
    column-gap: 3.5rem;
    align-items: start;
  }
  .board { position: sticky; top: 1.25rem; }
  .stage { position: static; padding-top: 0; }
  .derivation li:last-child .form { font-size: 3.2rem; }
  .palette h3:first-child { margin-top: .2rem; }
}

.status {
  margin: .55rem 0 0;
  min-height: 1.5rem;
  font-size: .88rem;
  color: var(--text-secondary);
}
.status.miss { color: var(--accent); }

/* ---------- controls ---------- */

.actions { display: flex; flex-wrap: wrap; gap: .4rem; margin: .85rem 0 1.2rem; }
.actions button {
  font: inherit;
  font-family: var(--serif);
  font-size: .82rem;
  padding: .4rem .7rem;
  min-height: 2.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: .4rem;
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
}
.actions button:hover:not(:disabled) { color: var(--text-primary); border-color: var(--accent); }
.actions button:disabled { opacity: .45; cursor: default; }
.actions .primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 700; }
.actions .primary:hover { filter: brightness(1.08); }

.palette h3 {
  margin: 1.4rem 0 .5rem;
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 400;
}
.palette h3:first-child { margin-top: 0; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .5rem; }
.chip {
  display: block;
  text-align: left;
  font: inherit;
  font-family: var(--serif);
  padding: .5rem .6rem;
  min-height: 3.2rem;
  border: 1px solid var(--rule);
  border-radius: .4rem;
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
}
""
.chip .pattern {
  display: block;
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--text-primary);
  letter-spacing: -.01em;
}
.chip .label { display: block; font-size: .72rem; line-height: 1.3; color: var(--text-muted); margin-top: .12rem; }
.chip i { font-style: italic; }
.chip:hover:not(:disabled) { border-color: var(--accent); color: var(--text-primary); }
.chip:disabled { opacity: .5; cursor: default; }
.chip.shake { animation: shake .3s; border-color: var(--accent); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- result card ---------- */

.card {
  margin: 1.3rem 0 0;
  padding: 1.1rem 1.15rem;
  background: var(--bg-surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--done);
  border-radius: .4rem;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .3rem; font-size: 1.3rem; }
.card h3 .gloss { font-weight: 400; font-size: .95rem; color: var(--text-muted); }
.card p { margin: .4rem 0 0; font-size: .95rem; color: var(--text-secondary); }
.card .chain { font-family: var(--mono); font-size: .82rem; color: var(--text-muted); }

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

section.prose { padding: 1.6rem 0 0; }
#intro { padding-top: .6rem; }
#intro p { margin-top: .5rem; }
section.prose h2 {
  font-size: clamp(1.35rem, 5vw, 1.8rem);
  margin: 0 0 .2rem;
}
section.prose > .wrap > p, section.prose p.lede { max-width: var(--measure); color: var(--text-secondary); }
section.prose h2 + p { margin-top: .4rem; }

.rulebook { list-style: none; margin: 1.2rem 0 0; padding: 0; display: grid; gap: .75rem; }
.rulebook li {
  display: grid;
  gap: .12rem;
  padding: .75rem .9rem;
  background: var(--bg-surface);
  border: 1px solid var(--rule);
  border-radius: .4rem;
}
.rulebook .pattern { font-family: var(--mono); font-size: .84rem; color: var(--accent); }
.rulebook .name { font-weight: 700; font-size: .98rem; }
.rulebook .hint { font-size: .9rem; color: var(--text-secondary); }
.rulebook .sample { font-size: .84rem; color: var(--text-muted); font-family: var(--mono); }

@media (min-width: 46rem) {
  .rulebook { grid-template-columns: repeat(2, 1fr); }
}

.wordlist { list-style: none; margin: 1.2rem 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: .1rem; }
.wordlist li {
  min-width: 0;
  padding: .55rem 0;
  border-bottom: 1px solid var(--rule);
  display: grid;
  gap: .1rem;
}
.wordlist .chain { font-size: 1rem; }
.wordlist .chain .start { font-variant-caps: small-caps; letter-spacing: .08em; color: var(--text-muted); }
.wordlist .chain .step { color: var(--text-muted); }
.wordlist .chain .end { font-weight: 700; color: var(--text-primary); }
.wordlist .chain .arrow { color: var(--rule-strong); padding: 0 .2em; }
.wordlist .gloss { font-size: .85rem; color: var(--text-muted); }
.wordlist .note { font-size: .88rem; color: var(--text-secondary); max-width: var(--measure); }

@media (min-width: 46rem) {
  .wordlist { display: block; columns: 2; column-gap: 2.5rem; }
  .wordlist li { break-inside: avoid; }
}

.sources { list-style: none; margin: 1rem 0 0; padding: 0; max-width: var(--measure); }
.sources li { padding: .5rem 0; border-top: 1px solid var(--rule); font-size: .92rem; color: var(--text-secondary); }

footer.page {
  margin-top: 3rem;
  padding: 1.6rem 0 3rem;
  border-top: 1px solid var(--rule);
  font-size: .85rem;
  color: var(--text-muted);
}
footer.page a { color: var(--text-secondary); }
footer.page p { margin: .3rem 0; max-width: var(--measure); }

.top-link { display: inline-block; margin-top: .6rem; }

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