:root {
  --ink: #1d2340;
  --paper: #fffaf0;
  --accent: #ff4757;
  --accent2: #ffc21a;
  --blue: #2f8cff;
  --shadow: 0 6px 0 rgba(29, 35, 64, .25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

[hidden] { display: none !important; }

/* ---------- Menu ---------- */
.overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,.35), rgba(30,60,110,.45));
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.panel {
  width: min(560px, 100%);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 22px;
  padding: 24px 24px 18px;
  box-shadow: 0 10px 0 var(--ink);
}

h1 {
  font-family: 'Lilita One', sans-serif;
  font-size: clamp(38px, 8vw, 56px);
  margin: 0;
  line-height: 1;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--ink);
  letter-spacing: 1px;
}
h1 span { color: var(--accent2); }
.sub { margin: 6px 0 18px; font-weight: 600; opacity: .8; }

label { display: block; font-weight: 800; margin-bottom: 12px; }

.toggles { gap: 18px; margin-bottom: 14px; }
.toggle { display: flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
label input { display: block; width: 100%; margin-top: 4px; }

input, select, button {
  font: inherit;
  font-weight: 800;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 9px 12px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 3px solid var(--accent2); outline-offset: 1px; }

button {
  cursor: pointer;
  background: #fff;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .06s, box-shadow .06s;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.small { padding: 3px 8px; font-size: 13px; box-shadow: 0 2px 0 var(--ink); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row #locInput { flex: 1 1 200px; min-width: 0; }
.or { font-weight: 800; opacity: .6; }
.code { width: 92px; text-transform: uppercase; text-align: center; letter-spacing: 3px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.presets button { padding: 5px 10px; font-size: 14px; background: #eef6ff; box-shadow: 0 3px 0 var(--ink); }

/* ---------- Kaartkiezer ---------- */
#pickMap {
  height: 280px; margin-top: 10px;
  border: 3px solid var(--ink); border-radius: 14px;
  z-index: 0;
}
.pickhint { margin: 6px 0 8px; font-size: 13px; font-weight: 700; opacity: .7; }
.pickrow { justify-content: space-between; }
.seg { display: flex; gap: 0; }
.seg button { border-radius: 0; margin-left: -3px; box-shadow: 0 4px 0 var(--ink); }
.seg button:first-child { border-radius: 12px 0 0 12px; margin-left: 0; }
.seg button:last-child { border-radius: 0 12px 12px 0; }
.seg button.sel { background: var(--accent2); }
#startHere { flex: 1 1 140px; font-size: 18px; }
#pickLabel { margin-top: 8px; font-weight: 800; min-height: 1.3em; }
.pickpin {
  background: var(--accent); border: 3px solid var(--ink); border-radius: 50%;
  box-shadow: 0 0 0 3px #fff; cursor: grab;
}
.leaflet-container { font-family: 'Nunito', system-ui, sans-serif; }
.leaflet-container button, .leaflet-container a { box-shadow: none; }

.roomhead { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.roomhead b {
  font-family: 'Lilita One', sans-serif; font-size: 26px; letter-spacing: 3px;
  background: var(--accent2); padding: 0 10px; border-radius: 8px; border: 3px solid var(--ink);
}

#playerList { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 6px; }
#playerList li {
  display: flex; align-items: center; gap: 6px;
  border: 3px solid var(--ink); border-radius: 999px; padding: 3px 12px 3px 4px; font-weight: 800; background: #fff;
}
#playerList .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--ink); }

#guestWait { font-weight: 700; opacity: .75; }
#resumeBtn { width: 100%; margin-top: 12px; font-size: 20px; }

#status { min-height: 1.4em; margin-top: 12px; font-weight: 800; }
#iosTip { font-size: 13px; font-weight: 700; background: #eef6ff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 10px; margin: 10px 0 0; }

#progress {
  height: 22px; margin-top: 14px;
  border: 3px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden;
}
#progressFill {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(-45deg, var(--accent2) 0 14px, #ffd65c 14px 28px);
  background-size: 40px 40px;
  border-right: 3px solid var(--ink);
  transition: width .25s ease;
  animation: stripes 0.8s linear infinite;
}
@keyframes stripes { to { background-position: 40px 0; } }
#status.err { color: var(--accent); }

.keys { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 14px; font-size: 13px; font-weight: 700; opacity: .8; }
kbd {
  display: inline-block; min-width: 20px; text-align: center;
  border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 6px;
  padding: 0 4px; margin-right: 2px; background: #fff; font-family: inherit; font-size: 12px;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }

#speed {
  position: absolute; right: 20px; bottom: 20px;
  font-family: 'Lilita One', sans-serif; font-size: 64px; color: #fff; line-height: 1;
  text-shadow: 4px 4px 0 var(--ink);
}
#speed small { font-size: 22px; margin-left: 6px; }

#raceInfo {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  text-align: center; color: #fff; font-family: 'Lilita One', sans-serif;
  text-shadow: 3px 3px 0 var(--ink);
}
#timer { font-size: 40px; }
#cp { font-size: 20px; }

#board {
  position: absolute; left: 16px; top: 16px; margin: 0; padding: 8px 12px 8px 32px;
  background: rgba(255, 250, 240, .92); border: 3px solid var(--ink); border-radius: 14px;
  font-weight: 800; font-size: 15px; min-width: 170px;
  box-shadow: var(--shadow);
}
#board:empty { display: none; }
#board li { padding: 1px 0; }
#board li span.c { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 6px; vertical-align: -1px; }
#board li.me { color: var(--accent); }
#board li small { opacity: .7; margin-left: 4px; }

#minimap {
  position: absolute; left: 16px; bottom: 16px; width: 220px; height: 220px;
  border-radius: 50%;
  filter: drop-shadow(0 5px 0 rgba(29,35,64,.4));
}

/* Straatnaambord onderaan de minimap */
#street {
  position: absolute; left: 16px; bottom: 6px; width: 220px;
  display: flex; justify-content: center;
  font-weight: 800; font-size: 14px; white-space: nowrap;
}
#street > b {
  max-width: 210px; overflow: hidden; text-overflow: ellipsis;
  background: #1f4e9c; color: #fff;
  border: 3px solid #fff; outline: 3px solid var(--ink); border-radius: 8px;
  padding: 2px 10px;
}
#street[hidden] { display: none; }

#big {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  font-family: 'Lilita One', sans-serif; font-size: 120px; color: var(--accent2);
  text-shadow: 6px 6px 0 var(--ink);
}
#msg {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%);
  font-family: 'Lilita One', sans-serif; font-size: 30px; color: #fff; text-align: center;
  text-shadow: 3px 3px 0 var(--ink); white-space: pre-line;
}
#hint {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: rgba(255,250,240,.92); border: 3px solid var(--ink); border-radius: 12px;
  padding: 6px 14px; font-weight: 800; text-align: center;
}
#hint:empty { display: none; }

#track {
  position: absolute; right: 20px; bottom: 96px;
  font-weight: 800; font-size: 14px; color: #fff; text-shadow: 2px 2px 0 var(--ink);
  opacity: 0;
}
#track.fade { animation: trackFade 5s ease forwards; }
@keyframes trackFade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

#weather {
  position: absolute; right: 8px; top: 30px;
  font-weight: 800; font-size: 15px; color: #fff; text-shadow: 2px 2px 0 var(--ink);
}
#wrongway {
  position: absolute; left: 50%; top: 34%; transform: translateX(-50%);
  font-family: 'Lilita One', sans-serif; font-size: 40px; color: #fff;
  background: var(--accent); border: 4px solid var(--ink); border-radius: 16px; padding: 4px 18px;
  animation: blink .5s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .35; } }
#camflash { position: absolute; inset: 0; background: #fff; opacity: 0; }
#camflash.on { animation: camflash .6s ease-out; }
@keyframes camflash { 0% { opacity: .9; } 100% { opacity: 0; } }

#attrib {
  position: absolute; right: 8px; top: 6px; font-size: 11px; font-weight: 700;
  color: var(--ink); background: rgba(255,255,255,.7); padding: 2px 6px; border-radius: 6px;
  pointer-events: auto;
}
#attrib a { color: inherit; }

@media (max-width: 700px) {
  #speed { font-size: 44px; right: 12px; bottom: 12px; }
  #minimap { width: 140px; height: 140px; left: 10px; bottom: 10px; }
  #street { left: 10px; width: 140px; bottom: 2px; font-size: 12px; }
  #street > b { max-width: 150px; }
  #timer { font-size: 30px; }
  #board { font-size: 13px; top: 44px; left: 10px; min-width: 0; }
  #big { font-size: 80px; }
}

/* ---------- Touch-bediening ---------- */
#touch { display: none; }
body.touch #touch { display: block; }
body.touch #game { touch-action: none; }
#touch .tbtn {
  pointer-events: auto; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  font-family: 'Lilita One', sans-serif; color: var(--ink);
  background: rgba(255, 250, 240, .78); border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 0 5px 0 var(--ink);
}
#touch .tbtn.on { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); background: var(--accent2); }
#touch .tbtn.small { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 16px; padding: 6px 12px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }

.ttop { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); display: flex; gap: 6px; }
#thost { position: absolute; left: 50%; top: 92px; transform: translateX(-50%); display: flex; gap: 8px; }

.tsteer {
  position: absolute; left: calc(14px + env(safe-area-inset-left)); bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; gap: 12px;
}
.tsteer .tbtn { width: 84px; height: 84px; font-size: 34px; border-radius: 50%; }

.tpedals {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 10px; align-items: end;
}
.tpedals .hand { grid-column: 1 / 3; height: 40px; font-size: 15px; letter-spacing: 1px; }
.tpedals .brake { width: 78px; height: 78px; font-size: 18px; background: rgba(255, 220, 220, .8); }
.tpedals .gas { width: 92px; height: 112px; font-size: 22px; background: rgba(210, 255, 220, .8); }

#rotate {
  display: none; position: absolute; left: 50%; top: 46%; transform: translateX(-50%);
  background: rgba(255,250,240,.92); border: 3px solid var(--ink); border-radius: 12px; padding: 6px 12px; font-weight: 800;
}
@media (orientation: portrait) { body.touch #rotate { display: block; } }

/* HUD verschuiven zodat niets onder de duimen zit */
body.touch #minimap { left: auto; right: calc(10px + env(safe-area-inset-right)); top: 52px; bottom: auto; width: 120px; height: 120px; }
body.touch #street { left: auto; right: calc(10px + env(safe-area-inset-right)); top: 172px; bottom: auto; width: 120px; font-size: 11px; }
body.touch #street > b { max-width: 130px; }
body.touch #speed { right: 50%; transform: translateX(50%); bottom: calc(10px + env(safe-area-inset-bottom)); font-size: 40px; }
body.touch #speed small { font-size: 16px; }
body.touch #weather { top: 52px; right: 140px; font-size: 13px; }
body.touch #attrib { top: auto; bottom: 2px; right: 50%; transform: translateX(50%); font-size: 9px; }
body.touch #board { top: 10px; left: 10px; font-size: 12px; padding: 4px 8px 4px 24px; }
body.touch #hint { bottom: auto; top: 136px; font-size: 13px; }
body.touch #track { display: none; }
body.touch .keys { display: none; }
