/* X4 Factories Planner

   Shape rule: controls and rows 6px, cards and panels 8px, small marks
   (checkboxes, tags, flow chips) 4px. Nothing else.

   Color rule: neutral graphite surfaces, one accent (teal) for interaction
   and for "you have this", one semantic colour (coral) for shortfalls.
   Dark only on purpose: this sits next to a dark game on a second monitor. */

@font-face {
  font-family: "Red Hat Text";
  src: url("fonts/RedHatText-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: "Red Hat Mono";
  src: url("fonts/RedHatMono-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  color-scheme: dark;

  --bg: #0d0f11;
  --surface: #131619;
  --surface-2: #191d21;
  --surface-3: #20252a;
  --line: #252a30;
  --line-strong: #39414a;

  --text: #e7eaed;
  --text-2: #a9b1ba;
  --text-3: #8a939e;

  --accent: #4fcab9;
  --accent-ink: #05211d;
  --accent-soft: rgba(79, 202, 185, 0.12);
  --accent-line: rgba(79, 202, 185, 0.5);

  --danger: #f08a73;
  --danger-soft: rgba(240, 138, 115, 0.12);
  --danger-line: rgba(240, 138, 115, 0.55);
  --warn: #e6b45c;

  --r-mark: 4px;
  --r-control: 6px;
  --r-card: 8px;

  --font-ui: "Red Hat Text", "Segoe UI", system-ui, sans-serif;
  --font-num: "Red Hat Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --sidebar-w: 292px;
  --inspector-w: 324px;
}

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

button,
input {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon { display: block; flex-shrink: 0; }
[data-icon] { display: inline-flex; }

.num,
.num-input,
input[type="number"] {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- shared controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.12s var(--ease), border-color 0.12s var(--ease), color 0.12s var(--ease);
}

.btn:hover { background: var(--surface-3); border-color: var(--line-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }

.btn.is-confirming {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.num-input {
  height: 28px;
  width: 84px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  text-align: right;
  transition: border-color 0.12s var(--ease);
}

.num-input:hover { border-color: var(--line-strong); }
.num-input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.stepper {
  display: inline-flex;
  align-items: stretch;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--bg);
  overflow: hidden;
  transition: border-color 0.12s var(--ease);
}

.stepper:hover { border-color: var(--line-strong); }
.stepper:focus-within { border-color: var(--accent); }

.stepper button {
  display: grid;
  place-items: center;
  width: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-3);
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease);
}

.stepper button:hover { background: var(--surface-3); color: var(--text); }
.stepper button:active { background: var(--line-strong); }
.stepper button:focus-visible { outline-offset: -2px; }

.stepper input {
  width: 46px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  text-align: center;
}

.stepper input:focus-visible { outline: none; }

.stepper.is-small { height: 24px; }
.stepper.is-small button { width: 22px; }
.stepper.is-small input { width: 36px; font-size: 12px; }

.quiet-note {
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------- app frame ---------- */

#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 48px;
  padding: 0 14px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.brand-mark {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

/* status messages float as a toast, so they never push the top bar buttons */
#status {
  position: fixed;
  right: 16px;
  bottom: 52px;
  z-index: 15;
  max-width: min(440px, calc(100vw - 32px));
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: 0 12px 28px -14px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  animation: modal-rise 0.2s var(--ease);
}

#status:empty { display: none; }

.topbar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

/* the Empire view gets the full width: no ware list, no network drawer */
#app[data-view="empire"] #sidebar,
#app[data-view="empire"] #network { display: none; }
#app[data-view="empire"] #layout { grid-template-columns: minmax(0, 1fr) auto; }

#layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(380px, 1fr) auto;
  min-height: 0;
  overflow-x: auto;
  position: relative;
}

/* ---------- sidebar ---------- */

#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.search-field {
  position: relative;
  margin: 12px 12px 8px;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

#search {
  width: 100%;
  height: 32px;
  padding: 0 34px 0 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--bg);
  transition: border-color 0.12s var(--ease);
}

#search::placeholder { color: var(--text-3); }
#search::-webkit-search-cancel-button { display: none; }
#search:hover { border-color: var(--line-strong); }
#search:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.search-field kbd {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: var(--r-mark);
  color: var(--text-3);
  font-family: var(--font-num);
  font-size: 11px;
  text-align: center;
  pointer-events: none;
}

#search:focus ~ kbd { visibility: hidden; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin: 0 12px 8px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--bg);
}

.segmented button {
  height: 26px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-mark);
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease);
}

.segmented button .num { margin-left: 4px; font-size: 11px; opacity: 0.8; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }

#ware-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 6px 12px;
}

#ware-empty { padding: 8px 14px; }

.category-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
}

.category-head:hover { color: var(--text); }
.category-head .num { color: var(--text-3); font-size: 11px; font-weight: 400; }
.category-head .caret { margin-left: auto; color: var(--text-3); transition: transform 0.15s var(--ease); }
.category.collapsed .category-head .caret { transform: rotate(-90deg); }
.category.collapsed:not(.force-open) .category-items { display: none; }

.ware-item {
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--r-control);
  transition: background-color 0.1s var(--ease);
}

.ware-item:hover { background: var(--surface-2); }
.ware-item.active { background: var(--accent-soft); }

.built-toggle {
  appearance: none;
  position: relative;
  width: 15px;
  height: 15px;
  margin: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-mark);
  background: var(--bg);
  cursor: pointer;
  transition: background-color 0.12s var(--ease), border-color 0.12s var(--ease);
}

.built-toggle:hover { border-color: var(--text-3); }
.built-toggle:checked { background: var(--accent); border-color: var(--accent); }

.built-toggle:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.5px;
  width: 4px;
  height: 8px;
  border: solid var(--accent-ink);
  border-width: 0 1.7px 1.7px 0;
  transform: rotate(45deg);
}

.ware-item-label {
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ware-item:hover .ware-item-label,
.ware-item.built .ware-item-label,
.ware-item.active .ware-item-label { color: var(--text); }

.ware-item-label:focus-visible { outline-offset: -2px; border-radius: var(--r-mark); }

.module-count {
  width: 38px;
  height: 22px;
  padding: 0 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-mark);
  background: var(--surface-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

.module-count:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.ware-item-price {
  min-width: 52px;
  color: var(--text-3);
  font-size: 11.5px;
  text-align: right;
}

/* ---------- chain view ---------- */

#chain-view {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#chain-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 24px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.chain-heading { min-width: 0; }

#chain-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

#chain-sub { color: var(--text-3); font-size: 12px; }

.target {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.target-label { color: var(--text-2); font-weight: 500; }
.target-modules { display: inline-flex; align-items: center; gap: 8px; }
.target-unit,
.target-eq { color: var(--text-3); font-size: 12.5px; }

#chain-canvas {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
}

#empty-state {
  max-width: 520px;
  padding: 56px 40px;
}

#empty-state h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  text-wrap: balance;
}

#empty-state p {
  margin-top: 10px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.55;
}

.quick-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 22px;
}

#chain-scroll {
  position: relative;
  display: flex;
  width: max-content;
  min-width: 100%;
  padding: 20px 28px 36px;
}

#chain-lines {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

#chain-lines path {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1.25;
  transition: stroke 0.12s var(--ease), opacity 0.12s var(--ease);
}

#chain-lines.focus path:not(.hot) { opacity: 0.25; }
#chain-lines path.hot { stroke: var(--accent); stroke-width: 1.6; }

#chain-columns {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 72px;
}

.chain-col {
  display: flex;
  flex-direction: column;
  width: 216px;
  flex-shrink: 0;
}

.chain-col-label {
  padding-bottom: 12px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
}

.chain-col-nodes {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

/* ---------- node ---------- */

.node {
  position: relative;
  padding: 10px 12px 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s var(--ease), background-color 0.12s var(--ease), opacity 0.12s var(--ease);
}

.node:hover,
.node:focus-within { border-color: var(--line-strong); background: var(--surface-2); }

.node.root { border-color: var(--text-3); background: var(--surface-2); }
.node.is-short { border-color: var(--danger-line); }

#chain-columns.focus .node:not(.linked) { opacity: 0.45; }

.node-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
}

.node-title {
  min-width: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
}

.node-title:focus-visible { border-radius: var(--r-mark); }

.node-built {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  padding: 0 3px 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--surface-3);
  color: var(--accent);
  flex-shrink: 0;
}

.node-built:focus-within { border-color: var(--accent); }

.node-module-count {
  width: 30px;
  height: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.node-module-count:focus-visible { outline: none; }

.node-add,
.node-source {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text-3);
  flex-shrink: 0;
  transition: background-color 0.12s var(--ease), border-color 0.12s var(--ease), color 0.12s var(--ease);
}

.node-add:hover,
.node-source:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }
.node-add:active,
.node-source:active { transform: translateY(1px); }

.node-source .icon { visibility: hidden; }
.node-source[aria-pressed="true"] { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }
.node-source[aria-pressed="true"] .icon { visibility: visible; }

.node-rate {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 4px;
}

.node-rate .num { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; }
.node-rate .unit { color: var(--text-3); font-size: 11.5px; }

.node-need {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  color: var(--text-2);
  font-size: 12px;
}

.node-need .have { color: var(--accent); white-space: nowrap; }
.node-need .short { color: var(--danger); font-weight: 500; white-space: nowrap; }

.node-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: 11.5px;
}

.flow-chip {
  position: absolute;
  top: 50%;
  z-index: 2;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-mark);
  background: var(--surface-3);
  color: var(--text);
  font-family: var(--font-num);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}

.flow-chip.is-out { left: calc(100% + 8px); }
.flow-chip.is-in { right: calc(100% + 8px); }

/* ---------- inspector ---------- */

#details {
  width: var(--inspector-w);
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

#details-content { padding: 14px 16px 20px; }

.inspector-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.inspector-head h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.inspector-sub { margin-top: 2px; color: var(--text-3); font-size: 12px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text-3);
  flex-shrink: 0;
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease);
}

.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.is-danger:hover { background: var(--danger-soft); color: var(--danger); }

.inspector-built {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface-2);
}

.inspector-built label { color: var(--text-2); }
.inspector-built .check-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.inspector-actions { margin-top: 10px; }
.inspector-actions .btn { width: 100%; justify-content: center; }

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin: 16px 0 0;
}

.stats dt { color: var(--text-3); }
.stats dd { margin: 0; font-family: var(--font-num); font-size: 12.5px; text-align: right; }

.inspector-section { margin-top: 20px; }
.inspector-section h3 { margin-bottom: 6px; color: var(--text-2); font-size: 12px; font-weight: 600; }

.link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 64px;
  align-items: center;
  gap: 12px;
  width: calc(100% + 16px);
  height: 28px;
  margin: 0 -8px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background-color 0.1s var(--ease);
}

.link-row:hover { background: var(--surface-3); }
.link-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row .num { color: var(--text-2); font-size: 12px; text-align: right; }
.link-row .num.dim { color: var(--text-3); }

.cols-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 64px;
  gap: 12px;
  color: var(--text-3);
  font-size: 11.5px;
}

.cols-head span:not(:first-child) { text-align: right; }

/* ---------- network drawer ---------- */

#network {
  display: flex;
  flex-direction: column;
  max-height: 42vh;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

#network-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 36px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  text-align: left;
  flex-shrink: 0;
  transition: background-color 0.12s var(--ease);
}

#network-toggle:hover { background: var(--surface-2); }
#network-toggle:focus-visible { outline-offset: -2px; }

.network-title { font-weight: 600; }

#network-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--r-mark);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.tag.is-ok { background: var(--accent-soft); color: var(--accent); }
.tag.is-short { background: var(--danger-soft); color: var(--danger); }
.tag.is-plain { background: var(--surface-3); color: var(--text-2); }

#network-toggle .caret { margin-left: auto; color: var(--text-3); transition: transform 0.15s var(--ease); }
#network.collapsed #network-toggle .caret { transform: rotate(180deg); }
#network.collapsed #network-body { display: none; }

#network-body {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.35fr) minmax(0, 1fr);
  min-height: 0;
  border-top: 1px solid var(--line);
}

.net-col {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 14px;
}

.net-col + .net-col { border-left: 1px solid var(--line); }

.net-col h2 {
  margin-bottom: 8px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.net-row {
  display: grid;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  margin: 0 -8px;
  padding: 0 8px;
  border-radius: var(--r-control);
}

.net-row:hover { background: var(--surface-2); }

.net-row.is-built { grid-template-columns: minmax(0, 1fr) auto 76px 24px; }
.net-row.is-balance { grid-template-columns: minmax(0, 1fr) 62px 62px 70px 78px; }
.net-row.is-suggest { grid-template-columns: minmax(0, 1fr) auto; padding-top: 4px; padding-bottom: 4px; }

.net-head { color: var(--text-3); font-size: 11.5px; }
.net-head:hover { background: transparent; }
.net-head span:not(:first-child) { text-align: right; }

.net-name {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.net-name:hover { color: var(--accent); }
.net-name:focus-visible { border-radius: var(--r-mark); }

.net-row .num { color: var(--text-2); font-size: 12px; text-align: right; }
.net-row .num.dim { color: var(--text-3); }
.net-row .num.is-short { color: var(--danger); font-weight: 500; }
.net-row .num.is-ok { color: var(--accent); }

.net-action { display: flex; justify-content: flex-end; }

.btn.is-small { height: 22px; padding: 0 7px; font-size: 11.5px; gap: 4px; }
.btn.is-fix { border-color: var(--danger-line); color: var(--danger); }
.btn.is-fix:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.suggest-sub {
  display: block;
  color: var(--text-3);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- topbar additions ---------- */

.btn.is-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn.is-primary:hover { background: #6fd8c9; border-color: #6fd8c9; color: var(--accent-ink); }

.view-switch {
  display: inline-grid;
  grid-auto-flow: column;
  grid-template-columns: none;
  margin: 0;
  flex-shrink: 0;
}

.view-switch button { padding: 0 12px; }

#rank-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.12s var(--ease), border-color 0.12s var(--ease);
}

#rank-chip:hover { background: var(--surface-3); border-color: var(--line-strong); }
#rank-chip .badge { margin: -4px -2px -2px -4px; }
.rank-chip-num { color: var(--text-3); font-size: 11.5px; font-weight: 500; }

/* ---------- level badges (drawn by badges.js) ---------- */

.badge { display: block; flex-shrink: 0; overflow: visible; }

/* ---------- empire view ---------- */

#empire-view {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 40px;
}

#empire-view .tab-panel { max-width: 1120px; }
#empire-view .tab-panel[hidden] { display: none; }

.rank-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(260px, 340px);
  align-items: center;
  gap: 24px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
}

.rank-badge .badge { margin: -6px 0; }

.rank-level { color: var(--text-3); font-size: 12px; font-weight: 500; }

#rank-name {
  margin-top: 2px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  text-wrap: balance;
}

.rank-flavor {
  margin-top: 6px;
  max-width: 52ch;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.5;
}

.rank-profit { display: flex; align-items: baseline; gap: 8px; }
.rank-profit .num { font-size: 30px; font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; }
.rank-profit .unit { color: var(--text-3); font-size: 12.5px; }
.rank-day { margin-top: 4px; color: var(--text-3); font-size: 12px; line-height: 1.45; }

.rank-next { margin-top: 12px; }
.rank-next p { margin-top: 6px; color: var(--text-2); font-size: 12px; }
.rank-next strong { color: var(--text); font-weight: 600; }

.rank-bar {
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface-3);
}

.rank-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transition: transform 0.4s var(--ease);
}

.empire-source {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 16px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

.source-text h2 { font-size: 14px; font-weight: 600; }
.source-text p { margin-top: 4px; max-width: 72ch; color: var(--text-2); font-size: 12.5px; line-height: 1.55; }
.source-text p.quiet-note { color: var(--text-3); }

.source-text code {
  padding: 1px 4px;
  border-radius: var(--r-mark);
  background: var(--surface-3);
  color: var(--text);
  font-family: var(--font-num);
  font-size: 11.5px;
}

.source-actions { display: flex; gap: 6px; flex-shrink: 0; }

.load-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 240px;
  flex-shrink: 0;
}

.load-progress .rank-bar { flex: 1; }
.load-progress .rank-bar span { transition: none; }
.load-progress .num { width: 38px; color: var(--text-2); font-size: 12px; text-align: right; }

.levels { margin-top: 28px; }
.levels h2 { margin-bottom: 10px; font-size: 15px; font-weight: 600; }

#level-ladder {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#level-ladder li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 8px 4px 9px;
  border: 1px solid transparent;
  border-radius: var(--r-card);
  text-align: center;
}

#level-ladder .badge { margin-bottom: 2px; }
.ladder-num { color: var(--text-3); font-size: 11px; }
.ladder-name { min-height: 2.6em; color: var(--text); font-size: 11.5px; font-weight: 500; line-height: 1.3; text-wrap: balance; }
.ladder-min { color: var(--text-3); font-size: 11px; }

#level-ladder li.is-current { border-color: var(--accent-line); background: var(--accent-soft); }
#level-ladder li.is-current .ladder-num { color: var(--accent); font-weight: 600; }
#level-ladder li.is-locked .ladder-name { color: var(--text-3); letter-spacing: 0.1em; }

.stations { margin-top: 28px; }

.stations-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.stations-head h2 { font-size: 15px; font-weight: 600; }

.st-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1.5fr) minmax(0, 1fr) 60px 104px 80px 80px 80px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.st-row > .num { text-align: right; font-size: 12.5px; }
.st-row .num.dim { color: var(--text-3); }
.st-row .num.is-ok { color: var(--accent); }
.st-row .num.is-short { color: var(--danger); }

button.st-row { cursor: pointer; transition: background-color 0.1s var(--ease); }
button.st-row:hover { background: var(--surface-2); }
button.st-row:focus-visible { outline-offset: -2px; }

.st-head {
  min-height: 28px;
  color: var(--text-3);
  font-size: 11.5px;
}

.st-head span:nth-child(n + 4) { text-align: right; }

.st-caret { color: var(--text-3); transition: transform 0.15s var(--ease); }
.st-item.is-open .st-caret { transform: rotate(90deg); color: var(--text); }
.st-item.is-open > .st-row { background: var(--surface-2); border-bottom-color: transparent; }

.st-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.st-name .tag { margin-left: 4px; vertical-align: 1px; }
.st-sector { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

.st-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 24px;
  padding: 12px 16px 18px 38px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.mod-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 72px 84px 72px;
  align-items: center;
  gap: 10px;
  min-height: 26px;
}

.mod-row > .num { text-align: right; font-size: 12px; }
.mod-row .num.dim { color: var(--text-3); }
.mod-row .num.is-ok { color: var(--accent); }
.mod-row .num.is-short { color: var(--danger); }
.mod-head { color: var(--text-3); font-size: 11.5px; }
.mod-head span:not(:first-child) { text-align: right; }

.method {
  margin-left: 4px;
  padding: 0 5px;
  border-radius: var(--r-mark);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
}

.st-flows { display: grid; gap: 14px; align-content: start; }
.st-flows h3 { margin-bottom: 4px; color: var(--text-2); font-size: 12px; font-weight: 600; }

.recipe-note { margin: -2px 0 6px; font-size: 11.5px; }

/* ---------- empire tabs ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap; /* the save-age note drops to its own line when space runs out */
  gap: 2px;
  max-width: 1120px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.tabs button[data-tab] {
  position: relative;
  height: 34px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s var(--ease);
}

.tabs button[data-tab]:hover { color: var(--text); }
.tabs button[data-tab][aria-pressed="true"] { color: var(--text); }
.tabs button[data-tab][aria-pressed="true"]::after {
  content: "";
  position: absolute;
  right: 10px;
  bottom: -1px;
  left: 10px;
  height: 2px;
  border-radius: 1px;
  background: var(--text);
}

.rank-share { margin-top: 12px; }

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.card {
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

.card h2 { margin-bottom: 10px; font-size: 14px; font-weight: 600; }

/* ---------- save age, terms, sorting, filter ---------- */

.save-age {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 0 4px 0 12px;
  color: var(--text-3);
  font-size: 12px;
  white-space: nowrap;
}

.save-age[hidden] { display: none; }
.save-age.is-stale { color: var(--warn); }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.link-btn:hover { color: var(--accent); }

.term {
  text-decoration: underline dotted var(--text-3);
  text-underline-offset: 3px;
  cursor: help;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.sort-btn:hover,
.sort-btn.is-active { color: var(--text); }
.sort-btn.is-asc .icon { transform: rotate(180deg); }
.st-head > span { display: flex; }
.st-head > span:nth-child(n + 4) { justify-content: flex-end; }

.filter-field { position: relative; width: min(280px, 50%); }
.filter-field input {
  width: 100%;
  height: 30px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}

.filter-field input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.stations-note { margin: 0 0 8px; }
.st-empty { padding: 14px 10px; }

/* ---------- needs attention ---------- */

.issues { display: grid; gap: 2px; margin: 0 0 8px; padding: 0; list-style: none; }

.issue {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.1s var(--ease);
}

.issue:hover { background: var(--surface-2); }
.issue-icon { padding-top: 1px; color: var(--text-3); }
.issue.sev-3 .issue-icon { color: var(--danger); }
.issue.sev-2 .issue-icon { color: var(--warn); }
.issue-text { display: grid; gap: 1px; min-width: 0; }
.issue-title { font-size: 13px; font-weight: 500; }
.issue-sub { color: var(--text-3); font-size: 12px; line-height: 1.45; }

summary.issue { grid-template-columns: 18px minmax(0, 1fr) auto; list-style: none; }
summary.issue::-webkit-details-marker { display: none; }
button.issue { grid-template-columns: 18px minmax(0, 1fr) auto; }
.issue-count {
  align-self: start;
  min-width: 24px;
  padding: 1px 6px;
  border-radius: var(--r-mark);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11.5px;
  text-align: center;
}

.issue-go { align-self: center; color: var(--text-3); }
details[open] > summary.issue { background: var(--surface-2); }
.issue-items { display: grid; gap: 1px; margin: 2px 0 8px 28px; padding: 0; list-style: none; }

.issue-item {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  width: 100%;
  padding: 5px 8px;
  border: 0;
  border-radius: var(--r-mark);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.issue-item:hover { background: var(--surface-2); color: var(--text); }
.issue-item-st { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.issue-item.is-link { display: inline-flex; align-items: center; gap: 6px; width: auto; color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.all-good { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.btn.is-ghost { border-color: transparent; background: transparent; color: var(--text-2); }

/* ---------- earnings history ---------- */

.history-chart { display: block; width: 100%; height: auto; max-height: 220px; overflow: visible; }
.history-chart .axis { stroke: var(--line); stroke-width: 1; }
.history-chart .area { fill: var(--accent-soft); }
.history-chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.history-chart .dot { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
.history-axis { display: flex; justify-content: space-between; margin-top: 4px; color: var(--text-3); font-size: 11.5px; }
.history-delta { margin-bottom: 8px; color: var(--text-2); font-size: 12.5px; }
.history-delta .num { font-size: 15px; font-weight: 500; }
.history-delta.is-ok .num { color: var(--accent); }
.history-delta.is-short .num { color: var(--danger); }
.history-now { margin-bottom: 6px; color: var(--text-2); font-size: 12.5px; }
.history-now .num { color: var(--text); font-size: 18px; font-weight: 500; }

/* ---------- what-if plan ---------- */

#plan-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 14px 18px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-card);
  background: var(--accent-soft);
}

#plan-bar[hidden] { display: none; }
.plan-text h2 { font-size: 13.5px; font-weight: 600; }
.plan-text p { margin-top: 4px; color: var(--text-2); font-size: 12.5px; line-height: 1.55; }
.plan-text strong { color: var(--text); font-weight: 600; }
.plan-text .is-ok { color: var(--accent); }
.plan-text .is-short { color: var(--danger); }

.plan-step { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }
.plan-step .icon-btn { width: 20px; height: 20px; opacity: 0.55; }
.mod-row:hover .plan-step .icon-btn,
.plan-step .icon-btn:focus-visible { opacity: 1; }
.plan-step .num { min-width: 34px; font-size: 12px; text-align: center; }
.plan-delta { margin-left: 2px; font-size: 10.5px; }
.plan-delta.is-ok { color: var(--accent); }
.plan-delta.is-short { color: var(--danger); }
.mod-row .tag { margin-left: 4px; }
.plan-add { margin-top: 10px; }

.flow-row { grid-template-columns: minmax(0, 1fr) auto 64px; }
.flow-row .num.is-short { color: var(--danger); }
.flow-head { margin-left: 8px; color: var(--text-3); font-size: 12px; font-weight: 400; }

.fill-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 10px;
  min-height: 22px;
  color: var(--text-2);
  font-size: 12px;
}

.fill-row .num { text-align: right; }
.rank-bar.is-full span { background: var(--danger); }

/* ---------- select fields (chain options, plan) ---------- */

.select-field { display: inline-flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12px; }
.select-field[hidden] { display: none; }

.select-field select {
  max-width: 230px;
  height: 28px;
  padding: 0 26px 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Cpath fill='%238a939e' d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E") no-repeat right 8px center / 11px;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  appearance: none;
  cursor: pointer;
}

.select-field select:hover { border-color: var(--line-strong); }

.chain-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  flex-basis: 100%;
}

.chain-cost { color: var(--text-3); font-size: 12px; line-height: 1.5; }
.chain-cost strong { color: var(--text-2); font-weight: 500; }
.chain-cost .cost-line { display: block; }

/* ---------- prices ---------- */

.prices-note { max-width: 75ch; margin-bottom: 16px; line-height: 1.55; }
.prices-note strong { color: var(--accent); }
.price-section + .price-section { margin-top: 24px; }
.price-section h3 { margin-bottom: 6px; color: var(--text-2); font-size: 13px; font-weight: 600; }

.price-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px 150px 150px minmax(0, 1.8fr) 84px;
  align-items: start;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.price-row > span { display: grid; min-width: 0; }
.price-row > .num { text-align: right; }
.price-row .num.is-ok { color: var(--accent); }
.price-row .num.dim,
.price-sub { color: var(--text-3); }
.price-sub { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.price-head { padding-top: 0; color: var(--text-3); font-size: 11.5px; }
.price-head span:last-child { text-align: right; }
.price-row > .price-advice { display: block; color: var(--text-2); line-height: 1.45; }
.price-advice .tag { margin-right: 6px; text-transform: capitalize; }
.price-row.is-ok .price-advice,
.price-row.is-none .price-advice,
.price-row.is-internal .price-advice { color: var(--text-3); }

/* ---------- supply and market opportunities ---------- */

.section-gap { margin-top: 28px; }

.sup-row,
.opp-row {
  display: grid;
  align-items: start;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.sup-row { grid-template-columns: minmax(0, 0.9fr) 84px 132px 104px 116px minmax(0, 1.6fr); }
.opp-row { grid-template-columns: minmax(0, 1.1fr) 150px 84px 108px minmax(0, 1fr) 92px; }

.sup-row > span,
.opp-row > span { display: grid; min-width: 0; }
.sup-row > .num,
.opp-row > .num { text-align: right; }
.sup-head,
.opp-head { padding-top: 0; color: var(--text-3); font-size: 11.5px; }
.sup-head > :nth-child(2),
.opp-head > :nth-child(3),
.opp-head > :nth-child(4) { text-align: right; }
.sup-row .num.dim,
.opp-row .num.dim,
.opp-row .dim { color: var(--text-3); }
.opp-row .num.is-ok { color: var(--accent); }

.sup-cover { grid-template-columns: minmax(0, 1fr) 40px; align-items: center; gap: 8px; padding-top: 6px; }
.sup-cover .num { font-size: 12px; text-align: right; }
.sup-advice { display: block !important; color: var(--text-2); line-height: 1.45; }
.sup-advice .tag { margin-right: 6px; }
.sup-stalled { color: var(--danger); }
.sup-intro { max-width: 75ch; margin: 0 0 8px; line-height: 1.55; }
.sup-intro:last-child { margin: 10px 0 0; }

.opp-name { display: flex !important; flex-wrap: wrap; align-items: center; gap: 6px; }
.opp-missing { display: block !important; color: var(--text-2); line-height: 1.45; }

.int-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.int-main p { margin-top: 3px; color: var(--text-2); line-height: 1.45; }
.int-main .int-stations { color: var(--text-3); font-size: 12px; }
.int-gain { display: grid; justify-items: end; align-content: start; gap: 2px; flex-shrink: 0; }
.int-gain .num { font-size: 13.5px; font-weight: 500; }
.int-gain .num.is-ok { color: var(--accent); }

@media (max-width: 1280px) {
  .sup-row { grid-template-columns: minmax(0, 1fr) 84px 132px 104px 116px; row-gap: 4px; }
  .sup-row > .sup-advice { grid-column: 1 / -1; }
  .sup-head > :last-child { display: none; }
  .opp-row { grid-template-columns: minmax(0, 1fr) 150px 108px 92px; row-gap: 4px; }
  .opp-row > :nth-child(3) { display: none; }
  .opp-row > .opp-missing { grid-column: 1 / -1; grid-row: 2; }
  .opp-head > .opp-missing,
  .opp-head > :nth-child(5) { display: none; }
}

/* ---------- logistics ---------- */

.hub-card {
  margin-bottom: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

.hub-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.hub-head h3 { font-size: 15px; font-weight: 600; }
.hub-name { color: var(--text); text-decoration: none; }
.hub-name:hover { text-decoration: underline; }
.hub-head .quiet-note { margin-top: 2px; }

.hub-advice { display: grid; gap: 6px; margin: 12px 0 4px; padding: 0; list-style: none; }
.hub-advice li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 8px 10px;
  border-radius: var(--r-control);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.5;
}

.hub-advice strong { color: var(--text); font-weight: 600; }
.hub-advice .tag { margin-top: 1px; }
.tag.is-warn { background: rgba(230, 180, 92, 0.12); color: var(--warn); }
.hub-card > .all-good { margin-top: 10px; }

.hub-body { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(220px, 1fr); gap: 24px; margin-top: 14px; }
.hub-side { display: grid; gap: 14px; align-content: start; }
.hub-side h4 { margin-bottom: 4px; color: var(--text-2); font-size: 12px; font-weight: 600; }
.hub-flow { display: flex; justify-content: space-between; gap: 10px; min-height: 22px; font-size: 12px; color: var(--text-2); }
.hub-flow .link-btn { color: var(--text); }
.fill-trend { grid-column: 1 / -1; margin-top: -4px; color: var(--text-3); font-size: 12px; }

.hw-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 76px 84px 70px 112px;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.hw-row > .num { text-align: right; font-size: 12px; }
.hw-row .num.dim { color: var(--text-3); }
.hw-row .num.is-short { color: var(--danger); }
.hw-head { min-height: 24px; color: var(--text-3); font-size: 11.5px; }
.hw-head span:not(:first-child) { text-align: right; }
.hub-add { margin-top: 4px; }

.tr-row,
.route-row {
  display: grid;
  align-items: start;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.tr-row { grid-template-columns: minmax(0, 1.2fr) 84px 84px minmax(0, 1fr) minmax(0, 1.5fr); }
.route-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.8fr) 90px 56px; }
.tr-row > .num,
.route-row > .num { text-align: right; }
.tr-row .num.dim,
.route-row .num.dim,
.tr-row .dim { color: var(--text-3); }
.tr-head,
.route-head { padding-top: 0; color: var(--text-3); font-size: 11.5px; }
.tr-head > :nth-child(2),
.tr-head > :nth-child(3),
.route-head > :nth-child(4),
.route-head > :nth-child(5) { text-align: right; }
.tr-row.is-hub { background: var(--surface-2); }
.tr-hub { display: grid; color: var(--text-2); }
.tr-row .link-btn,
.route-row .link-btn { color: var(--text); text-decoration: none; text-align: left; }
.tr-row .link-btn:hover,
.route-row .link-btn:hover { text-decoration: underline; }

@media (max-width: 1280px) {
  .hub-body { grid-template-columns: minmax(0, 1fr); }
  .tr-row { grid-template-columns: minmax(0, 1fr) 72px 72px minmax(0, 1fr); row-gap: 4px; }
  .tr-row > .sup-advice { grid-column: 1 / -1; }
  .tr-head > :last-child { display: none; }
}

.fl-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px minmax(0, 1fr) 64px minmax(0, 2fr);
  align-items: start;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}

.fl-row > .num { text-align: right; }
.fl-row .num.dim,
.fl-row .dim { color: var(--text-3); }
.fl-head { padding-top: 0; color: var(--text-3); font-size: 11.5px; }
.fl-head > :nth-child(4) { text-align: right; }
.fl-ship { display: grid; min-width: 0; }
.fl-name { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.fl-order { color: var(--text-2); font-family: var(--font-num); font-size: 11.5px; }
.fl-row .sup-advice .tag { margin-right: 6px; text-transform: capitalize; }
.fl-row .link-btn { color: var(--text); text-decoration: none; text-align: left; }

@media (max-width: 1280px) {
  .fl-row { grid-template-columns: minmax(0, 1fr) 110px minmax(0, 1fr) 56px; row-gap: 4px; }
  .fl-row > .sup-advice { grid-column: 1 / -1; }
  .fl-head > :last-child { display: none; }
}

/* ---------- missions ---------- */

.m-summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.m-summary > div {
  display: grid;
  gap: 2px;
  min-width: 120px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  color: var(--text-3);
  font-size: 12px;
}
.m-summary .num { color: var(--text); font-size: 22px; font-weight: 500; line-height: 1.1; }

.m-group { margin: 16px 0 8px; color: var(--text-2); font-size: 13px; font-weight: 600; }
.m-group .num { margin-left: 4px; font-weight: 400; }

.m-card {
  margin-bottom: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}
.m-card.is-thread { border-color: var(--line-strong); }
.m-children { display: grid; gap: 8px; margin-top: 12px; padding-left: 14px; border-left: 1px solid var(--line); }
.m-children .m-card { margin: 0; background: var(--surface-2); }

.m-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.m-head h3 { font-size: 14.5px; font-weight: 600; }
.m-meta { margin-top: 2px; color: var(--text-2); font-size: 12px; }
.m-meta .dim { margin-left: 6px; color: var(--text-3); }
.m-reward { flex-shrink: 0; max-width: 40%; color: var(--accent); font-family: var(--font-num); font-size: 12.5px; text-align: right; }

.m-progress { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; margin-top: 12px; }
.m-progress .num { color: var(--text-2); font-size: 12px; }

.m-steps { display: grid; gap: 4px; margin: 10px 0 0; padding: 0; list-style: none; }
.m-steps li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 8px; align-items: start; color: var(--text-3); font-size: 12.5px; line-height: 1.45; }
.m-dot {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  margin-top: 2px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  color: var(--accent-ink);
}
.m-steps li.is-done { color: var(--text-2); }
.m-steps li.is-done .m-dot { border-color: var(--accent); background: var(--accent); }
.m-steps li.is-current { color: var(--text); font-weight: 500; }
.m-steps li.is-current .m-dot { border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 7px var(--accent); }

.m-desc { margin-top: 10px; }
.m-desc summary { color: var(--text-3); font-size: 12px; cursor: pointer; }
.m-desc p { margin-top: 6px; max-width: 80ch; color: var(--text-2); font-size: 12.5px; line-height: 1.55; white-space: pre-line; }

.m-upkeep { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.m-up { padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r-control); }
.m-up summary { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; cursor: pointer; list-style: none; }
.m-up summary::-webkit-details-marker { display: none; }
.m-up .quiet-note { margin-top: 6px; font-size: 11.5px; line-height: 1.5; }

.m-offer {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) 84px 120px;
  align-items: start;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.m-offer > span { display: grid; min-width: 0; }
.m-offer .dim { color: var(--text-3); }
.m-offer > .num { text-align: right; color: var(--accent); }
.m-offer-name { font-weight: 500; }
.m-tut { margin-top: 12px; line-height: 1.55; }

.m-log { display: grid; gap: 2px; margin: 0 0 8px; padding: 0; list-style: none; }
.m-log li { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 10px; align-items: start; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.m-log .tag { justify-self: start; margin-top: 1px; }
.m-log strong { color: var(--text); font-weight: 600; }
.m-log-text { display: grid; }

@media (max-width: 1100px) {
  .m-offer { grid-template-columns: minmax(0, 1fr) 84px 110px; }
  .m-offer > :nth-child(2) { display: none; }
}

/* ---------- achievements ---------- */

.achievements { margin-top: 28px; }

#achievement-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#achievement-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

#achievement-list li.is-earned { border-color: var(--accent-line); }
.medal { display: block; flex-shrink: 0; }
.ach-text { display: grid; gap: 2px; min-width: 0; }
.ach-name { font-size: 13px; font-weight: 600; }
.ach-desc { color: var(--text-3); font-size: 11.5px; line-height: 1.4; }
.is-locked .ach-name { color: var(--text-2); }

/* ---------- modal ---------- */

#modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 7, 9, 0.72);
  animation: modal-fade 0.18s var(--ease);
}

#modal[hidden] { display: none; }

.modal-card {
  width: min(640px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: 0 24px 64px -16px rgba(0, 0, 0, 0.8);
  animation: modal-rise 0.24s var(--ease);
}

.modal-card:focus { outline: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.celebrate { text-align: center; }
.celebrate h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
.celebrate.has-level h2 { margin-top: 2px; }
.celebrate-badge { display: flex; justify-content: center; margin: 4px 0 14px; }
.celebrate-badge .badge {
  animation: badge-reveal 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
  filter: drop-shadow(0 8px 24px rgba(79, 202, 185, 0.25));
}
.celebrate-flavor { max-width: 44ch; margin: 6px auto 0; color: var(--text-2); font-size: 13.5px; line-height: 1.5; }
.celebrate-also { margin-top: 20px; color: var(--text-3); font-size: 12px; }
.celebrate .modal-actions { justify-content: center; }

.celebrate-achs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}
.celebrate-achs li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-card);
  animation: modal-rise 0.3s var(--ease) both;
}
.celebrate-achs li:nth-child(2) { animation-delay: 0.08s; }
.celebrate-achs li:nth-child(3) { animation-delay: 0.16s; }
.celebrate-achs span { display: grid; gap: 2px; color: var(--text-3); font-size: 12px; }
.celebrate-achs strong { color: var(--text); font-size: 13px; }

.share h2 { font-size: 16px; font-weight: 600; }
.share .quiet-note { margin-top: 4px; }
.share-preview { display: block; width: 100%; height: auto; margin-top: 14px; border: 1px solid var(--line); border-radius: var(--r-control); }
a.btn { text-decoration: none; }

@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes badge-reveal {
  0% { opacity: 0; transform: scale(0.4) rotate(-12deg); }
  100% { opacity: 1; transform: none; }
}

/* ---------- scrollbars ---------- */

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border: 2px solid var(--surface); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- narrower windows ---------- */

@media (max-width: 1180px) {
  /* the inspector floats over the chain instead of squeezing it */
  #details {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    box-shadow: -18px 0 32px -18px rgba(0, 0, 0, 0.7);
  }
}

@media (max-width: 1280px) {
  .rank-panel { grid-template-columns: auto minmax(0, 1fr); }
  .rank-figures { grid-column: 1 / -1; }
  .st-detail { grid-template-columns: minmax(0, 1fr); }
  .price-row { grid-template-columns: minmax(0, 1fr) 112px 150px 150px 84px; row-gap: 4px; }
  .price-row > .price-advice { grid-column: 1 / -1; grid-row: 2; }
  .price-head > .price-advice { display: none; }
}

@media (max-width: 1100px) {
  .topbar-actions .btn:not(.is-primary) { padding: 0 8px; }
  .topbar-actions .btn:not(.is-primary):not(.is-confirming) .btn-label { display: none; }
  .rank-chip-name { display: none; }
  #level-ladder { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .st-row { grid-template-columns: 16px minmax(0, 1.6fr) minmax(0, 1fr) 56px 72px 72px 72px; }
  .st-row > :nth-child(5) { display: none; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .price-row { grid-template-columns: minmax(0, 1fr) 112px 150px 84px; }
  .price-row > :nth-child(4) { display: none; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 248px; }
  .empire-source { flex-direction: column; align-items: flex-start; }
  #network { max-height: 55vh; }
  #network-body { grid-template-columns: minmax(0, 1fr); overflow-y: auto; }
  .net-col { overflow: visible; }
  .net-col + .net-col { border-left: 0; border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition: none !important; animation: none !important; }
}
.m-offer .price-sub { white-space: normal; text-overflow: clip; }

/* ---------- overview: estimate and actual side by side ---------- */

.rank-dual { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.fig { display: grid; gap: 2px; }
.fig-label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.fig-num { font-size: 28px; font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; }
.fig-num.is-ok { color: var(--accent); }
.fig-num.is-short { color: var(--danger); }
.fig-unit { color: var(--text-3); font-size: 12px; line-height: 1.4; }
.rank-figures .rank-day { margin-top: 10px; }

/* ---------- action plan ---------- */

.action-plan { margin-top: 16px; }
.action-plan[hidden] { display: none; }
.plan-list { display: grid; gap: 2px; margin: 0 0 10px; padding: 0; list-style: none; }
.plan-list li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}
.plan-list li:last-child { border-bottom: 0; }
.plan-rank { color: var(--text-3); font-size: 13px; text-align: center; }
.plan-main { display: grid; gap: 2px; min-width: 0; }
.plan-main strong { color: var(--text); font-size: 13.5px; font-weight: 600; }
.plan-main span { color: var(--text-3); font-size: 12.5px; line-height: 1.45; }
.plan-impact { color: var(--accent); font-size: 13px; white-space: nowrap; }
.plan-list .btn .icon { margin-left: 2px; }

/* ---------- supply: verdict, then detail ---------- */

.sup-advice .tag { margin-right: 8px; }
.sup-detail { color: var(--text-2); font-size: 12.5px; }
.sup-detail + .sup-detail { display: block; margin-top: 2px; }
.rank-bar.is-warn span { background: var(--warn); }

/* ---------- logistics: compact fixes ---------- */

.hub-advice.is-compact li { display: block; padding: 0; }
.hub-advice.is-compact summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 8px 10px;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}
.hub-advice.is-compact summary::-webkit-details-marker { display: none; }
.hub-advice.is-compact details[open] summary { padding-bottom: 4px; }
.hub-advice.is-compact p { padding: 0 10px 10px; color: var(--text-2); font-size: 12.5px; line-height: 1.5; }

/* ---------- planner: the save's knowledge on the chain ---------- */

.node.is-stalled { border-color: var(--danger-line); }
.node-stall { margin-top: 4px; color: var(--danger); font-size: 12px; font-weight: 500; }

/* ---------- missions: found by search ---------- */

.m-card { transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease); }
.m-card.is-found { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- search palette ---------- */

.search-btn kbd {
  margin-left: 4px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-mark);
  color: var(--text-3);
  font-family: var(--font-num);
  font-size: 11px;
}

#palette {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 16px 16px;
  background: rgba(5, 7, 9, 0.6);
  animation: modal-fade 0.15s var(--ease);
}
#palette[hidden] { display: none; }

.palette-card {
  width: min(600px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: 0 20px 48px -16px rgba(0, 0, 0, 0.8);
  animation: modal-rise 0.18s var(--ease);
}

.palette-field { position: relative; display: block; border-bottom: 1px solid var(--line); }
.palette-field .search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
#palette-input {
  width: 100%;
  height: 50px;
  padding: 0 16px 0 42px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
}
#palette-input:focus { outline: none; }

#palette-list { flex: 1; overflow-y: auto; margin: 0; padding: 6px; list-style: none; }
#palette-list li {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--r-control);
  font-size: 13px;
  cursor: pointer;
}
#palette-list li.is-active { background: var(--surface-3); }
.pal-kind { color: var(--text-3); font-size: 11.5px; }
.pal-label { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.pal-sub { overflow: hidden; max-width: 220px; color: var(--text-3); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
#palette-list li.pal-empty { display: block; color: var(--text-3); cursor: default; }

.palette-hint { padding: 8px 14px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 11.5px; }
.palette-hint kbd {
  margin-right: 3px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-mark);
  font-family: var(--font-num);
  font-size: 11px;
}

@media (max-width: 1100px) {
  .search-btn kbd { display: none; }
  .plan-list li { grid-template-columns: 22px minmax(0, 1fr) auto; }
  .plan-list .btn { grid-column: 2 / -1; justify-self: start; }
}

.filter-field[hidden],
.tab-panel > section[hidden] { display: none; }

/* ---------- blueprints ---------- */

.bp-head { margin-bottom: 16px; }
.bp-total { margin-bottom: 12px; color: var(--text-2); font-size: 13px; }
.bp-total .num { color: var(--text); font-size: 22px; font-weight: 500; margin-right: 4px; }
.bp-total .dim { color: var(--text-3); }
.bp-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.bp-cat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s var(--ease), background-color 0.12s var(--ease);
}
.bp-cat:hover { border-color: var(--line-strong); background: var(--surface-2); }
.bp-cat .num { color: var(--text-2); }
.bp-cat .rank-bar { grid-column: 1 / -1; }
.bp-worth { margin-top: 4px; }
.bp-worth-list { display: grid; gap: 2px; margin: 8px 0 0; padding: 0; list-style: none; }
.bp-worth-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); gap: 14px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.bp-worth-list li:last-child { border-bottom: 0; }
.bp-worth-main { display: grid; gap: 2px; }
.bp-worth-main strong { color: var(--text); font-weight: 600; }
.bp-worth-main span, .bp-sellers { color: var(--text-3); }
.bp-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 12px; }
.bp-controls[hidden] { display: none; }
.bp-show { margin: 0; grid-template-columns: repeat(3, auto); }
.bp-show button { padding: 0 14px; }
.bp-filter { width: min(320px, 100%); }
.bp-filtered { margin-bottom: 8px; color: var(--text-2); font-size: 12.5px; }
.bp-group { margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--r-card); }
.bp-group > summary { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; list-style: none; }
.bp-group > summary::-webkit-details-marker { display: none; }
.bp-group[open] > summary { border-bottom: 1px solid var(--line); }
.bp-kind { margin: 12px 14px 4px; color: var(--text-3); font-size: 12px; font-weight: 500; }
.bp-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 18px; margin: 0; padding: 4px 14px 12px; list-style: none; }
.bp-items li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 8px; align-items: start; padding: 4px 0; font-size: 12.5px; }
.bp-text { display: grid; min-width: 0; }
.bp-mark { display: grid; place-items: center; width: 14px; height: 14px; margin-top: 2px; border: 1.5px solid var(--line-strong); border-radius: 50%; color: var(--accent-ink); }
.bp-items li.is-owned .bp-mark { border-color: var(--accent); background: var(--accent); }
.bp-items li.is-missing .bp-name { color: var(--text-2); }
.bp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bp-name .tag { margin-left: 4px; font-size: 10.5px; }
.bp-from { overflow: hidden; color: var(--text-3); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.node-stall.is-idle { color: var(--warn); }
