:root {
  --bg: #eef6f6;
  --panel-bg: #ffffff;
  --panel-bg-alt: #f4faf9;
  --text: #123539;
  --text-dim: #4f7377;
  --border: #cfe4e3;
  --accent: #1f7a8c;
  --accent-strong: #135a68;
  --danger: #c94f4f;
  --danger-strong: #a4342f;
  --nutrient-track-bg: #dcece9;
  --card-shadow: 0 1px 3px rgba(20, 60, 60, 0.12);
  --modal-overlay: rgba(8, 30, 33, 0.55);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #071a1e;
    --panel-bg: #0e2a2f;
    --panel-bg-alt: #0a2226;
    --text: #dcf1ee;
    --text-dim: #8fb8b5;
    --border: #1d454b;
    --accent: #4fd1c5;
    --accent-strong: #7de3d8;
    --danger: #ff8a80;
    --danger-strong: #ffab9e;
    --nutrient-track-bg: #123338;
    --card-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    --modal-overlay: rgba(2, 10, 12, 0.7);
  }
}
:root[data-theme="dark"] {
  --bg: #071a1e;
  --panel-bg: #0e2a2f;
  --panel-bg-alt: #0a2226;
  --text: #dcf1ee;
  --text-dim: #8fb8b5;
  --border: #1d454b;
  --accent: #4fd1c5;
  --accent-strong: #7de3d8;
  --danger: #ff8a80;
  --danger-strong: #ffab9e;
  --nutrient-track-bg: #123338;
  --card-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  --modal-overlay: rgba(2, 10, 12, 0.7);
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  padding: 12px clamp(12px, 3vw, 28px) 28px;
  gap: 12px;
  max-width: 1180px;
  margin: 0 auto;
}

h1, h2, h3 { margin: 0; }

/* ---------- HUD ---------- */

#hud {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--card-shadow);
}

.hud-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
  margin-bottom: 10px;
}

.hud-stat {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.hud-stat--breach { color: var(--danger); }
.hud-stat--pause { margin-left: auto; font-weight: 500; }

.nutrient-meter { position: relative; }

.nutrient-meter-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.nutrient-track {
  position: relative;
  height: 22px;
  border-radius: 11px;
  background: var(--nutrient-track-bg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.nutrient-red-zone {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    135deg,
    rgba(201, 79, 79, 0.4),
    rgba(201, 79, 79, 0.4) 6px,
    rgba(201, 79, 79, 0.6) 6px,
    rgba(201, 79, 79, 0.6) 12px
  );
  border-right: 1px solid var(--danger-strong);
  z-index: 3;
  pointer-events: none;
}

.nutrient-fill {
  position: relative;
  z-index: 2;
  height: 100%;
  background: linear-gradient(90deg, #2fa6a8, #4fd1c5);
  transition: width 0.4s ease, background 0.4s ease;
  border-radius: 11px 0 0 11px;
}

.nutrient-fill.in-red {
  background: linear-gradient(90deg, var(--danger-strong), var(--danger));
}

.nutrient-value {
  position: absolute;
  right: 8px;
  top: 26px;
  font-size: 12px;
  color: var(--text-dim);
}

.nutrient-danger-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--danger-strong);
  margin-top: 4px;
}

.dino-banner {
  margin-top: 20px;
  background: var(--danger-strong);
  color: #fff8f6;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  animation: dino-pulse 1.1s ease-in-out infinite;
}

@keyframes dino-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

.hidden { display: none !important; }

/* ---------- layout ---------- */

#main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: start;
}

@media (max-width: 780px) {
  #main { grid-template-columns: 1fr; }
}

#stage-wrap {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--card-shadow);
}

#rif-svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  overflow: hidden;
}

#rif-svg.dino-active {
  filter: saturate(0.55) sepia(0.25);
}

.zone-rect { transition: filter 0.3s ease; }

.zone-hit { cursor: pointer; }
.zone-group:hover .zone-rect { filter: brightness(1.08); }

/* ---------- plaatsingsselectie: welke zones zijn geldig ---------- */

.zone-highlight {
  fill: transparent;
  stroke: transparent;
  stroke-width: 3px;
  pointer-events: none;
  transition: fill 0.2s ease, stroke 0.2s ease;
}

#rif-svg.selecting .zone-group.zone-home .zone-highlight {
  fill: rgba(255, 255, 255, 0.18);
  stroke: var(--accent-strong);
}

#rif-svg.selecting .zone-group.zone-offhome .zone-highlight {
  fill: rgba(6, 20, 22, 0.3);
}

#rif-svg.selecting .zone-group.zone-occupied .zone-highlight {
  fill: rgba(6, 20, 22, 0.55);
}

#rif-svg.selecting .zone-group:hover .zone-highlight {
  stroke: var(--accent);
  stroke-width: 4px;
}

#rif-svg.selecting .zone-group.zone-occupied:hover .zone-highlight {
  stroke: var(--danger);
}

.zone-effect-label {
  font-size: 9px;
  font-weight: 700;
  fill: #ffffff;
  stroke: rgba(4, 14, 16, 0.6);
  stroke-width: 2px;
  paint-order: stroke fill;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.zone-effect-label.show { opacity: 0.9; }

.flow-line {
  fill: none;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.zone-label {
  font-size: 11px;
  font-weight: 700;
  fill: rgba(6, 24, 26, 0.82);
}
.zone-sublabel {
  font-size: 9px;
  fill: rgba(6, 24, 26, 0.6);
}

.zone-group.slijmalg-actief .zone-rect {
  filter: brightness(0.8) saturate(0.6);
}

.pest-overflow {
  font-size: 10px;
  fill: rgba(6, 24, 26, 0.85);
  font-weight: 700;
}

/* ---------- shop / resident cards ---------- */

#shop {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#shop h2 {
  font-size: 15px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.resident-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  background: var(--panel-bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}

.resident-card:hover { border-color: var(--accent); }
.resident-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
  background: var(--panel-bg);
}
.resident-card.unaffordable { opacity: 0.5; }

.resident-icon { width: 36px; height: 36px; flex: none; }

.resident-info { display: flex; flex-direction: column; gap: 2px; }
.resident-naam { font-weight: 700; font-size: 14px; }
.resident-kost { font-size: 12px; color: var(--accent-strong); font-weight: 600; }
.resident-beschrijving { font-size: 11.5px; color: var(--text-dim); line-height: 1.3; }
.resident-thuiszone { font-size: 11px; color: var(--text-dim); font-style: italic; }

#controls { display: flex; }

.start-wave-btn {
  flex: 1;
  background: var(--accent);
  color: #06282c;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.start-wave-btn:hover { background: var(--accent-strong); color: #fff; }

#hint {
  font-size: 12.5px;
  color: var(--text-dim);
  min-height: 2.6em;
}

/* ---------- game over modal ---------- */

#gameover-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal-box {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 420px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.modal-box h2 { font-size: 20px; margin-bottom: 10px; }
.modal-box p { font-size: 14px; color: var(--text-dim); margin: 8px 0; }
.modal-fact {
  background: var(--panel-bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-style: italic;
  color: var(--text);
}
.modal-box button {
  margin-top: 14px;
  background: var(--accent);
  color: #06282c;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}
.modal-box button:hover { background: var(--accent-strong); color: #fff; }

/* modified_by: codex-spellenfabriek-speelronde / gpt-6-astra / 2026-09-06: zichtbare toetsenbordfocus. */
button:focus-visible{outline:3px solid var(--accent-strong);outline-offset:3px}
.zone-hit:focus-visible{outline:none;stroke:var(--accent-strong);stroke-width:5px}

/* Speelronde 2026-09-06, codex-spellenfabriek-speelronde, gpt-6-astra: mobiele speelruimte en zichtbare zonebediening. */
#ns-bootstrap{display:none!important}
body{margin:0}
.zone-controls{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin:8px 0}
.zone-control{font:inherit;font-size:12px;padding:8px 4px;border:1px solid var(--border);border-radius:6px;background:var(--panel-bg-alt);color:var(--text);min-height:40px}
@media(min-width:900px){.zone-controls{grid-template-columns:repeat(6,minmax(0,1fr));}}

/* ---------- plaatsing, bereik, meldingen en zichtbare gevolgen ---------- */
#rif-svg .zone-group, #rif-svg .zone-group * { pointer-events: none; }
#rif-svg .zone-hit { pointer-events: all; }
.zone-effect-label { font-size: 12px; }
#rif-svg.selecting .zone-group.zone-in-range .zone-highlight,
.zone-group.zone-reach-flash .zone-highlight {
  fill: rgba(255, 209, 102, 0.24);
  stroke: #ffd166;
  stroke-width: 4px;
  stroke-dasharray: 8 5;
}
.zone-group.zone-placed .zone-highlight { fill: rgba(255, 255, 255, 0.2); stroke: #fff8e0; stroke-width: 6px; stroke-dasharray: none; }
.zone-group.zone-breach .zone-highlight { fill: rgba(201, 79, 79, 0.42); stroke: #c94f4f; stroke-width: 6px; stroke-dasharray: none; }
.zone-group.zone-deny .zone-highlight { stroke: var(--danger); stroke-width: 6px; stroke-dasharray: none; }
.cover-pip { stroke: rgba(6, 24, 26, 0.8); stroke-width: 1.5px; }
.cover-pip--half { fill-opacity: 0.45; stroke-dasharray: 2 2; }
.half-badge { fill: #0d3244; stroke: #ffd166; stroke-width: 1.5px; }
.half-badge-text { fill: #ffd166; font-size: 11px; font-weight: 700; }
.pest-hp-bg { fill: rgba(6, 24, 26, 0.6); }
.pest-hp { fill: #fff2c2; }
.pest-near-ring { fill: none; stroke: #ff6b5a; stroke-width: 2.2px; }
.pause-badge rect { fill: rgba(6, 24, 26, 0.8); }
.pause-badge text { fill: #fff8e0; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }

#hint { margin: 8px 2px 0; font-size: 14px; line-height: 1.4; color: var(--text); min-height: 2.8em; }
#flow-label.is-negative { color: var(--danger-strong); }
.hud-stat--breach.is-hit { background: var(--danger-strong); color: #fff8f6; border-radius: 4px; padding: 0 6px; }
.resident-need { font-size: 12px; font-weight: 700; color: var(--danger-strong); }
.resident-need:empty { display: none; }

.zone-control { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; text-align: left; min-height: 48px; padding: 6px 8px; cursor: pointer; }
.zc-name { font-weight: 700; }
.zc-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent-strong); }
.zc-tag:empty { display: none; }
.zc-state { font-size: 11.5px; color: var(--text-dim); }
#stage-wrap .zone-control.zc-home { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
#stage-wrap .zone-control.zc-off { border-style: dashed; }
#stage-wrap .zone-control.zc-off .zc-tag { color: var(--text-dim); }
#stage-wrap .zone-control.zc-occupied { opacity: 0.7; }
#stage-wrap .zone-control.zc-occupied .zc-tag { color: var(--danger-strong); }
#stage-wrap .zone-control.zc-in-range { background: rgba(255, 209, 102, 0.18); }

@media (prefers-reduced-motion: no-preference) {
  .zone-group.zone-placed .zone-highlight { animation: zone-pop 0.6s ease-out; }
  .zone-group.zone-breach .zone-highlight { animation: zone-blink 0.4s ease-in-out 3; }
}
@keyframes zone-pop { from { stroke-width: 14px; opacity: 0.4; } to { stroke-width: 6px; opacity: 1; } }
@keyframes zone-blink { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  .dino-banner { animation: none; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* smalle schermen: bewoners boven het rif, zodat kiezen en tikken bij elkaar liggen */
@media (max-width: 780px) {
  #shop { order: -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
  #shop h2 { grid-column: 1 / -1; font-size: 13px; }
  .resident-card { padding: 8px; gap: 6px; min-height: 64px; }
  .resident-card .resident-beschrijving { display: none; }
  .resident-icon { width: 28px; height: 28px; }
  .zone-label { font-size: 15px; }
  .zone-sublabel { display: none; }
  .zone-effect-label { font-size: 16px; }
  .nutrient-danger-label { display: none; }
  .nutrient-meter.is-low .nutrient-danger-label { display: block; }
  .hud-stat--pause { margin-left: 0; flex-basis: 100%; }
  .hud-row { margin-bottom: 6px; }
}

/* gedeelde schil: hoekige afwerking (richting B) voor dit spel; rifkleuren blijven */
html:root[data-game=rifwachter] :is(#hud, #stage-wrap, #shop, .modal-box) { border-radius: 6px; }
html:root[data-game=rifwachter] :is(.resident-card, .zone-control, .start-wave-btn, .modal-box button, .modal-fact) { border-radius: 4px; }
html:root[data-game=rifwachter] #pause-btn.game-primary.start-wave-btn { border-radius: 4px; }
html:root[data-game=rifwachter] #rif-svg { border-radius: 4px; }

.modal-breaches { text-align: left; font-size: 13.5px; color: var(--text); margin: 8px 0; padding-left: 1.2em; }
.modal-breaches li { margin: 4px 0; }
.modal-tip { text-align: left; font-weight: 600; color: var(--text) !important; }
#controls { flex-wrap: wrap; gap: 8px; }
#controls .start-wave-btn { flex: 1 1 40%; min-height: 48px; }
#controls .help-text { flex-basis: 100%; margin: 4px 0 0; }

/* ---------- namiddag 2026-10-20: compacte sticky HUD, doelstrook, duidelijke selectie ---------- */
/* De HUD blijft sticky (ook zonder gedeelde schil), maar is een compact raster: op 360 px circa
   100 px i.p.v. 155 px. Op zeer lage schermen (liggende telefoon) scrolt hij gewoon mee. */
html:root { scroll-padding-top: calc(var(--rw-hud-h, 0px) + 8px); }
html:root #hud {
  position: sticky; top: 0; z-index: 15;
  display: grid; align-items: center;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "wave   breach status status"
    "mtitle track  track  value"
    "flow   flow   danger danger"
    "dino   dino   dino   dino";
  gap: 4px 16px; padding: 8px 14px;
}
html:root #hud .hud-row, html:root #hud .nutrient-meter { display: contents; }
#hud .hud-stat { font-size: 14px; line-height: 1.25; }
#hud .hud-stat:nth-child(1) { grid-area: wave; color: var(--text); }
#hud .hud-stat--breach { grid-area: breach; }
#hud .hud-stat--pause { grid-area: status; margin: 0; flex-basis: auto; text-align: right; color: var(--text); }
#hud .nutrient-meter-title { grid-area: mtitle; margin: 0; font-size: 11px; }
#hud .nutrient-track { grid-area: track; height: 12px; }
#hud .nutrient-value { grid-area: value; position: static; font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
#hud #flow-label { grid-area: flow; font-size: 13px; }
#hud .nutrient-danger-label { grid-area: danger; margin: 0; text-align: right; }
#hud .dino-banner { grid-area: dino; margin: 2px 0 0; padding: 6px 10px; font-size: 12.5px; }

@media (max-width: 780px) {
  html:root #hud {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "wave   breach breach"
      "mtitle track  value"
      "status status status"
      "flow   flow   flow"
      "danger danger danger"
      "dino   dino   dino";
    gap: 3px 12px; padding: 7px 10px;
  }
  #hud .hud-stat { font-size: 13px; }
  #hud .hud-stat--pause { text-align: left; font-size: 12.5px; }
  #hud #flow-label { font-size: 12px; }
  #hud .nutrient-track { height: 10px; }
  #hud .nutrient-danger-label { text-align: left; }
}
/* lage schermen: HUD niet vastzetten, anders blijft er te weinig rif over */
@media (max-height: 500px) {
  html:root #hud, html:root[data-game] #hud { position: relative; }
  html:root { scroll-padding-top: 8px; }
}
/* het rif past altijd in de hoogte die over is (lage laptops, liggende telefoons) */
@media (max-height: 760px) {
  #rif-svg { width: min(100%, calc((100dvh - var(--rw-hud-h, 0px) - 190px) * 2.5)); min-width: min(100%, 420px); margin-inline: auto; }
}

/* doelstrook boven het rif: doel + drie beginstappen, of de gekozen bewoner */
.guide {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; align-items: center;
  margin: 0 0 8px;
}
.guide-goal { grid-column: 1 / -1; margin: 0; font-size: 13px; font-weight: 600; color: var(--text-dim); }
.guide-main { min-height: 44px; display: flex; align-items: center; min-width: 0; }
.guide-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; width: 100%; }
.guide-step {
  display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 8px;
  border: 2px solid var(--border); border-radius: 4px; font-size: 13px; line-height: 1.2;
  color: var(--text-dim); background: var(--panel-bg-alt);
}
.guide-step-nr {
  flex: none; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 2px;
  font-weight: 700; font-size: 12px; border: 2px solid currentColor;
}
.guide-step.is-done { color: var(--text); }
.guide-step.is-done .guide-step-nr { background: var(--accent); border-color: var(--accent); color: var(--panel-bg); font-size: 0; }
.guide-step.is-done .guide-step-nr::after { content: "✓"; font-size: 13px; }
.guide-step.is-current { color: var(--text); font-weight: 700; border-color: var(--rw-sel); background: var(--panel-bg); box-shadow: inset 0 0 0 1px var(--rw-sel); }
.guide-step.is-current .guide-step-nr { background: var(--rw-sel); border-color: var(--rw-sel); color: #0c0b14; }
.guide-text { margin: 0; font-size: 13.5px; line-height: 1.35; color: var(--text); }
.guide.is-selecting .guide-text { font-weight: 700; padding-left: 10px; border-left: 4px solid var(--rw-sel); }
.guide-cancel {
  min-height: 44px; min-width: 44px; padding: 6px 12px; display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  background: transparent; color: var(--text); border: 2px solid var(--rw-sel); border-radius: 4px;
}
.guide-cancel.is-hidden { visibility: hidden; }
:root { --rw-sel: var(--gs-gold, var(--accent-strong)); }
@media (max-width: 480px) {
  .guide-cancel-text { display: none; }
  .guide-cancel { padding: 6px; justify-content: center; }
  .guide-step { flex-direction: column; align-items: flex-start; gap: 2px; padding: 4px 6px; font-size: 12px; }
  .guide-step-nr { width: 18px; height: 18px; font-size: 11px; }
  .guide-goal { font-size: 12.5px; }
}

/* gekozen bewoner: niet alleen randkleur, ook een label */
.resident-card { position: relative; }
.resident-card.selected { outline: 3px solid var(--rw-sel); outline-offset: 2px; }
.resident-card.selected::after {
  content: "Gekozen"; position: absolute; top: -10px; right: 8px; padding: 1px 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em; border-radius: 2px;
  background: var(--rw-sel); color: #0c0b14;
}
/* thuiszones tijdens kiezen iets steviger omlijnd */
#rif-svg.selecting .zone-group.zone-home .zone-highlight { stroke-width: 4px; }
/* heel smal (320–360): icoon boven de naam, zodat "Poetsgarnaal" niet midden in het woord breekt */
@media (max-width: 360px) {
  .resident-card { flex-direction: column; gap: 2px; }
  .resident-naam { overflow-wrap: normal; word-break: normal; font-size: 13.5px; }
}
.platform-nav,.platform-footer{padding:16px;max-width:760px;margin:auto}.platform-nav a,.platform-footer a{color:inherit}.platform-footer{padding-bottom:110px;font-size:.85rem}
