/* ==========================================================================
   AYITI ATLAS — 3D map page
   Uses the atlas variable set; everything else is map-specific.
   ========================================================================== */

.map-hero { padding: 56px 0 26px; }
.map-hero h1 {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(42px, 7vw, 82px); line-height: .92; letter-spacing: -.03em;
  margin: 18px 0 16px; max-width: 18ch;
}
.map-hero .lede { max-width: 76ch; color: var(--ink-2); font-size: 16px; }

.map-key-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.key-pill {
  display: inline-flex; align-items: baseline; gap: 7px;
  padding: 6px 11px; border: 1px solid var(--line-soft); border-radius: 999px;
  background: var(--bg-2);
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--ink-3);
}
.key-pill b { color: var(--ink); font-size: 12px; letter-spacing: 0; }

/* ----------------------------------------------------------------- layout */
.map-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 372px;
  gap: 16px; align-items: start; padding-bottom: 8px;
}
.map-main { min-width: 0; }

.stage {
  position: relative; overflow: hidden;
  height: clamp(500px, 68vh, 720px);
  border: 1px solid var(--line); border-radius: var(--r);
  background:
    radial-gradient(120% 90% at 50% 8%, color-mix(in srgb, var(--teal) 9%, transparent), transparent 62%),
    linear-gradient(180deg, var(--panel), var(--bg-2));
  box-shadow: var(--shadow);
  isolation: isolate;
}
#map-canvas {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%;
  touch-action: none; cursor: grab;
}
#map-canvas.is-dragging { cursor: grabbing; }
#map-canvas.is-hovering { cursor: pointer; }

.stage-top {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 4;
  display: flex; justify-content: space-between; gap: 8px; pointer-events: none;
}
.layer-toggles { display: flex; flex-wrap: wrap; gap: 6px; pointer-events: auto; }
.map-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 29px; padding: 0 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 84%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--line); color: var(--ink-3);
  font-size: 11.5px; cursor: pointer;
  transition: color .16s, border-color .16s, background .16s;
}
.map-toggle:hover { color: var(--ink); border-color: var(--ink-3); }
.map-toggle.is-on { color: var(--ink); border-color: color-mix(in srgb, var(--ink-3) 60%, var(--line)); }
.map-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw { width: 7px; height: 7px; border-radius: 50%; flex: none; opacity: .38; }
.map-toggle.is-on .sw { opacity: 1; }
.sw-city { background: var(--blue); }
.sw-road { background: var(--ink-2); }
.sw-gang { background: var(--red); }
.sw-label { background: var(--gold); }
.sw-spin { background: var(--teal); }

.stage-hint {
  position: absolute; left: 50%; bottom: 12px; z-index: 3;
  transform: translateX(-50%);
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .04em;
  color: var(--ink-3); white-space: nowrap; pointer-events: none;
  transition: opacity .4s;
}
.stage-hint.is-faded { opacity: 0; }

.map-legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 3;
  display: grid; gap: 5px; padding: 9px 11px;
  border: 1px solid var(--line-soft); border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-family: var(--font-mono); font-size: 9px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
  pointer-events: none;
}
.legend-row { display: flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 9px; height: 9px; border-radius: 2px; flex: none; }
.lg-dept { background: linear-gradient(90deg, var(--teal), var(--gold)); }
.lg-road { height: 2px; border-radius: 1px; background: var(--ink-2); }
.lg-road2 { height: 1px; border-radius: 1px; background: color-mix(in srgb, var(--ink-2) 70%, transparent); }
.lg-city { border-radius: 50%; background: var(--blue); }
.lg-gang { background: var(--red); transform: rotate(45deg); border-radius: 1px; }
.lg-contested { background: transparent; border: 1px solid var(--red); border-radius: 50%; }

.stage-attr {
  position: absolute; right: 12px; bottom: 12px; z-index: 3;
  max-width: 46%; text-align: right;
  font-family: var(--font-mono); font-size: 9px; line-height: 1.5;
  color: var(--ink-3); opacity: .8; pointer-events: none;
}

.tooltip {
  position: absolute; z-index: 6; pointer-events: none;
  transform: translate(14px, -50%);
  max-width: 218px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); box-shadow: var(--shadow);
  font-size: 12px; line-height: 1.4;
}
.tooltip[hidden] { display: none; }
.tooltip .tt-k {
  display: block; margin-bottom: 2px;
  font-family: var(--font-mono); font-size: 9px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
}
.tooltip b { font-weight: 600; }
.tooltip .tt-s { color: var(--ink-3); font-size: 11px; }

.webgl-fallback {
  position: absolute; inset: 0; z-index: 7;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 32px; text-align: center;
  background: var(--bg-2);
}
.webgl-fallback[hidden] { display: none; }
.webgl-fallback b { font-size: 15px; }
.webgl-fallback p { max-width: 42ch; color: var(--ink-2); font-size: 13px; }

.stage-note { margin-top: 10px; font-size: 12px; color: var(--ink-3); line-height: 1.55; }

/* ---------------------------------------------------------------- labels */
.stage-labels {
  position: absolute; inset: 0; z-index: 3;
  pointer-events: none; overflow: hidden;
}
.stage-labels.is-off { display: none; }
.map-label {
  position: absolute; left: 0; top: 0;
  white-space: nowrap; pointer-events: none;
  will-change: transform;
  transition: opacity .12s;
}
.map-label.is-hidden { opacity: 0; visibility: hidden; }
.map-label-dept {
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 600;
  letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-2);
  opacity: .9;
  text-shadow: 0 1px 3px color-mix(in srgb, var(--bg) 85%, transparent), 0 0 8px color-mix(in srgb, var(--bg) 60%, transparent);
}
.map-label-gang {
  display: inline-flex; align-items: center;
  padding: 2px 6px; border-radius: 4px;
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  border: 1px solid color-mix(in srgb, var(--red) 38%, var(--line));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  font-size: 10px; font-weight: 500; color: var(--ink);
  box-shadow: 0 4px 14px -8px rgba(0, 0, 0, .8);
}
@media (max-width: 760px) {
  .map-label-dept { font-size: 8.5px; letter-spacing: .1em; }
  .map-label-gang { font-size: 9px; padding: 1px 5px; }
}

/* ----------------------------------------------------------------- detail */
.detail {
  position: sticky; top: 78px;
  max-height: calc(100vh - 96px); overflow: auto;
  padding: 18px;
}
.detail-empty .detail-lede { color: var(--ink-2); font-size: 13.5px; }
.detail-empty .note { margin-top: 16px; }

.detail-kicker {
  display: flex; align-items: center; gap: 7px; margin-bottom: 9px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3);
}
.detail-kicker .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.detail h2 {
  font-family: var(--font-display); font-weight: 600;
  font-size: 27px; line-height: 1.08; letter-spacing: -.02em;
}
.detail-sub { margin-top: 5px; color: var(--ink-3); font-size: 12.5px; }
.detail-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 14px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 5px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .04em;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2);
}
.badge.severe, .badge.controlled { color: #ff9a8c; border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }
.badge.high, .badge.contested { color: #e8b37a; border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.badge.elevated, .badge.disputed { color: var(--ink-2); }
.badge.low { color: #a8c07a; border-color: color-mix(in srgb, var(--green) 34%, var(--line)); }

.detail-facts { display: grid; gap: 0; margin: 0; }
.detail-facts > div {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 7px 0; border-bottom: 1px solid var(--line-soft);
}
.detail-facts > div:last-child { border-bottom: 0; }
.detail-facts dt { font-size: 11.5px; color: var(--ink-3); }
.detail-facts dd {
  margin: 0; text-align: right; font-family: var(--font-mono);
  font-size: 12px; color: var(--ink);
}

.detail-section { margin-top: 16px; }
.detail-section h4 {
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 7px;
}
.detail-section p { font-size: 13px; color: var(--ink-2); line-height: 1.55; }

.rev-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.rev-chips span {
  padding: 3px 8px; border-radius: 5px;
  background: var(--bg-2); border: 1px solid var(--line-soft);
  font-size: 11px; color: var(--ink-2);
}

.detail-note {
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line-soft);
  font-size: 11.5px; line-height: 1.55; color: var(--ink-3);
}
.detail-actions { display: flex; gap: 8px; margin-top: 14px; }
.detail-btn {
  flex: 1; height: 32px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--ink-2); font-size: 12px; cursor: pointer;
}
.detail-btn:hover { color: var(--ink); border-color: var(--ink-3); }

/* ------------------------------------------------------------------ index */
.map-index-wrap { padding: 22px 0 64px; }
.index-tools {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  justify-content: space-between; gap: 14px; margin-bottom: 14px;
}
.index-search { width: min(320px, 100%); }
.place-index {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px; background: var(--line-soft);
  border: 1px solid var(--line-soft); border-radius: 10px; overflow: auto;
  max-height: 424px;
}
.place-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 0; text-align: left;
  background: var(--bg-2); color: var(--ink-2);
  cursor: pointer; font-size: 13px;
  transition: background .14s, color .14s;
}
.place-item:hover { background: var(--panel-2); color: var(--ink); }
.place-item.is-selected { background: var(--panel-2); color: var(--ink); box-shadow: inset 2px 0 0 var(--accent); }
.place-item .pi-sw {
  width: 8px; height: 8px; border-radius: 2px; flex: none;
  background: var(--ink-3);
}
.place-item[data-kind="city"] .pi-sw { border-radius: 50%; background: var(--blue); }
.place-item[data-kind="gang"] .pi-sw { transform: rotate(45deg); background: var(--red); }
.place-item[data-kind="dept"] .pi-sw { background: var(--gold); }
.place-item .pi-txt { min-width: 0; flex: 1; }
.place-item .pi-txt b { display: block; font-weight: 500; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place-item .pi-txt small { display: block; font-size: 10.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place-item .pi-val { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); flex: none; }

.map-method { display: grid; gap: 16px; margin-top: 16px; }
.map-method .facts { display: grid; gap: 11px; }
.map-method .facts p { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
.map-method .facts b { color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1020px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .detail { position: static; max-height: none; }
  .map-method { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .map-hero { padding: 40px 0 20px; }
  .stage { height: clamp(320px, 46vh, 560px); min-height: 0; }
  .map-legend { display: none; }
  .stage-attr { display: none; }
  .stage-hint { bottom: 10px; font-size: 9.5px; }
  .place-index { grid-template-columns: minmax(0, 1fr); max-height: 380px; }
  .map-method { grid-template-columns: minmax(0, 1fr); }
  .layer-toggles { gap: 4px; }
  .map-toggle { padding: 0 8px; font-size: 10.5px; height: 27px; }
}
@media (prefers-reduced-motion: reduce) {
  .stage-hint { transition: none; }
}
@media print {
  .stage, .stage-note, .layer-toggles { display: none; }
  .map-layout { display: block; }
}
