@import url("../playful-games/base.css?v=1");
:root {
  --paper: #edf2f0;
  --ink: #263c4a;
  --muted: #61777b;
  --accent: #285f6b;
  --tint: #e0edef;
  --line: #d6e2e0;
  --profit: #286655;
  --loss: #a73b35;
  --control: #f3f6f3;
}
.mode-explanation {
  font-size: 14px !important;
  line-height: 1.6 !important;
  margin: 0 0 8px !important;
  max-width: 36em;
}
.rail-mode {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.rail-mode button[aria-pressed="true"] {
  background: var(--tint);
  border-color: var(--accent);
}
body.playing {
  overflow-anchor: none;
  overflow-x: hidden;
}
#game {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100dvh;
  max-width: none;
  border: 0;
  border-radius: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  overflow: hidden;
}
#game button {
  min-height: 40px;
  font-size: 13px;
  padding: 7px 12px;
}
#game button:focus-visible,
#game select:focus-visible,
#game input:focus-visible {
  outline: 3px solid #d68a20;
  outline-offset: 2px;
}
.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.run-heading,
.run-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}
.run-heading > strong {
  font-size: 17px;
}
.run-heading > span {
  font-size: 12px;
  color: var(--muted);
}
#run-status {
  padding: 5px 8px;
  border-radius: 4px;
  background: #e7efe9;
  color: var(--profit);
}
#run-status.paused {
  background: #fff0c9;
  color: #795216;
  font-weight: 800;
}
#game #pause {
  min-width: 152px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 800;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
#game #pause.resume-ready {
  background: #23694f;
  border-color: #23694f;
  box-shadow: 0 0 0 2px #c6e5d6;
}
#game #pause:disabled {
  background: #78918b;
  box-shadow: none;
}
.progress {
  height: 3px;
  flex-shrink: 0;
}
.finance-strip {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, 1fr);
  gap: 16px;
  background: #f7faf8;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.finance-strip > div {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.finance-strip span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.finance-strip strong {
  font-size: 17px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#budget-profit {
  color: var(--profit);
}
.negative,
#budget-profit.negative {
  color: var(--loss);
}
.budget-alert {
  background: #fff0d7;
  color: #794f1a;
  font-size: 12px;
  padding: 6px 16px;
  flex-shrink: 0;
}
.map-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  background: white;
  flex-shrink: 0;
}
.map-tools > span {
  font-size: 12px;
  color: var(--muted);
}
#place-station {
  border-color: var(--accent);
  font-weight: 800;
}
#place-station[aria-pressed="true"] {
  background: var(--tint);
}
.map-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.map-zoom button {
  min-width: 40px;
}
.map-zoom output {
  font-size: 12px;
  min-width: 42px;
  text-align: center;
}
.map-options {
  position: relative;
}
#map-options-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 12;
  background: #fff;
  box-shadow: 0 4px 14px #263c4a26;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  width: 150px;
}
#map-options-panel button {
  display: block;
  width: 100%;
  margin: 4px 0;
}
.map-instruction {
  font-size: 12px;
  line-height: 1.4;
  padding: 5px 16px;
  margin: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  min-height: 28px;
  flex-shrink: 0;
}
.rail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
}
.map-column {
  min-width: 0;
  min-height: 0;
  position: relative;
}
.map-viewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
  cursor: grab;
  scrollbar-width: none;
  scrollbar-color: #9aafa8 transparent;
  background: #e7ede8;
}
.map-viewport::-webkit-scrollbar {
  display: none;
}
.map-viewport.dragging {
  cursor: grabbing;
  user-select: none;
}
.map-viewport.placing {
  cursor: crosshair;
}
.map-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: #f2f5ec;
}
.rail-map,
.stations {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.stations {
  pointer-events: none;
}
#game .station {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 46px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  box-shadow: none;
}
.station .symbol {
  font-size: 24px;
  line-height: 28px;
  min-width: 30px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-family: Arial, sans-serif;
}
.station b {
  position: absolute;
  top: 38px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  line-height: 1.2;
  background: #f3f6edf0;
  padding: 2px 4px;
  border-radius: 3px;
}
.station .queue,
.station .order {
  position: absolute;
  top: -2px;
  right: -3px;
  background: var(--ink);
  color: white;
  border-radius: 10px;
  padding: 3px 5px;
  border: 2px solid white;
  font-size: 10px;
  line-height: 1;
}
.station .order {
  left: -3px;
  right: auto;
  background: #fff;
  color: var(--accent);
  border-color: var(--accent);
}
.station.busy .queue {
  background: #bd453c;
}
.station.selected .symbol {
  border-color: #c27d1c;
  box-shadow: 0 0 0 4px #efb94566;
}
.station.candidate .symbol {
  border-style: dashed;
  color: #75878a;
  border-color: #869a9b;
}
.station.candidate .queue {
  background: #738786;
}
.station.available .queue {
  background: #286655;
}
.station:disabled {
  opacity: 0.45;
}
.site-marker {
  position: absolute;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 50%;
  background: #f6fff4dc;
  color: var(--accent);
  pointer-events: none;
  z-index: 2;
}
.site-marker span {
  font-size: 24px;
}
.site-marker b {
  position: absolute;
  top: 40px;
  font-size: 11px;
  white-space: nowrap;
  background: white;
  padding: 3px;
}
.rail-panel {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background: #fbfcfa;
  border-left: 1px solid var(--line);
  overscroll-behavior: contain;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  min-height: 28px;
}
.panel-heading h2 {
  font-size: 15px;
  margin: 0;
}
#game #close-panel {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 12px;
  border: 0;
  background: transparent;
}
.line-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
}
#game .line-select {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  min-width: 126px;
  text-align: left;
  padding: 6px;
}
.line-select i {
  width: 8px;
  height: 26px;
  border-radius: 3px;
  background: var(--route);
}
.line-select small {
  font-size: 11px;
  color: var(--muted);
}
.train-buttons {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-size: 11px;
}
#game .train-buttons button {
  min-width: 36px;
  padding: 4px;
  min-height: 36px;
}
.resources {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  padding-top: 10px;
}
.status {
  font-size: 12px;
  line-height: 1.4;
  margin: 6px 0 0;
  min-height: 0;
}
.status:empty {
  display: none;
}
.station-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.station-heading h3,
.site-plan h3 {
  font-size: 17px;
  margin: 0;
  overflow-wrap: anywhere;
}
.station-info p {
  font-size: 12px;
  line-height: 1.45;
  margin: 6px 0;
}
.station-info .small {
  color: var(--muted);
  font-size: 11px;
}
.station-actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 6px;
  margin: 12px 0 4px;
}
#game .text-button {
  background: transparent;
  border: 0;
  padding: 4px 0;
  min-height: 32px;
  font-size: 12px;
  color: var(--muted);
}
.connect-station {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.connect-station button {
  border-left: 4px solid var(--route);
}
.station-info:has(.connect-station) #station-flow,
.station-info:has(.connect-station) #station-wait,
.station-info:has(#station-name-form) #station-flow,
.station-info:has(.delete-note) #station-flow {
  display: none;
}
#game .danger-button {
  background: #a73b35;
  border-color: #a73b35;
  color: #fff;
}
.station-name-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.station-name-row input {
  min-width: 0;
  flex: 1;
}
.station-name-row button {
  flex-shrink: 0;
}
#station-name-form {
  margin-top: 10px;
}
#station-name-form label,
.site-plan label,
.route-editor label {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-bottom: 5px;
}
#game input,
#game select {
  font: inherit;
  font-size: 16px;
  min-height: 40px;
  border: 1px solid #b8cbc7;
  border-radius: 6px;
  padding: 7px 9px;
  background: white;
  color: var(--ink);
}
.site-plan input,
.route-editor select {
  width: 100%;
}
.site-plan p {
  font-size: 12px;
  line-height: 1.4;
  margin: 8px 0;
}
.site-totals {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0;
  font-size: 12px;
}
.game-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}
.game-actions > button {
  flex: 1;
}
#game .game-actions button {
  padding: 7px 8px;
  font-size: 12px;
}
.route-editor h3 {
  font-size: 14px;
  margin: 0 0 6px;
}
.route-path {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  margin: 0 0 10px;
  line-height: 1.4;
  color: var(--muted);
}
#editor-hint {
  font-size: 11px;
  margin: 7px 0;
  color: var(--muted);
}
.route-quote {
  font-size: 12px;
  margin: 10px 0;
  font-variant-numeric: tabular-nums;
}
.route-editor .game-actions {
  flex-wrap: wrap;
}
.route-editor .game-actions button {
  flex: 1 1 40%;
}
.rail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 5px 16px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--muted);
  background: #fbfcfa;
  flex-shrink: 0;
}
#accounts-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: 88dvh;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  color: var(--ink);
  background: #fbfcfa;
}
#accounts-dialog::backdrop {
  background: #19323866;
}
#accounts-dialog > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: -18px;
  background: #fbfcfa;
  z-index: 2;
  padding: 8px 0;
}
#accounts-dialog h2 {
  font-size: 20px;
  margin: 0;
}
#accounts-dialog h3 {
  font-size: 15px;
  margin: 18px 0 10px;
}
.finance-detail > summary {
  display: none;
}
.fare-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.fare-options button[aria-pressed="true"] {
  background: var(--tint);
  border-color: var(--accent);
}
.account-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.account-columns dl > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin: 8px 0;
}
.account-columns dd {
  margin: 0;
  font-weight: 700;
}
.account-columns dt {
  color: var(--muted);
}
.funding-controls p,
.economy-note,
.fare-controls p,
.traffic-detail p {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
.table-scroll {
  overflow: auto;
}
#accounts-dialog table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}
#accounts-dialog td,
#accounts-dialog th {
  padding: 8px 5px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}
#accounts-dialog th:first-child {
  text-align: left;
}
.cash-ledger {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cash-ledger li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}
.cash-ledger small {
  color: var(--muted);
  margin-right: 6px;
}
.traffic-detail {
  margin-top: 20px;
}
.traffic-detail summary {
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.result-grid > div {
  padding: 16px;
  background: var(--tint);
  border-radius: 8px;
}
.result-grid span {
  display: block;
  font-size: 12px;
}
.result-grid strong {
  display: block;
  font-size: 22px;
  margin-top: 8px;
}
@media (max-width: 900px) {
  .rail-layout {
    grid-template-columns: minmax(0, 1fr) 290px;
  }
  .finance-strip {
    gap: 8px;
  }
  .finance-strip > div {
    display: block;
  }
  .finance-strip span {
    display: block;
    margin-bottom: 2px;
  }
  .run-heading > strong {
    font-size: 15px;
  }
  .run-heading {
    gap: 7px;
  }
  .run-buttons {
    gap: 6px;
  }
}
@media (max-width: 900px) and (orientation: portrait), (max-width: 700px) {
  .control-bar {
    display: block;
    padding: 6px 10px;
  }
  .run-heading {
    margin-bottom: 6px;
    justify-content: space-between;
  }
  .run-heading > span {
    font-size: 10px;
  }
  .run-buttons {
    gap: 5px;
  }
  .run-buttons #pause {
    flex: 1;
  }
  .run-buttons button {
    padding: 5px 8px !important;
    font-size: 11px !important;
  }
  #game #pause {
    font-size: 14px !important;
    min-width: 130px;
    min-height: 44px;
  }
  .finance-strip {
    grid-template-columns: repeat(3, 1fr);
    padding: 7px 10px;
    gap: 10px;
  }
  .finance-strip .secondary-budget {
    display: none;
  }
  .finance-strip strong {
    font-size: 15px;
  }
  .finance-strip span {
    font-size: 10px;
  }
  .finance-strip > div {
    display: block;
  }
  .map-tools {
    padding: 4px 8px;
    gap: 5px;
  }
  .map-tools > #period-label,
  .map-tools > #permits {
    display: none;
  }
  .map-tools .map-zoom {
    gap: 2px;
  }
  #game .map-tools button {
    padding: 6px 8px;
    min-height: 40px;
  }
  .map-zoom output {
    min-width: 36px;
    font-size: 11px;
  }
  .map-zoom button {
    min-width: 34px;
  }
  .map-instruction {
    font-size: 11px;
    padding: 4px 10px;
    min-height: 25px;
    max-height: 42px;
    overflow: hidden;
  }
  .rail-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .rail-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 7px 10px;
    max-height: 44dvh;
  }
  .rail-panel .panel-heading {
    min-height: 24px;
    margin-bottom: 4px;
  }
  .panel-heading h2 {
    font-size: 13px;
  }
  .line-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }
  .line-card {
    display: block;
    padding: 0;
    border: 0;
  }
  .line-card .train-buttons {
    display: none;
  }
  #game .line-select {
    min-width: 0;
    width: 100%;
    border: 1px solid var(--line);
    padding: 5px;
    min-height: 40px;
    justify-content: center;
    gap: 5px;
  }
  .line-select small {
    font-size: 10px;
  }
  .line-select b {
    font-size: 12px;
  }
  .line-select i {
    height: 22px;
    width: 5px;
  }
  .resources {
    padding-top: 5px;
    font-size: 10px;
  }
  #rail-message {
    display: none;
  }
  #game .station {
    width: 44px;
    height: 44px;
  }
  .station .symbol {
    font-size: 18px;
    line-height: 23px;
    min-width: 25px;
  }
  .station b {
    top: 33px;
    font-size: 11px;
    max-width: 100px;
  }
  .station .queue {
    font-size: 9px;
    right: 0;
    top: 0;
  }
  .station-heading h3 {
    font-size: 15px;
  }
  .station-actions {
    margin: 7px 0 2px;
  }
  .station-info p {
    margin: 4px 0;
  }
  .station-info .delete-note {
    font-size: 12px;
  }
  .connect-station {
    margin-top: 4px;
  }
  .station-info #expand {
    min-height: 28px;
  }
  .site-plan p {
    font-size: 11px;
    margin: 6px 0;
  }
  .site-totals {
    margin: 7px 0;
  }
  .site-plan label {
    display: inline-block;
    margin: 0 8px 4px 0;
  }
  .site-plan input {
    min-height: 40px;
  }
  .route-editor h3 {
    display: none;
  }
  .route-path {
    margin: 0 0 5px;
    font-size: 11px;
  }
  .route-editor label {
    font-size: 11px;
    margin-bottom: 3px;
  }
  .route-editor select {
    font-size: 14px;
  }
  #editor-hint {
    margin: 4px 0;
  }
  .route-quote {
    margin: 5px 0;
  }
  .route-editor .game-actions {
    flex-wrap: nowrap;
  }
  .route-editor .game-actions button {
    flex: 1;
    white-space: nowrap;
  }
  .rail-footer {
    padding: 3px 10px;
    font-size: 9px;
  }
  .account-columns {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .funding-controls .game-actions {
    flex-wrap: wrap;
  }
  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
/* The game fits one viewport; content ads stay in normal document flow.
   Keep 150px between the interactive game and the manual ad placement. */
body.playing > .page-header,
body.playing > .skip,
body.playing main > .title-row {
  display: none !important;
}
body.playing main.shell {
  max-width: none;
  width: 100%;
  padding: 0;
  margin: 0;
}
body.playing main > :not(#game) {
  max-width: 1120px;
  margin-left: auto;
  margin-right: auto;
}
body.playing #ad-zone {
  margin-top: 150px;
  width: min(calc(100vw - 48px), 970px);
}
body.playing .help,
body.playing .related,
body.playing .footer {
  width: calc(100% - 32px);
}
#map-overview {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 120px;
  height: 90px;
  border: 2px solid #fff;
  border-radius: 5px;
  box-shadow: 0 1px 6px #263c4a25;
  pointer-events: none;
}
#game input {
  font-size: 16px;
}

.editor-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.editor-top h3 {
  margin: 0;
}
@media (max-width: 900px) and (orientation: portrait), (max-width: 700px) {
  .editor-top h3 {
    display: block;
    font-size: 12px;
  }
  .editor-top {
    margin-bottom: 4px;
  }
  #game #editor-fleet button {
    min-height: 32px;
    min-width: 36px;
  }
}

/* A tablet in portrait keeps a real map alongside a narrow control column. */
@media (min-width: 901px) and (max-width: 1050px) {
  .rail-layout {
    grid-template-columns: minmax(0, 1fr) 272px;
  }
  .run-heading #mode-label {
    display: none;
  }
  .control-bar {
    gap: 6px;
    padding: 6px 12px;
  }
  .run-buttons {
    gap: 4px;
  }
}
@media (max-width: 900px) and (orientation: portrait), (max-width: 700px) {
  #map-overview {
    width: 96px;
    height: 72px;
    bottom: 8px;
    right: 8px;
  }
  .finance-strip {
    padding: 5px 10px;
  }
  .finance-strip > div {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
  }
  .finance-strip span {
    margin: 0;
  }
  .map-instruction {
    line-height: 1.45;
  }
  .rail-panel:not(.working) .panel-heading {
    display: none;
  }
  .rail-panel:not(.working) {
    padding-top: 5px;
    padding-bottom: 5px;
  }
  .station b {
    font-size: 11px;
  }
  #game .map-tools button {
    min-width: 40px;
  }
  #zoom-level {
    display: none;
  }
  .map-options {
    margin-left: 2px;
  }
  #game #insert-position {
    font-size: 16px;
  }
  .rail-footer {
    padding-bottom: max(3px, env(safe-area-inset-bottom));
  }
}
@media (orientation: landscape) and (max-height: 540px) and (min-width: 560px) {
  .control-bar {
    display: flex;
    padding: 4px 10px;
    gap: 8px;
  }
  .run-heading {
    margin: 0;
    gap: 6px;
  }
  .run-heading > strong {
    font-size: 13px;
    white-space: nowrap;
  }
  .run-heading #mode-label,
  .run-heading #run-status {
    display: none;
  }
  #game #pause {
    min-height: 40px;
    min-width: 128px;
    font-size: 13px !important;
  }
  #game .run-buttons button {
    min-height: 36px;
    padding: 5px 8px;
    font-size: 12px;
  }
  .finance-strip {
    display: flex;
    gap: 20px;
    padding: 4px 10px;
  }
  .finance-strip > div {
    display: flex;
    align-items: baseline;
    gap: 6px;
  }
  .finance-strip span {
    margin: 0;
    font-size: 10px;
  }
  .finance-strip strong {
    font-size: 14px;
  }
  .finance-strip .secondary-budget {
    display: none;
  }
  .map-tools {
    padding: 2px 10px;
  }
  .map-tools #period-label {
    display: none;
  }
  #game .map-tools button {
    min-height: 34px;
    padding: 4px 8px;
  }
  .map-instruction {
    padding: 2px 10px;
    font-size: 11px;
    min-height: 22px;
  }
  .rail-layout {
    grid-template-columns: minmax(0, 1fr) 268px;
    grid-template-rows: minmax(0, 1fr);
  }
  .rail-panel {
    max-height: none;
    border-left: 1px solid var(--line);
    border-top: 0;
    padding: 6px 8px;
  }
  .rail-panel .panel-heading {
    min-height: 24px;
    margin-bottom: 4px;
  }
  .panel-heading h2 {
    font-size: 13px;
  }
  #game #close-panel {
    min-height: 28px;
    padding: 2px 8px;
  }
  .rail-panel .line-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  .line-card {
    padding: 0;
    border: 0;
  }
  .line-card .train-buttons {
    display: none;
  }
  #game .line-select {
    min-width: 0;
    width: 100%;
    border: 1px solid var(--line);
    padding: 4px;
    min-height: 38px;
    gap: 4px;
  }
  .line-select small {
    font-size: 10px;
  }
  .line-select b {
    font-size: 12px;
  }
  .resources {
    font-size: 10px;
    padding-top: 4px;
  }
  #rail-message,
  .rail-footer {
    display: none;
  }
  .station-heading h3 {
    font-size: 14px;
  }
  .station-info p {
    margin: 3px 0;
  }
  .station-actions {
    margin: 5px 0;
  }
  #game .station-actions button,
  #game #expand {
    min-height: 32px;
    padding: 4px 7px;
    font-size: 12px;
  }
  .editor-top {
    margin-bottom: 4px;
  }
  .editor-top h3 {
    font-size: 12px;
  }
  #game #editor-fleet button {
    min-height: 28px;
    min-width: 32px;
    padding: 3px 6px;
  }
  .route-path,
  .route-editor label {
    font-size: 11px;
    margin: 3px 0;
  }
  #editor-hint {
    display: none;
  }
  #game .route-editor select {
    min-height: 32px;
    padding: 4px;
  }
  .route-quote {
    margin: 4px 0;
    font-size: 11px;
  }
  .route-editor .game-actions {
    position: sticky;
    bottom: -6px;
    background: #fff;
    padding: 4px 0;
    flex-wrap: nowrap;
  }
  #game .route-editor .game-actions button {
    min-height: 34px;
    padding: 4px 6px;
    font-size: 12px;
  }
  #map-overview {
    width: 88px;
    height: 66px;
  }
}

@media (max-width: 900px) and (orientation: portrait), (max-width: 700px) {
  .rail-panel:has(#editor:not([hidden])) .panel-heading {
    display: none;
  }
  .rail-panel #editor-hint {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 540px) and (min-width: 560px) {
  #game .route-editor .game-actions button {
    padding: 4px 3px;
    font-size: 11px;
    white-space: nowrap;
  }
}

/* A roomy desktop can display the same ad beside the game with a 150px gap.
   Keep its width identical before/after starting; never refresh on play. */
#ad-zone {
  width: min(calc(100vw - 48px), 970px);
}
@media (min-width: 1700px) and (min-height: 700px) {
  #ad-zone {
    width: 300px;
  }
  body.playing main.shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    column-gap: 150px;
    padding-right: 16px;
    align-items: start;
  }
  body.playing #game {
    grid-column: 1;
    grid-row: 1;
  }
  body.playing #ad-zone {
    grid-column: 2;
    grid-row: 1;
    margin: 20px 0 0;
    width: 300px;
    min-width: 0;
  }
  body.playing .help,
  body.playing .related,
  body.playing .footer {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1700px) and (min-height: 700px) {
  body.playing:has(#ad-zone[hidden]) main.shell,
  body.playing:has(#ad-zone ins[data-ad-status="unfilled"]) main.shell {
    display: block;
    padding-right: 0;
  }
}
/* Keep the entry banner visible before starting, without covering controls. */
body:not(.playing) #ad-zone {
  margin-top: 8px;
  margin-bottom: 28px;
}
@media (max-width: 700px) {
  .intro-image {
    grid-row: auto;
    height: 160px;
  }
  .intro-copy {
    padding: 20px;
  }
  .intro h2 {
    font-size: 24px;
  }
  .rail-mode {
    margin: 12px 0;
    order: 2;
  }
  .intro-copy > p {
    order: 1;
  }
  .intro-actions {
    order: 3;
  }
  .intro-copy > .mode-explanation {
    order: 4;
  }
  .intro-copy > .small {
    order: 5;
  }
  .intro-copy > .daily {
    order: 6;
  }
}
body.playing main.shell {
  display: flex;
  flex-direction: column;
}
body.playing #game {
  order: 1;
  flex-shrink: 0;
}
body.playing #ad-zone {
  order: 2;
}
body.playing .help {
  order: 3;
}
body.playing .related {
  order: 4;
}
body.playing .footer {
  order: 5;
}
.operation-coach {
  padding: 8px 10px;
  margin: 0 0 10px;
  border-left: 3px solid var(--accent);
  background: var(--tint);
}
.operation-coach p {
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}
#game #coach-connect {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 12px;
  margin-top: 6px;
}
.manual-connection {
  margin-top: 8px;
}
.manual-connection summary {
  min-height: 30px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}
#game #connect-recommended {
  width: 100%;
}
#game #build-only {
  font-size: 11px;
  min-height: 28px;
}
.break-even {
  padding: 10px;
  background: var(--tint);
  font-size: 13px;
  line-height: 1.5;
}
.quick-guide {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  color: var(--ink);
  background: #fbfcfa;
}
.quick-guide::backdrop {
  background: #16313d88;
}
.quick-guide header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}
.quick-guide h2 {
  font-size: 21px;
  line-height: 1.35;
  margin: 0;
}
#game #guide-close {
  min-height: 32px;
  padding: 4px 8px;
  flex-shrink: 0;
}
.guide-intro {
  font-size: 14px;
  margin: 12px 0 16px;
}
.quick-guide ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: guide;
}
.quick-guide li {
  position: relative;
  padding: 0 0 16px 34px;
  counter-increment: guide;
}
.quick-guide li::before {
  content: counter(guide);
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  text-align: center;
  font-weight: 700;
}
.quick-guide li b {
  font-size: 15px;
  display: block;
  margin-bottom: 4px;
}
.quick-guide li span {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  display: block;
}
.guide-money {
  background: var(--tint);
  border-radius: 6px;
  padding: 8px 12px;
}
.guide-money p {
  font-size: 12px;
  margin: 4px 0;
}
#guide-cost {
  color: var(--muted);
}
.quick-guide .small {
  font-size: 11px;
  margin: 10px 0;
}
#game #guide-run {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
}
@media (max-width: 900px) and (orientation: portrait), (max-width: 700px) {
  .operation-coach {
    padding: 6px 8px;
    margin-bottom: 6px;
  }
  .operation-coach p {
    font-size: 11px;
  }
  .rail-panel:not(.working) {
    max-height: 35dvh;
  }
  .quick-guide {
    padding: 16px;
  }
  .quick-guide h2 {
    font-size: 19px;
  }
}
@media (max-height: 540px) and (orientation: landscape) {
  .operation-coach {
    padding: 5px 6px;
    margin-bottom: 5px;
  }
  .operation-coach p {
    font-size: 11px;
  }
  .quick-guide {
    width: min(720px, calc(100vw - 32px));
    padding: 12px 18px;
  }
  .quick-guide h2 {
    font-size: 18px;
  }
  .guide-intro {
    margin: 4px 0 10px;
    font-size: 12px;
  }
  .quick-guide ol {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
  .quick-guide li {
    padding: 0 0 10px 30px;
  }
  .quick-guide li span {
    font-size: 11px;
  }
  .quick-guide li b {
    font-size: 13px;
  }
  .guide-money p {
    display: inline-block;
    margin-right: 10px;
  }
}
@media (min-width: 1700px) and (min-height: 700px) {
  body.playing main.shell {
    display: grid;
  }
  body.playing:has(#ad-zone[hidden]) main.shell,
  body.playing:has(#ad-zone ins[data-ad-status="unfilled"]) main.shell {
    display: block;
  }
}
