/* Places We Love — a static, serverless map of favorite places.
   Clean-room implementation. Design language: monospace, high-contrast,
   near-zero radius, a single signal accent, tag colours as the only legend. */

:root {
  --font-mono: "Space Mono", "JetBrains Mono", "Menlo", "Courier New", monospace;

  /* Ink + paper (light scheme) */
  --fg-1: #111111;
  --fg-2: #4a4a4a;
  --fg-3: #8a8a8a;
  --bg-1: #ffffff;
  --bg-2: #f6f5f2;
  --bg-3: #ececea;
  --border: #e3e3e3;
  --border-strong: #111111;

  /* Tag colours — the map's only legend */
  --tag-food:     #e35a1e;
  --tag-art:      #d11d1d;
  --tag-shop:     #b08a4d;
  --tag-music:    #2f6db5;
  --tag-outdoors: #2e7d4f;
  --tag-active:   #3a3a38;
  --tag-none:     #8c8c87;

  --accent: var(--tag-food);
  --panel-w: 23.5rem;

  /* Basemap is desaturated so the only colour on screen is the pins. */
  --tile-filter: grayscale(1) contrast(1.06) brightness(0.985);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fg-1: #ededea; --fg-2: #a8a8a4; --fg-3: #6e6e6a;
    --bg-1: #111111; --bg-2: #191918; --bg-3: #222221;
    --border: #2a2a28; --border-strong: #ededea;
    --tag-food: #ff7a3d; --tag-art: #f2453f; --tag-shop: #d4a866;
    --tag-music: #5b9bd8; --tag-outdoors: #4aa873; --tag-active: #b9b8b3;
    --tag-none: #7e7e79;
    --tile-filter: grayscale(1) invert(0.92) contrast(0.92) brightness(1.02);
  }
}

:root[data-theme="dark"] {
  --fg-1: #ededea; --fg-2: #a8a8a4; --fg-3: #6e6e6a;
  --bg-1: #111111; --bg-2: #191918; --bg-3: #222221;
  --border: #2a2a28; --border-strong: #ededea;
  --tag-food: #ff7a3d; --tag-art: #f2453f; --tag-shop: #d4a866;
  --tag-music: #5b9bd8; --tag-outdoors: #4aa873; --tag-active: #b9b8b3;
  --tag-none: #7e7e79;
  --tile-filter: grayscale(1) invert(0.92) contrast(0.92) brightness(1.02);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-1);
  color: var(--fg-1);
  font-family: var(--font-mono);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  grid-template-rows: 100%;
  height: 100vh;
  height: 100dvh;
}

a { color: inherit; }

/* ───────────────────────── panel ───────────────────────── */

.panel {
  border-right: 1px solid var(--border);
  background: var(--bg-1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 0;
}

.masthead { padding-bottom: 20px; border-bottom: 1px solid var(--border); }

.masthead__top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}

.brand {
  font-weight: 700; font-size: 11px; letter-spacing: 0.18em;
  color: var(--fg-3);
}

.theme { display: inline-flex; border: 1px solid var(--border); }
.theme__opt {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 11px; letter-spacing: 0.04em;
  padding: 5px 9px; color: var(--fg-3);
}
.theme__opt + .theme__opt { border-left: 1px solid var(--border); }
.theme__opt[aria-pressed="true"] { background: var(--fg-1); color: var(--bg-1); }

.masthead__row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.title {
  margin: 0; font-weight: 700; font-size: 34px; line-height: 1.05;
  letter-spacing: -0.01em;
}
.ver { font-size: 11px; color: var(--fg-3); margin-top: 4px; }
.subtitle { margin: 12px 0 0; font-size: 13px; color: var(--fg-2); line-height: 1.5; }

.block { padding: 18px 0; border-bottom: 1px solid var(--border); }
.block--places { display: block; }

.block__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.lbl {
  margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--fg-1);
}
.lbl--dim { color: var(--fg-3); font-weight: 400; }

/* ── list picker ── */
.lists { display: flex; flex-direction: column; gap: 6px; }
.list-btn {
  appearance: none; cursor: pointer; text-align: left; font-family: inherit;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg-1); color: var(--fg-1);
  border: 1px solid var(--border);
  --sw: var(--accent);
}
.list-btn:hover { border-color: var(--fg-3); }
.list-btn__box {
  width: 12px; height: 12px; border: 1px solid var(--fg-3); border-radius: 50%;
  position: relative;
}
.list-btn[aria-checked="true"] { border-color: var(--border-strong); }
.list-btn[aria-checked="true"] .list-btn__box { border-color: var(--sw); }
.list-btn[aria-checked="true"] .list-btn__box::after {
  content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--sw);
}
.list-btn__name { font-size: 14px; font-weight: 700; }
.list-btn__n { font-size: 12px; color: var(--fg-3); }

/* ── tag filter ── */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tagchip {
  appearance: none; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; font-size: 11px; letter-spacing: 0.02em;
  background: var(--bg-1); color: var(--fg-2); border: 1px solid var(--border);
}
.tagchip:hover { border-color: var(--fg-3); }
.tagchip[aria-pressed="true"] { border-color: var(--border-strong); color: var(--fg-1); }
.tagchip__sw { width: 8px; height: 8px; border-radius: 50%; background: var(--kind, var(--tag-none)); }
.tagchip__n { color: var(--fg-3); }

/* ── search ── */
.search-wrap { margin-bottom: 12px; }
.search {
  width: 100%; font-family: inherit; font-size: 13px;
  padding: 8px 10px; background: var(--bg-2); color: var(--fg-1);
  border: 1px solid var(--border);
}
.search:focus { outline: none; border-color: var(--border-strong); }

/* ── place list ── */
.places { list-style: none; margin: 0; padding: 0; }
.place {
  cursor: pointer; padding: 10px 12px 10px 14px;
  border: 1px solid transparent; border-bottom-color: var(--border);
  position: relative; --pin: var(--tag-none);
}
.place::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px;
  background: var(--pin);
}
.place:hover { background: var(--bg-2); }
.place.is-active { background: var(--bg-2); border-color: var(--border-strong); }
.place__name { font-size: 14px; font-weight: 700; }
.place__note { font-size: 12px; color: var(--fg-2); margin-top: 3px; line-height: 1.45; }
.place__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; }
.place__kind {
  font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 6px; color: var(--kind, var(--tag-none));
  border: 1px solid currentColor;
}
.place__go { font-size: 11px; color: var(--fg-3); text-decoration: none; margin-left: auto; }
.place__go:hover { color: var(--fg-1); }
.places__empty { padding: 16px 12px; color: var(--fg-3); font-size: 13px; }

/* ── export actions ── */
.actions { display: flex; flex-direction: column; gap: 6px; }
.act {
  appearance: none; cursor: pointer; text-align: left; font-family: inherit;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--bg-1); color: var(--fg-1);
  border: 1px solid var(--border); text-decoration: none;
}
.act:hover { border-color: var(--fg-3); }
.act__t { display: block; font-size: 13px; font-weight: 700; }
.act__d { display: block; font-size: 11px; color: var(--fg-3); margin-top: 2px; }
.act__k { color: var(--fg-3); }

/* ── colophon ── */
.colophon { padding: 16px 0 20px; font-size: 11px; color: var(--fg-3); }
.colophon__row { display: flex; justify-content: space-between; padding: 3px 0; }
.colophon__row a { text-decoration: none; }
.colophon__row a:hover { color: var(--fg-1); }

/* ───────────────────────── stage / map ───────────────────────── */

.stage { position: relative; min-width: 0; }
.map { position: absolute; inset: 0; background: var(--bg-2); }
.maplibregl-map { font-family: var(--font-mono); }
.maplibregl-canvas { outline: none; }

.readout {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  display: flex; gap: 6px; align-items: center;
  padding: 5px 9px; font-size: 11px; letter-spacing: 0.03em;
  background: color-mix(in srgb, var(--bg-1) 88%, transparent);
  color: var(--fg-2); border: 1px solid var(--border);
  pointer-events: none;
}
.readout__sep { color: var(--fg-3); }

.sheet-toggle { display: none; }
.sheet-grab { display: none; }

/* ── markers ── */
.pin-wrap { background: none; border: 0; cursor: pointer; }
.pin {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--pin, var(--tag-none));
  box-shadow: 0 0 0 1.5px var(--bg-1), 0 1px 2px rgba(0,0,0,0.35);
  margin: 6px; transition: transform var(--dur-fast) var(--ease);
}
.pin.is-active { transform: scale(1.55); }
.pin-n {
  min-width: 22px; height: 22px; padding: 0 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  background: var(--pin, var(--tag-none)); border-radius: 999px;
  box-shadow: 0 0 0 1.5px var(--bg-1), 0 1px 2px rgba(0,0,0,0.35);
}
.cluster {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 4px 8px; font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap;
  background: var(--pin, var(--accent)); border-radius: 999px;
  box-shadow: 0 0 0 1.5px var(--bg-1), 0 1px 3px rgba(0,0,0,0.4);
}
.cluster__n { opacity: 0.85; }

/* ── popup ── */
.maplibregl-popup { max-width: none !important; }
.maplibregl-popup-content {
  padding: 0; border-radius: 0; margin: 0; font-family: var(--font-mono);
  background: var(--bg-1); color: var(--fg-1);
  box-shadow: 0 2px 10px rgba(0,0,0,0.25); border: 1px solid var(--border-strong);
}
.maplibregl-popup-tip { border-top-color: var(--border-strong); border-bottom-color: var(--border-strong); }
.maplibregl-popup-close-button {
  width: 22px; height: 22px; font-size: 16px; color: var(--fg-3);
  right: 2px; top: 2px; background: none;
}
.maplibregl-popup-close-button:hover { color: var(--fg-1); background: none; }
.pop { width: 240px; --pin: var(--tag-none); }

/* ── hover tooltip ── */
.maplibregl-popup.tip { pointer-events: none; }
.maplibregl-popup.tip .maplibregl-popup-content {
  padding: 6px 9px; border: 1px solid var(--border-strong); box-shadow: 0 1px 5px rgba(0,0,0,0.2);
  display: flex; flex-direction: column; gap: 2px;
}
.maplibregl-popup.tip .maplibregl-popup-tip { display: none; }
.tip__name { font-size: 12px; font-weight: 700; }
.tip__kind { font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--kind, var(--fg-3)); }
.tip__row { font-size: 11px; color: var(--fg-2); }
.tip__row--more { color: var(--fg-3); }
.pop__img { display: block; width: 100%; height: 140px; object-fit: cover; background: var(--bg-3); }
.pop__body { padding: 12px 14px 14px; border-top: 3px solid var(--pin); }
.pop__idx { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-3); }
.pop__name { margin: 6px 0 0; font-size: 15px; font-weight: 700; }
.pop__note { margin: 6px 0 0; font-size: 12px; color: var(--fg-2); line-height: 1.5; }
.pop__kinds { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.pop__coord { margin-top: 10px; font-size: 11px; color: var(--fg-3); }
.pop__btn {
  display: block; margin-top: 12px; padding: 8px; text-align: center;
  font-size: 12px; font-weight: 700; text-decoration: none;
  background: var(--fg-1); color: var(--bg-1);
}
.pop__btn:hover { opacity: 0.88; }
.stack__list { display: flex; flex-direction: column; }
.stack__row {
  padding: 8px 0; border-top: 1px solid var(--border); position: relative;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; cursor: pointer;
}
.stack__row:first-child { border-top: 0; }
.stack__name { font-size: 13px; font-weight: 700; }
.stack__note { font-size: 11px; color: var(--fg-2); width: 100%; }

/* ── boot overlay ── */
.boot {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-1); color: var(--fg-3); font-size: 12px; letter-spacing: 0.1em;
  text-transform: uppercase; transition: opacity 0.4s var(--ease);
}
.boot.is-done { opacity: 0; pointer-events: none; }
.boot.is-error { color: var(--tag-art); }

/* ───────────────────────── responsive ───────────────────────── */

@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  .stage { grid-column: 1; }

  /* The panel becomes a bottom sheet: thumb-reachable, slides up over the map. */
  .panel {
    position: fixed; z-index: 1200; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 88dvh;
    padding: 0 16px calc(20px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border-strong); border-bottom: 0;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.18);
    transform: translateY(101%);
    transition: transform var(--dur) var(--ease);
    display: flex;
  }
  .panel.is-open { transform: translateY(0); }

  /* Grab handle doubles as the close control; sticky so it's always reachable. */
  .sheet-grab {
    display: flex; align-items: center; justify-content: center;
    position: sticky; top: 0; z-index: 5;
    margin: 0 -16px; padding: 12px; background: var(--bg-1);
    border: 0; border-bottom: 1px solid var(--border); cursor: pointer;
  }
  .sheet-grab__bar { width: 44px; height: 4px; border-radius: 999px; background: var(--fg-3); }

  .masthead { padding-top: 6px; }
  .title { font-size: 30px; }
  .block--places { flex: 0 0 auto; }
  .places { flex: 0 0 auto; overflow: visible; }

  /* Floating opener, centred at the bottom for the thumb; hidden while open. */
  .sheet-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 50%;
    transform: translateX(-50%); z-index: 900;
    padding: 11px 18px; border-radius: 999px;
    font-family: var(--font-mono); font-size: 13px; font-weight: 700;
    background: var(--fg-1); color: var(--bg-1); border: 1px solid var(--border-strong);
    box-shadow: 0 2px 10px rgba(0,0,0,0.25); cursor: pointer;
  }
  .sheet-toggle__bar { width: 16px; height: 2px; background: currentColor; }
  .panel.is-open ~ .stage .sheet-toggle { display: none; }

  /* Keep the map's own controls clear of the notch and home indicator. */
  .maplibregl-ctrl-top-right { margin-top: env(safe-area-inset-top); }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { margin-bottom: env(safe-area-inset-bottom); }

  /* The coordinate readout collides with the tile attribution on a phone. */
  .readout { display: none; }

  /* Bigger tap targets for the list rows and filter chips. */
  .place { padding: 12px 12px 12px 14px; }
  .tagchip { padding: 6px 10px; }
  .list-btn { padding: 12px; }
}
