/* Fountain — sovereignty upgrade map
   Geometry follows DOTLAN (pill systems, hairline jumps, hand-authored layout).
   Colour encodes the upgrade taxonomy: that is what this map is for. */

:root {
  --void: #070b12;
  --panel: #0c131d;
  --panel-2: #111a26;
  --line: #1e2a3a;
  --line-soft: #16202d;
  --grid: #0e1622;

  --ink: #e9eff8;
  --muted: #8598b0;
  --dim: #5b6b80;

  --ratting: #ff8a3d;
  --mining: #4cc2ff;
  --exploration: #b98cff;
  --strategic: #3ad6a2;
  --npc: #8892a6;
  --ice: #7fd8ff;
  --keepstar: #ffd45e;

  --sov: #a4c3f0;
  --jump: #33465e;
  --jump-const: #7a4a3a;
  --jump-region: #6b4a8a;
  --bridge: #2fa5c9;

  --sys-fill: #16212f;
  --sys-stroke: #33465e;
  --sys-text: #dfe8f4;
  --sys-sub: #7b8da3;

  --mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter Tight", Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --rail-w: 268px;
  --drawer-w: 320px;
}

/* DOTLAN's classic paper look, for when you want the familiar thing */
body.paper {
  --void: #ffffff;
  --panel: #f6f7f9;
  --panel-2: #eef1f5;
  --line: #c9d0da;
  --line-soft: #dfe4ea;
  --grid: #f0f2f5;

  --ink: #10151c;
  --muted: #55606f;
  --dim: #7a8494;

  --ratting: #c2570b;
  --mining: #1668b8;
  --exploration: #6f3fc4;
  --strategic: #0d7f5f;
  --npc: #6d7684;
  --ice: #2f9fd8;
  --keepstar: #b8860b;

  --jump: #000000;
  --jump-const: #ff0000;
  --jump-region: #800080;
  --bridge: #0d8fb5;

  --sys-fill: #a4c3f0;
  --sys-stroke: #2b3f5c;
  --sys-text: #0b1017;
  --sys-sub: #2b3648;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
}

/* ---------- top bar ---------- */

.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-region {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: .02em;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.readout { display: flex; gap: 20px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat b { font-family: var(--mono); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }

.topbar-actions { display: flex; gap: 8px; }

.ghost-btn {
  font: inherit;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  text-decoration: none;
  transition: color .15s, border-color .15s, background .15s;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--dim); background: var(--panel-2); }
.ghost-btn.wide { width: 100%; margin-top: 10px; }

/* ---------- layout ---------- */

.deck {
  display: flex;
  height: calc(100% - 54px);
}

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.panel.grow { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.panel[hidden] { display: none; }

.panel h2 {
  margin: 0 0 10px;
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
}
.panel h2 .count { color: var(--muted); font-family: var(--mono); letter-spacing: 0; }

.field { display: block; margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field > span {
  display: block;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 4px;
}

input[type="search"], select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
}
input[type="search"]::placeholder { color: var(--dim); }
input[type="search"]:focus-visible, select:focus-visible,
button:focus-visible, a:focus-visible, .toggle:focus-within {
  outline: 2px solid var(--mining);
  outline-offset: 1px;
}
select option { background: var(--panel-2); color: var(--ink); }
select optgroup { color: var(--dim); font-style: normal; }

.toggles { display: flex; flex-direction: column; gap: 7px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 3px;
}
.toggle:hover { color: var(--ink); }
.toggle.solo { margin-top: 9px; }
.toggle input { accent-color: var(--mining); margin: 0; }

.swatch { width: 9px; height: 9px; border-radius: 2px; background: var(--npc); }
.swatch[data-cat="ratting"] { background: var(--ratting); }
.swatch[data-cat="mining"] { background: var(--mining); }
.swatch[data-cat="exploration"] { background: var(--exploration); }
.swatch[data-cat="strategic"] { background: var(--strategic); }
.swatch[data-cat="ice"] { background: transparent; border: 1.5px solid var(--ice); }
.swatch[data-cat="keepstar"] { background: var(--keepstar); transform: rotate(45deg); border-radius: 1px; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.segmented button {
  font: inherit;
  font-size: 10.5px;
  letter-spacing: .04em;
  padding: 6px 2px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
}
.segmented button.on { color: var(--void); background: var(--sov); border-color: var(--sov); font-weight: 600; }
body.paper .segmented button.on { color: #fff; background: #2b3f5c; border-color: #2b3f5c; }

.matches { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.matches li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
}
.matches li:hover, .matches li.active { background: var(--panel-2); }
.matches b { font-family: var(--mono); font-weight: 500; color: var(--ink); }
.matches span { color: var(--dim); font-size: 10.5px; margin-left: auto; }

/* ---------- map stage ---------- */

.stage { position: relative; flex: 1 1 auto; min-width: 0; background: var(--void); }
.load-error {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(420px, calc(100% - 40px));
  padding: 18px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  text-align: center;
}
.load-error strong { color: var(--ink); }
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#grid-rect { width: 100%; height: 100%; }

/* jumps */
.jump { stroke: var(--jump); stroke-width: 1.1; }
.jump.constellation { stroke: var(--jump-const); stroke-width: 1.1; }
.jump.region { stroke: var(--jump-region); stroke-width: 1.6; }
.jump.lit { stroke: var(--ink); stroke-width: 1.8; }
.bridge {
  fill: none;
  stroke: var(--bridge);
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
  opacity: .85;
}

/* constellation shading */
.hull { fill: var(--hull-fill, #ffffff); opacity: .028; stroke: none; }
body.paper .hull { fill: #4a6fa5; opacity: .06; }

/* systems */
.system { cursor: pointer; }
.system .pill {
  fill: var(--sys-fill);
  stroke: var(--sys-stroke);
  stroke-width: 1;
}
.system .name {
  font-family: var(--mono);
  font-size: 8.6px;
  font-weight: 600;
  fill: var(--sys-text);
  text-anchor: middle;
  letter-spacing: -.02em;
}
.system .sub {
  font-family: var(--mono);
  font-size: 6.4px;
  fill: var(--sys-sub);
  text-anchor: middle;
}
.system .ice-ring { fill: none; stroke: var(--ice); stroke-width: 1; opacity: .85; }
.system .keepstar { fill: var(--keepstar); }
.system .chip { stroke: none; }
.system:hover .pill, .system.selected .pill { stroke: var(--ink); stroke-width: 1.6; }
.system.external .pill { fill: none; stroke: var(--dim); stroke-dasharray: 3 2; rx: 2; }
.system.external .name { fill: var(--muted); }
.system.dim { opacity: .16; }
.system.hit { fill: transparent; }

.system, .jump, .bridge { transition: opacity .18s ease; }
.jump.dim, .bridge.dim { opacity: .12; }

/* map chrome */
.map-controls {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.map-controls button {
  width: 28px;
  height: 28px;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.map-controls button:hover { color: var(--ink); border-color: var(--dim); }

.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.7;
  backdrop-filter: blur(6px);
  pointer-events: none;   /* never swallow a map drag */
}
.legend hr { border: none; border-top: 1px solid var(--line-soft); margin: 6px 0; }
.legend-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.legend .chip { width: 12px; height: 4px; border-radius: 1px; background: var(--npc); }
.legend .chip[data-cat="ratting"] { background: var(--ratting); }
.legend .chip[data-cat="mining"] { background: var(--mining); }
.legend .chip[data-cat="exploration"] { background: var(--exploration); }
.legend .chip[data-cat="strategic"] { background: var(--strategic); }
.legend .key { width: 12px; height: 8px; border-radius: 2px; }
.legend .key-ice { border: 1.5px solid var(--ice); }
.legend .key-keepstar { background: var(--keepstar); width: 7px; height: 7px; transform: rotate(45deg); border-radius: 1px; }
.legend .key-jump { border-top: 1.5px solid var(--jump); height: 0; }
.legend .key-region { border-top: 2px solid var(--jump-region); height: 0; }
.legend .key-bridge { border-top: 1.5px dashed var(--bridge); height: 0; }

.tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  padding: 8px 10px;
  min-width: 150px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11.5px;
  color: var(--muted);
  box-shadow: 0 8px 24px rgb(0 0 0 / .45);
}
body.paper .tooltip { box-shadow: 0 8px 24px rgb(0 0 0 / .18); }
.tooltip .tt-name { font-family: var(--mono); font-size: 13px; color: var(--ink); font-weight: 600; }
.tooltip .tt-meta { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); margin-bottom: 5px; }
.tooltip ul { list-style: none; margin: 4px 0 0; padding: 0; }
.tooltip li { display: flex; align-items: center; gap: 6px; }
.tooltip li i { width: 8px; height: 8px; border-radius: 2px; font-style: normal; flex: none; }

/* ---------- detail drawer ---------- */

.drawer {
  width: var(--drawer-w);
  flex: 0 0 var(--drawer-w);
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  position: relative;
  padding: 16px;
}
.drawer[hidden] { display: none; }
.drawer-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 24px;
  height: 24px;
  font-size: 18px;
  line-height: 1;
  color: var(--dim);
  background: none;
  border: none;
  cursor: pointer;
}
.drawer-close:hover { color: var(--ink); }

.d-name { font-family: var(--mono); font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.d-where { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); margin: 3px 0 14px; }

.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: 4px; overflow: hidden; margin-bottom: 16px; }
.d-grid div { background: var(--panel); padding: 8px 10px; }
.d-grid dt { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); margin: 0 0 2px; }
.d-grid dd { margin: 0; font-family: var(--mono); font-size: 13px; }

.d-h { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); margin: 0 0 8px; }
.d-upgrades { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.d-upgrades li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: var(--panel-2);
  border-left: 3px solid var(--slot, var(--dim));
  border-radius: 0 3px 3px 0;
  font-size: 12.5px;
}
.d-upgrades li.empty { color: var(--dim); border-left-color: var(--line); font-style: italic; }
.d-upgrades li b { white-space: nowrap; }
.d-upgrades small { margin-left: auto; color: var(--dim); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; text-align: right; }

.d-links { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.d-links li button {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 4px 7px;
  cursor: pointer;
}
.d-links li button:hover { color: var(--ink); border-color: var(--dim); }
.d-links li.bridge-link button { border-color: var(--bridge); color: var(--bridge); }

.d-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.tag {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 10px;
  border: 1px solid currentColor;
}
.tag.ice { color: var(--ice); }
.tag.keepstar { color: var(--keepstar); }
.tag.npc { color: var(--npc); }

.d-out { font-size: 12px; color: var(--dim); }
.d-out a { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 1100px) {
  .readout .stat:nth-child(n+4) { display: none; }
}
@media (max-width: 860px) {
  .deck { flex-direction: column; }
  .rail { width: 100%; flex: 0 0 auto; max-height: 42%; border-right: none; border-bottom: 1px solid var(--line); }
  .drawer { width: 100%; flex: 0 0 auto; max-height: 45%; border-left: none; border-top: 1px solid var(--line); }
  .readout { display: none; }
}
