* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #111827;
  --muted: #667085;
  --border: #d7dde7;
  --accent: #2563eb;
  --accent-2: #dbeafe;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --success: #067647;
  --success-bg: #d1fadf;
  --shadow: 0 16px 45px rgba(15, 23, 42, 0.08);
  --cell-size: clamp(38px, 8.5vw, 62px);
}

body.dark {
  --bg: #0b1020;
  --surface: #121a2d;
  --surface-2: #1b2740;
  --text: #f8fafc;
  --muted: #aab5c5;
  --border: #2b3a57;
  --accent: #60a5fa;
  --accent-2: #18355f;
  --danger: #ff8a80;
  --danger-bg: #4a1f24;
  --success: #6ee7a2;
  --success-bg: #173c2b;
  --shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
.cell:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding-bottom: 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 26px 0 18px;
}

.topbar h1,
.section-heading h2,
.game-title-wrap h2,
.modal-card h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 5px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.text-btn,
.secondary-btn,
.primary-btn,
.clue-tab,
.clue-nav button {
  border: 0;
  border-radius: 12px;
}

.icon-btn,
.text-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 12px;
}

.text-btn.compact {
  padding: 7px 9px;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  padding: 12px 16px;
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 750;
  padding: 11px 14px;
}

.danger-lite {
  color: var(--danger);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-card {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.hero-copy h2 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.98;
  margin: 10px 0 12px;
}

.hero-copy p {
  color: var(--muted);
  margin: 0 0 20px;
}

.pill {
  display: inline-flex;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--accent-2);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-self: end;
  gap: 10px;
}

.hero-stats div,
.stats-grid div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}

.hero-stats strong,
.stats-grid strong {
  display: block;
  font-size: 1.55rem;
}

.hero-stats span,
.stats-grid span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.section-block {
  margin-top: 34px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 14px;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.topic-card {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  padding: 18px;
  text-align: left;
  min-height: 118px;
  transition: transform .15s ease, box-shadow .15s ease;
}

.topic-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.topic-card .emoji {
  font-size: 1.6rem;
}

.topic-card strong {
  display: block;
  margin-top: 16px;
}

.topic-card span {
  color: var(--muted);
  font-size: .8rem;
}

.puzzle-list {
  display: grid;
  gap: 10px;
}

.puzzle-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 16px;
  padding: 16px;
}

.puzzle-card h3 {
  margin: 0 0 4px;
}

.puzzle-card p {
  margin: 0;
  color: var(--muted);
  font-size: .86rem;
}

.game-toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.game-title-wrap {
  text-align: center;
}

.game-title-wrap p {
  color: var(--muted);
  margin: 3px 0 0;
  font-size: .85rem;
}

.timer-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
  gap: 20px;
}

.board-panel,
.clues-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  justify-content: center;
  gap: 1px;
  margin: 0 auto;
  background: #111827;
  border: 3px solid #111827;
  width: fit-content;
  max-width: 100%;
}

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  background: #fff;
  color: #111827;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.cell.blocked {
  background: #111827;
}

.cell.active {
  background: #facc15;
}

.cell.word {
  background: #dbeafe;
}

.cell.word.active {
  background: #facc15;
}

.cell.incorrect {
  color: #b42318;
  background: #fee4e2;
}

.cell.revealed::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b42318;
}

.cell .number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: clamp(8px, 1.6vw, 11px);
  font-weight: 800;
  line-height: 1;
}

.cell .letter {
  font-size: clamp(1rem, 4vw, 1.65rem);
  font-weight: 850;
  line-height: 1;
}

.current-clue-card {
  margin-top: 14px;
  background: var(--surface-2);
  border-radius: 16px;
  padding: 12px;
}

.clue-nav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.clue-nav button {
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.4rem;
}

.clue-nav p {
  margin: 4px 0 0;
  color: var(--muted);
}

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.clue-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.clue-columns h3 {
  margin-top: 0;
}

.clue-list {
  margin: 0;
  padding-left: 28px;
}

.clue-list li {
  padding: 8px 8px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}

.clue-list li.active {
  background: var(--accent-2);
  color: var(--text);
}

.clue-list li.solved {
  text-decoration: line-through;
  opacity: .55;
}

.clue-tabs {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
}

.clue-tab {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px;
  font-weight: 800;
}

.clue-tab.active {
  background: var(--accent);
  color: white;
}

.mobile-keyboard {
  display: none;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  margin-top: 14px;
}

.key {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  min-height: 42px;
  font-weight: 800;
}

.key.backspace {
  grid-column: span 2;
}

.modal {
  border: 0;
  padding: 0;
  border-radius: 22px;
  background: transparent;
  max-width: min(520px, calc(100% - 26px));
}

.modal::backdrop {
  background: rgba(15, 23, 42, .58);
  backdrop-filter: blur(3px);
}

.modal-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  min-width: min(480px, calc(100vw - 36px));
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.completion-card {
  text-align: center;
}

.celebrate {
  font-size: 3rem;
}

.completion-time {
  font-size: 2.3rem;
  font-weight: 900;
  margin: 8px 0;
}

.badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.badge {
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--success-bg);
  color: var(--success);
  font-size: .78rem;
  font-weight: 800;
}

.share-result {
  text-align: left;
  white-space: pre-wrap;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 14px;
  margin: 16px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  :root {
    --cell-size: clamp(36px, 11vw, 58px);
  }

  .topic-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .clues-panel {
    order: 2;
  }

  .mobile-keyboard {
    display: grid;
  }

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

  .clue-tabs {
    display: flex;
  }

  .clue-columns > div:nth-child(2) {
    display: none;
  }

  .clues-panel.show-down .clue-columns > div:first-child {
    display: none;
  }

  .clues-panel.show-down .clue-columns > div:nth-child(2) {
    display: block;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
  }

  .topbar {
    padding-top: 18px;
  }

  .topbar h1 {
    font-size: 1.35rem;
  }

  .hero-card {
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .hero-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .hero-stats div {
    padding: 11px 7px;
  }

  .topic-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topic-card {
    min-height: 105px;
    padding: 14px;
  }

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

  .timer-wrap {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .board-panel,
  .clues-panel {
    padding: 12px;
    border-radius: 16px;
  }

  .mobile-keyboard {
    grid-template-columns: repeat(9, 1fr);
  }

  .key {
    min-height: 39px;
    padding: 0;
  }

  .key.backspace {
    grid-column: span 2;
  }

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

  .stacked-mobile {
    flex-direction: column;
  }

  .stacked-mobile button {
    width: 100%;
  }
}
