:root {
  --paper: #f5f1e8;
  --ink: #2b2d35;
  --ink-soft: #6b6d78;
  --accent: #d9583b;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #a9bf96; /* matches COLORS.outside */
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#map {
  position: fixed;
  top: var(--mc-top, 0px);
  left: 0;
  width: 100vw;
  height: calc(100dvh - var(--mc-top, 0px));
  display: block;
  touch-action: none;
  cursor: grab;
}
#map.panning { cursor: grabbing; }

body[data-tool="track"] #map,
body[data-tool="station"] #map { cursor: crosshair; }
body[data-tool="bulldoze"] #map { cursor: pointer; }

/* ---------- dock: tools on the left, cash + clock on the right ---------- */

.dock {
  position: fixed;
  left: max(10px, env(safe-area-inset-left, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: max(10px, env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.pill {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(40, 30, 10, 0.12), 0 4px 14px rgba(40, 30, 10, 0.1);
}

.sep {
  width: 1px;
  align-self: stretch;
  margin: 6px 4px;
  background: rgba(43, 45, 53, 0.14);
}

.tool {
  appearance: none;
  border: 0;
  margin: 0;
  width: 60px;
  height: 52px;
  padding: 4px 0 3px;
  border-radius: 13px;
  background: transparent;
  color: var(--ink);
  font: 600 10.5px/1 var(--font);
  cursor: pointer;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: center;
  gap: 2px;
  touch-action: manipulation;
}
.tool svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool svg .dot { fill: #fff; stroke-width: 1.8; }
.tool svg .cap { fill: #fff; stroke-width: 2; }
.tool svg .x { stroke: var(--accent); }
.tool:hover { background: rgba(43, 45, 53, 0.07); }
.tool.on { background: var(--ink); color: #fff; }
.tool.on svg .dot, .tool.on svg .cap { fill: var(--ink); stroke: #fff; }
.tool.on svg .x { stroke: #ff9f88; }
.tool:disabled { opacity: 0.35; cursor: default; background: transparent; }
.tool:focus-visible, .more:focus-visible, .menu-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.status { padding-left: 14px; }

.cash {
  appearance: none;
  border: 0;
  margin: 0;
  min-width: 6.4em;
  min-height: 44px;
  padding: 2px 8px;
  border-radius: 13px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font);
  cursor: pointer;
  display: grid;
  justify-items: end;
  align-content: center;
  gap: 1px;
  touch-action: manipulation;
}
.cash:hover, .cash[aria-expanded="true"] { background: rgba(43, 45, 53, 0.07); }
.cash:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cash-val {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.05;
}
.cash.low .cash-val { color: #c2261c; }
.cash.bump .cash-val { animation: bump 0.35s ease-out; display: inline-block; }
@keyframes bump { 30% { transform: scale(1.08); } }
.cash-sub { display: flex; align-items: center; gap: 5px; }
.net { font-size: 11px; font-weight: 700; color: #15803d; font-variant-numeric: tabular-nums; white-space: nowrap; }
.net.neg { color: #c2261c; }
.spark { width: 36px; height: 14px; display: block; }
.spark .mid { stroke: rgba(43, 45, 53, 0.25); stroke-width: 0.6; }
.spark .pos { fill: #16a34a; }
.spark .neg { fill: #dc2626; }
.spark .part { opacity: 0.45; }
.debt {
  align-self: center;
  margin: 0 2px;
  padding: 4px 8px;
  border-radius: 9px;
  background: #c2261c;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  animation: pulse 1.6s ease-in-out infinite;
}
.debt[hidden] { display: none; }
@keyframes pulse { 50% { opacity: 0.72; } }

/* ---------- clock (inside the status pill) ---------- */

.clock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
}

.date {
  min-width: 5.6em;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.clock.stopped .date { color: var(--ink-soft); }

.speeds { display: flex; gap: 2px; }

.speeds button, .more {
  appearance: none;
  border: 0;
  margin: 0;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  border-radius: 13px;
  background: transparent;
  color: var(--ink-soft);
  font: 700 14px/1 var(--font);
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}
.speeds button svg { width: 14px; height: 14px; fill: currentColor; }
.speeds button:hover, .more:hover { background: rgba(43, 45, 53, 0.07); color: var(--ink); }
.speeds button.on { background: var(--ink); color: #fff; }
.speeds button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.more svg { width: 18px; height: 18px; fill: currentColor; }
.more[aria-expanded="true"] { background: rgba(43, 45, 53, 0.1); color: var(--ink); }

/* ---------- map options menu ---------- */

.menu {
  position: fixed;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: calc(max(10px, env(safe-area-inset-bottom, 0px)) + 72px);
  width: 250px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.12), 0 10px 30px rgba(40, 30, 10, 0.16);
  z-index: 20;
}
.menu[hidden] { display: none; }
.menu p { margin: 2px 4px 4px; font-size: 14px; line-height: 1.35; }
.menu .row { display: flex; gap: 8px; }
.menu .row .menu-btn { flex: 1; }
.newmap-confirm[hidden] { display: none; }

.seed {
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
}
.seed:hover { text-decoration: underline; color: var(--ink); }

.menu-btn {
  appearance: none;
  border: 0;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(43, 45, 53, 0.07);
  color: var(--ink);
  font: 700 15px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.menu-btn:hover { background: rgba(43, 45, 53, 0.12); }
.menu-btn.danger { background: #c2261c; color: #fff; }

/* ---------- confirm card, cost tip, toast ---------- */

.card, .tip {
  position: fixed;
  left: 0;
  top: var(--mc-top, 0px);
  z-index: 12;
  will-change: transform;
}

.card {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  padding: 8px;
  max-width: 236px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 16px;
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.14), 0 8px 24px rgba(40, 30, 10, 0.14);
}
.card[hidden], .tip[hidden] { display: none; }
.card-text { flex: 1 0 100%; padding: 2px 4px 2px; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.card-ok { flex: 1; }
.card.bad .card-text { color: #c2261c; }
.card button {
  appearance: none;
  border: 0;
  height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 12px;
  font: 800 15px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.card-ok { background: #2563eb; color: #fff; }
.card-ok:disabled { background: #c9ccd4; cursor: default; }
.card-no { background: rgba(43, 45, 53, 0.08); color: var(--ink); font-size: 17px; }

/* Track tool: Direct / Cheap route choice (segmented, two big touch targets). */
.card.two { max-width: 316px; }
.card-modes {
  flex: 1 0 100%;
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 14px;
  background: rgba(43, 45, 53, 0.08);
}
.card-modes[hidden] { display: none; }
.card .card-mode {
  flex: 1 1 0;
  min-width: 0;
  height: auto;
  min-height: 58px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  background: transparent;
  color: var(--ink);
  border-radius: 11px;
  text-align: left;
  white-space: normal;
}
.card .card-mode.on { background: #fff; box-shadow: 0 1px 3px rgba(40, 30, 10, 0.22); outline: 2px solid #2563eb; outline-offset: -2px; }
.mode-name { font: 800 12px/1 var(--font); letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.65; }
.card-mode.on .mode-name { color: #2563eb; opacity: 1; }
.mode-cost { font: 800 17px/1.1 var(--font); font-variant-numeric: tabular-nums; }
.mode-info { font: 600 12px/1.2 var(--font); opacity: 0.8; font-variant-numeric: tabular-nums; }
.mode-info:empty { display: none; }
.card .card-mode.bad .mode-cost { color: #c2261c; }
.card .card-mode.bad.on { outline-color: #c2261c; }
.card-text[hidden] { display: none; }
.card.two .card-text { font-size: 13px; }
.card-text.note { color: #9a5b00; }

.tip {
  padding: 6px 10px;
  background: rgba(43, 45, 53, 0.92);
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.tip.bad { background: rgba(194, 38, 28, 0.95); }

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--mc-top, 0px) + 12px);
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  background: rgba(43, 45, 53, 0.92);
  color: #fff;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: rgba(194, 38, 28, 0.95); }

/* ---------- line tool ---------- */

body[data-tool="line"] #map { cursor: pointer; }
.tool svg .ln { stroke: #0d9488; stroke-width: 2.6; }
.tool.on svg .ln { stroke: #5eead4; }

.linecard {
  --line: #0d9488;
  position: fixed;
  left: max(10px, env(safe-area-inset-left, 0px));
  bottom: calc(max(10px, env(safe-area-inset-bottom, 0px)) + 72px);
  width: 330px;
  max-width: calc(100vw - 20px);
  box-sizing: border-box;
  padding: 10px 10px 10px 14px;
  display: grid;
  gap: 6px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 16px;
  border-left: 6px solid var(--line);
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.14), 0 8px 24px rgba(40, 30, 10, 0.14);
  z-index: 12;
}
.linecard.cargo { border-left-style: dashed; }
.linecard[hidden] { display: none; }

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(43, 45, 53, 0.07);
  border-radius: 12px;
}
.seg button {
  flex: 1;
  appearance: none;
  border: 0;
  height: 38px;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font: 700 14px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(40, 30, 10, 0.18); }
.seg[hidden] { display: none; }
.seg.shape button { height: 40px; padding: 0 6px; font-size: 13px; line-height: 1.15; }
.seg.shape button:disabled { opacity: 0.4; cursor: default; }

.line-text { padding: 2px 2px 0; font-size: 15px; font-weight: 800; line-height: 1.3; }
.line-hint { padding: 0 2px; font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.3; }
.line-hint:empty { display: none; }

.linecard .row { display: flex; gap: 6px; margin-top: 2px; }
.linecard .row button {
  appearance: none;
  border: 0;
  height: 44px;
  min-width: 48px;
  padding: 0 12px;
  border-radius: 12px;
  background: rgba(43, 45, 53, 0.08);
  color: var(--ink);
  font: 800 16px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.linecard .row .line-ok { flex: 1; background: var(--line); color: #fff; font-size: 15px; }
.linecard .row button:disabled { opacity: 0.4; cursor: default; }
.linecard .row .line-ok:disabled { background: #c9ccd4; opacity: 1; }

/* ---------- lines panel ---------- */

.lines {
  position: fixed;
  top: calc(var(--mc-top, 0px) + 10px);
  right: max(10px, env(safe-area-inset-right, 0px));
  width: 330px;
  max-width: calc(100vw - 20px);
  max-height: calc(100dvh - var(--mc-top, 0px) - 100px);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(40, 30, 10, 0.12), 0 4px 14px rgba(40, 30, 10, 0.1);
  z-index: 11;
  overflow: hidden;
}
.lines[hidden] { display: none; }
.lines:not(.open) { width: auto; }

.lines-head {
  appearance: none;
  border: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  background: transparent;
  color: var(--ink);
  font: 800 15px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  text-align: left;
}
.lines-head .count {
  min-width: 22px;
  padding: 3px 6px;
  box-sizing: border-box;
  border-radius: 11px;
  background: rgba(43, 45, 53, 0.09);
  font-size: 13px;
  text-align: center;
}
.lines-warn { color: #c2261c; font-size: 16px; }
.lines-warn[hidden] { display: none; }
.lines-head .chev { width: 14px; height: 14px; margin-left: auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s; }
.lines.open .lines-head .chev { transform: rotate(180deg); }
.lines-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.lines-list { overflow-y: auto; padding: 0 8px 8px; display: grid; gap: 6px; -webkit-overflow-scrolling: touch; }
.lines-list[hidden] { display: none; }
.lines-empty { margin: 4px 6px 6px; font-size: 14px; color: var(--ink-soft); }

.line-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border-radius: 12px;
  background: rgba(43, 45, 53, 0.045);
}
.line-row.trouble { background: rgba(194, 38, 28, 0.08); }
.swatch {
  --c: #0d9488;
  width: 8px;
  align-self: stretch;
  min-height: 34px;
  border-radius: 4px;
  background: var(--c);
}
.swatch.cargo { background: repeating-linear-gradient(180deg, var(--c) 0 7px, color-mix(in srgb, var(--c) 30%, transparent) 7px 11px); }
.line-main { min-width: 0; }
.line-name { font-size: 15px; font-weight: 800; }
.line-type { margin-left: 4px; font-size: 12px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.line-stops { margin-top: 2px; font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.3; overflow-wrap: anywhere; }
.line-warn { margin-top: 5px; font-size: 13px; font-weight: 700; color: #b0241b; line-height: 1.3; }
.line-hint { margin-top: 5px; font-size: 12.5px; font-weight: 600; color: #8a5a00; line-height: 1.3; }

.line-side { display: grid; gap: 6px; justify-items: end; }
.stepper { display: flex; align-items: center; gap: 2px; background: #fff; border-radius: 11px; padding: 2px; box-shadow: inset 0 0 0 1px rgba(43, 45, 53, 0.12); }
.stepper button {
  appearance: none;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: 800 20px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.stepper button:hover { background: rgba(43, 45, 53, 0.07); }
.stepper button:disabled { opacity: 0.3; cursor: default; background: transparent; }
.stepper button.confirm { background: #c2261c; color: #fff; font-size: 16px; }
.stepper .n { min-width: 22px; text-align: center; font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.line-del {
  appearance: none;
  border: 0;
  height: 32px;
  padding: 0 10px;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font: 700 13px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.line-del:hover { background: rgba(43, 45, 53, 0.07); color: var(--ink); }
.line-del.confirm { background: #c2261c; color: #fff; }

/* ---------- train info card ---------- */

.traincard {
  position: fixed;
  left: 0;
  top: var(--mc-top, 0px);
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 7px 11px 7px 8px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.14), 0 6px 18px rgba(40, 30, 10, 0.14);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  z-index: 12;
  will-change: transform;
  cursor: pointer;
}
.traincard[hidden] { display: none; }
.traincard .swatch { width: 6px; min-height: 0; }
.traincard .state { font-weight: 800; }
.traincard.bad .state { color: #c2261c; }

.toast { max-width: calc(100vw - 40px); white-space: normal; text-align: center; }

.traincard .carry { color: var(--ink-soft); font-weight: 600; }
.traincard .next { color: #8a5a00; font-weight: 700; }
.traincard-body { display: grid; gap: 6px; }
.traincard-acts { display: flex; gap: 4px; }
.traincard-acts button {
  appearance: none;
  border: 0;
  height: 36px;
  padding: 0 10px;
  border-radius: 9px;
  background: rgba(43, 45, 53, 0.08);
  color: var(--ink);
  font: 700 13px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.traincard-acts button:hover { background: rgba(43, 45, 53, 0.14); }
.traincard-acts .release { background: rgba(13, 148, 136, 0.18); }

/* ---------- lines panel: spacing strip ---------- */

.line-strip { margin-top: 6px; display: grid; gap: 2px; }
.line-strip small { font-size: 11px; font-weight: 600; color: var(--ink-soft); }
.strip-bar { position: relative; height: 18px; margin: 0 8px; }
.strip-bar::before { content: ''; position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--c, #0d9488) 30%, #fff); }
.strip-bar .tick { position: absolute; top: 4px; width: 2px; height: 10px; margin-left: -1px; border-radius: 1px; background: color-mix(in srgb, var(--c, #0d9488) 60%, #fff); }
.strip-bar .tick.end { left: 100%; }
.strip-bar .dot { position: absolute; top: 1px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; box-sizing: border-box; background: var(--c, #0d9488); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(43, 45, 53, 0.3); transition: left 0.25s linear; }
.strip-bar .dot.held { background: #fff; border: 4px solid var(--c, #0d9488); }
.strip-bar .dot.sel { box-shadow: 0 0 0 2px var(--ink, #2b2d35); }
.strip-bar .dot[hidden] { display: none; }
.line-opts .line-spacing.on { background: color-mix(in srgb, var(--c, #0d9488) 18%, #fff); }

/* ---------- lines panel: profit and load ---------- */

.line-opts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.line-opts:empty { display: none; }
.line-opts button {
  appearance: none;
  border: 0;
  height: 30px;
  padding: 0 10px;
  border-radius: 9px;
  background: rgba(43, 45, 53, 0.08);
  color: var(--ink);
  font: 700 13px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.line-opts .line-full.on { background: color-mix(in srgb, var(--c, #0d9488) 18%, #fff); }
.routecard .row .line-no { font-size: 15px; }
.line-profit { margin-top: 4px; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.line-profit > span:first-child { white-space: nowrap; }
.line-profit small { font-size: 11px; font-weight: 600; color: var(--ink-soft); }
.line-profit .pos { color: #15803d; }
.line-profit .neg { color: #c2261c; }
.line-profit .load { width: 40px; height: 6px; border-radius: 3px; background: rgba(43, 45, 53, 0.12); overflow: hidden; margin-left: 4px; }
.line-profit .load i { display: block; height: 100%; background: var(--c, #0d9488); }

/* ---------- money breakdown ---------- */

.ledger {
  position: fixed;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: calc(max(10px, env(safe-area-inset-bottom, 0px)) + 72px);
  width: 330px;
  max-width: calc(100vw - 20px);
  max-height: calc(100dvh - var(--mc-top, 0px) - 100px);
  overflow-y: auto;
  box-sizing: border-box;
  padding: 10px 12px 12px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.12), 0 10px 30px rgba(40, 30, 10, 0.16);
  z-index: 20;
}
.ledger[hidden] { display: none; }
.ledger-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; margin-bottom: 4px; }
.x {
  appearance: none;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: rgba(43, 45, 53, 0.06);
  color: var(--ink);
  font: 700 15px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.x:hover { background: rgba(43, 45, 53, 0.12); }
.ledger-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.ledger-table th, .ledger-table td { padding: 5px 2px; text-align: right; white-space: nowrap; }
.ledger-table th:first-child { text-align: left; font-weight: 600; white-space: normal; }
.ledger-table thead th { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.ledger-table thead th:not(:first-child) { white-space: normal; line-height: 1.2; width: 74px; padding-left: 8px; vertical-align: bottom; }
.ledger-table thead th small { display: block; font-weight: 600; letter-spacing: 0; }
.ledger-table tbody tr { border-top: 1px solid rgba(43, 45, 53, 0.08); }
.ledger-table .inc td { color: #15803d; font-weight: 700; }
.ledger-table .cost td { color: #9a3412; }
.ledger-table .net th, .ledger-table .net td { font-weight: 800; font-size: 14.5px; border-top: 2px solid rgba(43, 45, 53, 0.25); }
.ledger-table .net td { color: #15803d; }
.ledger-table .net td.neg { color: #c2261c; }
.ledger-table .ic, .info .ic { width: 18px; height: 18px; vertical-align: -4px; }
.ledger-note { margin: 8px 2px 0; font-size: 12px; line-height: 1.35; color: var(--ink-soft); }
.ledger-month { margin: 7px 2px 0; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.ledger-month .pos { color: #15803d; }
.ledger-month .neg { color: #c2261c; }

/* ---------- upgrade card (Upgrade tool) ---------- */

.tool svg .dbl { stroke-width: 1.8; }
.tool svg .up { stroke: #0f766e; }
.tool.on svg .up { stroke: #5eead4; }
body[data-tool="upgrade"] #map { cursor: pointer; }

.upcard {
  position: fixed;
  left: 0;
  top: var(--mc-top, 0px);
  width: 296px;
  max-width: calc(100vw - 20px);
  box-sizing: border-box;
  padding: 10px 10px 10px 12px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 16px;
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.14), 0 8px 24px rgba(40, 30, 10, 0.16);
  font-size: 13.5px;
  line-height: 1.35;
  z-index: 13;
  will-change: transform;
}
.upcard[hidden] { display: none; }
.upcard .x { position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; }
.up-title { font-size: 16px; font-weight: 800; padding-right: 44px; }
.up-sub { margin-top: 1px; padding-right: 40px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.up-acts { display: grid; gap: 6px; margin-top: 9px; }
.up-acts[hidden] { display: none; }
.up-row {
  appearance: none;
  border: 0;
  margin: 0;
  min-height: 52px;
  padding: 7px 12px;
  border-radius: 12px;
  background: #2563eb;
  color: #fff;
  font: inherit;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 8px;
  row-gap: 1px;
  cursor: pointer;
  touch-action: manipulation;
}
.up-row .up-name { font-size: 15px; font-weight: 800; }
.up-row .up-price { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.up-row .up-note { grid-column: 1 / -1; font-size: 12px; font-weight: 600; opacity: 0.85; font-variant-numeric: tabular-nums; }
.up-row .up-cov { grid-column: 1 / -1; margin-top: 2px; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.up-row .up-cov b { font-weight: 800; }
.up-row:disabled { background: rgba(43, 45, 53, 0.07); color: var(--ink-soft); cursor: default; }
.up-row.done:disabled { background: rgba(21, 128, 61, 0.1); color: #166534; }
.up-row:not(:disabled):active { background: #1d4ed8; }
.up-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.up-hint { margin: 8px 2px 0; font-size: 12px; color: var(--ink-soft); }
.up-hint:empty { display: none; }

/* ---------- info card (station / industry / town) ---------- */

.info {
  position: fixed;
  left: 0;
  top: var(--mc-top, 0px);
  width: 316px;
  max-width: calc(100vw - 20px);
  box-sizing: border-box;
  padding: 10px 12px 12px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 16px;
  box-shadow: 0 2px 4px rgba(40, 30, 10, 0.14), 0 8px 24px rgba(40, 30, 10, 0.16);
  font-size: 13.5px;
  line-height: 1.35;
  z-index: 13;
  will-change: transform;
}
.info[hidden] { display: none; }
.info .x { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; }
.info-title { font-size: 16px; font-weight: 800; padding-right: 40px; }
.info-sub { margin-top: 1px; padding-right: 40px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.info-row { display: grid; grid-template-columns: 96px 1fr; gap: 6px; align-items: start; margin-top: 7px; }
.info-k { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.02em; padding-top: 3px; }
.info-k.block { display: block; margin: 9px 0 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px 2px 4px; border-radius: 10px; background: rgba(43, 45, 53, 0.06); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip small { color: var(--ink-soft); font-weight: 600; }
.chip.full { background: rgba(194, 38, 28, 0.12); }
.chip.crate { border-radius: 3px; background: rgba(120, 84, 40, 0.1); box-shadow: inset 0 0 0 1px rgba(120, 84, 40, 0.35); }
.pqs { display: flex; flex-direction: column; gap: 2px; padding-top: 1px; }
.pq { overflow-wrap: anywhere; }
.pq small { white-space: nowrap; }
.pq b { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 5px; background: var(--c); margin: 0 3px 0 0; vertical-align: -1px; }
.info-hint { margin: 9px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.info-status { margin: 7px 0 0; font-weight: 700; }
.info-status .good { color: #15803d; }
.info-status .bad { color: #b45309; }
.need { display: grid; grid-template-columns: 20px 82px 1fr auto; gap: 6px; align-items: center; margin-top: 4px; }
.need .ic { opacity: 0.45; }
.need.met .ic { opacity: 1; }
.need-name { font-weight: 600; }
.need .bar { height: 8px; border-radius: 4px; background: rgba(43, 45, 53, 0.1); overflow: hidden; }
.need .bar i { display: block; height: 100%; background: #9ca3af; }
.need.met .bar i { background: #16a34a; }
.need-num { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.need-num small { color: var(--ink-soft); font-weight: 600; }

/* ---------- game over ---------- */

.gameover {
  position: fixed;
  inset: var(--mc-top, 0px) 0 0 0;
  display: grid;
  place-items: center;
  background: rgba(30, 32, 38, 0.42);
  z-index: 30;
}
.gameover[hidden] { display: none; }
.gameover-card {
  width: 340px;
  max-width: calc(100vw - 40px);
  box-sizing: border-box;
  padding: 20px 20px 18px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18), 0 20px 50px rgba(0, 0, 0, 0.25);
}
.gameover-card h2 { margin: 0 0 4px; font-size: 24px; color: #c2261c; }
.gameover-card p { margin: 0 0 12px; font-size: 14px; line-height: 1.4; color: var(--ink-soft); }
.gameover-card dl { margin: 0 0 16px; display: grid; gap: 6px; }
.gameover-card dl div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 10px; background: rgba(43, 45, 53, 0.05); }
.gameover-card dt { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.gameover-card dd { margin: 0; font-size: 14px; font-weight: 800; text-align: right; }
.gameover-card .row { display: flex; gap: 8px; }
.gameover-card .row .menu-btn { flex: 1; }
.menu-btn.primary { background: #2563eb; color: #fff; }

/* ---------- hover / long-press tooltip ---------- */

.hovertip {
  position: fixed;
  left: 0;
  top: var(--mc-top, 0px);
  z-index: 30;
  max-width: 240px;
  box-sizing: border-box;
  padding: 7px 9px 8px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 11px;
  box-shadow: 0 1px 3px rgba(40, 30, 10, 0.16), 0 6px 18px rgba(40, 30, 10, 0.16);
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--ink);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.hovertip[hidden] { display: none; }
.tt-title { font-size: 13.5px; font-weight: 800; margin-bottom: 3px; }
.tt-sub { font-size: 11.5px; font-weight: 600; color: var(--ink-soft); margin-left: 3px; }
.tt-row { display: grid; grid-template-columns: 62px 1fr; gap: 6px; align-items: baseline; margin-top: 3px; }
.tt-k { font-size: 10px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.02em; }
.tt-v { line-height: 1.55; }
.tt-line { margin-top: 2px; white-space: nowrap; font-weight: 600; color: var(--ink-soft); }
.tt-line .tt-c { color: var(--ink); }
.tt-line b { color: var(--ink); }
.tt-nw { white-space: nowrap; }
.tt-c { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; white-space: nowrap; box-shadow: inset 0 -2px 0 var(--cc); padding-bottom: 1px; }
.tt-c .ic { width: 16px; height: 16px; }
.tt-c b { font-variant-numeric: tabular-nums; }
.tt-need i { font-style: normal; font-weight: 800; margin-left: 2px; color: #b0241b; }
.tt-need.met i { color: #2e7d32; }
.tt-need:not(.met) .ic { opacity: 0.5; }
.hovertip .dot { margin-right: 4px; }
