:root {
  --bg: rgb(31 31 31);          /* V105 canvas (--card, dark) */
  --panel: rgb(16 18 25 / 0.78);
  --panel-border: rgb(255 255 255 / 0.08);
  --fg: #eceef4;
  --muted: #9aa0b1;
  --accent: #ff5a8a;
  --live: #3ddc84;
  --warn: #ffc542;
  --err: #ff6b6b;
  --radius: 12px;
  --gap: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
canvas#map { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; cursor: grab; }
canvas#map:active { cursor: grabbing; }

.panel { position: fixed; z-index: 2; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 12px 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.top-left { top: var(--gap); left: var(--gap); max-width: 340px; }
.top-right { top: var(--gap); right: var(--gap); width: 290px; }
.bottom-left { bottom: var(--gap); left: var(--gap); max-width: 360px; }
.bottom-right { bottom: var(--gap); right: var(--gap); }

h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: 0.01em; }
h2 { margin: 0 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
p { margin: 0; }
.lede { color: var(--muted); }
#count { color: var(--fg); font-variant-numeric: tabular-nums; }

.live { margin-top: 8px; display: flex; align-items: center; gap: 7px; font-size: 13px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live[data-state="live"] .dot { background: var(--live); box-shadow: 0 0 0 0 rgb(61 220 132 / 0.6); animation: pulse 2s infinite; }
.live[data-state="reconnecting"] .dot, .live[data-state="loading"] .dot { background: var(--warn); }
.live[data-state="error"] .dot, .live[data-state="closed"] .dot { background: var(--err); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(61 220 132 / 0.55); } 70% { box-shadow: 0 0 0 8px rgb(61 220 132 / 0); } 100% { box-shadow: 0 0 0 0 rgb(61 220 132 / 0); } }
.activity { margin-top: 4px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-height: 1.4em; }

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.feed li.empty { color: var(--muted); font-size: 13px; }
.feed button { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 10px 1fr; column-gap: 9px;
  padding: 6px 6px; border-radius: 8px; cursor: pointer; }
.feed button:hover, .feed button:focus-visible { background: rgb(255 255 255 / 0.06); }
.feed button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.feed i, .legend i, .kicker .swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-top: 4px; }
.feed .name { font-weight: 500; }
.feed .meta { grid-column: 2; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.legend-panel details > summary { list-style: none; cursor: pointer; }
.legend-panel details > summary::-webkit-details-marker { display: none; }
.legend-panel details > summary h2 { display: inline; }
.legend-panel details > summary::after { content: "▾"; color: var(--muted); margin-left: 6px; font-size: 11px; }
.legend-panel details:not([open]) > summary::after { content: "▸"; }
.legend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 5px; }
.legend li { display: grid; grid-template-columns: 10px 1fr; column-gap: 9px; }
.legend .mix { grid-column: 2; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 8px; }
.controls button { font: inherit; font-size: 13px; color: var(--fg); background: rgb(255 255 255 / 0.05); border: 1px solid var(--panel-border);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; min-height: 32px; }
.controls button:hover { background: rgb(255 255 255 / 0.1); }
.controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.controls button[aria-pressed="true"] { border-color: rgb(255 90 138 / 0.6); background: rgb(255 90 138 / 0.14); }
.readouts { display: inline-flex; flex-direction: column; padding: 0 4px; }
.fps, .zoom-level { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.drag-help { flex-basis: 100%; color: var(--muted); font-size: 11px; padding: 0 2px; }
.tabular-nums { font-variant-numeric: tabular-nums; }
/* V105 focus ring around the inspected cell */
.focus-ring { position: fixed; left: 0; top: 0; z-index: 1; width: 22px; height: 22px; border: 1px solid rgb(255 255 255 / 0.78);
  border-radius: 50%; pointer-events: none; box-shadow: 0 0 8px rgb(255 255 255 / 0.28), inset 0 0 6px rgb(255 255 255 / 0.16); }
.focus-ring[hidden] { display: none; }
.featured-hover { position: fixed; z-index: 4; width: 176px; pointer-events: none; display: grid; gap: 2px;
  color: var(--fg); background: rgb(15 17 25 / 0.94); border: 1px solid rgb(255 90 138 / 0.45);
  border-radius: 9px; padding: 8px 10px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.35); }
.featured-hover[hidden] { display: none; }
.featured-hover strong { font-size: 13px; }
.featured-hover span, .featured-hover small { color: var(--muted); font-size: 11px; }
.cell-fields { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0 0 8px; font-size: 12px; }
.cell-fields dt { color: var(--muted); }
.cell-fields dd { margin: 0; min-width: 0; }

.detail { top: 50%; right: var(--gap); transform: translateY(-50%); width: 340px; max-height: 60vh; overflow: auto; }
.detail[hidden] { display: none; }
.detail h2 { text-transform: none; letter-spacing: 0; font-size: 17px; color: var(--fg); margin: 2px 0 8px; }
.detail-return { width: 100%; margin: 0 0 10px; color: #151720; background: var(--accent);
  border: 1px solid rgb(255 255 255 / 0.4); border-radius: 8px; padding: 9px 12px;
  font: inherit; font-size: 14px; font-weight: 750; cursor: pointer; box-shadow: 0 0 18px rgb(255 90 138 / 0.2); }
.detail-return:hover { background: #ff7aa2; }
.detail-return:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.detail-return[hidden] { display: none; }
.detail .kicker { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); font-size: 12px; padding-right: 24px; }
.detail .origin { color: var(--muted); font-size: 12px; }
.detail blockquote { margin: 10px 0 0; padding-left: 10px; border-left: 2px solid var(--panel-border); white-space: pre-wrap; }
.close { position: absolute; top: 6px; right: 8px; font-size: 20px; line-height: 1; color: var(--muted); background: none; border: 0; cursor: pointer; padding: 4px 6px; }
.close:hover { color: var(--fg); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- add-a-text modal ---------------------------------------------------- */
dialog { width: min(560px, calc(100vw - 2 * var(--gap))); max-height: calc(100vh - 2 * var(--gap)); overflow: auto;
  background: #141722; color: var(--fg); border: 1px solid var(--panel-border); border-radius: 14px; padding: 18px 20px; }
dialog::backdrop { background: rgb(4 5 8 / 0.55); backdrop-filter: blur(2px); }
dialog h2 { text-transform: none; letter-spacing: 0; font-size: 18px; color: var(--fg); margin: 0 0 6px; }
dialog .hint { color: var(--muted); margin-bottom: 14px; }
dialog label { display: block; font-size: 13px; font-weight: 500; margin: 10px 0 5px; }
dialog .opt { color: var(--muted); font-weight: 400; }
dialog input, dialog textarea { width: 100%; font: inherit; color: var(--fg); background: #0c0e14; border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 9px 10px; }
dialog textarea { resize: vertical; min-height: 130px; }
dialog input:focus-visible, dialog textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
dialog .field-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 4px; }
dialog .submit-status { min-height: 1.5em; margin: 12px 0 0; font-size: 13px; }
dialog .submit-status[data-kind="error"] { color: var(--err); }
dialog .submit-status[data-kind="wait"] { color: var(--warn); }
dialog .submit-status[data-kind="ok"] { color: var(--live); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
dialog .actions button { font: inherit; font-size: 14px; color: var(--fg); background: rgb(255 255 255 / 0.06); border: 1px solid var(--panel-border);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 38px; }
.controls button.primary, dialog .actions button.primary { background: var(--accent); border-color: var(--accent); color: #1a0710; font-weight: 600; }
.controls button.primary:hover, dialog .actions button.primary:hover { background: #ff7ba1; }
dialog .actions button:disabled { opacity: 0.55; cursor: progress; }
dialog button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.detail .mine { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: #1a0710; background: var(--accent); border-radius: 4px; padding: 1px 6px; margin-bottom: 6px; }
.detail-actions { margin-top: 12px; }
.detail-actions .danger { font: inherit; font-size: 13px; color: var(--err); background: none; border: 1px solid rgb(255 107 107 / 0.45);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.detail-actions .danger:hover { background: rgb(255 107 107 / 0.1); }

.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-actions button:not(.danger) { font: inherit; font-size: 13px; color: var(--fg); background: rgb(255 255 255 / 0.06);
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.detail-actions button:hover:not(.danger) { background: rgb(255 255 255 / 0.12); }
.detail-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.detail-actions .origin { flex-basis: 100%; min-height: 1.2em; overflow-wrap: anywhere; }
.detail .badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--panel-border); border-radius: 4px; padding: 0 5px; margin: 0 0 6px 4px; }
.detail .badge.featured { color: var(--accent); border-color: rgb(255 90 138 / 0.5); }
.detail-actions .primary { color: #1a0710 !important; background: var(--accent) !important; border-color: var(--accent) !important; font-weight: 600 !important; }
.detail .private-note { margin-top: 10px; color: var(--muted); font-size: 13px; font-style: italic; }

/* ---- visibility choice (add-a-text modal) -------------------------------- */
dialog fieldset.visibility { border: 1px solid var(--panel-border); border-radius: 8px; margin: 12px 0 0; padding: 6px 12px 10px; }
dialog fieldset.visibility legend { font-size: 13px; font-weight: 500; padding: 0 4px; }
dialog fieldset.visibility label { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; font-weight: 400; margin: 6px 0 0; cursor: pointer; }
dialog fieldset.visibility input { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
dialog fieldset.visibility .opt { display: block; font-size: 12px; }

/* ---- semantic search ------------------------------------------------------ */
.search { display: flex; gap: 6px; margin-top: 10px; }
.search[hidden], .search-results[hidden] { display: none; }
.search input { flex: 1; min-width: 0; font: inherit; font-size: 13px; color: var(--fg); background: #0c0e14;
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 9px; }
.search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.search button, .search-results .link { font: inherit; font-size: 13px; color: var(--fg); background: rgb(255 255 255 / 0.06);
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.search button:hover { background: rgb(255 255 255 / 0.12); }
.search button:focus-visible, .search-results .link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search button:disabled { opacity: 0.55; cursor: progress; }
.search-results { margin-top: 8px; }
.search-status { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.search-status[data-kind="error"] { color: var(--err); }
.search-results .link { background: none; border: 0; padding: 4px 0 0; color: var(--accent); }
.search-results .link:hover { text-decoration: underline; }
.search-results .feed button { grid-template-columns: 10px 1fr auto; align-items: center; padding: 3px 6px; }
.search-results .feed i { margin-top: 0; }
.search-results .score { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---- hide / show panels ------------------------------------------------ */
.panels-toggle { position: fixed; z-index: 3; top: var(--gap); right: var(--gap); width: 44px; height: 44px;
  display: grid; place-items: center; border-radius: 50%; cursor: pointer; color: var(--fg);
  background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.panels-toggle:hover { background: rgb(40 44 58 / 0.9); }
.panels-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.panels-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.panels-toggle .icon-eye-off, .panels-toggle[aria-pressed="true"] .icon-eye { display: none; }
.panels-toggle[aria-pressed="true"] .icon-eye-off { display: block; }
/* with panels hidden only the map and this button remain */
body.ui-hidden #ui-panels { display: none; }
/* desktop: the feed sits below the toggle */
.top-right { top: calc(var(--gap) + 52px); }
.short { display: none; }
.count-compact { display: none; }

@media (max-width: 760px) {
  :root { --gap: 10px; }
  html, body { font-size: 13px; }
  /* header: one compact line, leaving room for the toggle */
  .top-left { right: calc(var(--gap) + 52px); max-width: none; padding: 8px 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .top-left h1 { font-size: 16px; margin: 0; }
  .top-left .lede, .top-left .activity { display: none; }
  .search, .search-results { flex-basis: 100%; margin-top: 2px; }
  .search-results #search-top { display: none; }
  .live { margin: 0; }
  .count-compact { display: inline; color: var(--muted); font-variant-numeric: tabular-nums; }
  .count-compact::before { content: "·"; margin: 0 6px; }
  .top-right { display: none; }
  /* legend: collapsed to a single line by default, opens upward over the map */
  .bottom-left { left: var(--gap); right: var(--gap); max-width: none; bottom: calc(var(--gap) + 52px); padding: 8px 12px; max-height: 50vh; overflow: auto; }
  .legend-panel h2 { margin: 0; }
  /* controls: one row */
  .bottom-right { left: var(--gap); right: var(--gap); flex-wrap: nowrap; justify-content: space-between; gap: 4px; padding: 6px; }
  .controls button { flex: 1 1 0; padding: 6px 4px; min-height: 36px; font-size: 12px; }
  .long, .readouts, .drag-help { display: none; }
  .short { display: inline; }
  dialog { padding: 14px; }
  dialog textarea { min-height: 110px; }
  .detail { top: auto; bottom: calc(var(--gap) + 52px); transform: none; left: var(--gap); right: var(--gap); width: auto; max-height: 45vh; }
}
@media (prefers-reduced-motion: reduce) { .live[data-state="live"] .dot { animation: none; } }
