/* ==========================================================================
   NECROMAP: industrial grimdark cogitator theme
   ========================================================================== */
:root {
  --bg: #0d0f12;
  --bg-1: #14171c;
  --bg-2: #1b1f26;
  --bg-3: #252a33;
  --line: #2f3640;
  --line-2: #3d4652;
  --ink: #c9ced6;
  --ink-dim: #7d8794;
  --hazard: #e5a93c;
  --hazard-dim: #8a6524;
  --phos: #39ff14;
  --phos-dim: #1e7a10;
  --blood: #ff4b3e;
  --mono: ui-monospace, "JetBrains Mono", "IBM Plex Mono", "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 3px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --drawer-w: 400px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--mono); }
body { overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--hazard); color: var(--bg); }

#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  grid-template-areas: "top" "stage" "sub" "tools";
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 40px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: var(--r);
  background: linear-gradient(var(--bg-3), var(--bg-2)); color: var(--ink);
  letter-spacing: .08em; text-transform: uppercase; font-size: 12px; cursor: pointer;
  box-shadow: inset 0 1px 0 #ffffff0d, 0 1px 0 #000;
}
.btn:hover { border-color: var(--hazard-dim); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .tool:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--phos); outline-offset: 2px;
}
.btn.icon { width: 40px; padding: 0; font-size: 18px; }
.btn.primary { background: var(--hazard); color: #15110a; border-color: #f5c46a; font-weight: 700; }
.btn.primary:hover { background: #f0b74d; }
.btn.danger { border-color: #7a2520; color: var(--blood); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.busy { position: relative; color: transparent; }
.btn.busy::after { content: "▮▮▮"; position: absolute; color: #15110a; animation: blink 0.8s steps(3) infinite; }

/* ---------- top bar ---------- */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 8px;
  padding: calc(6px + var(--safe-t)) 8px 6px;
  background: repeating-linear-gradient(-45deg, #0000 0 10px, #e5a93c0d 10px 20px), var(--bg-1);
  border-bottom: 2px solid var(--hazard);
  box-shadow: 0 2px 0 #000, 0 6px 20px #0008; z-index: 5;
}
.campaign-title {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 2px 4px; cursor: pointer;
  display: flex; flex-direction: column;
}
.campaign-title .eyebrow { font-size: 10px; color: var(--hazard); letter-spacing: .25em; }
#campaign-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.sync-chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--line);
  font-size: 10px; letter-spacing: .12em; color: var(--ink-dim); background: #0008; border-radius: var(--r);
  max-width: 34vw; white-space: nowrap; overflow: hidden;
}
.led { width: 8px; height: 8px; border-radius: 50%; background: #555; flex: none; box-shadow: 0 0 0 1px #000; }
.led.ok { background: var(--phos); box-shadow: 0 0 8px var(--phos); }
.led.stale { background: var(--hazard); box-shadow: 0 0 8px var(--hazard); }
.led.err { background: var(--blood); box-shadow: 0 0 8px var(--blood); }
.led.busy { background: var(--phos); animation: blink .5s steps(2) infinite; }
@media (max-width: 520px) { .sync-chip #sync-text { display: none; } .topbar .btn.primary { padding: 0 10px; } }

/* ---------- stage / map ---------- */
.stage { grid-area: stage; position: relative; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #151a14, var(--bg) 70%); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; display: block; }
#map:active { cursor: grabbing; }
.scanlines, .vignette { position: absolute; inset: 0; pointer-events: none; }
.scanlines { background: repeating-linear-gradient(to bottom, #0000 0 2px, #00000038 2px 3px); mix-blend-mode: multiply; animation: roll 8s linear infinite; }
.vignette { box-shadow: inset 0 0 120px #000c; }
@keyframes roll { to { background-position: 0 30px; } }
@media (prefers-reduced-motion: reduce) { .scanlines { animation: none; } * { animation-duration: 0s !important; } }

.hud { position: absolute; font-size: 11px; letter-spacing: .15em; color: var(--phos); text-shadow: 0 0 6px var(--phos-dim); pointer-events: none; padding: 4px 8px; background: #000a; border: 1px solid #39ff1433; }
.hud-tl { top: 8px; left: 8px; max-width: calc(100% - 72px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .hud { font-size: 9px; letter-spacing: .1em; } }
.hud-br { bottom: 8px; left: 8px; }
.zoom-stack { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }

/* SVG world */
.world-base { fill: #0b0d0f; }
.world-frame { fill: none; stroke: var(--hazard-dim); stroke-width: 6; stroke-dasharray: 40 20; }
.grid-line { fill: none; stroke: #39ff140d; stroke-width: 1.5; }
.bg-image image { image-rendering: auto; }

/* procedural sector */
.pg-sump { fill: #0a1a1c; stroke: #1c4b4f; stroke-width: 4; }
.pg-sump-ripple { fill: none; stroke: #1c4b4f66; stroke-width: 2; stroke-dasharray: 18 14; }
.pg-spire { fill: #12161b; stroke: var(--hazard-dim); stroke-width: 5; }
.pg-spire-core { fill: #1d140a; stroke: var(--hazard); stroke-width: 6; }
.pg-dome { fill: #11151a; stroke: #3a434e; stroke-width: 8; }
.pg-dome-ring { fill: none; stroke: #39ff1418; stroke-width: 3; stroke-dasharray: 6 10; }
.pg-hex { fill: none; stroke: #ffffff0a; stroke-width: 2; }
.pg-corridor { fill: none; stroke: #1a1f26; stroke-width: 70; stroke-linecap: round; }
.pg-corridor-core { fill: none; stroke: #2a313b; stroke-width: 4; stroke-dasharray: 30 18; }
.pg-pipe { fill: none; stroke: #5a3d1a55; stroke-width: 10; }
.pg-rubble { fill: #262c34; }
.pg-label, .pg-sublabel, .pg-title { font-family: var(--mono); text-anchor: middle; fill: var(--ink-dim); pointer-events: none; }
.pg-label { font-size: 34px; letter-spacing: 8px; font-weight: 700; fill: #6f7a86; }
.pg-label--sump { fill: #2f7f86; }
.pg-label--spire { fill: var(--hazard-dim); }
.pg-sublabel { font-size: 20px; letter-spacing: 4px; fill: #4a5560; }
.pg-title { text-anchor: start; font-size: 40px; letter-spacing: 10px; fill: #39ff1455; }

/* routes */
.route .rt-hit { fill: none; stroke: transparent; stroke-width: 40; pointer-events: stroke; }
.route .rt-casing { fill: none; stroke: #000; stroke-width: 14; stroke-linecap: round; opacity: .8; pointer-events: none; }
.route .rt-line { fill: none; stroke: var(--rt); stroke-width: 6; stroke-linecap: round; filter: drop-shadow(0 0 6px var(--rt)); pointer-events: none; }
.route.rt-supply .rt-line { stroke-dasharray: 26 16; animation: flow 1.6s linear infinite; }
.route.selected .rt-casing { stroke: var(--hazard); opacity: 1; }
@keyframes flow { to { stroke-dashoffset: -42; } }

/* fog */
.fog-base { fill: #050607; opacity: .9; }
.fog-scan { fill: #39ff1410; }

/* territory nodes */
.node { cursor: pointer; }
.terr .hex-halo { fill: #000a; stroke: var(--line-2); stroke-width: 3; }
.terr .hex { fill: #2a2f37; stroke: #000; stroke-width: 5; }
.terr.unowned .hex { fill: #1a1e24; stroke: #6b7280; stroke-dasharray: 10 6; }
.terr .hex-inner { fill: none; stroke: #ffffff40; stroke-width: 2; }
.terr .hex-ruin { opacity: .55; pointer-events: none; }
.ruin-stripe { fill: #000; }
.terr.ruined .hex-halo { stroke: var(--blood); }
.node-glyph { font-family: var(--mono); font-size: 28px; font-weight: 800; text-anchor: middle; dominant-baseline: central; fill: var(--ink); pointer-events: none; letter-spacing: 1px; }
.node-label { font-family: var(--mono); font-size: 22px; font-weight: 700; text-anchor: middle; fill: #e8eaee; letter-spacing: 2px; paint-order: stroke; stroke: #000; stroke-width: 6px; stroke-linejoin: round; pointer-events: none; }
.node-sub { font-family: var(--mono); font-size: 17px; text-anchor: middle; fill: var(--hazard); paint-order: stroke; stroke: #000; stroke-width: 5px; pointer-events: none; }
.terr.orphaned { opacity: .5; }
.terr.orphaned .node-sub { fill: var(--blood); }
.terr.fogged .hex { fill: #0f1215; stroke: #39ff1455; stroke-dasharray: 4 6; }
.terr.fogged .node-glyph { fill: var(--phos); }
.terr.fogged .node-label { fill: #39ff1499; font-size: 18px; }
.terr.shift .hex-halo { stroke: var(--phos); animation: pulse 1.4s ease-in-out infinite; }
.node.selected .hex-halo, .node.selected .mk-halo { stroke: var(--hazard); stroke-width: 6; fill: #e5a93c22; }
.node.route-from .hex-halo, .node.route-from .mk-halo { stroke: var(--phos); stroke-width: 8; animation: pulse .8s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-opacity: .25; } }
#map.tool-arrange .node { cursor: move; }
/* Hide labels when zoomed far out */
#map[data-far="1"] .node-sub, #map[data-far="1"] .mk-label { display: none; }

/* markers */
.marker .mk-halo { fill: #000b; stroke: var(--mk); stroke-width: 3; }
.marker .mk-body { fill: #0d0f12; stroke: var(--mk); stroke-width: 4; }
.marker .mk-glyph { font-size: 28px; text-anchor: middle; dominant-baseline: central; fill: var(--mk); pointer-events: none; }
.marker .mk-label { font-size: 18px; fill: var(--mk); }

/* ---------- toolbar ---------- */
.toolbar {
  grid-area: tools; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
  background: var(--bg-1); border-top: 2px solid var(--line); padding: 4px 4px calc(4px + var(--safe-b));
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; min-height: 52px;
  background: none; border: 1px solid transparent; border-radius: var(--r); color: var(--ink-dim);
  font-size: 10px; letter-spacing: .14em; cursor: pointer;
}
.tool .ti { font-size: 20px; line-height: 1; }
.tool[aria-pressed="true"] { color: var(--phos); border-color: #39ff1455; background: #39ff140d; text-shadow: 0 0 8px var(--phos-dim); }
.subbar {
  grid-area: sub; display: flex; gap: 6px; overflow-x: auto; padding: 6px 8px; background: #0b0d10;
  border-top: 1px solid var(--line); scrollbar-width: none;
}
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line-2);
  border-radius: 999px; background: var(--bg-2); font-size: 11px; letter-spacing: .08em; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { border-color: var(--hazard); color: var(--hazard); background: #e5a93c14; }
.chip .sw { width: 10px; height: 10px; border-radius: 2px; background: var(--c); box-shadow: 0 0 6px var(--c); }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; z-index: 20; background: linear-gradient(#171b21, #101317);
  border: 1px solid var(--line-2); box-shadow: 0 -10px 40px #000c;
  transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column;
}
.drawer::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: repeating-linear-gradient(-45deg, var(--hazard) 0 8px, #111 8px 16px); }
.drawer-body { overflow-y: auto; padding: 18px 16px calc(16px + var(--safe-b)); overscroll-behavior: contain; }
@media (max-width: 799px) {
  .drawer { left: 0; right: 0; bottom: 0; max-height: 72dvh; border-radius: 10px 10px 0 0; transform: translateY(105%); }
  .drawer.open { transform: none; }
  .drawer-grip { height: 22px; flex: none; display: grid; place-items: center; cursor: grab; touch-action: none; }
  .drawer-grip::after { content: ""; width: 44px; height: 4px; border-radius: 2px; background: var(--line-2); margin-top: 8px; }
}
@media (min-width: 800px) {
  .drawer { top: 64px; right: 10px; bottom: 80px; width: var(--drawer-w); transform: translateX(calc(100% + 20px)); }
  .drawer.open { transform: none; }
  .drawer-grip { display: none; }
}

.d-eyebrow { font-size: 10px; letter-spacing: .3em; color: var(--hazard); }
.d-title { font-size: 20px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; margin: 2px 0 10px; word-break: break-word; }
.d-title input { width: 100%; }
.d-close { position: absolute; right: 10px; top: 14px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 10px 0 14px; font-size: 13px; }
.kv dt { color: var(--ink-dim); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; padding-top: 2px; }
.kv dd { margin: 0; }
.gang-pill { display: inline-flex; align-items: center; gap: 8px; }
.gang-pill .sw { width: 14px; height: 14px; border-radius: 3px; background: var(--c); border: 1px solid #000; box-shadow: 0 0 8px var(--c); }
.tag { display: inline-block; padding: 1px 7px; border: 1px solid currentColor; border-radius: 2px; font-size: 10px; letter-spacing: .14em; margin-right: 4px; }
.tag.red { color: var(--blood); } .tag.amber { color: var(--hazard); } .tag.green { color: var(--phos); } .tag.dim { color: var(--ink-dim); }
.section { border-top: 1px dashed var(--line-2); padding-top: 12px; margin-top: 12px; }
.section h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .25em; color: var(--phos); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { background: #0006; border: 1px solid var(--line); padding: 6px; text-align: center; }
.stat b { display: block; font-size: 16px; color: var(--hazard); }
.stat span { font-size: 9px; letter-spacing: .14em; color: var(--ink-dim); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }
.battle { font-size: 12px; padding: 6px 8px; border-left: 2px solid var(--hazard-dim); background: #0005; margin-bottom: 6px; }
.battle time { color: var(--ink-dim); font-size: 11px; }
.hint { font-size: 11px; color: var(--ink-dim); margin: 6px 0; }

/* ---------- forms ---------- */
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 10px; letter-spacing: .2em; color: var(--ink-dim); margin-bottom: 4px; text-transform: uppercase; }
input[type=text], input[type=url], input[type=search], textarea, select {
  width: 100%; background: #07090b; border: 1px solid var(--line-2); border-radius: var(--r); padding: 10px;
  color: var(--phos); caret-color: var(--hazard); font-size: 14px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
textarea.notes { min-height: 140px; background: repeating-linear-gradient(#07090b 0 23px, #39ff1410 23px 24px); }
input[type=color] { width: 44px; height: 36px; padding: 0; border: 1px solid var(--line-2); background: none; border-radius: var(--r); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--phos); }

/* ---------- dialogs ---------- */
dialog.panel {
  width: min(640px, 100vw); max-height: min(88dvh, 900px); padding: 0; border: 1px solid var(--hazard-dim);
  background: var(--bg-1); color: var(--ink); border-radius: 6px; box-shadow: 0 20px 80px #000;
}
dialog.panel::backdrop { background: #000b; backdrop-filter: blur(2px); }
@media (max-width: 640px) { dialog.panel { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; } }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 2px solid var(--hazard); background: var(--bg-2); position: sticky; top: 0; z-index: 1; }
.panel-title { flex: 1; letter-spacing: .2em; font-size: 12px; color: var(--hazard); padding-left: 6px; }
.tabs { flex: 1; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tab { flex: none; padding: 8px 10px; background: none; border: 1px solid transparent; font-size: 11px; letter-spacing: .14em; color: var(--ink-dim); cursor: pointer; border-radius: var(--r); }
.tab[aria-selected="true"] { color: var(--phos); border-color: #39ff1444; background: #39ff140a; }
.panel-body { padding: 14px 16px 24px; overflow-y: auto; max-height: calc(88dvh - 60px); }
@media (max-width: 640px) { .panel-body { max-height: calc(100dvh - 60px); } }
.panel h3 { font-size: 12px; letter-spacing: .25em; color: var(--hazard); margin: 18px 0 8px; font-weight: 600; }
.panel h3:first-child { margin-top: 0; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); background: #0005; border-radius: var(--r); }
.list-item.active { border-color: var(--phos); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow small { display: block; color: var(--ink-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trail { font-size: 12px; padding: 8px; background: #000; border: 1px solid var(--line); color: var(--phos); white-space: pre-wrap; word-break: break-word; }
.report li { margin: 3px 0; }
code { color: var(--hazard); word-break: break-all; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: calc(64px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 460px); pointer-events: none; }
.toast { pointer-events: auto; padding: 10px 12px; background: #0b0d10f2; border: 1px solid var(--line-2); border-left: 4px solid var(--phos); font-size: 12px; letter-spacing: .04em; box-shadow: 0 8px 30px #000; animation: tin .2s ease-out; display: flex; gap: 10px; align-items: center; }
.toast.warn { border-left-color: var(--hazard); }
.toast.err { border-left-color: var(--blood); }
.toast .grow { flex: 1; }
@keyframes tin { from { transform: translateY(-8px); opacity: 0; } }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- boot ---------- */
.boot { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 100; transition: opacity .4s; }
#app:not(.booting) .boot { opacity: 0; pointer-events: none; }
.boot-logo { font-size: 34px; font-weight: 800; letter-spacing: .4em; color: var(--hazard); text-shadow: 0 0 20px #e5a93c66; }
.boot-line { color: var(--phos); letter-spacing: .2em; font-size: 12px; margin: 10px 0; animation: blink 1s steps(2) infinite; }
.boot-bar { height: 4px; background: var(--bg-3); overflow: hidden; }
.boot-bar span { display: block; height: 100%; width: 40%; background: var(--phos); animation: load 1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
