/* "Vind het station op de Spoorkaart van Nederland"
   Single coherent visual treatment derived from the spec's visual_cues:
   an official, schematic NS network-map look — cream land, soft blue-green
   water, dark navy rail lines, red/orange line accents, white panels. */

:root {
  /* palette */
  --c-land: #f2ead4;
  --c-sea: #bcd8d4;
  --c-lake: #a9ccc8;
  --c-rail: #1d2742;
  --c-rail-soft: #3a4660;
  --c-accent-red: #d33329;
  --c-accent-orange: #e2862b;
  --c-panel: #ffffff;
  --c-ink: #1d2742;
  --c-ink-soft: #5d6678;
  --c-line: #d7dbe2;
  --c-bg: #e9edf1;
  --c-bg-2: #f6f8fa;

  /* feedback */
  --c-perfect: #1f8a4c;
  --c-goed: #3f9d5a;
  --c-redelijk: #c79320;
  --c-matig: #db7b27;
  --c-mis: #c0392b;

  /* type */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --fs-title: 1.15rem;
  --fs-base: 0.95rem;
  --fs-small: 0.8rem;

  /* spacing */
  --gap: 12px;
  --radius: 14px;
  --radius-sm: 9px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* SW-reload overlay (driven by pwa.js) */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--c-bg);
  color: var(--c-ink-soft);
  font-family: var(--font);
}
.loading-overlay--hidden { display: none; }
.loading-spinner {
  width: 38px;
  height: 38px;
  border: 4px solid var(--c-line);
  border-top-color: var(--c-rail);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--c-ink);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100svh;
  padding:
    calc(var(--safe-top) + 8px)
    calc(var(--safe-right) + 10px)
    calc(var(--safe-bottom) + 8px)
    calc(var(--safe-left) + 10px);
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
}

/* ── header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-title {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--c-ink);
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c-ink-soft);
  flex: 0 0 auto;
}
.status-dot--online { background: var(--c-perfect); }
.status-dot--connecting { background: var(--c-accent-orange); }
.status-dot--offline { background: var(--c-ink-soft); }

.scorebar { display: flex; gap: 8px; }
.scorebar-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  min-width: 58px;
}
.scorebar-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-ink-soft);
}
.scorebar-value { font-size: 1rem; font-weight: 800; line-height: 1.1; }

/* ── stage ── */
.stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

/* ── prompt ── */
.prompt {
  flex: 0 0 auto;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  border-left: 5px solid var(--c-rail);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.prompt--reveal { border-left-color: var(--c-accent-red); }
.prompt-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.prompt-label { color: var(--c-ink-soft); font-size: var(--fs-small); }
.prompt-where {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--c-ink);
  line-height: 1.15;
}
.prompt-sub { margin: 2px 0 0; font-size: var(--fs-small); color: var(--c-ink-soft); }
.reveal-pts {
  font-size: 1.05rem;
  font-weight: 800;
  white-space: nowrap;
}
.reveal-pts--perfect { color: var(--c-perfect); }
.reveal-pts--goed { color: var(--c-goed); }
.reveal-pts--redelijk { color: var(--c-redelijk); }
.reveal-pts--matig { color: var(--c-matig); }
.reveal-pts--mis { color: var(--c-mis); }

/* ── map ── */
.map-wrap {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--c-sea);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  position: relative;
}

/* ── action bar ── */
.action-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}
.btn {
  appearance: none;
  border: 1px solid var(--c-line);
  background: var(--c-panel);
  color: var(--c-ink);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  flex: 1 1 auto;
  background: var(--c-rail);
  border-color: var(--c-rail);
  color: #fff;
}
.btn-secondary {
  flex: 1 1 auto;
  background: var(--c-accent-red);
  border-color: var(--c-accent-red);
  color: #fff;
}
.btn-ghost { flex: 1 1 auto; }
.btn:disabled { opacity: 0.7; cursor: default; }

/* ── finish overlay ── */
.finish {
  position: absolute;
  inset: 0;
  padding:
    calc(var(--safe-top) + 12px)
    calc(var(--safe-right) + 12px)
    calc(var(--safe-bottom) + 12px)
    calc(var(--safe-left) + 12px);
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: var(--c-bg);
  z-index: 5;
}
.finish--hidden { display: none; }
.finish-card {
  width: 100%;
  max-width: 460px;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.finish-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: var(--fs-small);
  color: var(--c-accent-red);
  font-weight: 800;
}
.finish-score { display: flex; align-items: baseline; gap: 6px; }
.finish-score-value { font-size: 2.6rem; font-weight: 900; line-height: 1; }
.finish-score-max { font-size: 1.1rem; color: var(--c-ink-soft); font-weight: 700; }
.finish-sub { margin: 0; color: var(--c-ink-soft); font-size: var(--fs-small); }
.finish-form { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.name-input {
  flex: 1 1 auto;
  font-family: var(--font);
  font-size: 16px; /* keep >=16px so iOS Safari does not zoom on focus */
  padding: 12px;
  min-height: 48px;
  border: 1px solid var(--c-line);
  border-radius: var(--radius-sm);
  color: var(--c-ink);
  background: var(--c-bg-2);
}
.name-input:focus { outline: 2px solid var(--c-rail); border-color: var(--c-rail); }
.finish-form .btn-primary { flex: 0 0 auto; }
.submit-note { margin: 0; font-size: var(--fs-small); color: var(--c-ink-soft); min-height: 1em; }
.finish-actions { display: flex; }
.finish-sb-title { margin: 6px 0 0; font-size: 1rem; }

/* ── scoreboard list ── */
.sb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sb-list--embedded {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 60px;
}
.sb-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--c-bg-2);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-sm);
}
.sb-row--me { background: #eef3ff; border-color: #b9ccf5; }
.sb-rank { font-weight: 800; color: var(--c-ink-soft); text-align: center; }
.sb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-score { font-weight: 800; }
.sb-empty { color: var(--c-ink-soft); padding: 10px; text-align: center; }
.sb-note { margin: 8px 0 0; font-size: var(--fs-small); color: var(--c-ink-soft); }

/* ── modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 48, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: 0;
}
.modal--hidden { display: none; }
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 80dvh;
  background: var(--c-panel);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal .sb-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.icon-btn {
  appearance: none;
  border: none;
  background: var(--c-bg-2);
  color: var(--c-ink);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
