:root {
  --ink: #172026;
  --muted: #64717a;
  --paper: #fbf7ef;
  --panel: #ffffff;
  --line: #d7dde0;
  --block: #1f2a30;
  --cell: #fffdf8;
  --active: #b7e6df;
  --current: #ffd166;
  --accent: #e85d4f;
  --accent-dark: #b83e34;
  --success: #2b9c73;
  --shadow: 0 18px 60px rgba(23, 32, 38, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(135deg, rgba(232, 93, 79, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(43, 156, 115, 0.13), transparent 30%),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 650px) minmax(280px, 1fr);
  gap: 24px;
  align-items: start;
  padding: 32px 0;
}

.game-panel,
.clue-panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(215, 221, 224, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-panel {
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 4vw, 2.8rem);
  line-height: 1;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat {
  min-width: 92px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  text-align: right;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 1.25rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.tool-button,
.primary-link {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
  text-decoration: none;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.tool-button:hover,
.primary-link:hover {
  transform: translateY(-1px);
  border-color: #9facb3;
}

.tool-button.accent,
.primary-link {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.tool-button.accent:hover,
.primary-link:hover {
  background: var(--accent-dark);
}

.crossword-grid {
  width: min(100%, 620px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  border: 3px solid var(--block);
  background: var(--block);
  user-select: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--block);
  background: var(--cell);
}

.cell.is-block {
  background: var(--block);
}

.cell.bar-right {
  border-right-width: 5px;
}

.cell.bar-bottom {
  border-bottom-width: 5px;
}

.cell.is-active-word {
  background: var(--active);
}

.cell.is-current {
  background: var(--current);
  box-shadow: inset 0 0 0 3px rgba(23, 32, 38, 0.35);
}

.cell.is-correct input {
  color: var(--success);
}

.cell-number {
  position: absolute;
  top: 3px;
  left: 4px;
  color: rgba(23, 32, 38, 0.74);
  font-size: clamp(0.52rem, 1.5vw, 0.72rem);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.cell input {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  text-align: center;
  text-transform: uppercase;
  font-size: clamp(1rem, 4.7vw, 2rem);
  font-weight: 900;
  caret-color: transparent;
}

.cell input::selection {
  background: transparent;
}

.clue-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
  max-height: calc(100vh - 64px);
  overflow: auto;
}

.clue-panel h2 {
  margin-bottom: 10px;
  font-size: 1rem;
}

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

.clue-list li {
  margin: 0;
}

.clue-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  line-height: 1.35;
}

.clue-button strong {
  margin-right: 6px;
}

.clue-button small {
  color: var(--muted);
  font-weight: 800;
}

.clue-button.is-active {
  border-color: var(--accent);
  background: #fff1ef;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 38, 0.54);
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  overflow: hidden;
  border-radius: 8px;
  padding: 34px;
  background: #fffdf8;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.28);
  text-align: center;
}

.modal-kicker {
  margin-bottom: 8px;
  color: var(--success);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.modal-card h2 {
  margin-bottom: 12px;
  font-size: clamp(1.8rem, 7vw, 3rem);
  line-height: 1.05;
}

.result-time {
  margin-bottom: 22px;
  color: var(--muted);
  font-size: 1.05rem;
}

.result-time strong {
  color: var(--ink);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -18px;
  width: 9px;
  height: 16px;
  border-radius: 2px;
  animation: fall 1100ms ease-out forwards;
}

.game-panel.is-complete .crossword-grid {
  animation: solvedPulse 900ms ease-in-out;
}

[hidden] {
  display: none !important;
}

@keyframes fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(620px) rotate(560deg);
  }
}

@keyframes solvedPulse {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.025);
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 18px 0;
  }

  .game-panel {
    padding: 18px;
  }

  .topbar {
    flex-direction: column;
  }

  .stats {
    justify-content: flex-start;
  }

  .clue-panel {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
  }

  .tool-button,
  .primary-link {
    flex: 1 1 auto;
  }

  .modal-card {
    padding: 26px 18px;
  }
}
