:root {
  --paper: #F6F1E7;
  --paper-line: #E1D8C4;
  --white: #FFFDF8;
  --ink: #2B2823;
  --ink-soft: #5A5548;
  --indigo: #3A4B6B;
  --indigo-dark: #2C3A54;
  --correct: #4C7A5E;
  --present: #C79A3D;
  --absent: #B0A99B;

  --font-display: 'Fraunces', serif;
  --font-body: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

/* ---------- Masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 18px;
  margin-bottom: 28px;
}

.masthead__title h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2.4rem;
  margin: 0;
  letter-spacing: 0.01em;
}

.masthead__tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  color: var(--ink-soft);
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.stamp {
  font-family: var(--font-mono);
  border: 2px dashed var(--indigo);
  color: var(--indigo);
  border-radius: 50%;
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: rotate(-6deg);
  line-height: 1.1;
}

.stamp__label { font-size: 0.6rem; letter-spacing: 0.1em; }
.stamp__number { font-size: 1.3rem; font-weight: 700; }
.stamp__date { font-size: 0.55rem; letter-spacing: 0.03em; }

/* ---------- Board ---------- */

.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.control-group {
  display: flex;
  border: 1.5px solid var(--ink-soft);
  border-radius: 20px;
  overflow: hidden;
}

.control-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.8rem;
  border: none;
  background: var(--white);
  color: var(--ink-soft);
  padding: 8px 16px;
  cursor: pointer;
}

.control-btn + .control-btn {
  border-left: 1.5px solid var(--ink-soft);
}

.control-btn.active {
  background: var(--indigo);
  color: var(--white);
}

.control-btn:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: -3px;
}

.new-round {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  border: 1.5px solid var(--indigo);
  background: transparent;
  color: var(--indigo);
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
}

.new-round:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: 2px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px 22px;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: -8px;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend__swatch {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--white);
  flex-shrink: 0;
}

.legend__swatch.correct { background: var(--correct); }
.legend__swatch.present { background: var(--present); }
.legend__swatch.absent  { background: var(--absent); }
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 8px;
}

.board__row {
  display: grid;
  grid-template-columns: repeat(var(--word-length, 5), 54px);
  gap: 8px;
}

.tile {
  width: 54px;
  height: 54px;
  border: 2px solid var(--paper-line);
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.5rem;
  color: var(--ink);
  border-radius: 3px;
  transition: transform 0.15s ease;
}

.tile.filled {
  border-color: var(--ink-soft);
}

.tile.stamp-in {
  animation: stampPress 0.28s ease;
}

.tile.correct,
.tile.present,
.tile.absent {
  color: var(--white);
  border-color: transparent;
}

.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent  { background: var(--absent); }

@keyframes stampPress {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  70%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

.tile.shake {
  animation: shake 0.32s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.message {
  min-height: 1.2em;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  color: var(--indigo-dark);
  margin: 0;
  text-align: center;
}

/* ---------- Keyboard ---------- */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 480px;
}

.keyboard__row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.85rem;
  border: none;
  border-radius: 4px;
  background: var(--white);
  border: 1.5px solid var(--paper-line);
  color: var(--ink);
  padding: 0 10px;
  height: 46px;
  min-width: 32px;
  flex: 1;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.key:active { transform: translateY(1px); }

.key:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: 1px;
}

.key--wide { flex: 1.6; font-size: 0.7rem; }

.key.correct { background: var(--correct); color: var(--white); }
.key.present { background: var(--present); color: var(--white); }
.key.absent  { background: var(--absent); color: var(--white); }

/* ---------- Leaderboard panel ---------- */

.panel {
  margin-top: 32px;
  border-top: 2px solid var(--ink);
  padding-top: 18px;
}

.panel h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  margin: 0 0 12px;
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid var(--paper-line);
}

.leaderboard li:first-child {
  color: var(--indigo-dark);
  font-weight: 700;
}

.footer {
  margin-top: 40px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 40, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 28px;
  max-width: 380px;
  width: 100%;
}

.modal h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 10px;
}

.modal p {
  color: var(--ink-soft);
  margin: 0 0 18px;
  line-height: 1.4;
}

.score-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-form label {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.score-form input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 10px 12px;
  border: 1.5px solid var(--paper-line);
  border-radius: 4px;
  background: var(--white);
}

.score-form input:focus-visible {
  outline: 3px solid var(--indigo);
}

.score-form button,
.modal-dismiss {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.score-form button {
  background: var(--indigo);
  color: var(--white);
}

.modal-dismiss {
  margin-top: 10px;
  background: transparent;
  color: var(--indigo-dark);
  text-decoration: underline;
}

/* ---------- Responsive ---------- */

@media (max-width: 420px) {
  .tile { width: 46px; height: 46px; font-size: 1.25rem; }
  .board__row { grid-template-columns: repeat(var(--word-length, 5), 46px); }
  .masthead__title h1 { font-size: 1.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.stamp-in, .tile.shake { animation: none; }
}
