:root {
  --paper: #faf6ec;
  --ink: #181614;
  --text: #1e1c18;
  --muted: #6b6459;
  --surface: #ede9df;
  --rule: #e8e5db;
  --accent: #6a5aa6;
  --accent-ink: #55488c;
  --accent-border: #c8bfd4;
  --spark: #a8431f;
  --lavender: #d3cae8;
  --butter: #f2eacf;
  --sun: #f5cb5c;
  --mint: #bcd8c1;
  color: var(--text);
  background: var(--paper);
  font-family: "PT Serif", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgb(24 22 20 / 5%) 1px, transparent 1.2px) 0 0 / 23px 23px,
    var(--paper);
}

button {
  font: inherit;
}

.page-shell {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 100vh;
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: clamp(40px, 7vw, 96px);
  isolation: isolate;
}

.intro {
  position: relative;
  z-index: 3;
  max-width: 800px;
}

.eyebrow {
  width: fit-content;
  margin: 0 0 clamp(22px, 3vw, 34px);
  color: var(--spark);
  font-family: Inter, sans-serif;
  font-size: clamp(12px, 1.1vw, 15px);
  font-weight: 600;
  letter-spacing: 0.015em;
}

.eyebrow::before {
  content: "●";
  margin-right: 8px;
  color: var(--sun);
  -webkit-text-stroke: 1px var(--ink);
}

h1 {
  max-width: 800px;
  margin: 0;
  color: var(--ink);
  font-family: "PT Serif", Georgia, serif;
  font-size: clamp(48px, 7.5vw, 104px);
  font-weight: 700;
  letter-spacing: -0.055em;
  line-height: 0.92;
  text-wrap: balance;
}

.intro__copy {
  display: grid;
  gap: 12px;
  max-width: 680px;
  margin-top: clamp(30px, 4vw, 48px);
}

.intro__copy p {
  margin: 0;
  font-size: clamp(19px, 2vw, 27px);
  line-height: 1.38;
}

.intro__copy p + p {
  max-width: 620px;
  color: var(--muted);
  font-style: italic;
}

.action-row {
  display: flex;
  gap: clamp(18px, 3vw, 34px);
  align-items: center;
  margin-top: clamp(32px, 5vw, 52px);
}

.start-button {
  position: relative;
  flex: 0 0 auto;
  min-width: 142px;
  padding: 16px 26px 17px;
  border: 1px solid var(--accent-ink);
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 7px 0 var(--accent-ink);
  font-family: Inter, sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.start-button:hover:not(:disabled) {
  background: var(--accent-ink);
  transform: translateY(2px);
  box-shadow: 0 5px 0 #40366e;
}

.start-button:active:not(:disabled) {
  transform: translateY(6px);
  box-shadow: 0 1px 0 var(--accent-ink);
}

.start-button:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 5px;
}

.start-button:disabled {
  cursor: not-allowed;
}

.caption {
  max-width: 390px;
  margin: 0;
  color: var(--muted);
  font-family: Inter, sans-serif;
  font-size: clamp(12px, 1.1vw, 14px);
  line-height: 1.5;
}

.mystery-stack {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: clamp(24px, 6vw, 88px);
  width: clamp(250px, 28vw, 390px);
  height: 430px;
  transform: translateY(-46%);
  pointer-events: none;
}

.mystery-card {
  position: absolute;
  right: 0;
  display: grid;
  place-items: center;
  width: 84%;
  height: 118px;
  border: 1px solid var(--ink);
  border-radius: 18px;
  box-shadow: 7px 8px 0 var(--ink);
  font-family: Inter, sans-serif;
  font-size: 32px;
  font-weight: 600;
}

.mystery-card:nth-child(1) {
  top: 34px;
  background: var(--lavender);
  transform: rotate(7deg);
}

.mystery-card:nth-child(2) {
  top: 155px;
  right: 34px;
  background: var(--butter);
  transform: rotate(-4deg);
}

.mystery-card:nth-child(3) {
  top: 280px;
  right: 5px;
  background: var(--mint);
  transform: rotate(3deg);
}

.mystery-card span {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
}

.score-orbit {
  position: absolute;
  z-index: 4;
  top: -32px;
  left: -20px;
  display: grid;
  place-items: center;
  align-content: center;
  width: 146px;
  height: 146px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 6px 7px 0 var(--ink);
  transform: rotate(-8deg);
}

.score-orbit strong {
  font-family: Fraunces, Georgia, serif;
  font-size: 66px;
  font-weight: 600;
  line-height: 0.78;
}

.score-orbit span {
  margin-top: 8px;
  font-family: Inter, sans-serif;
  font-size: 12px;
  font-weight: 600;
}

.play-shapes {
  position: absolute;
  z-index: -1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.play-shape {
  position: absolute;
  display: block;
}

.play-shape--one {
  top: 6%;
  right: 23%;
  width: 26px;
  height: 26px;
  border: 1px solid var(--ink);
  background: var(--spark);
  transform: rotate(18deg);
}

.play-shape--two {
  right: 3%;
  bottom: 8%;
  width: 80px;
  height: 80px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--lavender);
}

.play-shape--three {
  bottom: 4%;
  left: 42%;
  width: 64px;
  height: 20px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  transform: rotate(-10deg);
}

.load-error {
  position: relative;
  z-index: 5;
  width: fit-content;
  margin: 24px 0 0;
  padding: 12px 14px;
  border-left: 4px solid var(--spark);
  color: var(--text);
  background: var(--surface);
  font-family: Inter, sans-serif;
  font-size: 14px;
  font-weight: 600;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.game-screen,
.result-screen {
  position: relative;
  z-index: 3;
  width: min(900px, 100%);
  margin: 0 auto;
  padding-block: 24px;
}

.game-screen {
  width: min(760px, 100%);
}

.result-screen {
  width: min(1080px, 100%);
}

.game-header {
  display: flex;
  gap: 28px;
  align-items: start;
  justify-content: space-between;
}

.game-header h2,
.result-screen h2,
.reveal-dialog h2 {
  margin: 0;
  color: var(--ink);
  font-family: "PT Serif", Georgia, serif;
  font-size: clamp(32px, 4.5vw, 58px);
  line-height: 1;
  letter-spacing: -0.035em;
}

.game-header .eyebrow {
  margin-bottom: 12px;
}

.round-source {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-style: italic;
}

.score-box {
  position: relative;
  flex: 0 0 auto;
  min-width: 156px;
  padding: 14px 18px 16px;
  border: 1px solid var(--accent-ink);
  border-radius: 16px;
  background: var(--lavender);
  box-shadow: 5px 6px 0 var(--accent-ink);
  font-family: Inter, sans-serif;
}

.score-box > span {
  display: block;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
}

.score-box strong {
  display: block;
  color: var(--ink);
  font-family: Fraunces, Georgia, serif;
  font-size: 42px;
  line-height: 1;
}

.score-box small {
  margin-left: 3px;
  font-family: "PT Serif", Georgia, serif;
  font-size: 18px;
}

.score-box i {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.score-box i:empty {
  display: none;
}

.score-flight {
  position: fixed;
  z-index: 20;
  display: grid;
  place-items: center;
  min-width: 58px;
  height: 40px;
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  color: var(--ink);
  background: var(--sun);
  box-shadow: 3px 4px 0 var(--ink);
  font-family: Oswald, "Arial Narrow", sans-serif;
  font-size: 25px;
  font-weight: 600;
  pointer-events: none;
}

.game-meta {
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin: 30px 0 14px;
  color: var(--muted);
  font-family: Inter, sans-serif;
  font-size: 13px;
}

.game-meta span:last-child {
  color: var(--spark);
  text-align: right;
}

.board {
  display: grid;
  gap: 7px;
  width: min(640px, 100%);
  margin-inline: auto;
  padding: 14px;
  border: 3px solid #111211;
  border-radius: 10px;
  background:
    linear-gradient(90deg, rgb(39 174 205 / 82%) 0 49.5%, rgb(194 72 39 / 82%) 50.5% 100%),
    #222;
  box-shadow:
    0 18px 35px rgb(24 22 20 / 22%),
    inset 0 0 0 2px rgb(255 255 255 / 14%);
  perspective: 900px;
}

.word-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 58px;
  padding: 3px 16px 6px;
  overflow: hidden;
  border: 2px solid #090a09;
  border-radius: 4px;
  color: #f8f5e9;
  background: linear-gradient(#242725 0 49%, #101110 51% 100%);
  box-shadow:
    0 3px 0 rgb(0 0 0 / 45%),
    inset 0 1px 0 rgb(255 255 255 / 12%);
  font-family: Oswald, "Arial Narrow", sans-serif;
  font-size: clamp(27px, 4vw, 35px);
  font-weight: 500;
  letter-spacing: 0.025em;
  line-height: 1;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
  transition: filter 140ms ease, box-shadow 140ms ease;
}

.word-card::after {
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: 1px;
  background: rgb(0 0 0 / 72%);
  box-shadow: 0 1px 0 rgb(255 255 255 / 8%);
  content: "";
  pointer-events: none;
}

.word-card:hover:not(:disabled) {
  filter: brightness(1.35);
  box-shadow:
    0 4px 0 rgb(0 0 0 / 55%),
    0 0 0 2px var(--sun);
}

.word-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}

.word-card.is-revealed {
  border-color: #d8d3c6;
  color: #171714;
  background: linear-gradient(#fffdf5 0 49%, #e7e2d7 51% 100%);
  box-shadow:
    0 3px 0 rgb(0 0 0 / 42%),
    inset 0 1px 0 #fff;
  cursor: default;
}

.word-card__count {
  min-width: 48px;
  color: inherit;
  font-family: Oswald, "Arial Narrow", sans-serif;
  font-size: 0.95em;
  font-weight: 500;
  text-align: right;
}

.word-card__label,
.word-card__count {
  transform: translateY(-2px);
}

.word-card.is-flipping {
  z-index: 2;
  will-change: transform;
}

.board.is-moving .word-card {
  pointer-events: none;
}

.reveal-button {
  display: block;
  margin: 28px auto 0;
  padding: 9px 13px;
  border: 0;
  border-bottom: 1px dashed var(--accent);
  color: var(--accent-ink);
  background: transparent;
  font-family: Inter, sans-serif;
  font-size: 13px;
  cursor: pointer;
}

.result-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 1fr);
  gap: clamp(36px, 6vw, 72px);
  align-items: start;
}

.result-screen h2:focus {
  outline: none;
}

.result-score {
  margin: 0 0 28px;
  color: var(--ink);
}

.result-score strong {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(92px, 13vw, 168px);
  font-weight: 600;
  line-height: 0.75;
}

.result-score span {
  font-size: 28px;
}

.result-copy {
  max-width: 480px;
  margin: 22px 0 34px;
  color: var(--muted);
  font-size: 21px;
  line-height: 1.4;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.result-actions .start-button {
  padding: 15px 22px;
  font-size: 14px;
}

.secondary-button,
.text-button {
  padding: 13px 16px;
  border: 1px solid var(--accent-ink);
  border-radius: 999px;
  color: var(--accent-ink);
  background: transparent;
  font-family: Inter, sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.text-button {
  padding-inline: 6px;
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.share-status {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--muted);
  font-family: Inter, sans-serif;
  font-size: 12px;
}

.episode-link {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 17px 19px;
  border: 1px solid var(--ink);
  border-radius: 14px;
  color: var(--text);
  background: color-mix(in srgb, var(--spark) 10%, var(--paper));
  box-shadow: 4px 5px 0 var(--ink);
  text-decoration: none;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.episode-link:hover {
  box-shadow: 2px 3px 0 var(--ink);
  transform: translate(2px, 2px);
}

.episode-link > span {
  color: var(--spark);
  font-family: Inter, sans-serif;
  font-size: 12px;
  font-weight: 700;
}

.episode-link > strong {
  font-size: 20px;
  line-height: 1.12;
}

.episode-link > small {
  color: var(--muted);
  font-family: Inter, sans-serif;
  font-size: 13px;
  line-height: 1.4;
}

.result-brand {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 22px;
  align-items: end;
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

.result-brand__name {
  margin: 0 0 8px;
  color: var(--spark);
  font-family: Inter, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.result-brand__copy > p:not(.result-brand__name) {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.42;
}

.result-brand__copy a {
  color: var(--accent-ink);
  font-family: Inter, sans-serif;
  font-size: 14px;
  font-weight: 600;
  text-underline-offset: 4px;
}

.result-qr {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-family: Inter, sans-serif;
  font-size: 10px;
  text-align: center;
  text-decoration: none;
}

.result-qr img {
  display: block;
  width: 118px;
  height: 118px;
  border: 1px solid var(--ink);
  background: var(--paper);
}

button:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 4px;
}

.episode-link:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 4px;
}

.final-ranking {
  border-top: 1px solid var(--rule);
}

.final-ranking > div {
  display: flex;
  justify-content: space-between;
  padding: 13px 4px;
  border-bottom: 1px solid var(--rule);
  font-size: 18px;
}

.final-ranking strong {
  color: var(--accent-ink);
  font-family: Inter, sans-serif;
  font-size: 13px;
}

.reveal-dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 18px;
  color: var(--text);
  background: var(--paper);
  box-shadow: 9px 10px 0 var(--ink);
}

.reveal-dialog::backdrop {
  background: rgb(24 22 20 / 48%);
  backdrop-filter: blur(3px);
}

.reveal-dialog form {
  padding: 28px;
}

.reveal-dialog p {
  margin: 18px 0 26px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.4;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.dialog-actions button {
  padding: 11px 15px;
  border: 1px solid var(--accent-ink);
  border-radius: 999px;
  color: var(--accent-ink);
  background: transparent;
  font-family: Inter, sans-serif;
  font-size: 13px;
  font-weight: 600;
}

.dialog-actions button:last-child {
  color: white;
  background: var(--accent);
}

@media (max-width: 1040px) {
  .intro {
    max-width: 680px;
  }

  .mystery-stack {
    right: -20px;
    width: 290px;
    opacity: 0.78;
  }
}

@media (max-width: 820px) {
  .page-shell {
    align-content: start;
    padding-top: 54px;
  }

  .intro {
    max-width: none;
  }

  h1 {
    max-width: 680px;
  }

  .mystery-stack {
    position: relative;
    top: auto;
    right: auto;
    width: min(390px, 90vw);
    height: 300px;
    margin: 48px 0 10px auto;
    transform: none;
    opacity: 1;
  }

  .mystery-card {
    height: 92px;
  }

  .mystery-card:nth-child(1) { top: 20px; }
  .mystery-card:nth-child(2) { top: 112px; }
  .mystery-card:nth-child(3) { top: 204px; }

  .score-orbit {
    top: -24px;
    width: 116px;
    height: 116px;
  }

  .score-orbit strong {
    font-size: 50px;
  }

  .result-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .page-shell {
    padding: 34px 22px 54px;
  }

  h1 {
    font-size: clamp(43px, 13.5vw, 68px);
    line-height: 0.96;
  }

  .intro__copy {
    margin-top: 28px;
  }

  .intro__copy p {
    font-size: 19px;
  }

  .action-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .start-button {
    width: 100%;
  }

  .mystery-stack {
    width: 94%;
    margin-top: 44px;
  }

  .play-shape--one {
    top: 3%;
    right: 8%;
  }

  .play-shape--three {
    display: none;
  }

  .play-shape--two {
    display: none;
  }

  .game-header {
    display: grid;
  }

  .score-box {
    min-width: 136px;
    justify-self: start;
  }

  .game-meta {
    display: grid;
    gap: 6px;
  }

  .game-meta span:last-child {
    text-align: left;
  }

  .word-card {
    min-height: 52px;
    padding-inline: 12px;
    font-size: clamp(25px, 8.5vw, 31px);
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .result-brand {
    grid-template-columns: 1fr;
  }

  .result-qr {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
