:root {
  color-scheme: dark;
  --bg: #121213;
  --fg: #f4f4f4;
  --muted: #9a9a9c;
  --tile-border: #3a3a3c;
  --tile-filled: #565758;
  --key: #818384;
  --key-fg: #f4f4f4;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --accent: #538d4e;
  --tile: min(62px, calc((100vw - 2rem - 4 * 5px) / 5));
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--tile-border);
}
.brand-group { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.brand { font-weight: 800; font-size: 1.4rem; letter-spacing: 0.08em; text-decoration: none; text-transform: uppercase; }
.status { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.topbar nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--muted); padding: 0.35rem 0.6rem; border-radius: 6px; font-size: 0.95rem; }
.topbar nav a:hover, .topbar nav a[aria-current="page"] { color: var(--fg); background: #1f1f20; }

.page { flex: 1; padding: 0.75rem 1rem 1rem; display: flex; flex-direction: column; align-items: center; width: 100%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }

/* landing */
.hero { max-width: 36rem; text-align: center; margin-top: 2rem; }
.hero h1 { font-size: 3rem; letter-spacing: 0.1em; text-transform: uppercase; margin: 0 0 0.5rem; }
.lead { font-size: 1.15rem; color: var(--muted); }
.hint { background: #1f1f20; border: 1px solid var(--tile-border); border-radius: 8px; padding: 0.75rem 1rem; }
.choices { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); margin-top: 2rem; text-align: left; }
.choice { display: flex; flex-direction: column; gap: 0.35rem; padding: 1.25rem; border: 1px solid var(--tile-border); border-radius: 12px; text-decoration: none; background: #1a1a1b; transition: border-color 0.15s; }
.choice:hover { border-color: var(--accent); }
.choice strong { font-size: 1.2rem; }
.choice span { color: var(--muted); font-size: 0.95rem; }

/* board */
.play { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.75rem; width: 100%; max-width: 32rem; }
.board { display: grid; gap: 5px; }
.row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: 5px; }
.tile {
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  border: 2px solid var(--tile-border);
  font-size: calc(var(--tile) * 0.5);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  transition: transform 0.1s;
}
.tile.filled { border-color: var(--tile-filled); animation: pop 0.1s ease-in-out; }
.tile.g, .tile.y, .tile.x { border-color: transparent; color: #fff; }
.tile.g { background: var(--correct); }
.tile.y { background: var(--present); }
.tile.x { background: var(--absent); }
.tile.flip { animation: flip 0.5s ease forwards; }
.row.shake { animation: shake 0.5s; }
.row.dance .tile { animation: dance 0.6s ease; }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@keyframes dance { 20% { transform: translateY(-50%); } 40% { transform: translateY(5%); } 60% { transform: translateY(-25%); } 80% { transform: translateY(2%); } }

/* demo rows in tutorial/intro */
.demo-row { --tile: 48px; display: grid; grid-template-columns: repeat(5, var(--tile)); gap: 5px; margin: 0.75rem 0 0.25rem; }

/* keyboard */
.keyboard { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 32rem; margin-top: auto; }
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1; max-width: 46px; height: 56px;
  border: 0; border-radius: 4px;
  background: var(--key); color: var(--key-fg);
  font: inherit; font-weight: 700; font-size: 0.95rem; text-transform: uppercase;
  cursor: pointer; touch-action: manipulation; user-select: none;
  transition: background 0.2s;
}
.key.wide { flex: 1.6; max-width: 72px; font-size: 0.75rem; }
.key.g { background: var(--correct); }
.key.y { background: var(--present); }
.key.x { background: var(--absent); color: var(--muted); }
.key:active { filter: brightness(1.2); }
.key.ready { background: var(--accent); color: #fff; animation: ready 1.2s ease-in-out infinite; }
@keyframes ready { 50% { transform: scale(1.06); box-shadow: 0 0 0 4px rgb(83 141 78 / 0.35); } }
@media (prefers-reduced-motion: reduce) { .key.ready { animation: none; } }

/* feedback */
/* Overlays the top of the board instead of reserving a line of its own. */
.toast { position: absolute; top: 0.5rem; left: 50%; transform: translateX(-50%); z-index: 2; font-weight: 700; background: var(--fg); color: var(--bg); border-radius: 6px; padding: 0 0.75rem; line-height: 1.8rem; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.toast.show { opacity: 1; }

.result { text-align: center; background: #1a1a1b; border: 1px solid var(--tile-border); border-radius: 12px; padding: 1.25rem; width: 100%; }
.result h2 { margin: 0 0 0.5rem; }
.result .solution { text-transform: uppercase; letter-spacing: 0.1em; }
.actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }
.actions form { display: contents; }
.btn { display: inline-block; padding: 0.6rem 1rem; border-radius: 8px; border: 1px solid var(--tile-border); background: #262627; color: var(--fg); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:hover { filter: brightness(1.1); }

.modal { position: fixed; inset: 0; background: rgb(0 0 0 / 0.7); display: grid; place-items: center; padding: 1rem; z-index: 10; }
.modal-card { background: #1a1a1b; border: 1px solid var(--tile-border); border-radius: 12px; padding: 1.5rem; max-width: 26rem; width: 100%; }
.modal-card h2 { margin-top: 0; }

/* text pages */
.prose { max-width: 38rem; width: 100%; line-height: 1.55; }
.prose h1 { font-size: 2rem; }
.prose h2 { margin-top: 2rem; font-size: 1.3rem; }
.practice { margin: 1rem 0; }
.practice .keyboard { margin-top: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; text-align: center; }
.stat strong { display: block; font-size: 2rem; }
.stat span { color: var(--muted); font-size: 0.85rem; }
.dist { display: grid; gap: 4px; }
.dist-row { display: grid; grid-template-columns: 1.5rem 1fr; align-items: center; gap: 0.5rem; }
.dist-bar { min-width: 1.5rem; background: var(--absent); color: #fff; font-weight: 700; text-align: right; padding: 0.15rem 0.5rem; border-radius: 3px; }

@media (max-width: 480px) {
  .topbar { padding: 0.45rem 0.75rem; }
  .topbar nav a { padding: 0.3rem 0.4rem; font-size: 0.8rem; }
  .status { display: none; }
  .page { padding-top: 0.5rem; }
  .key { height: 50px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
