/* Parchment / ink theme. Swap these variables to restyle everything. */
:root {
  --bg: #f3ede2;
  --surface: #fbf8f2;
  --ink: #2a2733;
  --muted: #7b7468;
  --line: #d9d0c1;
  --line-strong: #a89f90;
  --key: #e3dacb;
  --correct: #2a8c82;  /* right letter, right spot */
  --present: #e08a2e;  /* right letter, wrong spot */
  --absent: #8f887c;   /* not in the word */
  --accent: #2a8c82;
  --gap: 6px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a22;
    --surface: #24232d;
    --ink: #efe9dd;
    --muted: #9a93a6;
    --line: #3a3846;
    --line-strong: #5d5a6b;
    --key: #3a3846;
    --correct: #2f9e92;
    --present: #e3913a;
    --absent: #4a4757;
    --accent: #2f9e92;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  user-select: none;
}

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

/* ---------- Header ---------- */
header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 4px;
}
h1 {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 30px;
  letter-spacing: 0.01em;
}
.tabs {
  display: inline-flex;
  background: var(--key);
  border-radius: 999px;
  padding: 3px;
}
.tab {
  background: none;
  border: none;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
#subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 0 0;
  min-height: 20px;
  font-family: Georgia, serif;
  font-style: italic;
}

/* ---------- Board ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 0;
  padding: 8px 0;
}
#board {
  --len: 5;
  --tile: min(
    60px,
    calc((100vw - 32px - (var(--len) - 1) * var(--gap)) / var(--len)),
    calc((100dvh - 390px) / 6 - var(--gap))
  );
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: var(--gap);
}
.row {
  display: grid;
  grid-template-columns: repeat(var(--len), var(--tile));
  gap: var(--gap);
}
.tile {
  width: var(--tile);
  height: var(--tile);
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.5);
  font-weight: 700;
  line-height: 1;
}
body.upper .tile, body.upper .key { text-transform: uppercase; }
.tile.filled { border-color: var(--line-strong); }
.tile.filled.pop { animation: pop 120ms ease-out; }
.tile.correct { --c: var(--correct); }
.tile.present { --c: var(--present); }
.tile.absent  { --c: var(--absent); }
.tile.correct, .tile.present, .tile.absent {
  background: var(--c);
  border-color: var(--c);
  color: #fff;
}
.tile.reveal { animation: stamp 420ms ease-out both; }
.tile.win { animation: hop 600ms ease both; }
.row.shake { animation: shake 450ms ease; }

#board .message {
  grid-row: 1 / -1;
  max-width: 320px;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
  align-self: center;
}

#action { min-height: 40px; }
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 700;
}
.btn.secondary { background: var(--key); color: var(--ink); }

/* Tiles "stamp" down and come back up coloured. */
@keyframes stamp {
  0%     { transform: scale(1); background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
  45%    { transform: scale(0.8); background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
  45.1%  { background: var(--c); border-color: var(--c); color: #fff; }
  75%    { transform: scale(1.08); }
  100%   { transform: scale(1); }
}
@keyframes pop {
  0% { transform: scale(0.88); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes hop {
  0%, 20% { transform: translateY(0) rotate(0); }
  40% { transform: translateY(-25%) rotate(-4deg); }
  60% { transform: translateY(-10%) rotate(3deg); }
  100% { transform: translateY(0) rotate(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

/* ---------- Keyboard ---------- */
#keyboard {
  padding: 0 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  max-width: 44px;
  height: 54px;
  border: none;
  border-radius: 8px;
  background: var(--key);
  font-size: 16px;
  font-weight: 700;
  padding: 0;
  transition: background-color 150ms, color 150ms;
}
.key.wide { flex: 1.5; max-width: 66px; font-size: 12px; text-transform: none !important; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent {
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 1.5px var(--line);
  opacity: .6;
}
.key:active { filter: brightness(0.9); }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 999px;
  transition: opacity 300ms;
}
.toast.fade { opacity: 0; }
