:root {
  color-scheme: light;
  --paper: #ffffff;
  --surface: #fffefb;
  --surface-strong: #ffffff;
  --ink: #181816;
  --muted: #6f6b62;
  --line: #d8d3c8;
  --line-strong: #a8a196;
  --accent: #a73522;
  --accent-soft: #f2ded7;
  --machine: #ece8df;
  --success: #256244;
  --focus: #165c9e;
  --max-game: 680px;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #161613;
  --surface: #1d1d19;
  --surface-strong: #24241f;
  --ink: #f1eee5;
  --muted: #aaa59a;
  --line: #3b3932;
  --line-strong: #625f55;
  --accent: #df7158;
  --accent-soft: #41251f;
  --machine: #292821;
  --success: #79c798;
  --focus: #75b8ed;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 20;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--surface);
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.site-header {
  width: min(100% - 32px, 1040px);
  min-height: 70px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.brand {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -.015em;
}

.brand-mark {
  position: relative;
  width: 32px;
  height: 20px;
  display: inline-block;
}

.brand-mark i {
  position: absolute;
  top: 2px;
  width: 19px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: rotate(-18deg);
}
.brand-mark i:first-child { left: 0; }
.brand-mark i:last-child { right: 0; transform: rotate(18deg); }

.challenge-label {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.challenge-label strong { color: var(--ink); }

.header-actions {
  justify-self: end;
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 50%;
  font-weight: 700;
  cursor: pointer;
}
.icon-button:hover { background: var(--machine); }

.theme-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 50%;
  box-shadow: inset -5px -3px 0 var(--paper);
}
:root[data-theme="dark"] .theme-icon {
  box-shadow: none;
  background: currentColor;
}

.page-grid {
  width: min(100% - 32px, 1040px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, var(--max-game));
  justify-content: center;
  align-items: start;
}

.game-shell {
  width: 100%;
  min-height: 650px;
  background: var(--surface);
  border-inline: 1px solid var(--line);
}

.screen,
.loading-state,
.fatal-error {
  padding: clamp(28px, 6vw, 54px);
}

.screen[hidden],
[hidden] { display: none !important; }

.loading-state {
  min-height: 520px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.no-js .loading-state { display: none; }

.no-script {
  min-height: 520px;
  padding: clamp(36px, 8vw, 72px);
  display: grid;
  align-content: center;
  text-align: center;
}
.no-script h1 {
  max-width: 16ch;
  margin: 0 auto 16px;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: clamp(2.2rem, 7vw, 3.8rem);
  line-height: 1;
  letter-spacing: -.035em;
}
.no-script p:last-child {
  max-width: 48ch;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.6;
}

.overline {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.intro-screen {
  min-height: 650px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.intro-screen h1,
.turn-heading h1,
.result-screen h1,
dialog h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  letter-spacing: -.035em;
  text-wrap: balance;
}

.intro-screen h1 {
  max-width: 12ch;
  margin: 0 auto 18px;
  font-size: clamp(2.5rem, 7vw, 4.2rem);
  line-height: .98;
}

.intro-copy {
  max-width: 42ch;
  margin: 0 auto;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
}

.mini-chain {
  width: min(100%, 420px);
  margin: 34px auto;
  display: grid;
  grid-template-columns: 1fr 38px 1fr;
  align-items: center;
  text-align: left;
}

.mini-chain > div { padding-block: 12px; }
.mini-chain strong { display: block; font-size: 1.02rem; letter-spacing: .05em; }
.mini-chain span { color: var(--muted); font-size: .86rem; }
.mini-chain b { color: var(--accent); }

.mini-link {
  width: 12px;
  height: 12px;
  margin: auto;
  border-right: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
  transform: rotate(-45deg);
}

.primary-button,
.secondary-button,
.submit-button,
.give-up-button {
  min-height: 52px;
  border: 1px solid transparent;
  font-weight: 750;
  cursor: pointer;
}

.primary-button {
  width: min(100%, 360px);
  margin-inline: auto;
  padding: 14px 22px;
  background: var(--ink);
  color: var(--surface);
}
.primary-button:hover { background: var(--accent); color: #fff; }
.play-button { margin-top: 2px; }

.secondary-button {
  width: min(100%, 360px);
  margin: 10px auto 0;
  padding: 13px 20px;
  color: var(--ink);
  background: transparent;
  border-color: var(--line-strong);
}
.secondary-button:hover { border-color: var(--ink); }

.privacy-line,
.tomorrow-copy {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: .78rem;
}

.play-screen { padding-top: 32px; }

.score-strip {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.score-strip > div { display: flex; align-items: end; gap: 12px; }
.score-strip span {
  max-width: 9ch;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 800;
  letter-spacing: .1em;
  line-height: 1.2;
  text-transform: uppercase;
}
.score-strip strong {
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 2.4rem;
  line-height: .8;
  color: var(--accent);
}
.score-strip p {
  margin: 0;
  color: var(--muted);
  font-size: .84rem;
  text-align: right;
}

.turn-heading { padding: 28px 0 18px; }
.turn-heading p {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.turn-heading h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  line-height: 1.08;
}

mark {
  padding: 0 .14em;
  background: var(--accent-soft);
  color: var(--accent);
}

.chain {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.chain-item,
.full-chain-item {
  position: relative;
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 20px;
  align-items: center;
  padding: 16px 4px;
  border-bottom: 1px solid var(--line);
}
.chain-item:last-child { animation: chain-in .24s ease-out both; }

.chain-item::before,
.full-chain-item::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 50%;
  width: 4px;
  height: 28px;
  background: var(--line-strong);
  transform: translateY(-50%);
}
.chain-item.player::before,
.full-chain-item.player::before { background: var(--accent); }

.chain-meta span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: .61rem;
  font-weight: 800;
  letter-spacing: .12em;
}
.chain-meta b { font-size: .9rem; letter-spacing: .04em; }

.syllables {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  font-family: "Avenir Next", sans-serif;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: .035em;
}
.syllables i { color: var(--line-strong); font-style: normal; }
.syllables .linked-in { color: var(--accent); }
.syllables .linked-out {
  padding: 3px 4px 1px;
  border-bottom: 2px solid var(--accent);
}

.text-button {
  border: 0;
  padding: 5px 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 4px;
  cursor: pointer;
}
.text-button:hover { color: var(--ink); }
.history-button { margin: 12px 0 0 auto; display: block; font-size: .78rem; }

.word-form {
  position: sticky;
  bottom: 0;
  z-index: 3;
  margin-top: 24px;
  padding: 18px 0 8px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.word-form label {
  display: block;
  margin-bottom: 8px;
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.input-row { display: grid; grid-template-columns: 1fr auto; }
.input-row input {
  width: 100%;
  height: 58px;
  min-width: 0;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-right: 0;
  border-radius: 0;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 1.05rem;
}
.input-row input[aria-invalid="true"] { border-color: var(--accent); }
.submit-button {
  min-width: 124px;
  padding: 0 17px;
  background: var(--ink);
  color: var(--surface);
}
.submit-button:hover { background: var(--accent); color: #fff; }
.submit-button:disabled,
.give-up-button:disabled { opacity: .45; cursor: wait; }
.form-message {
  min-height: 1.35em;
  margin: 8px 0 0;
  color: var(--accent);
  font-size: .85rem;
}

.give-up-button {
  display: block;
  min-height: 44px;
  margin: 8px auto 0;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.give-up-button:hover { color: var(--ink); }

.result-screen { text-align: center; }
.result-screen:focus { outline: none; }
.death-mark {
  width: 74px;
  height: 74px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  font-size: 2.2rem;
  animation: settle .5s ease-out both;
}
.result-screen h1 {
  max-width: 14ch;
  margin: 0 auto 14px;
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  line-height: 1;
}
.final-score {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
}
.final-score strong {
  color: var(--accent);
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 4.5rem;
  line-height: 1;
}
.final-score span { font-size: 1.05rem; font-weight: 700; }
.personal-best { margin: 2px 0 24px; color: var(--muted); font-size: .88rem; }

.verdict {
  margin: 0 auto 22px;
  padding: 16px 0;
  border-block: 1px solid var(--line);
}
.verdict strong,
.verdict span { display: block; }
.verdict strong { margin-bottom: 4px; }
.verdict span { color: var(--muted); font-size: .9rem; }
#escape-word { margin-top: 9px; color: var(--success); font-weight: 750; }

.share-card {
  width: min(100%, 360px);
  margin: 0 auto 16px;
  padding: 17px 20px;
  border: 1px dashed var(--line-strong);
  background: var(--machine);
  text-align: left;
}
.share-card pre {
  margin: 0;
  white-space: pre-wrap;
  color: var(--ink);
  font: 700 .88rem/1.5 "Avenir Next", sans-serif;
}
.share-options-label {
  margin: 17px 0 9px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.social-share-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  width: min(100%, 440px);
  margin: 0 auto;
}
.social-share {
  min-width: 0;
  min-height: 66px;
  padding: 8px 3px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: .63rem;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
}
.social-share:hover {
  border-color: var(--ink);
  background: var(--machine);
}
.social-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: -.04em;
}
.social-share.x .social-icon { font-size: 1rem; }
.social-share.facebook .social-icon { font: 800 1.15rem/1 Georgia, serif; }
#result-history-button { display: block; margin: 14px auto 0; font-size: .82rem; }

.site-footer {
  width: min(100% - 32px, 680px);
  margin: 28px auto 0;
  padding: 0 0 calc(34px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-size: .75rem;
}
.site-footer p { margin: 7px 0; }
.site-footer .text-button { flex: 0 0 auto; }
.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 16px;
}

.clipboard-fallback {
  position: fixed;
  width: 1px;
  height: 1px;
  inset: 0 auto auto 0;
  opacity: 0;
  pointer-events: none;
}

.content-page {
  width: min(100% - 32px, 720px);
  min-height: calc(100vh - 160px);
  margin: 0 auto;
  padding: clamp(46px, 8vw, 84px) 0;
}
.content-page h1,
.content-page h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  letter-spacing: -.03em;
}
.content-page h1 {
  max-width: 16ch;
  margin: 0 0 24px;
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  line-height: .98;
}
.content-page h2 { margin: 34px 0 10px; font-size: 1.45rem; }
.content-page p,
.content-page li { color: var(--muted); line-height: 1.65; }
.content-page strong { color: var(--ink); }
.content-page a { color: var(--accent); text-underline-offset: 3px; }
.content-page ul { padding-left: 22px; }
.content-page .primary-button {
  display: inline-grid;
  place-items: center;
  margin-top: 20px;
  color: var(--surface);
  text-decoration: none;
}

dialog {
  width: min(calc(100% - 28px), 540px);
  max-height: min(82vh, 720px);
  margin: auto;
  padding: 32px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 12px 32px rgb(0 0 0 / .18);
}
dialog::backdrop { background: rgb(12 12 10 / .58); }
dialog h2 { margin: 0 0 22px; font-size: 2rem; }
.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.8rem;
  cursor: pointer;
}
.rules-list {
  margin: 0;
  padding-left: 24px;
}
.rules-list li { margin-bottom: 10px; padding-left: 5px; line-height: 1.4; }
.rules-list li::marker { color: var(--accent); font-weight: 800; }
.dialog-example {
  margin: 24px 0;
  padding: 18px;
  display: grid;
  place-items: center;
  gap: 8px;
  background: var(--machine);
  font-weight: 750;
}
.dialog-example b { color: var(--accent); }
.dialog-example i { color: var(--accent); }
.rules-note { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }

.full-chain { margin: 0; padding: 0; list-style: none; }
.full-chain-item { grid-template-columns: 112px 1fr; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 30;
  padding: 11px 16px;
  background: var(--ink);
  color: var(--surface);
  font-size: .86rem;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.fatal-error { color: var(--accent); text-align: center; }

@keyframes settle {
  from { opacity: 0; transform: scale(.72) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes chain-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 1099px) {
  .page-grid { width: min(100% - 24px, var(--max-game)); grid-template-columns: 1fr; }
  .game-shell { min-height: 620px; }
}

@media (max-width: 560px) {
  .site-header {
    width: calc(100% - 24px);
    min-height: 62px;
    grid-template-columns: 1fr auto;
  }
  .challenge-label {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: .64rem;
  }
  .brand > span:last-child { display: none; }
  .header-actions { grid-column: 2; }
  .page-grid { width: 100%; }
  .game-shell { min-height: calc(100svh - 62px); border-inline: 0; }
  .screen,
  .loading-state,
  .fatal-error { padding: 26px 20px; }
  .intro-screen {
    min-height: calc(100svh - 62px);
    justify-content: flex-start;
    padding-top: clamp(38px, 9vh, 76px);
  }
  .intro-screen h1 { font-size: clamp(2.5rem, 12vw, 3.25rem); }
  .intro-copy { font-size: .98rem; }
  .mini-chain { margin: 26px auto; grid-template-columns: 1fr 28px 1fr; }
  .mini-chain > div { padding: 7px 0; }
  .mini-chain strong { font-size: .88rem; }
  .mini-chain span { font-size: .76rem; }
  .primary-button { width: 100%; }
  .privacy-line { margin-top: 14px; }
  .play-screen { padding-top: 20px; padding-bottom: 16px; }
  .score-strip { padding-bottom: 17px; }
  .score-strip p { max-width: 19ch; font-size: .73rem; }
  .turn-heading { padding: 22px 0 15px; }
  .turn-heading h1 { font-size: 1.72rem; }
  .chain-item { grid-template-columns: 92px 1fr; gap: 10px; padding: 13px 3px; }
  .chain-item:nth-last-child(-n+4) { display: grid; }
  .chain-meta b { font-size: .76rem; }
  .syllables { gap: 4px; font-size: .86rem; }
  .word-form { margin-top: 18px; padding-top: 14px; }
  .input-row input { height: 56px; padding-inline: 13px; }
  .submit-button { min-width: 108px; padding-inline: 12px; font-size: .87rem; }
  .give-up-button { margin-top: 2px; }
  .result-screen { padding-top: 34px; }
  .death-mark { width: 64px; height: 64px; margin-bottom: 16px; }
  .final-score strong { font-size: 4rem; }
  .social-share-list { gap: 5px; }
  .social-share { min-height: 62px; font-size: .58rem; }
  .social-icon { width: 26px; height: 26px; }
  .site-footer { width: calc(100% - 32px); margin-top: 18px; flex-direction: column; align-items: center; gap: 0; text-align: center; }
  .footer-links { justify-content: center; }
  .content-page { width: calc(100% - 40px); padding-block: 44px; }
  dialog { padding: 28px 20px; }
  .full-chain-item { grid-template-columns: 90px 1fr; gap: 8px; }
}

@media (max-width: 370px) {
  .screen { padding-inline: 16px; }
  .challenge-label { left: 47%; }
  .score-strip p { display: none; }
  .chain-item { grid-template-columns: 78px 1fr; }
  .chain-meta b { font-size: .7rem; }
  .syllables { font-size: .8rem; }
  .submit-button { min-width: 96px; }
}

@media (max-width: 560px) and (max-height: 650px) {
  .play-screen { padding-top: 12px; }
  .score-strip { padding-bottom: 12px; }
  .score-strip p { display: none; }
  .turn-heading { padding: 12px 0 10px; }
  .chain-item { padding-block: 9px; }
  .word-form { margin-top: 12px; padding-top: 10px; }
  .give-up-button { min-height: 40px; }
}

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