:root {
  --bg: #0c0c0e;
  --bg-panel: #121214;
  --bg-elevated: #1a1a1e;
  --border: #2a2a30;
  --text: #d4d4d8;
  --muted: #71717a;
  --lime: #c8ff00;
  --lime-dim: #8fb300;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Fira Code", "Consolas", ui-monospace, monospace;
  --sidebar-w: min(420px, 40vw);

  /* chart series colors — validated (dataviz six checks, dark surface #0e0e11) */
  --c-canon: #3987e5;    /* Canon only */
  --c-legends: #199e70;  /* Legends/EU only */
  --c-both: #e4e4e7;     /* Canon and EU — neutral ink, not a series hue */
  --c-edge: #c98500;     /* all lineage edges; type is carried by dash pattern */
  --chart-surface: #0e0e11;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

a { color: var(--lime); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  height: 100%;
  min-height: 0;
}

/* ---------- Chart panel ---------- */
.preview {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: #08080a;
  border-right: 1px solid var(--border);
}

.preview-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.55rem 0.9rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.brand-line .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 8px var(--lime);
}
.brand-line .title { font-weight: 600; letter-spacing: 0.02em; }
.badge {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  font-size: 0.75rem;
}
.transport button {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.28rem 0.55rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}
.transport button:hover { border-color: var(--lime); color: var(--lime); }
.transport button.active {
  border-color: var(--lime);
  color: var(--lime);
  background: #1a2200;
}
.transport .count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, #121218 0%, #08080a 70%);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.stage.panning { cursor: grabbing; }
.stage svg { display: block; width: 100%; height: 100%; }

/* chart legend (always present — identity is never color-alone) */
.chart-legend {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  background: rgba(14, 14, 17, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.68rem;
  line-height: 1.9;
  color: var(--text);
  pointer-events: none;
  user-select: none;
}
.chart-legend .swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 0.45rem;
  vertical-align: -1px;
}
.chart-legend .edge-sample {
  display: inline-block;
  width: 26px;
  margin-right: 0.45rem;
  vertical-align: 3px;
}

/* tooltip */
.tooltip {
  position: absolute;
  max-width: 300px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font-size: 0.74rem;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transition: opacity 80ms linear;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.tooltip.show { opacity: 1; }
.tooltip .t-name { font-weight: 700; color: #f4f4f5; }
.tooltip .t-status { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.06em; }
.tooltip .t-dates, .tooltip .t-note { color: var(--muted); }
.tooltip .t-hint { color: var(--muted); font-size: 0.64rem; margin-top: 0.3rem; }

/* detail card (click a ship) */
.detail {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  width: min(320px, calc(100% - 1.5rem));
  background: rgba(18, 18, 20, 0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem 1rem;
  font-size: 0.8rem;
  line-height: 1.5;
  z-index: 11;
  box-shadow: 0 12px 32px rgba(0,0,0,0.55);
  display: none;
}
.detail.show { display: block; }
.detail h3 { color: #f4f4f5; font-size: 0.95rem; margin-bottom: 0.15rem; padding-right: 1.4rem; }
.detail .d-close {
  position: absolute; top: 0.45rem; right: 0.55rem;
  background: none; border: none; color: var(--muted);
  font-size: 1rem; cursor: pointer; line-height: 1;
}
.detail .d-close:hover { color: var(--text); }
.detail .d-status { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 0.4rem; }
.detail .d-dates { color: var(--muted); font-size: 0.74rem; margin-bottom: 0.35rem; }
.detail .d-note { color: #a1a1aa; font-size: 0.74rem; margin-bottom: 0.55rem; }
.detail .d-links { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.55rem; }
.detail .d-links a {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.55rem;
  font-size: 0.7rem;
  color: var(--lime);
}
.detail .d-links a:hover { border-color: var(--lime); text-decoration: none; }

.status-chip { font-weight: 700; }
.status-chip.canon { color: var(--c-canon); }
.status-chip.legends { color: var(--c-legends); }
.status-chip.both { color: var(--c-both); }

/* footer hud */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: var(--lime);
  color: #111;
  font-size: 0.78rem;
  font-weight: 600;
}
.hud-credit {
  margin: 0;
  color: #111;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 0.72rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hud-credit a {
  color: #111;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.hud-credit a:hover { color: #000; text-decoration-thickness: 2px; }
.hud-meta {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  opacity: 0.85;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  background: var(--bg-panel);
}

/* ---------- In Detail panel (ephemeral tab) ---------- */
#panel-detail .panel-scroll { position: relative; padding-top: 0.9rem; }
#panel-detail h3 { color: #f4f4f5; font-size: 1.05rem; margin-bottom: 0.2rem; padding-right: 4.5rem; }
.d-close-panel {
  position: absolute; top: 0.65rem; right: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.25rem 0.5rem;
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  line-height: 1;
  font-family: var(--font);
}
.d-close-panel:hover { border-color: var(--lime); color: var(--lime); }
#panel-detail .d-status { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 0.45rem; }
#panel-detail .d-dates { color: var(--muted); font-size: 0.76rem; margin-bottom: 0.4rem; }
#panel-detail .d-note { color: #a1a1aa; font-size: 0.76rem; margin-bottom: 0.55rem; }
#panel-detail .d-links { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.6rem 0; }
#panel-detail .d-links a {
  border: 1px solid #3f4718;
  background: #1a2200;
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--lime);
}
#panel-detail .d-links a:hover { border-color: var(--lime); text-decoration: none; }
.d-sum { margin-top: 0.6rem; }
.d-sum p { color: #b4b4bc; font-size: 0.8rem; margin-bottom: 0.6rem; }
.d-sum p:last-child { margin-bottom: 0; }
.d-edge-ships { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem; }
.d-edge-ships button {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.55rem;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: var(--font);
}
.d-edge-ships button:hover { border-color: var(--lime); color: var(--lime); }
.d-ship {
  float: left;
  max-width: 110px;
  max-height: 84px;
  margin: 0 0.7rem 0.4rem 0;
}
/* on desktop the floating stage card is replaced by the sidebar tab */
@media (min-width: 821px) {
  .detail { display: none !important; }
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #0e0e10;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.7rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--lime);
  border-bottom-color: var(--lime);
  background: linear-gradient(180deg, transparent, rgba(200,255,0,0.04));
}

.tab-panels { min-height: 0; position: relative; }
.panel { display: none; height: 100%; min-height: 0; }
.panel.active { display: flex; flex-direction: column; }

.panel-scroll {
  overflow-y: auto;
  padding: 1.1rem 1.15rem 2rem;
  font-size: 0.86rem;
  line-height: 1.55;
  color: #b4b4bc;
}

.panel-scroll h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #f4f4f5;
  letter-spacing: -0.02em;
  margin-bottom: 0.55rem;
}
.panel-scroll h2 {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lime);
  margin-bottom: 0.55rem;
}
.lede { color: #a1a1aa; margin-bottom: 1.25rem; font-size: 0.9rem; }
.lede strong { color: #e4e4e7; }

.block {
  margin-bottom: 1.35rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid #1f1f24;
}
.block:last-of-type { border-bottom: none; }
.block p + p { margin-top: 0.55rem; }

.credit {
  background: linear-gradient(135deg, #14160c 0%, #121214 60%);
  border: 1px solid #2a3010;
  border-radius: 8px;
  padding: 0.9rem 1rem 1rem;
  margin-bottom: 1.25rem;
}

kbd {
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
}

/* SVG node/edge states */
.node { cursor: pointer; }
.node text {
  fill: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  paint-order: stroke;
  stroke: #08080a;
  stroke-width: 3px;
  stroke-linejoin: round;
}
.node .n-date { fill: #898781; }
.node.dim { opacity: 0.18; pointer-events: none; }
.node .sel-ring {
  display: none;
  fill: none;
  stroke: var(--lime);
  stroke-width: 2.5px;
}
.node.selected .sel-ring { display: block; }
.node:hover image { filter: brightness(1.25); }
.edge { fill: none; }
.edge.dim { opacity: 0.08; }
.edge.hovered { stroke-width: 3.5px; opacity: 1; }
.edge.selected { stroke: var(--lime); stroke-width: 3px; opacity: 1; }
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18px;
  cursor: pointer;
}
.edge-hit.dim { pointer-events: none; }
.edge-q {
  fill: #898781;
  font-size: 13px;
  font-weight: 700;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.section-label {
  fill: #71717a;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.section-caption {
  fill: #52525b;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  font-style: italic;
  letter-spacing: 0.08em;
}
.era-label {
  fill: #63636d;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.yavin-label {
  fill: #b9b9c0;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

/* ---------- Small screens ---------- */
.btn-info { display: none; }
.tab-close { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .btn-info { display: inline-block; }

  /* sidebar becomes a fullscreen overlay behind the Info button */
  .sidebar { display: none; }
  .app.show-info .sidebar {
    display: grid;
    position: fixed;
    inset: 0;
    z-index: 30;
  }
  .tab-close {
    display: block;
    flex: 0 0 auto;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text);
    padding: 0.7rem 0.9rem;
    font-size: 0.8rem;
    cursor: pointer;
  }

  /* selected-ship card becomes a bottom sheet */
  .detail {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: auto;
    max-height: 52vh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
    padding-top: 1rem;
    z-index: 20;
  }
  .detail .d-close {
    position: sticky;
    float: right;
    top: 0;
  }

  /* compact chrome */
  .preview-top { padding: 0.45rem 0.6rem; gap: 0.35rem 0.6rem; }
  .transport { gap: 0.3rem 0.4rem; }
  .transport button { padding: 0.3rem 0.5rem; }
  .transport .count { display: none; }
  .brand-line .badge { display: none; }
  .chart-legend {
    font-size: 0.58rem;
    line-height: 1.7;
    padding: 0.4rem 0.55rem;
    left: 0.5rem; top: 0.5rem;
  }
  .hud { padding: 0.45rem 0.7rem; }
  .hud-credit { font-size: 0.62rem; }
  .tooltip { display: none; }
}
