:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.92);
  --text: #152033;
  --muted: #657084;
  --line: #d8deea;
  --tile-empty: #ffffff;
  --tile-filled: #eef2f8;
  --correct: #2f8f5b;
  --present: #c99b2e;
  --absent: #4d5564;
  --key: #e2e7f1;
  --key-text: #152033;
  --shadow: 0 12px 42px rgba(31, 42, 68, 0.12);
  --radius: clamp(14px, 2.4vmin, 22px);
  --tile: clamp(34px, min(11.5vw, 6.5dvh), 64px);
  --gap: clamp(3px, min(1.1vw, 0.9dvh), 7px);
  --app-pad: clamp(6px, min(2vw, 1.7dvh), 18px);
  --app-gap: clamp(5px, min(1.3vw, 1.2dvh), 13px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

html {
  height: 100%;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(92, 134, 255, 0.18), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(47, 143, 91, 0.16), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.app {
  width: min(760px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--app-pad);
  display: flex;
  flex-direction: column;
  gap: var(--app-gap);
}

.hero {
  background: var(--panel);
  border: 1px solid rgba(216, 222, 234, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(10px, min(2.5vw, 2.2dvh), 22px);
  display: grid;
  gap: clamp(8px, min(2vw, 1.5dvh), 16px);
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--correct);
  font-size: clamp(0.66rem, min(2vw, 1.6dvh), 0.82rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, min(6vw, 5dvh), 3.3rem);
  line-height: 0.96;
  letter-spacing: -0.06em;
}

.intro {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: clamp(0.82rem, min(2.3vw, 1.9dvh), 1.06rem);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, min(1.6vw, 1.2dvh), 12px);
}

.stat-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: clamp(12px, 2vmin, 16px);
  padding: clamp(7px, min(1.8vw, 1.4dvh), 13px);
}

.stat-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.86rem, min(3.3vw, 2.6dvh), 1.35rem);
  font-weight: 900;
  letter-spacing: -0.03em;
}

.stat-card small {
  display: block;
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: clamp(0.62rem, min(1.7vw, 1.4dvh), 0.76rem);
}

.spotlight {
  border-color: rgba(47, 143, 91, 0.3);
  background: linear-gradient(180deg, #ffffff, #f1fff7);
}

.message {
  min-height: clamp(1.7rem, 4.8dvh, 2.35rem);
  display: grid;
  place-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 750;
  font-size: clamp(0.82rem, min(2.4vw, 1.9dvh), 1rem);
  text-align: center;
}

.message.pop {
  animation: pop 160ms ease-out;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  justify-content: center;
  gap: var(--gap);
  padding: 0;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: clamp(8px, 1.8vmin, 16px);
  background: var(--tile-empty);
  color: var(--text);
  font-size: clamp(1.15rem, min(5.5vw, 4.4dvh), 2.4rem);
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  box-shadow: 0 4px 13px rgba(31, 42, 68, 0.08);
}

.tile.filled {
  background: var(--tile-filled);
  border-color: #aeb8c9;
  animation: bump 90ms ease-out;
}

.tile.correct,
.tile.present,
.tile.absent {
  color: #fff;
  border-color: transparent;
}

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

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

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

.keyboard {
  display: grid;
  gap: clamp(4px, min(1vw, 0.8dvh), 7px);
  width: min(680px, 100%);
  margin: 0 auto;
  touch-action: manipulation;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: clamp(3px, min(0.9vw, 0.8dvh), 7px);
}

.key {
  min-width: 0;
  height: clamp(34px, 6.2dvh, 54px);
  flex: 1 1 0;
  max-width: 48px;
  border: 0;
  border-radius: clamp(8px, 1.8vmin, 12px);
  background: var(--key);
  color: var(--key-text);
  font-weight: 950;
  box-shadow: 0 4px 10px rgba(31, 42, 68, 0.1);
  cursor: pointer;
}

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

.key.wide {
  flex-basis: clamp(50px, 15vw, 86px);
  max-width: 92px;
  font-size: clamp(0.62rem, min(2vw, 1.6dvh), 0.82rem);
}

.key.correct,
.key.present,
.key.absent {
  color: #fff;
}

.key.correct {
  background: var(--correct);
}

.key.present {
  background: var(--present);
}

.key.absent {
  background: var(--absent);
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(0.35rem, 1.4vw, 0.7rem);
  color: var(--muted);
  font-size: clamp(0.76rem, min(2.1vw, 1.7dvh), 0.9rem);
}

.secondary {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: clamp(0.45rem, 1.5dvh, 0.65rem) clamp(0.75rem, 2.2vw, 1rem);
  background: #fff;
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
}

.secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.next-puzzle {
  text-align: center;
}

.rules {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(216, 222, 234, 0.8);
  border-radius: clamp(12px, 2vmin, 18px);
  padding: clamp(0.55rem, 1.6dvh, 0.85rem) clamp(0.75rem, 2vw, 1rem);
  color: var(--muted);
  font-size: clamp(0.78rem, min(2vw, 1.7dvh), 1rem);
}

.rules summary {
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
}

.rules p {
  margin: 0.55rem 0 0;
}

@keyframes bump {
  50% { transform: scale(1.07); }
}

@keyframes pop {
  50% { transform: scale(1.03); }
}

@media (min-width: 640px) {
  .hero {
    grid-template-columns: 1fr 1.25fr;
    align-items: center;
  }
}

@media (max-width: 520px) {
  .app {
    width: 100%;
  }

  .hero {
    padding: 10px;
  }

  .intro {
    display: none;
  }

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

@media (max-width: 380px) {
  .stat-card small {
    display: none;
  }
}

@media (max-height: 720px) {
  :root {
    --tile: clamp(32px, min(10.5vw, 5.8dvh), 56px);
    --gap: clamp(3px, min(0.9vw, 0.7dvh), 6px);
    --app-pad: clamp(5px, 1.4dvh, 10px);
    --app-gap: clamp(4px, 0.9dvh, 8px);
  }

  .intro {
    display: none;
  }

  .eyebrow {
    display: none;
  }

  .hero {
    grid-template-columns: 1fr 1.55fr;
    align-items: center;
    padding: 8px;
  }

  h1 {
    font-size: clamp(1.12rem, min(5.2vw, 4.3dvh), 2.2rem);
  }

  .key {
    height: clamp(31px, 5.7dvh, 44px);
  }

  .message {
    min-height: clamp(1.45rem, 4dvh, 1.9rem);
    padding-block: 0.18rem;
  }

  .secondary {
    padding-block: 0.35rem;
  }

  .rules {
    padding-block: 0.45rem;
  }

  .rules p {
    margin-top: 0.4rem;
  }
}

@media (max-height: 620px) {
  :root {
    --tile: clamp(29px, min(9.4vw, 5.25dvh), 48px);
  }

  .hero {
    box-shadow: none;
  }

  .stat-card {
    padding: 5px 6px;
  }

  .stat-card small {
    display: none;
  }

  .action-row {
    line-height: 1.15;
  }

  .rules:not([open]) {
    padding-block: 0.35rem;
  }
}

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