/* ============================================================ foundations */
:root {
  --bg: #0e1116;
  --panel: rgba(20, 25, 33, 0.93);
  --panel-solid: #161b23;
  --edge: rgba(255, 255, 255, 0.10);
  --edge-strong: rgba(255, 255, 255, 0.18);
  --ink: #e9edf3;
  --ink-dim: #97a1b0;
  --ink-faint: #6b7686;
  --accent: #5b9dff;
  --danger: #f2555a;
  --ok: #35c48a;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --topbar-h: 46px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; }

.app { position: fixed; inset: 0; }
.app[hidden] { display: none; }

.stage { position: absolute; inset: 0; width: 100%; height: 100%; }
#globe { display: block; background: var(--bg); touch-action: none; cursor: grab; }
#globe.is-dragging { cursor: grabbing; }
#globe[hidden] { display: none; }

/* ================================================================ buttons */
.btn {
  border: 1px solid var(--edge-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, opacity 0.14s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; color: #06121f; font-weight: 640; }
.btn-primary:hover:not(:disabled) { background: #74acff; }
.btn-danger { color: var(--danger); border-color: rgba(242, 85, 90, 0.45); background: rgba(242, 85, 90, 0.10); }
.btn-danger:hover:not(:disabled) { background: rgba(242, 85, 90, 0.2); }
.btn-wide { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }

.icon-btn {
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-dim);
  border-radius: 8px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  cursor: pointer; flex: none;
  transition: background 0.14s, color 0.14s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: var(--ink); }
.icon-btn.tiny { width: 24px; height: 24px; font-size: 13px; border-radius: 7px; }

.linkish {
  background: none; border: none; padding: 0;
  color: var(--accent); font-size: 11.5px; cursor: pointer; text-decoration: none;
}
.linkish:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- tooltip */
/* A real popup rather than the browser's slow, unstyled title attribute. */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 9px); top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: var(--panel-solid); color: var(--ink);
  border: 1px solid var(--edge-strong); border-radius: 7px;
  padding: 5px 9px; font-size: 11.5px; line-height: 1.3; white-space: nowrap;
  box-shadow: var(--shadow); pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity 0.13s ease, transform 0.13s ease, visibility 0.13s;
  z-index: 640;
}
.tip:hover:not(:disabled)::after,
.tip:focus-visible::after {
  opacity: 1; visibility: visible; transform: translateY(-50%) translateX(0);
}

.zoom-divider {
  width: 16px; height: 1px; background: var(--edge); flex: none; margin: 1px 0;
}
#zoom-target:disabled { opacity: 0.32; cursor: default; }
#zoom-target:not(:disabled) { color: var(--accent); border-color: rgba(91, 157, 255, 0.35); }

/* ================================================================== gate */
.gate {
  position: fixed; inset: 0; z-index: 900;
  display: grid; place-items: center;
  background: radial-gradient(1200px 700px at 50% -10%, #1b2536 0%, #0b0e13 60%);
  padding: 20px;
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(360px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-mark { font-size: 30px; }
.gate-card h1 { margin: 6px 0 4px; font-size: 19px; letter-spacing: -0.01em; }
.gate-sub { margin: 0 0 20px; color: var(--ink-faint); font-size: 12.5px; }
.gate-who { display: grid; grid-auto-flow: column; gap: 8px; margin-bottom: 16px; }
.gate-who button {
  border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.04);
  border-radius: 10px; padding: 11px 8px; cursor: pointer; color: var(--ink-dim);
  transition: all 0.14s;
}
.gate-who button.is-on { border-color: var(--accent); background: rgba(91, 157, 255, 0.15); color: var(--ink); font-weight: 600; }
.field { display: block; text-align: left; margin-bottom: 16px; }
.field > span { display: block; font-size: 11.5px; color: var(--ink-faint); margin-bottom: 6px; letter-spacing: 0.04em; text-transform: uppercase; }
.field input {
  width: 100%; background: rgba(0, 0, 0, 0.28); border: 1px solid var(--edge);
  border-radius: 9px; padding: 10px 11px; outline: none; transition: border-color 0.14s;
}
.field input:focus { border-color: var(--accent); }

/* The reveal wrapper is a direct child of .field, so it has to opt out of the
   uppercase label styling above rather than inherit it. */
.field > span.pw {
  display: block; position: relative;
  margin: 0; font-size: inherit; color: inherit;
  text-transform: none; letter-spacing: normal;
}
.pw input { padding-right: 42px; }
.pw-eye {
  position: absolute; top: 50%; right: 5px; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  background: none; border: 0; border-radius: 8px;
  color: var(--ink-faint); cursor: pointer;
  transition: color 0.14s, background 0.14s;
}
.pw-eye:hover { color: var(--ink-dim); background: rgba(255, 255, 255, 0.06); }
.pw-eye.is-on { color: var(--accent); }
.pw-eye:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.gate-error { color: var(--danger); font-size: 12.5px; margin: 12px 0 0; }

/* =============================================================== surfaces */
.glass {
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
}

/* ================================================================ top row */
.topbar {
  /* Above the place layer (600): the account menu opens downwards out of here,
     and a panel covering it would trap you signed in with no way to the menu.
     Both side panels start below it, so nothing can hide underneath. */
  position: absolute; top: 0; left: 0; right: 0; z-index: 660;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: rgba(14, 17, 22, 0.86);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--edge);
}
.topbar-gap { flex: 1; min-width: 0; }

/*
 * The bell and the name menu must survive any width: losing the name menu
 * means no route to Change passcode or Sign out. So they never shrink, and
 * the controls on the left give up their space instead.
 */
.notify, .account { flex: none; }
.seg, .basemap-wrap, .pinlist { min-width: 0; }
.seg, .basemap-wrap { overflow: hidden; }

.seg {
  display: flex; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge); border-radius: 9px; padding: 2px;
}
.seg-btn {
  border: none; background: transparent; color: var(--ink-dim);
  padding: 5px 13px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
  transition: background 0.14s, color 0.14s;
}
.seg-btn.is-on { background: rgba(255, 255, 255, 0.14); color: var(--ink); font-weight: 600; }

.basemap-wrap {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge); border-radius: 9px; padding: 2px;
}
.basemap-wrap[hidden] { display: none; }
#basemap {
  background: transparent; border: none; outline: none; color: var(--ink-dim);
  padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
#basemap option { background: var(--panel-solid); color: var(--ink); }

.account { position: relative; }
.who {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px;
  min-width: 0; cursor: pointer;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--edge);
  border-radius: 9px; padding: 6px 10px; color: inherit;
  transition: background 0.14s;
}
.who:hover { background: rgba(255, 255, 255, 0.11); }
.who .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.who .dot.is-off { background: var(--ink-faint); }
.who b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .caret { color: var(--ink-faint); font-size: 10px; }

.account-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 620;
  min-width: 178px; padding: 5px;
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 10px; box-shadow: var(--shadow);
  display: grid; gap: 2px;
}
.account-menu[hidden] { display: none; }
.account-menu button {
  text-align: left; background: none; border: none; color: var(--ink);
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
.account-menu button:hover { background: rgba(255, 255, 255, 0.09); }

/* =============================================================== pin list */
/* Not a <select>: the rows carry a colour, and a native one cannot. */
.pinlist { position: relative; }
.pinlist-btn {
  display: flex; align-items: center; gap: 7px; font-size: 12.5px;
  cursor: pointer; color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--edge);
  border-radius: 9px; padding: 6px 10px;
  transition: background 0.14s, color 0.14s;
}
.pinlist-btn:hover { background: rgba(255, 255, 255, 0.11); color: var(--ink); }
.pinlist-btn .caret { color: var(--ink-faint); font-size: 10px; }
.pinlist-count {
  font-variant-numeric: tabular-nums; font-size: 11px; color: var(--ink-faint);
  background: rgba(255, 255, 255, 0.07); border-radius: 999px; padding: 1px 6px;
}
.pinlist-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 620;
  width: min(280px, calc(100vw - 28px)); max-height: 340px; overflow-y: auto;
  padding: 5px;
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 10px; box-shadow: var(--shadow);
  display: grid; gap: 1px;
}
.pinlist-menu[hidden] { display: none; }
.pinlist-empty { margin: 0; padding: 10px; font-size: 12px; color: var(--ink-faint); }
.pinlist-row {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: none; border: none; color: var(--ink);
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
}
.pinlist-row:hover { background: rgba(255, 255, 255, 0.09); }
.pinlist-dot {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  border: 1px solid rgba(0, 0, 0, 0.45);
}
.pinlist-text { display: flex; flex-direction: column; min-width: 0; }
.pinlist-name {
  font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pinlist-who { font-size: 10.5px; color: var(--ink-faint); }

/* ============================================== TEMPORARY: size adjuster */
/* Remove this block with tuner.js and #tuner once the numbers are settled. */
.tuner {
  position: absolute; left: 12px; bottom: 66px; z-index: 690;
  display: flex; align-items: flex-end; gap: 6px; pointer-events: auto;
}
.tuner-toggle {
  width: 30px; height: 30px; flex: none; padding: 0;
  display: grid; place-items: center; font-size: 14px; cursor: pointer;
  background: var(--panel-solid); color: var(--ink-dim);
  border: 1px solid var(--edge-strong); border-radius: 9px;
  box-shadow: var(--shadow);
}
.tuner-toggle:hover { color: var(--ink); }
.tuner-body {
  width: 196px; padding: 9px 10px;
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 10px; box-shadow: var(--shadow);
  display: grid; gap: 7px;
}
.tuner-body[hidden] { display: none; }
.tuner-row {
  display: grid; grid-template-columns: 40px 1fr 30px; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-dim);
}
.tuner-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.tuner-row output { font-variant-numeric: tabular-nums; text-align: right; font-size: 11px; }
.tuner-read {
  margin: 0; font-size: 10.5px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* ========================================================== notifications */
.notify { position: relative; }
.notify-btn {
  position: relative; display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0; font-size: 14px; cursor: pointer;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--edge);
  border-radius: 9px; color: inherit;
  transition: background 0.14s, border-color 0.14s;
}
.notify-btn:hover { background: rgba(255, 255, 255, 0.11); }
.notify-btn.has-unread { border-color: var(--accent); }
.notify-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
  background: var(--danger); color: #fff;
  font-size: 9.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  border-radius: 999px; border: 1px solid var(--panel-solid);
}
.notify-badge[hidden] { display: none; }
.notify-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 620;
  width: min(310px, calc(100vw - 28px)); max-height: 360px; overflow-y: auto;
  padding: 5px;
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 10px; box-shadow: var(--shadow);
  display: grid; gap: 1px;
}
.notify-menu[hidden] { display: none; }
.notify-empty {
  margin: 0; padding: 12px 10px; font-size: 12px;
  color: var(--ink-faint); line-height: 1.45;
}
.notify-row {
  display: flex; align-items: flex-start; gap: 9px; width: 100%; text-align: left;
  background: none; border: none; color: var(--ink);
  padding: 8px 9px; border-radius: 7px; cursor: pointer;
}
.notify-row:hover { background: rgba(255, 255, 255, 0.09); }
/* What arrived since you last looked, still marked after opening clears it. */
.notify-row.is-new { background: rgba(91, 157, 255, 0.10); }
.notify-row.is-new:hover { background: rgba(91, 157, 255, 0.17); }
.notify-icon { font-size: 13px; line-height: 1.3; flex: none; }
.notify-text { display: flex; flex-direction: column; min-width: 0; }
.notify-head { font-size: 12.5px; line-height: 1.35; overflow-wrap: anywhere; }
.notify-meta { font-size: 10.5px; color: var(--ink-faint); }

/* ================================================================== modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 800;
  display: grid; place-items: center; padding: 20px;
  background: rgba(6, 9, 14, 0.66);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: min(340px, 100%);
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 14px; padding: 20px; box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
}
.modal-card h2 { margin: 0 0 4px; font-size: 16px; }
.modal-sub { margin: 0 0 18px; font-size: 12px; color: var(--ink-faint); line-height: 1.45; }
.modal-error { color: var(--danger); font-size: 12.5px; margin: 0 0 12px; line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ================================================================= legend */
.panel {
  position: absolute; z-index: 500;
  background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 8px 7px 11px;
}
.panel-head h2 { margin: 0; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.panel-body { padding: 0 9px 9px; }

/*
 * Three sizes, cycled by the tab on its edge: full, minimal (initials and
 * colours, packed tight) and hidden - slid off the left with only the tab
 * showing. It sits flush against the edge so hiding is a clean slide out.
 */
.legend {
  top: calc(var(--topbar-h) + 10px); left: 0; width: 202px;
  border-left: none; border-radius: 0 var(--radius) var(--radius) 0;
  transition: transform 0.24s ease, width 0.24s ease;
}
/*
 * The tab: thin, and just short of the panel's own height so it sits centred
 * against it with matching gaps top and bottom. "Legend" is written down it -
 * L at the top - so a hidden legend still announces itself.
 */
.legend-tab {
  position: absolute; left: 100%; top: 50%;
  transform: translateY(-50%);
  /* Always the panel's height less a matching inset top and bottom. No minimum:
     one would push it past a short panel and read as stuck on rather than part
     of it. Full and minimal are the same height, so the proportion holds. */
  width: 18px; height: calc(100% - 16px);
  padding: 0;
  display: grid; place-items: center;
  background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge); border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--ink-dim); cursor: pointer;
  box-shadow: var(--shadow);
  transition: color 0.14s, background 0.14s, width 0.24s ease;
  /* Reads top to bottom; the arrows rotate with it. */
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 9px; letter-spacing: 0.09em; text-transform: uppercase;
  white-space: nowrap;
}
.legend-tab:hover { color: var(--ink); background: var(--panel-solid); }
/*
 * 15px is a fine width to look at and a poor one to hit with a thumb, so the
 * target is larger than the drawing. It reaches right and vertically only -
 * never left, which would put it over the panel's own colour wells.
 */
.legend-tab::before {
  content: ''; position: absolute;
  top: -6px; bottom: -6px; left: 0; right: -10px;
}
/* Hidden, there is no panel for it to look slim against, and hitting it is the
   whole job - so it simply gets wider. */
.legend.is-hidden .legend-tab { width: 27px; }

/* Hidden: the panel slides out, leaving the tab against the screen edge. */
.legend.is-hidden { transform: translateX(-100%); }

/*
 * Minimal: an initial and the two colour wells, packed as tight as they go.
 * No tick boxes - showing and hiding people's pins is a full-size job, and
 * dropping them is most of what makes this narrow.
 */
.lbl-min { display: none; }
/* The ✕ row supplies the top edge now, so the body starts tighter. */
.legend .panel-body { padding: 4px 9px 9px; }
/* A ✕ on each panel hides that panel. It shows at both open sizes, so either
   can be put away without opening it up first. */
.panel-x-row { display: flex; justify-content: flex-end; padding: 4px 4px 0; }
.panel-x { width: 20px; height: 20px; font-size: 11px; border-radius: 6px; }

/*
 * Minimal differs from full in width and in what is shown - never in height.
 * Every vertical measurement below is deliberately left alone so the two are
 * the same height, which is what keeps the tab in the same proportion to both.
 */
.legend.is-min { width: 78px; }
.legend.is-min .panel-body { padding: 4px 5px 9px; }
.legend.is-min .lbl-full { display: none; }
.legend.is-min .lbl-min { display: inline; }
.legend.is-min .h-show,
.legend.is-min .legend-row input[type="checkbox"] { display: none; }
.legend.is-min .legend-head-row,
.legend.is-min .legend-row { grid-template-columns: 12px 24px 24px; gap: 3px; }
.legend.is-min .swatch { width: 24px; }

/* 30px, not 24: "Show" is wider than the column was and ran into "Goal". */
.legend-head-row, .legend-row {
  display: grid; grid-template-columns: 1fr 30px 28px 28px; gap: 6px; align-items: center;
}
.legend-head-row {
  font-size: 9.5px; color: var(--ink-faint); text-transform: uppercase;
  letter-spacing: 0.04em; padding-bottom: 4px;
}
.legend-head-row span:not(:first-child) { text-align: center; }
.legend-row { padding: 3px 0; border-top: 1px solid rgba(255, 255, 255, 0.05); }
.legend-name { display: flex; align-items: baseline; gap: 5px; min-width: 0; }
.legend-name b { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-name .count { color: var(--ink-faint); font-size: 10.5px; font-style: normal; font-variant-numeric: tabular-nums; }
.legend-row input[type="checkbox"] { width: 14px; height: 14px; margin: 0 auto; accent-color: var(--accent); cursor: pointer; }
.swatch {
  width: 26px; height: 19px; padding: 0; margin: 0 auto; display: block;
  border: 1px solid var(--edge-strong); border-radius: 5px; background: none;
  cursor: pointer; overflow: hidden;
}
.swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.swatch::-webkit-color-swatch { border: none; border-radius: 3px; }
.swatch::-moz-color-swatch { border: none; border-radius: 3px; }

/* ========================================================= zoom (vertical) */
.zoombar {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%); z-index: 500;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 8px 7px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 11px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.zoom-read {
  font-size: 10px; color: var(--ink-faint); font-variant-numeric: tabular-nums;
  min-height: 12px;
}
#zoom-range {
  writing-mode: vertical-lr;
  direction: rtl;                       /* up = zoom in */
  -webkit-appearance: slider-vertical;
  appearance: slider-vertical;
  width: 18px;
  /* The whole bar - buttons, slider and readout - stays under a third of the
   * window height, so the slider itself gets what is left of that budget. */
  height: min(22vh, 190px);
  background: transparent;
  cursor: pointer;
}
#zoom-range::-webkit-slider-runnable-track {
  width: 4px; border-radius: 3px; background: rgba(255, 255, 255, 0.18);
}
#zoom-range::-moz-range-track { width: 4px; border-radius: 3px; background: rgba(255, 255, 255, 0.18); }
#zoom-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-left: -5px;
  border-radius: 50%; background: #fff; border: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
}
#zoom-range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
}

/* ============================================================ place panel */
.place-layer { position: absolute; inset: 0; z-index: 600; pointer-events: none; }
/*
 * Anchored against the right edge with a tab on it, mirroring the legend on
 * the left. Three sizes cycle from the tab: full, minimal, and hidden - slid
 * off the right with only the tab, which carries the place's own name so a
 * hidden panel still says what is selected.
 */
.place-panel {
  position: absolute; right: 0; top: calc(var(--topbar-h) + 10px);
  width: 300px; pointer-events: auto;
  display: flex; flex-direction: column;
  max-height: calc(100vh - var(--topbar-h) - 130px);
  background: var(--panel-solid);
  border: 1px solid var(--edge-strong); border-right: none;
  border-radius: 13px 0 0 13px;
  box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
  transition: transform 0.24s ease, width 0.24s ease;
}
/* Lets the body give up height to the note feed below it, and makes anything
   that no longer fits reachable instead of clipped by the panel. */
.place-panel .panel-body { min-height: 0; overflow-y: auto; }
@keyframes pop { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

.place-tab {
  position: absolute; right: 100%; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: calc(100% - 16px);
  padding: 0 0 6px;
  display: grid; place-items: center;
  background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge); border-right: none;
  border-radius: 8px 0 0 8px;
  color: var(--ink-dim); cursor: pointer;
  box-shadow: var(--shadow);
  transition: color 0.14s, background 0.14s, width 0.24s ease;
  writing-mode: vertical-rl; text-orientation: mixed;
  font-size: 9px; letter-spacing: 0.09em; text-transform: uppercase;
  /* Names run long - "Esplanade – Theatres on the Bay" needs more height than
     a minimal panel has - so they are cut rather than allowed to overflow. */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.place-tab:hover { color: var(--ink); background: var(--panel-solid); }
/* Bigger to hit than to look at; reaches left and vertically, never right into
   the panel's own controls. */
.place-tab::before {
  content: ''; position: absolute;
  top: -6px; bottom: -6px; right: 0; left: -10px;
}
.place-panel.is-hidden { transform: translateX(100%); }
.place-panel.is-hidden .place-tab { width: 27px; }

/*
 * Minimal: enough to know what this is and to act on it - the name, one line
 * about it, who has marked it, and the three buttons. No picture, no notes, no
 * chrome.
 */
/* Driven live by the temporary tuner; these are the values to bake in. */
:root { --place-min-w: 130px; --place-min-h: 300px; }
/*
 * A set height rather than a cap. As a cap it did nothing until the content
 * grew past it, so the slider appeared stuck between 90 and 120. Now the panel
 * is the height it is told: text at the top, buttons at the bottom, and blank
 * panel between them.
 */
.place-panel.is-min {
  width: var(--place-min-w);
  height: var(--place-min-h);
  max-height: calc(100vh - var(--topbar-h) - 80px);
}
.place-panel.is-min .p-bar { margin-top: auto; }
.place-panel.is-min .lbl-full { display: none; }
.place-panel.is-min .p-levels,
.place-panel.is-min .note-feed { display: none; }
/*
 * The write-up takes whatever height is left between the description and the
 * buttons, and fades where it runs out - rather than stopping after two lines
 * and leaving a gap, which read as "that is all there is".
 */
.place-panel.is-min .panel-body {
  padding: 9px; gap: 6px;
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.place-panel.is-min .p-info {
  flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto;
}
.place-panel.is-min .info-text {
  display: block; -webkit-line-clamp: unset; max-height: none; overflow: visible;
}
/* The write-up follows the description, without its picture or its links -
   the words are what is wanted here, not the furniture. */
.place-panel.is-min .info-thumb,
.place-panel.is-min .info-foot { display: none; }
.place-panel.is-min .info { padding: 0; border: none; background: none; }
.place-panel.is-min .info-text { font-size: 11.5px; }

/* Too narrow to truncate into, so the name wraps and the panel takes the
   height instead. It is a heading, not a field: renaming is gone. */
.p-name {
  margin: 0; font-size: 14px; font-weight: 600; line-height: 1.3;
  overflow-wrap: anywhere;
}
.place-panel.is-min .p-name { font-size: 13px; }
/* No clamp: the description runs to whatever length it needs, and the panel
   has the room now that its height is set rather than fitted. */

/*
 * Minimal's own row: Goal, Been, the pin and the dots as four equal quarters,
 * so all of them cost one line and the width above is left to the text.
 */
/*
 * A scroll container with more below it fades at its bottom edge, so clipped
 * text reads as scrollable rather than simply cut off. Masking the box rather
 * than the content keeps the fade at the edge as you scroll, and the class only
 * goes on while there is actually something more to reach.
 */
.scroll-fade.is-fading {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent);
}

/* What sort of place it is, on its own line above the buttons. */
.p-kind-row { padding: 0 10px 8px; }
.p-kind-row[hidden] { display: none; }
.place-panel.is-min .p-kind-row { padding: 0 7px 6px; }

/*
 * One row of controls, ordered differently by size. Full keeps the dots on the
 * left and groups Goal, Been and the action to the right; minimal gives all
 * four an equal quarter and puts the dots last, since three buttons pressed up
 * against the screen edge are the awkward ones to hit.
 */
.p-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-top: 1px solid var(--edge);
}
.p-bar .status-btn { flex: none; padding: 5px 10px; font-size: 11.5px; }
/* Pushes Goal, Been and the action away from the dots, over to the right. */
.p-bar .status-btn:first-of-type { margin-left: auto; }
.p-bar .p-action {
  flex: none; padding: 5px 10px;
  display: inline-flex; align-items: center; justify-content: center;
}

.place-panel.is-min .p-bar {
  gap: 3px; padding: 0 7px 8px; border-top: none; align-items: stretch;
}
.place-panel.is-min .p-bar > * { flex: 1 1 0; min-width: 0; margin-left: 0; }
.place-panel.is-min .p-bar .who-dots { order: 9; justify-content: center; gap: 1px; }
.place-panel.is-min .p-bar .status-btn,
.place-panel.is-min .p-bar .p-action { padding: 5px 0; font-size: 11px; }
.place-panel.is-min .p-bar .who-dot { width: 12px; height: 12px; font-size: 8px; }

.lbl-min { display: none; }
.place-panel.is-min .lbl-min { display: inline-flex; align-items: center; gap: 3px; }

.p-top { display: flex; align-items: center; gap: 7px; }
.p-top .p-name { flex: 1; min-width: 0; }
.p-kind {
  flex: none; font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-dim); background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--edge); border-radius: 5px; padding: 1px 5px;
}
.p-kind[hidden] { display: none; }

.place-panel .panel-body {
  padding: 10px; display: grid; gap: 9px;
  overflow-y: auto; min-height: 0;
}
.p-notes {
  width: 100%; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--edge);
  border-radius: 8px; padding: 8px 9px; outline: none; font-size: 13px;
  transition: border-color 0.14s;
}
.p-notes:focus { border-color: var(--accent); }
.p-notes:disabled { opacity: 0.65; cursor: not-allowed; }
.p-notes { resize: vertical; min-height: 58px; max-height: 160px; line-height: 1.45; }
.p-context {
  margin: 0; flex: 1; min-width: 0;
  font-size: 11.5px; color: var(--ink-faint); line-height: 1.4;
}
.p-context:empty { display: none; }
/* Deliberately unclamped: the description runs to as many lines as it needs.
   A leftover clamp here is what kept trailing it off in an ellipsis. */

/* ------------------------------------------------------------- note feed */
/* The box composes a note; nothing is saved until + is pressed. */
.note-compose { position: relative; }
.note-compose .p-notes { padding-right: 34px; }
.note-add {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px; padding: 0; line-height: 1;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 600;
  background: rgba(255, 255, 255, 0.06); color: var(--ink-dim);
  border: 1px solid var(--edge); border-radius: 7px; cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.note-add:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.note-add:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Pinned below the action button, so the place's history reads as a feed
   underneath everything that describes the place itself. */
.note-feed {
  flex: none; min-height: 0;
  display: flex; flex-direction: column; gap: 7px;
  padding: 9px 10px; border-top: 1px solid var(--edge);
}
.note-feed[hidden] { display: none; }
/* Only the list scrolls. The toggle below it is always in view - a single long
   note used to push it out of sight, which is exactly when it is wanted. */
.note-list {
  display: flex; flex-direction: column; gap: 7px;
  overflow-y: auto; min-height: 0; max-height: 104px;
}
.note-more { align-self: flex-start; flex: none; }

/* Expanded, the write-up gives up its space to the conversation, and the feed
   only scrolls once it has filled what is there. */
.place-panel.is-notes-open .p-info { display: none; }
.place-panel.is-notes-open .note-feed { flex: 1 1 auto; }
.place-panel.is-notes-open .note-list { flex: 1 1 auto; max-height: none; }
.note { display: flex; align-items: flex-start; gap: 7px; }
.note-body { flex: 1; min-width: 0; }
.note-text {
  margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.note-when { font-size: 10.5px; color: var(--ink-faint); }
.note-remove {
  flex: none; width: 20px; height: 20px; padding: 0; line-height: 1;
  display: grid; place-items: center;
  background: none; color: var(--ink-faint);
  border: 1px solid var(--edge); border-radius: 6px; cursor: pointer;
  font-size: 15px; transition: color 0.14s, border-color 0.14s;
}
.note-remove:hover { color: var(--danger); border-color: var(--danger); }

/* The place ladder: street · district · city · region · country */
.p-levels {
  display: flex; gap: 5px; overflow-x: auto; padding-bottom: 3px;
  scrollbar-width: thin; margin-top: -2px;
}
.p-levels[hidden] { display: none; }
.p-levels.is-busy { opacity: 0.5; pointer-events: none; }
.p-levels::-webkit-scrollbar { height: 4px; }
.p-levels::-webkit-scrollbar-thumb { background: var(--edge-strong); border-radius: 2px; }
.level-chip {
  flex: none; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim); border-radius: 20px;
  padding: 4px 10px; font-size: 11.5px;
  transition: background 0.13s, color 0.13s, border-color 0.13s;
}
.level-chip:hover { background: rgba(255, 255, 255, 0.11); color: var(--ink); }
.level-chip.is-on {
  background: rgba(91, 157, 255, 0.18); border-color: rgba(91, 157, 255, 0.55);
  color: var(--ink); font-weight: 600;
}

.info {
  border: 1px solid var(--edge); border-radius: 9px; padding: 9px;
  background: rgba(255, 255, 255, 0.03);
}
.info-thumb {
  width: 100%; height: 96px; object-fit: cover; border-radius: 6px;
  margin-bottom: 8px; display: block; background: rgba(255, 255, 255, 0.05);
}
.info-text {
  font-size: 12px; line-height: 1.5; color: var(--ink-dim);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4;
  overflow: hidden;
}
.info-text.is-open {
  display: block; -webkit-line-clamp: unset;
  max-height: 168px; overflow-y: auto;
}
.info-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 7px;
}
.info-loading { margin: 0; font-size: 11.5px; color: var(--ink-faint); font-style: italic; }

.status-btn {
  flex: 1; border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.04);
  border-radius: 8px; padding: 7px 6px; cursor: pointer; font-size: 12px;
  color: var(--ink-dim); display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.14s;
}
.status-btn.is-on { color: var(--ink); border-color: var(--edge-strong); background: rgba(255, 255, 255, 0.11); font-weight: 600; }

.panel-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border-top: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.02);
}
.saved-flag { font-size: 11px; color: var(--ink-faint); transition: opacity 0.3s; }
.saved-flag.is-on { color: var(--ok); }

/* One initialled dot per person who has marked this place, in that person's
   own colour for their own mark. The pin on the map may be a single shared
   colour; these always say who thinks what. */
.who-dots { display: flex; align-items: center; gap: 4px; }
.who-dot {
  width: 19px; height: 19px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; font-style: normal; line-height: 1;
  /* Every colour in the palette is bright enough to carry dark text. */
  color: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* ============================================================ search dock */
.searchdock {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  z-index: 550; width: min(560px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 8px;
}
.search-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--edge-strong); border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.search-icon { color: var(--ink-faint); flex: none; }
.search-bar input {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  padding: 3px 0; font-size: 14px;
}
.search-bar input::placeholder { color: var(--ink-faint); }
.search-bar input::-webkit-search-cancel-button { display: none; }

.search-results {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 12px;
  box-shadow: var(--shadow); padding: 5px;
  max-height: 244px; overflow-y: auto;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.search-results.is-expanded { max-height: min(58vh, 460px); }
.search-results[hidden] { display: none; }

.search-status {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 8px 7px; font-size: 11.5px; color: var(--ink-faint); line-height: 1.4;
}
.search-status b { color: var(--ink-dim); font-weight: 600; }
.search-status.is-hint { font-style: italic; }

.result {
  display: flex; align-items: flex-start; gap: 9px; width: 100%;
  padding: 8px 9px; border: none; background: none; border-radius: 9px;
  cursor: pointer; text-align: left; color: inherit;
  transition: background 0.12s;
}
.result:hover { background: rgba(255, 255, 255, 0.06); }
.result.is-active { background: rgba(91, 157, 255, 0.16); }
.result-mark { color: var(--ink-faint); font-size: 12px; line-height: 1.5; flex: none; }
.result-mark.is-wiki { color: #f0b429; }
.result-body { flex: 1; min-width: 0; display: block; }
.result-name { display: block; font-size: 13.5px; font-weight: 560; }
.result-ctx {
  display: block; font-size: 11.5px; color: var(--ink-faint); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.result-kind {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-faint); border: 1px solid var(--edge); border-radius: 5px;
  padding: 2px 5px; flex: none; white-space: nowrap; margin-top: 2px;
}

/* ============================================================ pin marker */
.pin-icon, .crosshair-icon { background: none !important; border: none !important; }
.pin-svg { display: block; overflow: visible; cursor: pointer; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55)); }
.pin-svg .body { transition: transform 0.13s ease; transform-origin: 50% 100%; }
.pin-svg:hover .body { transform: scale(1.16); }
.pin-svg .ring { fill: rgba(255, 255, 255, 0.92); }
.pin-svg .halo { fill: none; stroke: #fff; stroke-width: 2; opacity: 0; }
.pin-svg.is-selected .halo { opacity: 0.85; }
.pin-svg.is-selected .body { transform: scale(1.2); }

/* the "looking at this, not committed" marker */
.crosshair { display: block; overflow: visible; pointer-events: none; }
.crosshair .rim { fill: rgba(91, 157, 255, 0.14); stroke: var(--accent); stroke-width: 2; }
.crosshair .tick { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.crosshair .dot { fill: #fff; }
.crosshair .pulse {
  fill: none; stroke: var(--accent); stroke-width: 1.5;
  transform-origin: 22px 22px; animation: crosspulse 1.9s ease-out infinite;
}
@keyframes crosspulse {
  0% { transform: scale(0.75); opacity: 0.85; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* ================================================================ toasts */
.toasts {
  position: absolute; bottom: 92px; right: 14px; z-index: 700;
  display: grid; gap: 8px; justify-items: end; pointer-events: none;
}
.toast {
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 10px; padding: 9px 13px; font-size: 12.5px; box-shadow: var(--shadow);
  animation: slidein 0.18s ease-out; max-width: 300px; line-height: 1.45;
}
.toast.is-bad { border-color: rgba(242, 85, 90, 0.5); }
.toast.is-good { border-color: rgba(53, 196, 138, 0.5); }
@keyframes slidein { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

.hint {
  position: absolute; top: calc(var(--topbar-h) + 12px); left: 50%; transform: translateX(-50%);
  z-index: 490; font-size: 11px; color: var(--ink-faint);
  background: rgba(10, 13, 18, 0.72); padding: 5px 12px; border-radius: 20px;
  pointer-events: none; white-space: nowrap; transition: opacity 0.5s;
  max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.hint.is-gone { opacity: 0; }

/* ============================================================ leaflet trim */
.leaflet-container { background: #0d1017; font-family: var(--font); outline: none; }
.leaflet-control-attribution {
  background: rgba(10, 13, 18, 0.72) !important; color: var(--ink-faint) !important;
  font-size: 10px !important; border-radius: 6px 0 0 0;
}
.leaflet-control-attribution a { color: var(--ink-dim) !important; }
.leaflet-tooltip {
  background: var(--panel-solid); border: 1px solid var(--edge-strong); color: var(--ink);
  box-shadow: var(--shadow); border-radius: 7px; padding: 4px 8px; font-size: 12px;
}
.leaflet-tooltip-top::before { border-top-color: var(--edge-strong); }

.globe-tip {
  position: absolute; z-index: 520; pointer-events: none;
  background: var(--panel-solid); border: 1px solid var(--edge-strong);
  border-radius: 7px; padding: 4px 9px; font-size: 12px; box-shadow: var(--shadow);
  transform: translate(-50%, -160%); white-space: nowrap;
}
.globe-tip[hidden] { display: none; }

/* ================================================================= mobile */
@media (max-width: 780px) {
  .legend { width: 190px; }
  .legend-head-row, .legend-row { grid-template-columns: 1fr 28px 26px 26px; gap: 6px; }
  /* SHOW, GOAL and BEEN are each about as wide as their own column here, so
     they read as one run at the full size. Smaller buys the gap back. */
  .legend-head-row { font-size: 8.5px; }
  /* The minimal sizes are already as tight as they go; leave them be. */
  .legend.is-min { width: 78px; }
  .legend.is-min .legend-head-row,
  .legend.is-min .legend-row { grid-template-columns: 12px 24px 24px; gap: 3px; }

  .zoombar { top: auto; bottom: 96px; transform: none; padding: 6px 5px; }
  #zoom-range { height: min(16vh, 130px); }

  .searchdock { bottom: 12px; left: 12px; right: 12px; transform: none; width: auto; }
  .search-results { max-height: 200px; }
  .search-results.is-expanded { max-height: 48vh; }

  .place-panel {
    /* Room on the left for this panel's own tab and the legend's. */
    width: calc(100vw - 86px);
    max-height: 58vh;
  }
  /*
   * The write-up used to fill the whole panel on a phone, leaving Goal, Been
   * and the notes box below the fold with nothing to say they were there. It
   * is the least urgent thing in the panel, so it is the thing that gives way -
   * Show more still opens it in full.
   */
  .info-thumb { height: 56px; }
  .info-text { -webkit-line-clamp: 2; }
  .info-text.is-open { max-height: 96px; }
  .p-notes { min-height: 44px; }
  /* A hard ceiling, because a short write-up is never clamped and could still
     fill the panel on its own. Whatever it costs, it costs itself. */
  .p-info { max-height: 132px; overflow-y: auto; }

  /* Shown on a phone too: this is where the two-tap gesture most needs
     saying, and where the strip used to be hidden. */
  .hint {
    white-space: normal; line-height: 1.35; text-align: center;
    max-width: calc(100vw - 120px); border-radius: 12px;
  }
  .toasts { bottom: 86px; left: 12px; right: 12px; justify-items: stretch; }
  .toast { max-width: none; }
}

/*
 * Phones in portrait. Six controls at desktop sizes do not fit across ~360px,
 * and what fell off the end was the name menu on the right. Everything shrinks
 * enough to fit rather than scrolling, so nothing has to be hunted for.
 */
@media (max-width: 560px) {
  .topbar { gap: 4px; padding: 0 6px; }
  .seg-btn { padding: 5px 7px; font-size: 11.5px; }
  #basemap { font-size: 11.5px; padding: 5px 3px; max-width: 66px; }
  .pinlist-label { display: none; }        /* the count still says how many */
  .pinlist-btn { padding: 6px 7px; gap: 5px; }
  .notify-btn { width: 28px; height: 28px; font-size: 13px; }
  .who { padding: 5px 7px; gap: 5px; }
  .who b { max-width: 64px; }
}

@media (max-width: 900px) and (max-height: 560px) {
  .legend { max-height: 42vh; overflow-y: auto; }
  .zoombar { bottom: 86px; }
  #zoom-range { height: 90px; }
  .place-panel { max-height: 60vh; }
}

/* A test copy announces itself here; production shows nothing. */
.env-badge {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #0b0e13; background: var(--danger);
  border-radius: 6px; padding: 3px 7px;
}
.env-badge[hidden] { display: none; }
.gate-card .env-badge { display: inline-block; margin-bottom: 6px; }

/* The mark a first tap leaves behind: enough to say the tap registered and a
   second is worth trying, not enough to be mistaken for a selection.
   It must not take pointer events - it sits exactly where the second tap is
   about to land, and would otherwise swallow it. */
.tap-mark { pointer-events: none !important; }
.tap-mark i {
  display: block; width: 14px; height: 14px; margin: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.6); border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  animation: tap-settle 0.45s ease-out forwards;
}
@keyframes tap-settle {
  from { opacity: 1; transform: scale(0.6); }
  to { opacity: 0.3; transform: scale(1); }
}
