:root {
  --canvas: #efeeeb;
  --paper: #ffffff;
  --ink: #0a0a0a;
  --muted: #6b6862;
  --accent: #d12424;
  --yellow: #ffc93c;
  --green: #2bb673;
  --blue: #3b5bff;
  --wire-off: #c9c5bd;
  --font: "Funnel Display", "Helvetica Neue", Arial, sans-serif;
  --mono: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;
  --pad: clamp(16px, 3vw, 40px);
  --radius: 24px;
  --shadow: 5px 5px 0 var(--ink);
  --ease: cubic-bezier(.22, 1, .36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle, rgba(10, 10, 10, .08) 1.5px, transparent 1.6px) 0 0 / 26px 26px,
    var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px var(--pad);
}
.back {
  font-family: var(--mono); font-size: .85rem; font-weight: 500; text-decoration: none;
  padding: 8px 14px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper);
}
.back:hover { background: var(--ink); color: var(--paper); }
.brand { margin: 0; line-height: 0; }
.brand img { height: clamp(44px, 7vw, 72px); width: auto; }
.top-right { display: flex; align-items: center; gap: 10px; }
.stars {
  font-family: var(--mono); font-weight: 700; white-space: nowrap;
  background: var(--yellow); border: 2px solid var(--ink); border-radius: 999px; padding: 6px 14px;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper);
  cursor: pointer; font-size: 1.1rem;
}
.icon-btn[aria-pressed="false"] { opacity: .55; }

/* ---------- level strip ---------- */
.levels {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding: 4px var(--pad) 20px;
}
.lvl {
  position: relative;
  width: 48px; height: 48px; border-radius: 16px;
  border: 3px solid var(--ink); background: var(--paper);
  font-weight: 800; font-size: 1.1rem; cursor: pointer;
  transition: transform .2s var(--ease);
}
.lvl:hover { transform: translateY(-3px) rotate(-3deg); }
.lvl.current { background: var(--ink); color: var(--paper); box-shadow: 3px 3px 0 var(--accent); }
.lvl.done::after {
  content: "⭐"; position: absolute; top: -12px; right: -10px; font-size: .95rem;
}
.lvl.kind-uitdaging { border-radius: 50%; }

/* ---------- layout ---------- */
.play {
  display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 24px;
  padding: 0 var(--pad) 32px; align-items: start;
}
.card {
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- board ---------- */
.board-card { padding: 20px; }
.board-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.level-tag {
  font-family: var(--mono); font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 5px 12px;
}
.board-head h2 { font-size: clamp(1.6rem, 3.4vw, 2.6rem); font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.board-wrap {
  border-radius: 18px; background: #faf9f6;
  border: 2px dashed rgba(10, 10, 10, .18);
}
#board { display: block; width: 100%; height: auto; }

/* SVG parts */
.wire { fill: none; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; stroke: var(--wire-off); transition: stroke .2s; }
.wire.on { stroke: var(--yellow); }
.wire-edge { fill: none; stroke-width: 14; stroke-linecap: round; stroke-linejoin: round; stroke: var(--ink); }
.junction { fill: var(--wire-off); stroke: var(--ink); stroke-width: 3; }
.junction.on { fill: var(--yellow); }
.flow {
  fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1 22; animation: flow .7s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -23; } }

.switch { cursor: pointer; outline: none; }
.switch .hit { fill: transparent; }
.sw-label { fill: var(--ink); }
.sw-letter { fill: #fff; font: 800 22px var(--font); text-anchor: middle; }
.sw-track { fill: var(--wire-off); stroke: var(--ink); stroke-width: 3; }
.switch.on .sw-track { fill: var(--green); }
.sw-knob { fill: #fff; stroke: var(--ink); stroke-width: 3; }
.sw-state { font: 700 13px var(--mono); text-anchor: middle; fill: var(--muted); letter-spacing: .06em; }
.switch.on .sw-state { fill: var(--green); }
.switch:hover .sw-track { stroke-width: 4; }
.switch.locked { cursor: not-allowed; }
.switch.locked:hover .sw-track { stroke-width: 3; }
.switch:focus-visible .sw-track { stroke: var(--accent); stroke-width: 5; }

.gate path:not(.g-line), .gate circle { fill: var(--c); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
.gate .g-line { fill: none; stroke: var(--ink); stroke-width: 3; }
.gate-name { font: 800 17px var(--font); fill: #fff; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.25); stroke-width: 2px; }
.slot { cursor: pointer; }
.slot rect { fill: #fff; stroke: var(--ink); stroke-width: 3; stroke-dasharray: 8 6; }
.slot.selected rect { fill: #fff6d6; stroke: var(--accent); }
.slot text { font: 800 34px var(--font); text-anchor: middle; fill: var(--accent); }
.slot .slot-hint { font: 700 11px var(--mono); fill: var(--muted); letter-spacing: .04em; }
.gate.filled.clickable { cursor: pointer; }
.gate.selected path:not(.g-line), .gate.selected circle { stroke: var(--accent); stroke-width: 5; }

.lamp-base { fill: #8e8a83; stroke: var(--ink); stroke-width: 3; }
.lamp-bulb { fill: #f4f2ee; stroke: var(--ink); stroke-width: 3; transition: fill .2s; }
.lamp-filament { fill: none; stroke: #8e8a83; stroke-width: 3; stroke-linecap: round; }
.lamp.on .lamp-bulb { fill: var(--yellow); }
.lamp.on .lamp-filament { stroke: #d12424; }
.lamp-glow { fill: var(--yellow); opacity: .35; animation: glow 1.2s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes glow { to { opacity: .6; transform: scale(1.12); } }
.ray { stroke: #f2a900; stroke-width: 5; stroke-linecap: round; }
.lamp-label { font: 700 15px var(--mono); text-anchor: middle; fill: var(--muted); letter-spacing: .06em; }
.lamp.on .lamp-label { fill: var(--ink); }

/* ---------- palette ---------- */
.palette { margin-top: 18px; }
.palette-hint { font-weight: 700; margin-bottom: 10px; }
.palette-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.pcard {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 8px 12px;
  border: 3px solid var(--ink); border-radius: 18px; background: var(--paper);
  cursor: pointer; box-shadow: 3px 3px 0 var(--ink);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), background .15s;
}
.pcard:hover { transform: translate(-2px, -2px) rotate(-1deg); box-shadow: 5px 5px 0 var(--ink); }
.pcard:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.pcard.nofit { opacity: .45; }
.pcard.nofit:hover { opacity: .7; }
.pcard.active { background: #fff6d6; outline: 3px solid var(--accent); outline-offset: 2px; }
.pcard svg { width: 100px; height: 56px; }
.pcard strong { font-size: 1.05rem; }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; gap: 20px; }
.mascot { display: flex; gap: 10px; align-items: flex-end; }
.mascot img { width: 130px; height: auto; flex: none; transform-origin: 50% 100%; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-2deg); } }
.bubble {
  position: relative; flex: 1;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 20px;
  padding: 14px 16px; box-shadow: var(--shadow);
  font-size: 1.05rem;
}
.bubble::before {
  content: ""; position: absolute; left: -14px; bottom: 26px;
  border: 12px solid transparent; border-right-color: var(--ink); border-left: 0;
}
.bubble::after {
  content: ""; position: absolute; left: -9px; bottom: 29px;
  border: 9px solid transparent; border-right-color: var(--paper); border-left: 0;
}
.bubble .progress {
  margin-top: 10px; font-family: var(--mono); font-size: .85rem; font-weight: 700; color: var(--accent);
}
.bubble .progress:empty { display: none; }

.gate-info { padding: 16px 18px; }
.gate-info:empty { display: none; }
.gi { display: flex; gap: 14px; align-items: center; }
.gi + .gi { margin-top: 14px; padding-top: 14px; border-top: 2px dashed rgba(10,10,10,.15); }
.gi svg { width: 90px; height: 52px; flex: none; }
.gi h3 { font-size: 1.2rem; letter-spacing: -.02em; }
.gi p { font-size: .95rem; color: #333; }

.table-card { padding: 16px 18px; }
.table-card h2 { font-size: 1.25rem; letter-spacing: -.02em; }
.hint { font-size: .85rem; color: var(--muted); margin: 2px 0 10px; }
table { width: 100%; border-collapse: separate; border-spacing: 0 6px; text-align: center; }
th { font-family: var(--mono); font-size: .75rem; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
td { padding: 6px 4px; background: #f6f5f2; font-weight: 700; }
td:first-child { border-radius: 12px 0 0 12px; }
td:last-child { border-radius: 0 12px 12px 0; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #eeece7; }
tr.current td { background: #fff1c2; }
tr.current td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.chip {
  display: inline-block; min-width: 42px; padding: 2px 8px; border-radius: 999px;
  font-family: var(--mono); font-size: .75rem; font-weight: 700; letter-spacing: .04em;
  background: var(--wire-off); color: var(--ink);
}
.chip.on { background: var(--green); color: #fff; }
.res { font-size: 1.2rem; }
.res.unknown { color: var(--muted); font-size: 1rem; }
.mark { font-size: .9rem; margin-left: 2px; }
tr.good td:last-child { background: #dbf5e7; }
tr.bad td:last-child { background: #fde0e0; }

/* ---------- buttons ---------- */
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  flex: 1 1 auto;
  padding: 14px 20px; border-radius: 18px; border: 3px solid var(--ink);
  font-weight: 800; font-size: 1.1rem; cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease);
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; transform: none; box-shadow: 4px 4px 0 var(--ink); }
.btn-yellow { background: var(--yellow); }
.btn-green { background: var(--green); color: #fff; }
.btn-green.pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
[hidden] { display: none !important; }

.foot { text-align: center; padding: 8px var(--pad) 32px; font-family: var(--mono); font-size: .8rem; color: var(--muted); }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 99; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .play { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .back { font-size: .9rem; padding: 6px 12px; }
  .back span { display: none; }
  .top { gap: 8px; }
  .stars { padding: 5px 10px; font-size: .85rem; }
  .lvl { width: 42px; height: 42px; }
  .brand img { height: 38px; }
  .board-card { padding: 12px; }
  .mascot img { width: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
