:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --muted: #6b6f72;
  --line: #d3d6da;
  --tbd: #878a8c;
  --key: #d3d6da;
  --key-text: #1a1a1b;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --warn: #c54949;
  --on-color: #ffffff;
  --dialog: #ffffff;
  --shadow: 0 8px 30px rgb(0 0 0 / 0.18);
  --toast-bg: #1a1a1b;
  --toast-text: #ffffff;
  --tile: 58px;
  --gap: 5px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121213;
    --text: #f8f8f8;
    --muted: #9a9ca0;
    --line: #3a3a3c;
    --tbd: #565758;
    --key: #818384;
    --key-text: #f8f8f8;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --dialog: #1f1f20;
    --shadow: 0 8px 30px rgb(0 0 0 / 0.6);
    --toast-bg: #f8f8f8;
    --toast-text: #121213;
  }
}
:root[data-theme="dark"] {
  --bg: #121213;
  --text: #f8f8f8;
  --muted: #9a9ca0;
  --line: #3a3a3c;
  --tbd: #565758;
  --key: #818384;
  --key-text: #f8f8f8;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --dialog: #1f1f20;
  --shadow: 0 8px 30px rgb(0 0 0 / 0.6);
  --toast-bg: #f8f8f8;
  --toast-text: #121213;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
  padding-top: max(4px, env(safe-area-inset-top));
}
.top h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: 0.5px; display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 13px; font-weight: 700; letter-spacing: 0;
  padding: 2px 7px; border-radius: 999px;
  background: var(--warn); color: var(--on-color);
  user-select: none; -webkit-user-select: none; touch-action: none; /* (the secret: scrolled, swiped and tapped, app.js) */
}
.badge.nudge { animation: pop 150ms; }
.icon {
  width: 40px; height: 40px; border: 0; background: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
}
.icon:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }

.tabs { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 12px 0; flex-wrap: wrap; }
.tabs a {
  text-decoration: none; color: var(--muted); font-weight: 700; font-size: 15px;
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
}
.tabs a[aria-current="page"] { color: var(--on-color); background: var(--correct); border-color: var(--correct); }
.tabs .label { color: var(--muted); font-size: 14px; margin-left: 6px; font-variant-numeric: tabular-nums; }

main {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 10px;
  padding: 8px 16px;
}
#board { display: grid; grid-template-rows: repeat(6, var(--tile)); gap: var(--gap); }
.row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: var(--gap); }
.row.shake { animation: shake 600ms; }
.tile {
  position: relative;
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  border: 2px solid var(--line);
  font-size: calc(var(--tile) * 0.55); font-weight: 800; line-height: 1;
  text-transform: uppercase; user-select: none;
  background: var(--bg); color: var(--text);
}
.tile.tbd { border-color: var(--tbd); animation: pop 100ms; }
.tile.correct, .tile.present, .tile.absent { color: var(--on-color); border-color: transparent; }
.tile.correct { background: var(--correct); --c: var(--correct); }
.tile.present { background: var(--present); --c: var(--present); }
.tile.absent { background: var(--absent); --c: var(--absent); }
.tile.reveal { animation: flip 500ms ease-in var(--d, 0ms) both; }
.tile.win { animation: bounce 600ms ease var(--d, 0ms); }
.tile.mini { width: 38px; height: 38px; font-size: 20px; }
@keyframes flip {
  0% { transform: rotateX(0); background: var(--bg); border-color: var(--tbd); color: var(--text); }
  49.9% { transform: rotateX(90deg); background: var(--bg); border-color: var(--tbd); color: var(--text); }
  50% { transform: rotateX(90deg); background: var(--c); border-color: transparent; color: var(--on-color); }
  100% { transform: rotateX(0); background: var(--c); border-color: transparent; color: var(--on-color); }
}
@keyframes pop { 0% { transform: scale(0.85); } 40% { transform: scale(1.1); } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); } 40% { transform: translateY(-30px); } 50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); } 80% { transform: translateY(2px); } 100% { transform: translateY(0); }
}

/* "Show the truth": the true colour, and a corner in the colour the square pretended to be */
/* .tile.lied { outline: 3px solid var(--warn); outline-offset: -3px; } */
.tile.lied { border: 3px solid var(--warn); }
.tile.lied::after {
  content: ""; position: absolute; top: -3px; right: -3px;
  border-style: solid; border-width: 0 calc(var(--tile) * 0.5) calc(var(--tile) * 0.5) 0;
  border-color: transparent var(--lied) transparent transparent;
  filter: drop-shadow(-2.12px 2.12px 0 var(--warn)); /* 3 / sqrt(2) */
}
.legend { color: var(--muted); font-size: 13px; text-align: center; max-width: 340px; margin: 0; }

.after { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 8px 16px; font-weight: 700; font-size: 15px;
}
.pill[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.primary {
  border: 0; background: var(--correct); color: var(--on-color); border-radius: 999px;
  padding: 10px 22px; font-weight: 800; font-size: 16px;
}

#keyboard {
  width: 100%; max-width: 500px; margin: 0 auto;
  padding: 0 8px calc(8px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; user-select: none;
}
.krow { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1; height: 56px; min-width: 0; padding: 0;
  border: 0; border-radius: 4px;
  background: var(--key); color: var(--key-text);
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  display: grid; place-items: center;
  transition: background-color 150ms;
}
.key.wide { flex: 1.5; font-size: 12px; }
.key.spacer { flex: 0.5; visibility: hidden; }
.key.correct, .key.present, .key.absent { color: var(--on-color); }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent { background: var(--absent); }
.key:active { filter: brightness(0.9); }

#toasts {
  position: fixed; top: 96px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 10; pointer-events: none;
}
.toast {
  background: var(--toast-bg); color: var(--toast-text);
  padding: 12px 16px; border-radius: 6px; font-weight: 700; font-size: 15px;
  transition: opacity 300ms; max-width: calc(100vw - 32px); text-align: center;
}
.toast.gone { opacity: 0; }

dialog {
  border: 0; border-radius: 10px; padding: 20px 20px 18px;
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--dialog); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin: 0 32px 12px 0; font-size: 20px; }
dialog h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; margin: 18px 0 8px; }
dialog p { line-height: 1.45; margin: 0 0 10px; }
dialog .close { position: absolute; top: 8px; right: 8px; margin: 0; }
dialog .close button { width: 36px; height: 36px; border: 0; background: none; font-size: 26px; line-height: 1; border-radius: 50%; }
.example { display: flex; gap: 4px; margin: 6px 0 10px; }
.warn { background: color-mix(in srgb, var(--present) 18%, transparent); border-radius: 8px; padding: 10px 12px; }
.answer { font-size: 18px; }
.answer b { letter-spacing: 2px; text-transform: uppercase; }
.lies { color: var(--muted); }
.nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.nums b { display: block; font-size: 30px; font-variant-numeric: tabular-nums; }
.nums span { font-size: 12px; color: var(--muted); }
#dist { display: flex; flex-direction: column; gap: 4px; }
.bar { display: flex; align-items: center; gap: 6px; font-size: 14px; font-variant-numeric: tabular-nums; }
.bar i {
  font-style: normal; font-weight: 700; color: var(--on-color); background: var(--absent);
  padding: 2px 8px; text-align: right; min-width: 24px;
}
.bar.now i { background: var(--correct); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.next { color: var(--muted); text-align: center; margin: 12px 0 0; font-size: 14px; }

body.scroll { height: auto; min-height: 100dvh; overflow: auto; }
body.scroll main { flex: none; }
@media (max-width: 359px) {
  .tabs .label { display: none; }
}
@media (max-height: 640px) {
  .key { height: 48px; }
  .top h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile.reveal, .tile.tbd, .tile.win, .row.shake, .badge.nudge { animation: none; }
}
