@font-face {
  font-family: 'Fraunces';
  src: url('/assets/fonts/fraunces-regular.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Fraunces';
  src: url('/assets/fonts/fraunces-italic.ttf') format('truetype');
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Space Grotesk';
  src: url('/assets/fonts/space-grotesk-regular.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Space Grotesk';
  src: url('/assets/fonts/space-grotesk-semibold.ttf') format('truetype');
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f3efe7;
  --paper-raised: #faf7f0;
  --paper-deep: #ebe5d9;
  --ink: #20201c;
  --ink-soft: #59564e;
  --ink-faint: #6a655b;
  --rule: #c9c0af;
  --rule-strong: #777064;
  --accent: #8a4e28;
  --correct: #285a35;
  --correct-bg: #dde9da;
  --wrong: #80352d;
  --wrong-bg: #f0dcd6;
  --serif: 'Fraunces', Iowan Old Style, Baskerville, Times New Roman, serif;
  --sans: 'Space Grotesk', Avenir Next, Avenir, Helvetica Neue, sans-serif;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --paper: #171713;
  --paper-raised: #201f1a;
  --paper-deep: #292720;
  --ink: #f0ece2;
  --ink-soft: #c3bcae;
  --ink-faint: #aaa294;
  --rule: #4e4a41;
  --rule-strong: #817a6d;
  --accent: #e1ad58;
  --correct: #b8dab4;
  --correct-bg: #263628;
  --wrong: #f0b2a4;
  --wrong-bg: #3c2925;
}

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 96px;
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-underline-offset: 0.22em;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
[tabindex='-1']:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}

h1,
h2,
p {
  overflow-wrap: break-word;
}

h1,
h2 {
  font-family: var(--serif);
  font-weight: 400;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.78rem;
  transform: translateY(-170%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: relative;
  z-index: 10;
  display: flex;
  width: min(calc(100% - 48px), 1280px);
  min-height: 84px;
  margin: 0 auto;
  border-bottom: 1px solid var(--rule);
  align-items: center;
  justify-content: space-between;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-decoration: none;
}

.wordmark-mark {
  width: 30px;
  height: 30px;
  overflow: visible;
}

.wordmark-mark circle,
.wordmark-mark path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.25;
}

.wordmark-mark circle:last-child {
  fill: var(--accent);
  stroke: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 22px;
}

.site-nav a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  font-size: 0.69rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--accent);
}

.theme-toggle {
  display: inline-grid;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  place-items: center;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  border-color: var(--rule-strong);
  background: var(--paper-deep);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.6;
}

:root[data-theme='dark'] .theme-toggle svg circle {
  fill: currentColor;
}

.home-page {
  min-height: 100svh;
}

.home-main {
  display: flex;
  width: min(calc(100% - 48px), 1280px);
  min-height: calc(100svh - 84px);
  margin: 0 auto;
  padding: clamp(72px, 13vh, 150px) 0 clamp(56px, 10vh, 110px);
  flex-direction: column;
  justify-content: center;
}

.home-main h1 {
  max-width: 900px;
  margin: 0;
  font-size: clamp(4rem, 9.5vw, 8.6rem);
  font-variation-settings: 'SOFT' 70, 'WONK' 1;
  letter-spacing: -0.06em;
  line-height: 0.94;
}

.home-main h1 em {
  color: var(--accent);
  font-weight: 400;
}

.game-door {
  display: grid;
  width: min(100%, 520px);
  margin-top: clamp(64px, 11vh, 112px);
  padding: 19px 2px;
  border-top: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule);
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 1.15rem;
  text-decoration: none;
}

.door-number {
  color: var(--ink-faint);
  font-family: var(--sans);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.door-arrow {
  color: var(--accent);
  font-family: var(--sans);
  transition: transform 180ms ease;
}

.game-door:hover,
.game-door:focus-visible {
  color: var(--accent);
}

.game-door:hover .door-arrow,
.game-door:focus-visible .door-arrow {
  transform: translate(3px, -3px);
}

.subscribe-panel {
  width: min(100%, 520px);
  margin-top: clamp(48px, 8vh, 78px);
}

.subscribe-panel h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.subscribe-copy {
  margin: 8px 0 20px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 0.96rem;
  line-height: 1.55;
}

.subscribe-form {
  position: relative;
}

.subscribe-form > label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-faint);
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.subscribe-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.subscribe-controls input,
.subscribe-controls button {
  min-height: 50px;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
}

.subscribe-controls input {
  width: 100%;
  min-width: 0;
  padding: 10px 13px;
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.subscribe-controls input:hover,
.subscribe-controls input:focus-visible {
  border-color: var(--ink);
}

.subscribe-controls button {
  padding: 10px 17px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.subscribe-controls button:hover:not(:disabled),
.subscribe-controls button:focus-visible:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper-raised);
}

.subscribe-controls button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.subscribe-trap {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.subscribe-result {
  min-height: 1.5em;
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 0.84rem;
}

.subscribe-result[data-state='success'] {
  color: var(--correct);
}

.subscribe-result[data-state='error'] {
  color: var(--wrong);
}

.polyglot-main {
  width: min(calc(100% - 48px), 1120px);
  margin: 0 auto;
  padding: clamp(68px, 9vw, 118px) 0 72px;
}

.game-intro {
  display: grid;
  max-width: 850px;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.72fr);
  align-items: end;
  gap: 36px;
}

.game-intro .eyebrow {
  grid-column: 1 / -1;
}

.game-intro h1 {
  margin: -16px 0 0;
  font-size: clamp(3.8rem, 8vw, 7.3rem);
  letter-spacing: -0.055em;
  line-height: 0.92;
}

.game-intro-copy {
  margin: 0 0 5px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.6;
}

.game-intro .edition-stamp {
  grid-column: 1 / -1;
  margin: 1px 0 0;
  color: var(--ink-faint);
  font-family: var(--sans);
  font-size: 0.66rem;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.13em;
  line-height: 1.4;
}

.eyebrow,
.panel-label {
  margin: 0;
  color: var(--accent);
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  line-height: 1.4;
  text-transform: uppercase;
}

.game-shell {
  position: relative;
  margin-top: 48px;
  padding: clamp(24px, 4vw, 48px);
  border: 1px solid var(--rule-strong);
  background: var(--paper-raised);
}

.game-shell::before {
  position: absolute;
  inset: 7px;
  border: 1px solid var(--rule);
  content: '';
  pointer-events: none;
}

.game-folio,
.game-status {
  position: relative;
  z-index: 1;
  display: flex;
  color: var(--ink-faint);
  font-size: 0.59rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  justify-content: space-between;
}

.game-folio {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}

.game-status {
  display: grid;
  margin: 20px 0 28px;
  grid-template-columns: auto minmax(260px, 1fr);
  align-items: center;
  gap: 20px;
}

.game-status p {
  margin: 0;
}

.round-results {
  display: flex;
  margin: 0;
  padding: 0;
  gap: 6px;
  justify-self: end;
  list-style: none;
}

.round-result {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink-faint);
}

.round-result-glyph {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

/* Solid fill, not a tint. Glyph flips to paper so it stays legible on the fill,
   and keeps the grid readable without relying on colour alone. */
.round-result[data-state='correct'] {
  border-color: var(--correct);
  background: var(--correct);
  color: var(--paper);
}

.round-result[data-state='incorrect'] {
  border-color: var(--wrong);
  background: var(--wrong);
  color: var(--paper);
}

.game-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: clamp(28px, 5vw, 64px);
}

.phrase-panel,
.answer-panel {
  min-width: 0;
}

.phrase-panel {
  display: flex;
  min-height: 380px;
  padding: clamp(24px, 3.5vw, 42px);
  border: 1px solid var(--rule);
  background: var(--paper-deep);
  flex-direction: column;
  justify-content: center;
}

.phrase {
  margin: 32px 0 8px;
  font-family: var(--serif);
  font-size: clamp(2.15rem, 4.5vw, 4rem);
  letter-spacing: -0.035em;
  line-height: 1.04;
}

.romanization {
  margin: 0 0 32px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1rem;
  font-style: italic;
  line-height: 1.5;
}

.listen-button {
  display: inline-flex;
  width: fit-content;
  min-height: 48px;
  padding: 8px 17px;
  border: 1px solid var(--ink);
  background: transparent;
  align-items: center;
  gap: 9px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.035em;
  cursor: pointer;
}

.listen-button:hover,
.listen-button:focus-visible,
.listen-button[data-playing='true'] {
  background: var(--ink);
  color: var(--paper-raised);
}

.listen-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.5;
}

#phrase-audio {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.audio-note {
  margin: 12px 0 0;
  color: var(--ink-faint);
  font-family: var(--serif);
  font-size: 0.78rem;
  font-style: italic;
}

.choice-heading {
  display: flex;
  min-height: 48px;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.hint-actions {
  display: flex;
  gap: 6px;
}

.hint-button {
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.62rem;
  cursor: pointer;
}

.hint-button span {
  display: inline-grid;
  width: 17px;
  height: 17px;
  margin-right: 4px;
  border: 1px solid currentColor;
  border-radius: 50%;
  place-items: center;
}

.hint-button:hover:not(:disabled),
.hint-button:focus-visible:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.hint-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.family-hint {
  min-height: 1.4em;
  margin: 7px 0 12px;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 0.87rem;
  font-style: italic;
}

.choices {
  display: grid;
  margin-top: 18px;
  gap: 9px;
}

.choice-button {
  display: grid;
  width: 100%;
  min-height: 63px;
  padding: 12px 16px;
  border: 1px solid var(--rule);
  background: transparent;
  grid-template-columns: 34px 1fr 22px;
  align-items: center;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.choice-button:hover:not(:disabled),
.choice-button:focus-visible:not(:disabled) {
  border-color: var(--ink);
  background: var(--paper-deep);
}

.choice-button:disabled {
  cursor: default;
}

.choice-letter {
  color: var(--ink-faint);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.choice-name {
  font-family: var(--serif);
  font-size: 1.04rem;
}

.choice-glyph {
  font-size: 1rem;
  text-align: right;
}

.choice-button[data-state='correct'] {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: var(--correct);
}

.choice-button[data-state='wrong'] {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: var(--wrong);
}

.choice-button[data-state='dimmed'] {
  opacity: 0.58;
}

.choice-button[data-state='eliminated'] {
  opacity: 0.55;
  text-decoration: line-through;
}

.reveal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  margin-top: 32px;
  padding: 27px 0 4px;
  border-top: 1px solid var(--rule-strong);
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 21px;
}

.reveal-mark {
  display: grid;
  width: 44px;
  height: 44px;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: var(--correct);
  place-items: center;
}

.reveal-mark::before {
  content: '✓';
}

.reveal-mark[data-correct='false'] {
  color: var(--wrong);
}

.reveal-mark[data-correct='false']::before {
  content: '×';
}

.reveal-copy h2 {
  margin: 4px 0 2px;
  font-size: 1.9rem;
  line-height: 1.1;
}

.reveal-origin {
  margin: 5px 0 0;
  color: var(--ink-faint);
  font-size: 0.75rem;
}

.reveal-meaning {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1.04rem;
  font-style: italic;
}

.button {
  display: inline-flex;
  min-height: 48px;
  border: 1px solid var(--ink);
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: pointer;
}

.button-next {
  padding: 10px 17px;
  background: transparent;
  white-space: nowrap;
}

.button-next:hover,
.button-next:focus-visible {
  background: var(--ink);
  color: var(--paper-raised);
}

.button-primary {
  padding: 11px 20px;
  background: var(--ink);
  color: var(--paper);
}

.button-primary:hover,
.button-primary:focus-visible {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper-raised);
}

.result-panel {
  position: relative;
  z-index: 1;
  margin-top: 30px;
  padding: clamp(30px, 5vw, 56px);
  border: 1px solid var(--rule-strong);
  background: var(--paper-deep);
  text-align: center;
}

.result-panel h2 {
  margin: 11px 0 10px;
  font-size: clamp(2.4rem, 5vw, 4.2rem);
  letter-spacing: -0.035em;
  line-height: 1;
}

.result-panel > p:not(.eyebrow) {
  max-width: 530px;
  margin: 0 auto;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1.03rem;
}

.result-ledger {
  display: grid;
  max-width: 600px;
  margin: 30px auto;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  grid-template-columns: repeat(2, 1fr);
}

.result-ledger div {
  padding: 17px 12px;
}

.result-ledger div + div {
  border-left: 1px solid var(--rule);
}

.result-ledger dt {
  color: var(--ink-faint);
  font-size: 0.59rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-ledger dd {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 1.35rem;
}

.result-restart {
  margin: 0 auto;
}

.result-subscribe {
  margin: 40px auto 0;
  padding-top: 34px;
  border-top: 1px solid var(--rule-strong);
  text-align: left;
}

.result-subscribe h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1.2;
}

.noscript-note {
  max-width: 700px;
  margin: 22px auto 0;
  color: var(--ink-faint);
  font-family: var(--serif);
  font-size: 0.78rem;
  font-style: italic;
  text-align: center;
}

.error-page {
  display: flex;
  width: min(calc(100% - 32px), 720px);
  min-height: 100svh;
  margin: 0 auto;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
}

.error-page h1 {
  margin: 12px 0;
  font-size: clamp(3rem, 8vw, 6rem);
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.error-page > p:not(.eyebrow) {
  margin: 0 0 30px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1.08rem;
}

@media (max-width: 900px) {
  .game-intro {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .game-intro h1 {
    margin-top: -10px;
  }

  .game-intro-copy {
    max-width: 520px;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  .phrase-panel {
    min-height: 320px;
  }
}

@media (max-width: 640px) {
  html {
    scroll-padding-top: 78px;
  }

  .site-header,
  .home-main,
  .polyglot-main {
    width: min(calc(100% - 32px), 1120px);
  }

  .site-header {
    min-height: 74px;
  }

  .home-main {
    min-height: calc(100svh - 74px);
    padding-top: 60px;
  }

  .home-main h1 {
    font-size: clamp(3.55rem, 17.5vw, 6rem);
  }

  .game-door {
    margin-top: 64px;
  }

  .subscribe-panel {
    margin-top: 48px;
  }

  .polyglot-main {
    padding-top: 58px;
  }

  .game-intro h1 {
    font-size: clamp(3.5rem, 17vw, 5.7rem);
  }

  .game-shell {
    margin-top: 36px;
    padding: 24px;
  }

  .game-status {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .round-results {
    width: min(100%, 360px);
    justify-self: start;
  }

  .reveal-panel {
    grid-template-columns: 44px 1fr;
  }

  .button-next {
    width: 100%;
    margin-top: 9px;
    grid-column: 1 / -1;
  }
}

@media (max-width: 460px) {
  .wordmark {
    gap: 8px;
    font-size: 0.8rem;
    letter-spacing: 0.17em;
  }

  .wordmark-mark {
    width: 27px;
    height: 27px;
  }

  .site-nav {
    gap: 13px;
  }

  .home-main h1 {
    font-size: clamp(3.25rem, 17.8vw, 4.8rem);
  }

  .game-door {
    padding: 17px 1px;
  }

  .subscribe-controls {
    grid-template-columns: 1fr;
  }

  .subscribe-controls button {
    width: 100%;
  }

  .polyglot-main {
    padding-bottom: 52px;
  }

  .game-shell {
    padding: 21px;
  }

  .phrase-panel {
    min-height: 280px;
    padding: 23px 19px;
  }

  .phrase {
    margin-top: 27px;
    font-size: 2.25rem;
  }

  .choice-heading {
    flex-direction: column;
  }

  .hint-actions {
    width: 100%;
  }

  .hint-button {
    min-height: 44px;
    flex: 1;
  }

  .choice-button {
    min-height: 58px;
  }

  .reveal-panel {
    grid-template-columns: 1fr;
  }

  .reveal-mark {
    width: 38px;
    height: 38px;
  }

  .button-next {
    grid-column: auto;
  }

  .result-ledger {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-ledger div + div {
    border-left: 1px solid var(--rule);
  }

  .result-panel {
    padding: 24px;
  }

  .result-subscribe {
    margin-top: 34px;
    padding-top: 28px;
  }

  .round-results {
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (forced-colors: active) {
  .game-shell::before {
    display: none;
  }
}
