:root {
  color-scheme: light dark;
  --bg: #f3f6f1;
  --surface: rgba(255, 255, 255, .82);
  --text: #172019;
  --muted: #687269;
  --border: #cbd4cd;
  --key: #dce3dd;
  --green: #438b5c;
  --yellow: #b08a2e;
  --gray: #717a73;
  --accent: #287a4a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101411;
    --surface: rgba(29, 36, 31, .84);
    --text: #f5f7f2;
    --muted: #9ba59d;
    --border: #39423b;
    --key: #343c36;
    --green: #3f925c;
    --yellow: #a8832d;
    --gray: #4a524c;
    --accent: #57b979;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 38%),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
.page { width: min(100% - 24px, 520px); min-height: 100vh; margin: auto; padding: 16px 0 24px; }
.topbar { display: grid; grid-template-columns: 46px 1fr 46px; align-items: center; }
.topbar h1 { margin: 0; text-align: center; font-size: clamp(21px, 6vw, 29px); letter-spacing: .12em; }
.icon-link { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--text); text-decoration: none; backdrop-filter: blur(12px); }
.topbar .icon-link:last-child { justify-self: end; }
.intro { margin: 8px 0 0; color: var(--muted); text-align: center; font-size: 13px; }
.game { min-height: calc(100vh - 98px); display: flex; flex-direction: column; }
.board { display: grid; gap: 6px; width: max-content; margin: clamp(18px, 4vh, 38px) auto 12px; }
.row { display: grid; grid-template-columns: repeat(5, clamp(46px, 14vw, 58px)); gap: 6px; perspective: 600px; }
.cell {
  display: grid; place-items: center; aspect-ratio: 1; overflow: hidden;
  border: 2px solid var(--border); border-radius: 9px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  font-size: clamp(23px, 7vw, 30px); font-weight: 800; text-transform: uppercase;
  transition: border-color .18s, transform .12s;
}
.cell.filled { border-color: var(--muted); transform: scale(1.025); }
.cell.reveal { animation: flip .52s ease both; animation-delay: var(--delay); }
.cell.correct, .key.correct { border-color: var(--green); background: var(--green); color: #fff; }
.cell.present, .key.present { border-color: var(--yellow); background: var(--yellow); color: #fff; }
.cell.absent, .key.absent { border-color: var(--gray); background: var(--gray); color: #fff; }
.message { min-height: 22px; margin: 0 0 8px; color: var(--muted); text-align: center; font-size: 13px; font-weight: 650; }
.message.error { color: #c44f4f; animation: shake .32s ease; }
.message.success { color: var(--green); }
.keyboard { display: grid; gap: 6px; margin-top: auto; }
.key-row { display: flex; gap: 4px; justify-content: center; }
.key {
  flex: 1; min-width: 0; height: clamp(44px, 7vh, 54px); padding: 0 1px;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent); border-radius: 9px;
  background: var(--key); color: var(--text); box-shadow: 0 2px 5px rgba(0,0,0,.12);
  font-size: clamp(14px, 4vw, 19px); font-weight: 700; cursor: pointer;
}
.key:active { transform: translateY(1px); }
.key.wide { flex: 1.7; font-size: 22px; }
.submit {
  width: 100%; height: 52px; border: 0; border-radius: 11px;
  background: var(--accent); color: #fff; font-weight: 800; letter-spacing: .1em; cursor: pointer;
}
.submit:disabled { opacity: .55; cursor: default; }
#confetti { position: fixed; z-index: 10; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.content-card { margin-top: 34px; padding: 24px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: 0 18px 48px rgba(0,0,0,.08); backdrop-filter: blur(14px); }
.content-card h1 { margin: 0 0 12px; font-size: 28px; }
.content-card h2 { margin: 24px 0 8px; font-size: 18px; }
.content-card p, .content-card li { color: var(--muted); line-height: 1.65; }
.content-card a, .back-link { color: var(--accent); font-weight: 700; }
.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; }
.error-code { margin: 0; color: var(--accent); font-size: clamp(92px, 28vw, 150px); line-height: .9; letter-spacing: -.08em; }
.error-page h1 { margin: 18px 0 8px; }
.error-page p { color: var(--muted); }

@keyframes flip { 0% { transform: rotateX(0); } 48% { transform: rotateX(90deg); } 52% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
@media (max-height: 700px) {
  .page { padding-top: 8px; }
  .intro { display: none; }
  .board { margin: 10px auto 7px; gap: 4px; }
  .row { grid-template-columns: repeat(5, clamp(38px, 10.5vh, 50px)); gap: 4px; }
  .key { height: clamp(38px, 6.5vh, 46px); }
  .submit { height: 43px; }
}
