:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-glass: rgb(255 255 255 / 0.9);
  --text: #22262a;
  --muted: #5f666d;
  --border: #dcdcd8;
  --accent: #b4432f;
  --accent-hover: #963625;
  --on-accent: #ffffff;
  --focus: #2f6db4;
  --error: #a3311f;
  --ok: #2e6b34;

  /* Map; src/map.js reads these */
  --map-mask: #d9d9d6;
  --map-city-outline: #4b5157;
  --map-kentron-outline: #b4432f;

  --radius: 10px;
  --shadow: 0 2px 12px rgb(0 0 0 / 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --card-width: 360px;
}

* { box-sizing: border-box; }

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

body {
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}

#map { position: absolute; inset: 0; }

.map-error {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 24px; color: var(--muted); text-align: center;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:is(a, button, input, textarea, [tabindex]):focus-visible,
.maplibregl-canvas:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* Header */

.intro {
  position: absolute; z-index: 2; top: 12px; left: 12px;
  max-width: min(320px, calc(100vw - 24px));
  padding: 12px 14px 11px;
  background: var(--surface-glass);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.intro-top { display: flex; align-items: center; gap: 8px; }
.intro .logo { flex: none; }
.intro h1 { margin: 0; font-size: 18px; line-height: 1; font-weight: 800; letter-spacing: -0.02em; }
.x-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px;
  background: #111; color: #fff; font-size: 12px; font-weight: 600; text-decoration: none;
  transition: transform .12s ease, background .12s ease;
}
.x-chip:hover { background: #000; transform: translateY(-1px); }
.x-chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.intro .tagline { margin: 7px 0 0; color: var(--text); font-size: 13px; }
.intro .hint {
  margin: 6px 0 0; display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 11.5px;
}
.intro .dot {
  flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .3; transform: scale(.7); } }
@media (prefers-reduced-motion: reduce) { .intro .dot { animation: none; } }
.log-toggle {
  margin: 8px 0 0; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 11.5px; color: var(--accent); font-weight: 600;
}
.log-toggle[hidden] { display: none; }
.log-toggle:hover { text-decoration: underline; }
.log {
  list-style: none; margin: 8px 0 0; padding: 8px 0 0;
  border-top: 1px solid var(--border);
  max-height: min(50vh, 340px); overflow-y: auto;
  font-size: 12px;
}
.log[hidden] { display: none; }
.log > li + li { margin-top: 8px; }
.intro .log-head { margin: 0; color: var(--muted); font-size: 11.5px; }
.log-head b { color: var(--text); margin-right: 2px; }
.log ul { list-style: none; margin: 2px 0 0; padding: 0; color: var(--text); }
.log ul li { margin: 1px 0; padding-left: 12px; position: relative; }
.log ul li::before { content: '–'; position: absolute; left: 0; color: var(--muted); }
@media (max-width: 640px) { .log { max-height: 38vh; } }

/* Card: side panel on desktop */

.card {
  position: absolute; z-index: 3;
  top: 12px; right: 12px; bottom: 12px;
  width: var(--card-width);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card[hidden] { display: none; }

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 17px; font-variant-numeric: tabular-nums; outline-offset: 4px; }
.card-count { margin: 2px 0 0; color: var(--muted); font-size: 13px; min-height: 1em; }
.close {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; margin: -6px -4px 0 0;
  background: none; border: 0; border-radius: 50%; color: var(--muted); cursor: pointer;
}
.close:hover { background: var(--bg); color: var(--text); }

.card-scroll { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }

.notes { list-style: none; margin: 0; padding: 4px 16px; }
.note { padding: 10px 0; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: 0; }
.note-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.empty { padding: 12px 0; color: var(--muted); }

button.link {
  padding: 0; background: none; border: 0; color: var(--muted);
  font: inherit; text-decoration: underline; cursor: pointer;
}
button.link:hover:not(:disabled) { color: var(--accent); }
button.link:disabled { text-decoration: none; cursor: default; }

.note-form {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px 16px;
  background: #fafaf8;
  border-top: 1px solid var(--border);
}
.note-form h3 { margin: 0 0 4px; font-size: 14px; }
.note-form label { font-size: 13px; font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; }
.note-form textarea, .note-form input {
  width: 100%; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
}
.note-form textarea { resize: vertical; min-height: 76px; }
.form-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.counter { font-variant-numeric: tabular-nums; white-space: nowrap; }
.counter[data-near="true"] { color: var(--accent); font-weight: 600; }
.turnstile { min-height: 65px; margin-top: 6px; }

button.primary {
  min-height: 44px; padding: 8px 16px;
  background: var(--accent); border: 0; border-radius: 8px;
  color: var(--on-accent); font: inherit; font-weight: 600; cursor: pointer;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.status { margin: 2px 0 0; min-height: 1.2em; font-size: 13px; }
.status[data-kind="error"] { color: var(--error); }
.status[data-kind="ok"] { color: var(--ok); }

.card-attrib { display: none; margin: 0; padding: 8px 16px 10px; color: var(--muted); font-size: 11px; background: #fafaf8; }
.card-attrib a { color: inherit; }

/* MapLibre controls stay light */
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; border-radius: 8px !important; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* Desktop: the attribution moves left of the card while it is open */
@media (min-width: 641px) {
  body.card-open .maplibregl-ctrl-bottom-right { right: calc(var(--card-width) + 24px); }
}

/* Phone: the card is a bottom sheet */
@media (max-width: 640px) {
  .intro { top: 8px; left: 8px; right: 8px; max-width: none; padding: 8px 12px; }
  .intro h1 { font-size: 16px; }
  .intro p { font-size: 12.5px; }

  .card {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 56dvh;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -2px 14px rgb(0 0 0 / 0.14);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .card-head { padding-top: 16px; position: relative; }
  .card-head::before {
    content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px;
    margin-left: -18px; border-radius: 2px; background: var(--border);
  }
  body.card-open .maplibregl-ctrl-bottom-left,
  body.card-open .maplibregl-ctrl-bottom-right { display: none; }
  .card-attrib { display: block; } /* stands in for the map's attribution the sheet covers */
  /* Pinch zooms on touch phones; the buttons would sit under the attribution. */
  @media (pointer: coarse) { .maplibregl-ctrl-bottom-left { display: none; } }
}

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