/* Lingo, Reken Lingo en Mastermind (lingo.html, reken-lingo.html, mastermind.html).
   Layout: één smalle kolom als tv-studio — logo, scorebord, bord, tijdbalk, toetsenbord. Bewust één donkerblauwe studio-look, los van de rest van de site. */
:root {
  --studio: #071a52;
  --studio-hi: #163a9e;
  --cell: #1d4fd6;
  --cell-edge: #0b2a85;
  --cell-empty: #12379f;
  --hit: #e3262e;
  --hit-edge: #9c121a;
  --near: #ffcb1f;
  --near-ink: #3a2a00;
  --ink: #ffffff;
  --muted: #a9bdf5;
  --team-a: #ff8a1f;
  --team-b: #35d07f;
  --panel: #0d2468;
  --font-display: "Baloo 2", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 70% at 50% 0%, var(--studio-hi) 0%, var(--studio) 60%) fixed, var(--studio);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--near); outline-offset: 2px; }
.hl { color: var(--near); }

.app {
  max-width: 560px; margin: 0 auto; min-height: 100%;
  display: flex; flex-direction: column; gap: 10px;
  padding-block: 12px 16px;
}

/* ---------- kop ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { display: flex; gap: 4px; }
.logo span {
  width: 32px; height: 32px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 21px; line-height: 1;
  background: var(--cell); border-radius: 6px; box-shadow: inset 0 -3px 0 var(--cell-edge);
}
.logo span.r { background: var(--hit); box-shadow: inset 0 -3px 0 var(--hit-edge); }
.logo span.y { position: relative; color: var(--near-ink); }
.logo span.y::before { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--near); }
.logo span.y b { position: relative; }
.logo small { align-self: flex-end; font-family: var(--font-display); font-weight: 800; color: var(--near); font-size: 15px; margin-left: 4px; letter-spacing: .04em; }
.icons { display: flex; gap: 6px; }
.icon-btn {
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: 10px; border: 0;
  background: rgba(255,255,255,.08); font-weight: 800; font-size: 14px;
}
.icon-btn:hover { background: rgba(255,255,255,.16); }
a.icon-btn { display: grid; place-items: center; color: var(--ink); text-decoration: none; }
a.icon-btn:focus-visible { outline: 3px solid var(--near); outline-offset: 2px; }

/* ---------- scores ---------- */
.scores { display: flex; gap: 8px; }
.score {
  flex: 1; min-width: 0; padding: 4px 10px; border-radius: 12px; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; border: 2px solid transparent;
  transition: border-color .2s, transform .2s;
}
.score label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.score output { font-family: var(--font-display); font-weight: 800; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score.team-a output { color: var(--team-a); }
.score.team-b output { color: var(--team-b); }
.score.active.team-a { border-color: var(--team-a); transform: translateY(-2px); }
.score.active.team-b { border-color: var(--team-b); transform: translateY(-2px); }

/* ---------- bord ---------- */
.board-wrap {
  --gap: 6px;
  --fit-w: calc((100vw - 60px - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --tile: max(30px, min(64px, var(--fit-w), calc((100vh - var(--chrome)) / var(--rows) - var(--gap))));
  background: linear-gradient(180deg, #0a2a8c, #061c5e);
  border-radius: 18px; padding: 12px;
  box-shadow: 0 0 0 3px #2c5be6, 0 0 0 6px #0a2370, 0 18px 40px rgba(0,0,0,.45);
  align-self: center;
}
@supports (height: 100dvh) {
  .board-wrap { --tile: max(30px, min(64px, var(--fit-w), calc((100dvh - var(--chrome)) / var(--rows) - var(--gap)))); }
}
.board { display: grid; gap: var(--gap); }
.row { display: grid; gap: var(--gap); border-radius: 8px; }
.row.shake { animation: shake .4s; }
.row.current { box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.row.current.team-a { box-shadow: 0 0 0 3px var(--team-a); }
.row.current.team-b { box-shadow: 0 0 0 3px var(--team-b); }
.tile {
  width: var(--tile); height: var(--tile); position: relative;
  display: grid; place-items: center; border-radius: 6px;
  background: var(--cell-empty); box-shadow: inset 0 -4px 0 rgba(0,0,0,.25);
  font-family: var(--font-display); font-weight: 800; font-size: calc(var(--tile) * .62); line-height: 1;
  text-transform: uppercase; user-select: none;
}
.tile span { position: relative; z-index: 1; transform: translateY(.06em); }
.tile.filled, .tile.typed, .tile.absent, .tile.present { background: var(--cell); box-shadow: inset 0 -4px 0 var(--cell-edge); }
.tile.known span { color: rgba(255,255,255,.4); }
.tile.typed { animation: pop .12s; }
.tile.correct { background: var(--hit); box-shadow: inset 0 -4px 0 var(--hit-edge); }
.tile.present::before { content: ""; position: absolute; inset: 7%; border-radius: 50%; background: var(--near); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.tile.present span { color: var(--near-ink); }
.tile.flip { animation: flip .32s ease-in-out; }
.tile.timeout { background: #0c286f; box-shadow: none; }
.tile.timeout span { color: rgba(255,255,255,.25); }
.board.win .row.solved .tile { animation: bounce .5s ease both; }

/* pinnetjes (Mastermind) */
.pins {
  width: var(--tile); height: var(--tile); border-radius: 6px; background: rgba(0,0,0,.25);
  display: grid; grid-template-columns: 1fr 1fr; place-items: center; padding: 12%; gap: 6%;
}
.pin { width: 72%; aspect-ratio: 1; border-radius: 50%; background: rgba(255,255,255,.12); }
.pin.r { background: var(--hit); box-shadow: inset 0 -2px 0 var(--hit-edge); }
.pin.y { background: var(--near); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.pin.pop { animation: pinpop .25s ease; }

@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes pop { 0% { transform: scale(.85); } 100% { transform: scale(1); } }
@keyframes pinpop { 0% { transform: scale(0); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-14px); } }

/* ---------- tijdbalk, melding, hints ---------- */
.timer { height: 10px; border-radius: 99px; background: rgba(255,255,255,.1); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--near), #ff9c1a); border-radius: inherit; transform-origin: left; }
.timer.low i { background: var(--hit); }
.msg {
  min-height: 46px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  text-align: center; font-family: var(--font-display); font-weight: 800; font-size: 19px; line-height: 1.15; text-wrap: balance;
}
.msg .sub { font-family: var(--font-body); font-size: 15px; color: var(--muted); font-weight: 700; }
.clues { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.clues li {
  background: rgba(255,203,31,.12); border-left: 4px solid var(--near); border-radius: 6px;
  padding: 4px 10px; font-weight: 700; font-size: 14px;
}
.big-btn {
  border: 0; border-radius: 14px; padding: 10px 22px;
  background: var(--near); color: var(--near-ink);
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), 0 4px 0 #b88900;
}
.big-btn:active { transform: translateY(2px); box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), 0 2px 0 #b88900; }
.ghost-btn {
  border: 2px solid rgba(255,255,255,.3); border-radius: 14px; padding: 8px 16px; background: transparent;
  font-family: var(--font-display); font-weight: 800; font-size: 18px;
}

/* ---------- toetsenbord ---------- */
.kb { display: grid; gap: 6px; margin-top: auto; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; max-width: 46px; height: 52px; border: 0; border-radius: 8px;
  background: #2a4cb0; box-shadow: inset 0 -3px 0 rgba(0,0,0,.28);
  font-family: var(--font-display); font-weight: 800; font-size: 20px; text-transform: uppercase;
  display: grid; place-items: center; padding: 0;
}
.key.op { background: #3a2f9e; font-size: 24px; }
.key.wide { max-width: 80px; flex-grow: 1.6; font-size: 13px; letter-spacing: .04em; }
.key:active { transform: translateY(2px); }
.key.correct { background: var(--hit); }
.key.present { background: var(--near); color: var(--near-ink); }
.key.absent { background: #0b1f5e; color: rgba(255,255,255,.35); }

/* ---------- startscherm ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  background: rgba(4, 14, 48, .82); backdrop-filter: blur(4px);
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: flex-start; justify-content: center;
}
.panel {
  width: 100%; max-width: 480px; margin-block: auto;
  background: linear-gradient(180deg, #123599, #0a2470); border-radius: 22px; padding: 18px 18px 20px;
  box-shadow: 0 0 0 3px #2c5be6, 0 24px 60px rgba(0,0,0,.5);
  display: grid; gap: 14px;
}
.panel h1 { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 28px; line-height: 1.1; text-wrap: balance; }
.panel h1 em { font-style: normal; color: var(--near); }
.panel p { margin: 0; color: var(--muted); line-height: 1.45; }
.opt { display: grid; gap: 6px; }
.opt > span { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; min-width: 0; border: 0; border-radius: 12px; padding: 9px 6px;
  background: rgba(255,255,255,.08); font-family: var(--font-display); font-weight: 800; font-size: 17px; line-height: 1.1;
}
.seg button small { display: block; font-family: var(--font-body); font-size: 12px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--studio); }
.seg button[aria-pressed="true"] small { color: #3d5299; }
.legend { display: grid; gap: 10px; background: rgba(0,0,0,.18); border-radius: 14px; padding: 12px; }
.legend .row { --tile: 38px; justify-content: start; }
.legend ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; line-height: 1.35; }
.legend li { display: flex; gap: 8px; align-items: center; }
.dot { flex: none; width: 18px; height: 18px; border-radius: 4px; background: var(--hit); }
.dot.y { border-radius: 50%; background: var(--near); }
.dot.b { background: var(--cell); }
.dot.pr { width: 14px; height: 14px; margin-inline: 2px; border-radius: 50%; background: var(--hit); }
.dot.py { width: 14px; height: 14px; margin-inline: 2px; border-radius: 50%; background: var(--near); }
.dot.pn { width: 14px; height: 14px; margin-inline: 2px; border-radius: 50%; background: rgba(255,255,255,.18); }
.start-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.start-btns .big-btn { flex: 1 1 200px; font-size: 24px; padding: 12px; }
.best { text-align: center; font-size: 14px; color: var(--muted); }

canvas#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

@media (max-height: 760px) { .key { height: 44px; } .msg { min-height: 40px; font-size: 17px; } }
@media (max-width: 420px) {
  .logo { gap: 3px; } .logo span { width: 24px; height: 24px; font-size: 16px; border-radius: 5px; } .logo small { display: none; }
  .icons { gap: 4px; } .icon-btn { min-width: 34px; height: 36px; padding: 0 7px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile.flip, .tile.typed, .row.shake, .pin.pop, .board.win .row.solved .tile { animation: none !important; }
}
