:root {
  --ink: #171717;
  --muted: #68645e;
  --paper: #fffaf2;
  --surface: #fffefa;
  --line: #ded7ca;
  --accent: #2368b0;
  --accent-soft: #e6f0fb;
  --gold: #f2c744;
  --gold-soft: #fff3bd;
  --wrong: #d65a4a;
  --correct: #297a4f;
  --shadow: 0 24px 70px rgba(23, 23, 23, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
  background:
    radial-gradient(circle at top left, rgba(242, 199, 68, 0.16), transparent 34rem),
    linear-gradient(180deg, #fffefa 0%, #f8f4eb 58%, #f5f8fb 100%);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
}

button,
a {
  font: inherit;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.site-header {
  align-items: center;
  background: rgba(255, 254, 250, 0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 52px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: inherit;
  display: inline-flex;
  gap: 13px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border: 1px solid rgba(23, 23, 23, 0.18);
  box-shadow: 0 10px 24px rgba(23, 23, 23, 0.14);
  color: var(--paper);
  display: inline-flex;
  font-size: 18px;
  font-weight: 900;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1;
  white-space: nowrap;
}

.brand strong {
  font-size: clamp(18px, 2vw, 23px);
  font-weight: 900;
  letter-spacing: 0;
}

.brand small,
.puzzle-meta,
.status-message,
.eyebrow {
  color: var(--muted);
}

.brand small {
  font-size: 11px;
  font-weight: 800;
  margin-top: 5px;
}

.top-nav {
  display: flex;
  gap: 8px;
}

.top-nav a {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  min-height: 38px;
  padding: 9px 13px;
  text-decoration: none;
}

.top-nav a:hover,
.top-nav a:focus-visible {
  background: var(--ink);
  color: var(--paper);
}

main {
  padding: clamp(20px, 4vw, 48px);
}

.app-view[hidden] {
  display: none;
}

.app-view {
  animation: view-in 280ms ease both;
}

.home-view {
  align-items: center;
  display: grid;
  gap: clamp(28px, 6vw, 72px);
  grid-template-columns: minmax(0, 1fr) minmax(280px, 430px);
  margin: 0 auto;
  max-width: 1160px;
  min-height: calc(100vh - 138px);
  padding: clamp(26px, 5vw, 70px) 0;
}

.home-copy {
  max-width: 680px;
}

.home-copy h1 {
  font-size: clamp(52px, 9vw, 112px);
  line-height: 0.88;
  margin-bottom: 22px;
  max-width: 8ch;
}

.home-copy .home-tagline {
  color: #2a2927;
  font-size: clamp(22px, 3vw, 36px);
  font-weight: 800;
  line-height: 1.08;
  margin: 0 0 26px;
  max-width: 560px;
}

.home-tagline span {
  display: block;
}

.home-tagline span:nth-child(2) {
  font-size: 0.88em;
}

.home-tagline span:nth-child(3) {
  font-size: 0.76em;
}

.primary-cta {
  align-items: center;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 9px;
  color: var(--paper);
  display: inline-flex;
  font-size: 17px;
  font-weight: 900;
  justify-content: center;
  min-height: 54px;
  padding: 0 24px;
  text-decoration: none;
}

.primary-cta:hover,
.primary-cta:focus-visible {
  background: #303030;
  transform: translateY(-1px);
}

.home-copy small {
  color: var(--muted);
  display: block;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
  margin-top: 18px;
}

.home-preview {
  background: rgba(255, 254, 250, 0.74);
  border: 1px solid rgba(222, 215, 202, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 28px);
}

.preview-grid {
  border: 3px solid var(--ink);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: 100%;
}

.preview-grid span {
  align-items: center;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--ink);
  display: flex;
  font-size: clamp(28px, 4.5vw, 54px);
  font-weight: 900;
  justify-content: center;
}

.preview-grid .black {
  background: var(--ink);
}

.game-shell {
  margin: 0 auto;
  max-width: 1160px;
}

.game-intro {
  align-items: center;
  background: rgba(255, 254, 250, 0.62);
  border: 1px solid rgba(222, 215, 202, 0.86);
  border-radius: 8px;
  box-shadow: 0 18px 52px rgba(23, 23, 23, 0.06);
  display: grid;
  gap: clamp(18px, 4vw, 38px);
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 24px;
  padding: clamp(18px, 3vw, 30px);
}

.intro-copy {
  min-width: 0;
}

.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 10px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(34px, 6vw, 68px);
  font-weight: 900;
  line-height: 0.94;
  max-width: 12ch;
}

.game-intro h1 {
  font-size: clamp(36px, 5vw, 62px);
  line-height: 0.98;
  max-width: 11ch;
  overflow-wrap: anywhere;
}

.puzzle-bar {
  align-items: center;
  border-left: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  min-width: 170px;
  padding-left: clamp(18px, 3vw, 34px);
}

.puzzle-meta {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  margin: 0;
  max-width: 260px;
}

.timer {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(23, 23, 23, 0.06);
  display: inline-flex;
  font-size: 22px;
  font-weight: 900;
  gap: 10px;
  justify-content: center;
  min-height: 52px;
  padding: 0 18px;
  white-space: nowrap;
}

.timer-dot {
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  height: 7px;
  width: 7px;
}

.game-layout {
  align-items: start;
  display: grid;
  gap: clamp(22px, 4vw, 46px);
  grid-template-columns: minmax(280px, 510px) minmax(280px, 1fr);
}

.board-panel {
  background: rgba(255, 254, 250, 0.82);
  border: 1px solid rgba(216, 208, 195, 0.8);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
  padding: clamp(14px, 2.4vw, 24px);
  transition: padding-bottom 180ms ease;
}

.board-panel.menu-open {
  padding-bottom: clamp(142px, 12vw, 164px);
}

.active-clue {
  align-items: center;
  background: var(--gold-soft);
  border: 1px solid #e1c05f;
  border-left: 5px solid var(--gold);
  border-radius: 7px;
  display: flex;
  font-size: clamp(16px, 2vw, 19px);
  font-weight: 800;
  line-height: 1.35;
  min-height: 54px;
  padding: 12px 16px;
}

.crossword-grid {
  border: 3px solid var(--ink);
  display: grid;
  margin-inline: auto;
  width: min(100%, 510px);
}

.cell {
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--ink);
  color: var(--ink);
  cursor: pointer;
  display: block;
  min-width: 0;
  padding: 0;
  position: relative;
  text-transform: uppercase;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 120ms ease,
    box-shadow 120ms ease,
    transform 120ms ease;
}

.cell:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: -4px;
  z-index: 2;
}

.cell.black {
  background: var(--ink);
  cursor: default;
}

.cell.in-word {
  background: var(--accent-soft);
}

.cell.selected,
.cell.in-word.selected {
  background: var(--gold);
  box-shadow: inset 0 0 0 3px #a06d00;
  z-index: 3;
}

.cell.wrong .cell-letter {
  color: var(--wrong);
}

.cell.correct .cell-letter {
  color: var(--correct);
}

.cell-number {
  font-size: clamp(9px, 1.8vw, 12px);
  font-weight: 800;
  left: 4px;
  position: absolute;
  top: 2px;
}

.cell-letter {
  align-items: center;
  display: flex;
  font-size: clamp(24px, 7vw, 46px);
  font-weight: 800;
  inset: 0;
  justify-content: center;
  line-height: 1;
  position: absolute;
  text-align: center;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  position: relative;
}

.controls button,
.control-menu summary {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
}

.controls button:hover,
.control-menu summary:hover {
  box-shadow: inset 0 0 0 2px rgba(21, 21, 21, 0.08);
}

.control-menu {
  position: relative;
}

.control-menu summary {
  list-style: none;
}

.control-menu summary::-webkit-details-marker {
  display: none;
}

.control-menu:first-child summary {
  background: var(--ink);
  color: var(--paper);
}

.control-menu[open] summary {
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.menu-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(21, 21, 21, 0.16);
  display: grid;
  gap: 8px;
  left: 50%;
  min-width: 184px;
  padding: 10px;
  position: absolute;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  z-index: 20;
}

.menu-panel button {
  border-color: var(--line);
  border-radius: 6px;
  justify-content: flex-start;
  width: 100%;
}

.quiet-button {
  border-color: var(--line);
}

.status-message {
  min-height: 24px;
  margin: 0;
  text-align: center;
}

.mobile-keyboard {
  background: transparent;
  border: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-inline: auto;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: min(100%, 510px);
}

.keyboard-row {
  display: flex;
  gap: 6px;
}

.keyboard-row-middle {
  padding-inline: 5%;
}

.keyboard-row:last-child {
  padding-inline: 0;
}

.mobile-keyboard button {
  align-items: center;
  background: #d3d6da;
  border: 0;
  border-radius: 5px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  flex: 1 1 0;
  font-size: 18px;
  font-weight: 800;
  justify-content: center;
  line-height: 1;
  min-height: 56px;
  min-width: 0;
  padding: 0;
  text-transform: uppercase;
}

.mobile-keyboard button:active {
  background: #bcc1c8;
  transform: translateY(1px);
}

.mobile-keyboard .keyboard-action {
  background: #bfc4cc;
  flex: 1.55 1 0;
  font-size: 17px;
}

.clues-panel {
  display: grid;
  gap: 28px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.clues-panel > div {
  min-width: 0;
}

.clues-panel h2,
.archive-section h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

.clue-list {
  display: grid;
  gap: 7px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.clue-list li {
  border-left: 4px solid transparent;
  cursor: pointer;
  line-height: 1.35;
  padding: 8px 12px;
}

.clue-list li.active {
  background: var(--gold-soft);
  border-left-color: var(--accent);
  font-weight: 800;
}

.clue-number {
  color: var(--muted);
  font-weight: 800;
  margin-right: 8px;
}

.archive-section {
  background: rgba(255, 254, 250, 0.62);
  border: 1px solid rgba(222, 215, 202, 0.86);
  box-shadow: 0 18px 52px rgba(23, 23, 23, 0.06);
  display: grid;
  gap: 22px;
  margin: 0 auto;
  max-width: 1160px;
  padding: clamp(18px, 3vw, 30px);
}

.archive-note,
.empty-archive {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
  margin: 0;
}

.archive-note {
  margin-top: 6px;
}

.archive-list {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.empty-archive {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.archive-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  min-height: 92px;
  padding: 14px;
  text-align: left;
}

.archive-card:hover,
.archive-card:focus-visible {
  border-color: var(--ink);
  box-shadow: 0 10px 26px rgba(21, 21, 21, 0.09);
  transform: translateY(-1px);
}

.archive-card strong,
.archive-card span {
  display: block;
}

.archive-card span {
  color: var(--muted);
  margin-top: 5px;
}

.win-dialog {
  align-items: center;
  background: rgba(21, 21, 21, 0.35);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 40;
}

.win-dialog.show {
  display: flex;
}

.win-card {
  animation: pop-in 260ms ease both;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(21, 21, 21, 0.24);
  max-width: 360px;
  padding: 24px;
  position: relative;
  text-align: center;
  width: min(100%, 360px);
}

.win-card.celebrating {
  overflow: visible;
}

.win-card h2 {
  font-size: 36px;
  font-weight: 900;
  margin-bottom: 10px;
}

.win-card button {
  background: var(--ink);
  border: 0;
  border-radius: 8px;
  color: var(--paper);
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 18px;
}

.confetti-burst {
  inset: 50% auto auto 50%;
  pointer-events: none;
  position: absolute;
  z-index: 2;
}

.confetti-burst span {
  animation: confetti-pop 980ms cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: var(--confetti-delay);
  background: var(--confetti-color);
  border-radius: 2px;
  display: block;
  height: 16px;
  left: 0;
  position: absolute;
  top: 0;
  transform: translate(-50%, -50%);
  width: 8px;
}

.solved-flash .cell:not(.black) {
  animation: solve-flash 650ms ease both;
}

@keyframes confetti-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2) rotate(0deg);
  }

  22% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(var(--confetti-x), var(--confetti-y)) scale(1) rotate(var(--confetti-rotate));
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes solve-flash {
  0% {
    background: var(--gold);
  }

  50% {
    background: #8fd6b0;
  }

  100% {
    background: var(--surface);
  }
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 820px) {
  body {
    background:
      radial-gradient(circle at top right, rgba(35, 104, 176, 0.14), transparent 18rem),
      radial-gradient(circle at 20% 18%, rgba(242, 199, 68, 0.2), transparent 16rem),
      linear-gradient(180deg, #fffefa 0%, #f8f4eb 62%, #f5f8fb 100%);
  }

  .home-view,
  .game-intro,
  .game-layout,
  .clues-panel {
    grid-template-columns: 1fr;
  }

  .site-header {
    gap: 12px;
    padding: 12px;
  }

  main {
    padding: 10px 14px 24px;
  }

  .home-view {
    align-content: center;
    gap: 16px;
    min-height: calc(100dvh - 68px);
    padding: 10px 0 16px;
    text-align: center;
  }

  .home-copy {
    margin-inline: auto;
    max-width: 390px;
  }

  .home-copy .eyebrow {
    margin-bottom: 10px;
  }

  .home-copy h1 {
    font-size: clamp(42px, 14vw, 60px);
    line-height: 0.88;
    margin: 0 auto 14px;
    max-width: 7.2ch;
  }

  .home-copy .home-tagline {
    font-size: clamp(19px, 6vw, 25px);
    line-height: 1.08;
    margin: 0 auto 16px;
    max-width: 15ch;
  }

  .home-preview {
    background: rgba(255, 254, 250, 0.86);
    border-radius: 10px;
    box-shadow: 0 18px 48px rgba(23, 23, 23, 0.12);
    margin-inline: auto;
    max-width: min(72vw, 260px);
    order: -1;
    padding: 8px;
    transform: rotate(-1deg);
    width: min(72vw, 260px);
  }

  .preview-grid {
    border-width: 2px;
  }

  .preview-grid span {
    font-size: clamp(20px, 7.5vw, 31px);
  }

  .primary-cta {
    border-radius: 10px;
    min-height: 50px;
    width: min(100%, 340px);
  }

  .home-copy small {
    font-size: 13px;
    margin-inline: auto;
    margin-top: 12px;
    max-width: 280px;
  }

  .brand small {
    display: none;
  }

  .brand-mark {
    height: 34px;
    width: 34px;
  }

  .brand strong {
    font-size: 17px;
  }

  .top-nav {
    margin-left: auto;
  }

  .top-nav a {
    font-size: 13px;
    min-height: 34px;
    padding: 7px 9px;
  }

  .game-intro {
    align-items: center;
    gap: 16px;
    justify-items: center;
    margin-bottom: 18px;
    padding: 16px;
    text-align: center;
    width: 100%;
  }

  .intro-copy {
    display: grid;
    justify-items: center;
    width: 100%;
  }

  .puzzle-bar {
    align-items: center;
    border-left: 0;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: center;
    justify-self: center;
    min-width: 0;
    padding-left: 0;
    padding-top: 14px;
    width: min(100%, 230px);
  }

  .game-intro h1 {
    font-size: clamp(34px, 11vw, 48px);
    margin-inline: auto;
    max-width: 12ch;
  }

  .puzzle-meta {
    max-width: none;
  }

  .timer {
    font-size: 20px;
    margin-inline: auto;
    min-height: 48px;
    width: min(100%, 172px);
  }

  .crossword-grid {
    width: min(100%, 460px);
  }

  .board-panel {
    box-shadow: none;
    margin-inline: -4px;
    padding: 10px;
  }

  .cell-letter {
    font-size: clamp(28px, 12vw, 44px);
  }

  .menu-panel {
    left: 0;
    transform: none;
  }

  .clues-panel {
    gap: 18px;
  }

  .archive-list {
    grid-template-columns: 1fr;
  }

  .mobile-keyboard {
    gap: 8px;
    position: static;
    width: min(100%, 520px);
  }

  .mobile-keyboard button {
    font-size: clamp(17px, 5vw, 21px);
    min-height: clamp(54px, 14vw, 64px);
  }

  .keyboard-row {
    gap: 6px;
  }
}

@media (min-width: 821px) {
  .mobile-keyboard {
    display: none;
  }
}
