:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1d2124;
  --ink-2: #5a6166;
  --line: #d6d1c6;
  --tile-line: #bdb6a8;
  --key: #e2ddd2;
  --goed: #1b7f73;
  --goed-ink: #fff;
  --elders: #e08a1e;
  --elders-ink: #1d2124;
  --mis: #7d848a;
  --mis-ink: #fff;
  --accent: #1b7f73;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191c;
    --surface: #1f2327;
    --ink: #eceae4;
    --ink-2: #a3a9ad;
    --line: #353b40;
    --tile-line: #4a5157;
    --key: #3a4045;
    --goed: #22917f;
    --elders: #e69a35;
    --mis: #3c4246;
    --accent: #3fb3a1;
    color-scheme: dark;
  }
}
/* extra duidelijk: blauw/oranje-rood is ook bij kleurenblindheid goed te onderscheiden */
:root.contrast {
  --goed: #1f5fbf;
  --goed-ink: #fff;
  --elders: #f26b21;
  --elders-ink: #111;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}
.top h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: .02em;
}
.top h1 span { color: var(--accent); }
.top .right { justify-self: end; display: flex; gap: 4px; }
.ico {
  width: 40px; height: 40px;
  border: 0; background: none; border-radius: 8px;
  font-size: 20px; font-weight: 700;
  display: grid; place-items: center;
}
.ico:hover { background: var(--key); }
.ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding: 10px 12px 6px;
}
.lenbar {
  display: flex;
  gap: 4px;
  background: var(--key);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 10px;
}
.lenbar button {
  border: 0; background: none;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  color: var(--ink-2);
}
.lenbar button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .15); }

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  /* tegels vierkant houden binnen de beschikbare hoogte */
  height: 100%;
  max-height: 420px;
  aspect-ratio: var(--n) / 6;
  max-width: 100%;
}
.row { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 6px; }
.t {
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 6px;
  font-weight: 800;
  font-size: clamp(18px, 6vw, 32px);
  text-transform: uppercase;
  background: var(--surface);
  user-select: none;
}
.t.vol { border-color: var(--tile-line); animation: pop .1s; }
.t.goed { background: var(--goed); border-color: var(--goed); color: var(--goed-ink); }
.t.elders { background: var(--elders); border-color: var(--elders); color: var(--elders-ink); }
.t.mis { background: var(--mis); border-color: var(--mis); color: var(--mis-ink); }
.row.draai .t { animation: draai .5s both; }
.row.schud { animation: schud .4s; }
.row.juich .t { animation: spring .5s both; }
@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes draai { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes schud { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes spring { 40% { transform: translateY(-14px); } 70% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .t, .row { animation: none !important; } }

.toast {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 5;
  text-align: center;
  max-width: calc(100% - 32px);
}
.toast.zie { opacity: 1; }

.einde {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
}
.einde .woord { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.einde a { color: var(--accent); font-weight: 600; }

.btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  width: 100%;
  margin-top: 8px;
}
.einde .btn { width: auto; margin: 0; }
.btn.ghost { background: none; color: var(--ink); border: 1.5px solid var(--line); }

.kb {
  padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  display: grid;
  gap: 6px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}
.kb .r { display: flex; gap: 5px; justify-content: center; }
.kb button {
  flex: 1;
  height: 54px;
  border: 0;
  border-radius: 6px;
  background: var(--key);
  font-weight: 700;
  font-size: 17px;
  text-transform: uppercase;
  padding: 0;
  min-width: 0;
  touch-action: manipulation;
}
.kb button.wide { flex: 1.6; font-size: 13px; }
.kb button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; vertical-align: middle; }
.kb .sp { flex: .5; }
.kb button.goed { background: var(--goed); color: var(--goed-ink); }
.kb button.elders { background: var(--elders); color: var(--elders-ink); }
.kb button.mis { background: var(--mis); color: var(--mis-ink); }
@media (max-height: 620px) { .kb button { height: 46px; } }

dialog {
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  max-width: min(420px, calc(100vw - 32px));
  padding: 20px;
  box-shadow: 0 10px 40px rgb(0 0 0 / .3);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
dialog h3 { margin: 16px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
dialog p { margin: 8px 0; }
.klein { font-size: 13px; color: var(--ink-2); }
.k-goed { color: var(--goed); }
.k-elders { color: var(--elders); }
.contrast .k-elders, .contrast .k-goed { filter: none; }
.vb { display: flex; gap: 4px; --n: 5; }
.vb .t { width: 38px; height: 38px; font-size: 20px; }

.cijfers { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; }
.cijfers b { display: block; font-size: 28px; line-height: 1.1; }
.cijfers span { font-size: 12px; color: var(--ink-2); }
.verdeling { display: grid; gap: 4px; }
.verdeling .bar { display: grid; grid-template-columns: 14px 1fr; gap: 6px; align-items: center; font-size: 14px; font-weight: 600; }
.verdeling .bar i {
  display: block;
  background: var(--mis);
  color: var(--mis-ink);
  font-style: normal;
  text-align: right;
  padding: 1px 6px;
  border-radius: 4px;
  min-width: 24px;
}
.verdeling .bar.laatst i { background: var(--goed); color: var(--goed-ink); }

.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.opt input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.bron { margin-top: 14px; text-align: center; }
