:root {
  --yellow: #f2c01d;
  --yellow-dark: #a06000;
  --yellow-light: #ffea63;
  --navy: #0a1d42;
  --navy-light: #1b4998;
  --navy-soft: #2b68c4;
  --green: #3C8F4A;
  --green-dark: #2C6B37;
  --gold: #d99300;
  --red: #E5342B;
  --cream: #EFF2F7;
  --cream-hi: #F9FAFC;
  --ink: #0a1d42;
  --muted: #5C6B78;
  --line: #D7DCE6;
  --shadow: 0 2px 8px rgba(10,29,66,0.10);
  --shadow-lg: 0 12px 32px rgba(10,29,66,0.22);
  font-family: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy);
  color: var(--ink);
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

h1, h2 {
  font-family: 'Space Grotesk', 'Arial Black', sans-serif;
  margin: 0;
}

/* ===== TOPBAR ===== */
#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: var(--navy);
  color: var(--cream-hi);
  padding: 10px 22px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  flex-wrap: wrap;
  flex: none;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brandTitle {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
  letter-spacing: -0.5px;
}
.brandSub {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--yellow);
  font-weight: 700;
  text-transform: uppercase;
}

.stats {
  display: flex;
  gap: 26px;
  margin-left: auto;
}
.stat { display: flex; flex-direction: column; align-items: flex-start; min-width: 70px; }
.statLabel {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #9FB4C7;
}
.statValue {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  color: var(--yellow);
}
#statNetwork { color: var(--cream-hi); }

.topActions { display: flex; align-items: center; gap: 12px; }
.saveIndicator {
  font-size: 11px;
  color: #9FB4C7;
  opacity: 0;
  transition: opacity 0.4s;
}
.saveIndicator.show { opacity: 1; }

.ghostBtn {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.25);
  color: var(--cream-hi);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.ghostBtn:hover { border-color: var(--yellow); color: var(--yellow); }
.audioBtn { font-size: 14px; padding: 6px 9px; }
.audioBtn.muted { opacity: 0.35; }

/* ===== LAYOUT ===== */
#layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
  padding: 18px;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
  align-items: stretch;
}
@media (max-width: 980px) {
  #layout { grid-template-columns: 1fr; overflow-y: auto; }
}

#mapPanel, #sidePanel {
  background: var(--cream-hi);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.panelHead { padding: 16px 18px 6px; flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#mapZoomBtn { flex: none; white-space: nowrap; }
.panelHead h2 { font-size: 17px; color: var(--navy); }
.panelHint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

#mapWrap {
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 4px 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
#networkMap { display: block; height: 100%; width: 100%; object-fit: contain; }

/* map elements */
.routeLine { fill: none; stroke-linecap: round; stroke-linejoin: round; transition: stroke-width 0.15s; }
.routeLine.hidden-route { stroke: #B7BECC; stroke-width: 3; stroke-dasharray: 1 9; opacity: 0.4; cursor: default; }
.routeLine.researched { stroke: var(--yellow-dark); stroke-width: 5.5; stroke-dasharray: 9 7; cursor: pointer; }
.routeLine.owned { stroke-width: 8; cursor: pointer; }
.routeLine.owned:hover, .routeLine.researched:hover { filter: brightness(1.1); stroke-width: 10; }
.routeLine.incident { animation: routePulse 1s ease-in-out infinite; }
@keyframes routePulse {
  0%, 100% { stroke: var(--red); }
  50% { stroke: #FF8A80; }
}

.stationLabel { font-size: 14px; font-weight: 700; fill: var(--navy); font-family: 'Space Grotesk', sans-serif; pointer-events: none; paint-order: stroke; stroke: var(--cream-hi); stroke-width: 3px; stroke-linejoin: round; }
.stationLabel.intl { font-style: italic; fill: #7A5220; }

.trainMarker { pointer-events: none; filter: drop-shadow(0 2px 2px rgba(15,42,67,0.35)); }
.trainMarker.blocked { filter: drop-shadow(0 2px 2px rgba(229,52,43,0.55)); animation: blockedPulse 1s ease-in-out infinite; }
.trainMarker.lit { filter: drop-shadow(0 0 4px rgba(255,216,77,0.95)) drop-shadow(0 0 9px rgba(255,201,23,0.55)); }
@keyframes blockedPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.incidentIcon { pointer-events: none; }

.floatText {
  position: absolute;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 800;
  font-size: 20px;
  color: var(--green-dark);
  text-shadow: 0 1px 0 rgba(255,255,255,0.6);
  pointer-events: none;
  animation: floatUp 1.5s cubic-bezier(.2,.8,.3,1) forwards;
  white-space: nowrap;
}
.floatText.warn { color: #B92A22; }
@keyframes floatUp {
  0% { transform: translateY(4px) scale(0.7); opacity: 0; }
  15% { transform: translateY(-4px) scale(1.15); opacity: 1; }
  30% { transform: translateY(-10px) scale(1); opacity: 1; }
  100% { transform: translateY(-58px) scale(1); opacity: 0; }
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 12px 0;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tabBtn {
  background: none;
  border: none;
  padding: 9px 14px;
  border-radius: 10px 10px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  position: relative;
}
.tabBtn.active { color: var(--navy); background: var(--cream); }
.tabBtn:hover { color: var(--navy); }
.badge {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 6px;
  margin-left: 6px;
}
.badge.hidden { display: none; }

.tabPane { display: none; flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
.tabPane.active { display: block; }

/* ===== CARDS ===== */
.cardList { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.cardTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cardTitle { font-weight: 700; font-size: 14px; color: var(--navy); }
.cardSub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.lineChip {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}

.cardStats { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; font-size: 11.5px; color: var(--muted); }
.cardStats b { color: var(--navy); font-variant-numeric: tabular-nums; }

.barTrack {
  height: 7px;
  background: #E4E8EF;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 3px;
}
.barFill { height: 100%; border-radius: 999px; transition: width 0.25s; }
.barFill.durability { background: linear-gradient(90deg, var(--green), var(--green-dark)); }
.barFill.durability.low { background: linear-gradient(90deg, #E5342B, #B92A22); }
.barFill.durability.mid { background: linear-gradient(90deg, var(--yellow), var(--yellow-dark)); }
.barFill.track { background: linear-gradient(90deg, #7FB8E8, #4A8FC7); }
.barFill.trip { background: linear-gradient(90deg, var(--gold), var(--yellow)); }
.barFill.gold { background: linear-gradient(90deg, var(--yellow), var(--yellow-dark)); }

.barRow { margin: 6px 0; }
.barLabel { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-bottom: 2px; }

.cardActions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.warnText { color: #B92A22; font-weight: 600; margin-top: 8px; }

.staffRow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.staffChip {
  display: flex; align-items: center; gap: 6px;
  background: #E4F3E6; color: var(--green-dark);
  border-radius: 7px; padding: 6px 10px;
  font-size: 11.5px; font-weight: 700;
}
.staffChip .staffTimer { font-variant-numeric: tabular-nums; opacity: 0.8; font-weight: 600; }

.modelChip {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--navy);
  background: #EAEDF2;
  vertical-align: middle;
  margin-left: 4px;
}

.buyTrainRow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.buyTrainBtn {
  flex: 1 1 140px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--yellow); color: var(--navy);
  border: none; border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 3px 0 var(--yellow-dark);
  font-family: inherit;
}
.buyTrainBtn:hover:not(:disabled) { filter: brightness(1.04); }
.buyTrainBtn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--yellow-dark); }
.buyTrainBtn .buyTrainName { font-weight: 700; font-size: 13px; }
.buyTrainBtn .buyTrainCost { font-size: 11.5px; opacity: 0.75; font-weight: 600; }

.rarityChip {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
  background: var(--rc, var(--muted));
  white-space: nowrap;
}

.packGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
@media (max-width: 1180px) { .packGrid { grid-template-columns: 1fr; } }

.packCard {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  background: #fff;
  border: 2px solid var(--rc, var(--line));
  box-shadow: 0 0 0 3px var(--rg, transparent), var(--shadow);
  border-radius: 10px;
  padding: 10px 11px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.packCard:hover { transform: translateY(-3px); }
.packRarity {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--rc);
}
.packLine { display: block; width: 100%; height: 3px; border-radius: 2px; margin: 1px 0 2px; }
.packName { font-size: 13px; font-weight: 700; color: var(--navy); line-height: 1.25; }
.packStats { font-size: 10.5px; color: var(--muted); }

.smallBtn {
  background: var(--navy);
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
}
.smallBtn:hover:not(:disabled) { background: var(--navy-light); }
.smallBtn.gold { background: var(--yellow); color: var(--navy); }
.smallBtn.gold:hover:not(:disabled) { background: var(--yellow-dark); }
.smallBtn.outline { background: none; border: 1.5px solid var(--navy); color: var(--navy); }
.smallBtn.outline:hover:not(:disabled) { background: var(--navy); color: #fff; }
.smallBtn.danger { background: var(--red); color: #fff; }
.smallBtn.toggled { background: var(--green); color: #fff; }

.primaryBtn {
  width: 100%;
  background: var(--yellow);
  color: var(--navy);
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  box-shadow: 0 3px 0 var(--yellow-dark);
}
.primaryBtn:hover:not(:disabled) { filter: brightness(1.04); }
.primaryBtn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--yellow-dark); }

select.assignSelect {
  font-family: inherit;
  font-size: 11.5px;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  color: var(--navy);
  font-weight: 600;
}

.statusPill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.statusPill.running { background: #E4F3E6; color: var(--green-dark); }
.statusPill.broken { background: #FBE3E1; color: #B92A22; }
.statusPill.idle { background: #E7EAF0; color: var(--muted); }
.statusPill.repairing { background: #FFF3D6; color: var(--yellow-dark); }

.emptyState { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px 10px; }

/* upgrade card (detection) */
.upgradeCard {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}
.upgradeCard h3 { margin: 0 0 4px; font-size: 14px; color: var(--navy); }
.upgradeCard p { margin: 0 0 8px; font-size: 11.5px; color: var(--muted); }

/* ===== LOG ===== */
#log {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  z-index: 30;
  max-width: 300px;
}
.logItem {
  background: var(--navy);
  color: var(--cream-hi);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: logIn 0.25s ease-out, logOut 0.4s ease-in 4.6s forwards;
  border-left: 3px solid var(--yellow);
}
.logItem.warn { border-left-color: var(--red); }
.logItem.good { border-left-color: var(--green); }
@keyframes logIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes logOut { to { opacity: 0; transform: translateX(20px); } }

/* ===== OVERLAYS ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,42,67,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.overlay.hidden { display: none; }
.overlayCard {
  background: var(--cream-hi);
  border-radius: 18px;
  padding: 28px 30px;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}
.overlayCard h1 { font-size: 22px; color: var(--navy); margin-bottom: 10px; }
.overlayCard p { font-size: 13.5px; color: var(--muted); line-height: 1.5; margin-bottom: 16px; }
.overlayLogo { margin-bottom: 4px; }

.stationInfoCard { max-width: 380px; }
.stationInfoCard h3 { font-size: 19px; color: var(--navy); margin-bottom: 14px; }
.stationStatGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stationStat { display: flex; flex-direction: column; gap: 2px; background: #EEF3F6; border-radius: 10px; padding: 10px 6px; }
.stationStatVal { font-size: 17px; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
.stationStatLabel { font-size: 10px; color: var(--muted); font-weight: 600; }
.stationNote { font-style: italic; margin-bottom: 4px !important; }
.stationInfoClose { width: 100%; margin-top: 6px; }

.stationHit { cursor: pointer; }

.startRouteList {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  text-align: left;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 2px;
}
@media (max-width: 560px) { .startRouteList { grid-template-columns: 1fr; } }

.startRouteBtn {
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  font-family: inherit;
}
.startRouteBtn:hover { border-color: var(--yellow); background: #FFF8E1; }
.startRouteBtn .cardTitle { font-size: 13px; }
.startRouteBtn .cardSub { font-size: 10.5px; }
