:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f1f22;
  --muted: #66666d;
  --border: #d3d2cc;
  --key: #e3e2dc;
  --green: #3b8c5a;
  --yellow: #c79a1f;
  --gray: #74757a;
  --on-color: #ffffff;
  --focus: #2f6fd6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517;
    --surface: #1f1f23;
    --text: #ececef;
    --muted: #a0a0a8;
    --border: #3a3a40;
    --key: #3a3a41;
    --green: #3f9160;
    --yellow: #b8901f;
    --gray: #4b4c52;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Elements with their own display (flex, grid) would otherwise ignore `hidden`. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

header {
  text-align: center;
  padding: 16px 16px 4px;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 4px auto 0;
  max-width: 34em;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ---- Mode and pool toggles ---- */

.modes {
  display: inline-flex;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mode {
  padding: 6px 18px;
  border: 0;
  background: var(--surface);
  font-weight: 600;
}

.mode + .mode { border-left: 1px solid var(--border); }
.mode[aria-pressed="true"] { background: var(--green); color: var(--on-color); }

.pools { margin: 8px 0 0; }
#pool-note { margin-bottom: 12px; }

main {
  display: grid;
  gap: 24px;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

@media (min-width: 860px) {
  main { grid-template-columns: minmax(0, 1fr) 350px; align-items: start; }
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button:disabled { cursor: default; }

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

.board {
  --tile: min(14vw, 58px);
  display: grid;
  gap: 6px;
  justify-content: center;
}

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

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.55);
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 0;
  user-select: none;
}

.tile.empty { border-color: var(--border); }
.tile.c-b { background: var(--gray); color: var(--on-color); }
.tile.c-y { background: var(--yellow); color: var(--on-color); }
.tile.c-g { background: var(--green); color: var(--on-color); }

.row.active .tile.empty { border-color: var(--muted); }
.tile.typed { border-color: var(--text); }

button.tile { box-shadow: inset 0 -3px 0 rgb(0 0 0 / 0.18); }
button.tile:active { transform: scale(0.95); }

.submit {
  width: var(--tile);
  height: var(--tile);
  font-size: calc(var(--tile) * 0.5);
  border: 2px solid var(--green);
  border-radius: 50%;
  background: var(--surface);
  color: var(--green);
  transform: scale(0.8);
}

.submit:not(:disabled) { background: var(--green); color: var(--on-color); }
.submit:disabled { opacity: 0.35; }

.message {
  min-height: 1.4em;
  margin: 12px 0;
  text-align: center;
  font-weight: 600;
}

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

.keyboard {
  display: grid;
  gap: 6px;
  max-width: 500px;
  margin: 0 auto;
}

.key-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  flex: 1 1 0;
  max-width: 44px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: var(--key);
  font-weight: 600;
  text-transform: uppercase;
  touch-action: manipulation;
}

.key.wide {
  flex-grow: 1.6;
  max-width: 68px;
  font-size: 0.75rem;
}

.key.c-b { background: var(--gray); color: var(--on-color); }
.key.c-y { background: var(--yellow); color: var(--on-color); }
.key.c-g { background: var(--green); color: var(--on-color); }

.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.secondary {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.secondary:disabled { opacity: 0.45; }

/* ---- Results ---- */

.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.results h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.summary { margin: 0 0 12px; }

.suggestions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

.suggestion {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  text-align: left;
}

.suggestion:not(:disabled):hover { border-color: var(--muted); }

.suggestion .word {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.suggestion .score {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--green);
  color: var(--on-color);
}

.legend {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- Game recap ---- */

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

.recap li {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mini-row {
  display: flex;
  gap: 3px;
}

.tile.mini {
  --tile: 26px;
  border-width: 0;
  border-radius: 3px;
}

.recap-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#game-panel .actions { flex-wrap: wrap; }
