/* Terminus Noir: black surfaces, 1 px borders, white primary. Full-screen map, floating panels. */
@font-face { font-family: "Saira Condensed"; font-weight: 600; font-display: swap; src: local("Saira Condensed SemiBold"), url("fonts/saira-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Saira Condensed"; font-weight: 700; font-display: swap; src: local("Saira Condensed Bold"), url("fonts/saira-condensed-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: local("IBM Plex Mono"), url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap; src: local("IBM Plex Mono Medium"), url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }

:root {
  --bg: #050506;
  --panel: rgba(10, 10, 12, 0.92);
  --line: #2a2a2f;
  --fg: #ececef;
  --muted: #8b8b94;
  --hover: #16161a;
  --primary: #ffffff;
  --town: #ffffff;
  --road: #f2c14e;
  --view: #ff4b4b;
  --display: "Saira Condensed", "Bahnschrift SemiCondensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --gutter: max(12px, env(safe-area-inset-left, 0px));
  --gutter-r: max(12px, env(safe-area-inset-right, 0px));
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); overflow: hidden; font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--primary); outline-offset: 1px; }
[hidden] { display: none !important; }

.app { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 600; font-size: 14px; margin-left: 8px; letter-spacing: 0.12em; }

/* Segmented mode switch */
.seg { margin-left: auto; display: flex; border: 1px solid var(--line); }
.seg button { all: unset; cursor: pointer; padding: 5px 14px; font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--fg); }
.seg button[aria-checked="true"] { background: var(--primary); color: #000; }
.seg button:focus-visible { outline: 1px solid var(--primary); outline-offset: 2px; }

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#map { position: absolute !important; inset: 0; width: 100%; height: 100%; background: #0b0b0c; }
#map .openseadragon-canvas:focus-visible { outline: 1px solid var(--primary); outline-offset: -2px; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
#labels > div { position: absolute; left: 0; top: 0; will-change: transform; }

/* Town panel */
.panel {
  position: absolute; top: 12px; left: var(--gutter); z-index: 5;
  width: 230px; max-height: calc(100% - 72px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
}
.panel h2 { margin: 0; padding: 10px 12px; font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.panel h2 button { all: unset; cursor: pointer; color: var(--fg); font-size: 18px; line-height: 1; width: 24px; height: 24px; display: grid; place-items: center; }
.panel h2 button:focus-visible { outline: 1px solid var(--primary); }
.panel.closed h2 { border-bottom: 0; }
.panel.closed .body { display: none; }
.body { display: flex; flex-direction: column; min-height: 0; }
#search { margin: 10px 12px 6px; padding: 7px 9px; background: #000; border: 1px solid var(--line); border-radius: 0; min-width: 0; }
#search:focus-visible { outline: 1px solid var(--primary); outline-offset: 0; }
.towns { list-style: none; margin: 0; padding: 4px 0 8px; overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.towns button { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; padding: 7px 12px; display: flex; justify-content: space-between; gap: 8px; }
.towns button:hover, .towns button:focus-visible { background: var(--hover); }
.towns button:focus-visible { outline: 1px solid var(--primary); outline-offset: -1px; }
.towns .xy { font-family: var(--mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.towns .empty { padding: 7px 12px; color: var(--muted); }
.layers { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.layers label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.layers input[type="checkbox"] { accent-color: #fff; margin: 0; }
.iso-only { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
#mods { display: flex; flex-direction: column; gap: 6px; }
.floor { justify-content: space-between; }
.floor select { background: #000; border: 1px solid var(--line); padding: 4px 6px; border-radius: 0; }
.sw { width: 10px; height: 10px; border: 1px solid var(--line); flex: none; }
.sw-town { background: var(--town); }
.sw-road { background: var(--road); }
.sw-mod { background: #7fd1a0; }

/* Minimap */
.mini { position: absolute; top: 12px; right: var(--gutter-r); width: 160px; border: 1px solid var(--line); background: #000; z-index: 5; cursor: pointer; }
.mini img { display: block; width: 100%; height: auto; }
.mini svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; pointer-events: none; }
.mini polygon { fill: rgba(255, 75, 75, 0.12); stroke: var(--view); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* Bottom bar */
.controls { position: absolute; right: var(--gutter-r); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 6px; z-index: 5; }
.controls button { all: unset; cursor: pointer; min-width: 36px; height: 36px; padding: 0 10px; box-sizing: border-box; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); font-family: var(--display); font-weight: 600; font-size: 17px; letter-spacing: 0.08em; }
.controls button:hover { border-color: var(--muted); }
.controls button:focus-visible { outline: 1px solid var(--primary); outline-offset: 1px; }
.controls button.primary { background: var(--primary); color: #000; border-color: var(--primary); }
.coords { position: absolute; left: var(--gutter); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 5; background: var(--panel); border: 1px solid var(--line); padding: 7px 10px; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.coords b { color: var(--fg); font-weight: 500; display: inline-block; min-width: 3ch; }
.status { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 6; background: var(--panel); border: 1px solid var(--line); padding: 7px 12px; font-family: var(--mono); font-size: 12px; color: var(--fg); max-width: calc(100% - 24px); }

/* Labels */
.lbl-town { font-family: var(--display); font-weight: 700; font-size: 15px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--town); white-space: nowrap; text-shadow: 0 0 3px #000, 0 0 6px #000, 0 0 2px #000; }
.lbl-road { font-family: var(--mono); font-size: 10px; font-weight: 500; color: #000; background: var(--road); padding: 1px 4px; white-space: nowrap; }
.hide-towns .lbl-town, .hide-roads .lbl-road, .far .lbl-road { display: none; }
.pin { width: 14px; height: 14px; border: 2px solid var(--primary); border-radius: 50%; box-shadow: 0 0 0 2px #000; animation: ping 1.2s ease-out 2; }
@keyframes ping { from { box-shadow: 0 0 0 2px #000, 0 0 0 0 rgba(255,255,255,.7); } to { box-shadow: 0 0 0 2px #000, 0 0 0 18px rgba(255,255,255,0); } }
@media (prefers-reduced-motion: reduce) { .pin { animation: none; } }

@media (max-width: 560px) {
  .brand { font-size: 19px; }
  .brand small { display: none; }
  .seg button { padding: 5px 10px; }
  .panel { right: var(--gutter-r); width: auto; max-height: 50%; }
  .mini { display: none; }
  .coords { bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
}
