body[data-app="subway-last-train"] {
  --paper: #edf1f3;
  --surface: #fbfcfd;
  --ink: #203241;
  --muted: #4e6471;
  --line: #cbd7de;
  --accent: #244f73;
  --wash: #e3edf5;
  --current: #075888;
  --goal: #8b3d06;
  --answer: #6827a7;
  --answer-wash: #f2e8fc;
  background: var(--paper);
}

.line-1 { --line-color: #3866a3; }
.line-2 { --line-color: #21806b; }
.line-3 { --line-color: #ba591d; }
.line-4 { --line-color: #197995; }
.line-5 { --line-color: #7852a6; }
.line-6 { --line-color: #865130; }
.line-7 { --line-color: #5d671a; }
.line-8 { --line-color: #b91c61; }
.line-9 { --line-color: #85691e; }

.difficulty-picker { display: grid; grid-template-columns: minmax(0, 175px) minmax(0, 190px) auto; justify-content: start; align-items: end; gap: 8px; margin: 0 0 12px; }
.difficulty-picker label { display: grid; gap: 4px; min-width: 0; font-size: .84rem; font-weight: 750; }
.difficulty-picker :is(select, button) { min-height: 42px; }
.difficulty-picker button { white-space: nowrap; }

.subway-game {
  display: grid;
  grid-template-columns: minmax(0,1.44fr) minmax(280px,1fr);
  grid-template-areas: "journey journey" "map dispatch" "history history";
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: clip;
}

.journey {
  grid-area: journey;
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  margin: 0;
  padding: 10px 14px;
  background: #1d3749;
  color: #f8fcff;
}
.journey > div { display: grid; gap: 4px; padding: 2px 12px; border-inline-start: 1px solid #5a7281; }
.journey > div:first-child { border-inline-start: 0; }
.journey dt { display: flex; align-items: center; gap: 5px; color: #d1e2ec; font-size: .72rem; white-space: nowrap; }
.journey dt i { flex: none; width: 8px; height: 8px; }
.journey dt .key-current { background: #8bd6ff; }
.journey dt .key-goal { background: #ffbc75; }
.time-left { color: #ffd9a8; font-size: .68rem; white-space: nowrap; }
.journey dd { margin: 0; font-size: 1.06rem; font-weight: 790; font-variant-numeric: tabular-nums; word-break: keep-all; }

.network { grid-area: map; min-width: 0; align-self: start; }
.map-head, .dispatch-head { padding: 13px 14px; }
.map-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.map-head h2 { flex: none; white-space: nowrap; }
.map-head h2, .dispatch-head h2 { margin: 0; font-size: .96rem; }
#service-day { display: block; margin-top: 2px; color: var(--muted); font-size: .7rem; }
.intro a { white-space: nowrap; }
.line-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px 8px; }
.line-legend span { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; white-space: nowrap; }
.line-legend span::before { content: ""; width: 11px; height: 4px; border-radius: 3px; background: var(--line-color); }

.map-scroll { overflow-x: auto; border-block: 1px solid var(--line); }
.subway-game:not([data-expanded-map]) .map-scroll { overflow-x: hidden; }
.map-scroll:focus-visible { outline-offset: -2px; }
.map-board { position: relative; background: #e9eff1; }
.map-board canvas { display: block; width: 100%; height: auto; aspect-ratio: 2; }
.map-swipe { display: none; margin: 6px 10px 0; color: var(--muted); font-size: .72rem; }
[data-wide-map] .map-board { min-width: 870px; }
[data-wide-map] .map-swipe { display: block; }
.station-labels { position: absolute; inset: 0; pointer-events: none; }
.station-label {
  position: absolute;
  white-space: pre;
  text-align: center;
  line-height: 1.12;
  transform: translate(-50%, -100%);
  padding: 2px 4px;
  border-radius: 4px;
  background: #eff3f4;
  color: #263c49;
  font-size: clamp(.68rem, 1.4vw, .85rem);
  font-weight: 720;
}
.station-label[data-station="dongguk"] { margin-left: 10px; margin-top: -4px; }
.station-role { display: block; font-size: .72em; font-weight: 800; }
.station-role:empty { display: none; }
.station-label[data-current], .station-label[data-goal], .station-label[data-transfer] { z-index: 1; color: #fff; }
.station-label[data-transfer] { background: var(--answer); }
.station-label[data-current] { background: var(--current); }
.station-label[data-goal] { background: var(--goal); }
.train-marker, .goal-marker {
  position: absolute;
  width: 13px;
  height: 13px;
  transform: translate(-50%,-50%);
  border: 2px solid #fff;
  pointer-events: none;
}
.train-marker { border-radius: 3px; background: var(--current); box-shadow: 0 0 0 1px var(--current); }
.goal-marker { transform: translate(-50%,-50%) rotate(45deg); border-radius: 2px; background: var(--goal); box-shadow: 0 0 0 1px var(--goal); }
.train-marker[data-arrived] { background: var(--goal); border-color: var(--goal); box-shadow: none; width: 7px; height: 7px; }

.map-key { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 10px; padding: 10px 14px; font-size: .72rem; color: var(--muted); }
.map-key span, .map-key button { display: inline-flex; align-items: center; gap: 5px; }
.map-key button { padding: 4px 8px; min-height: 34px; font-size: .72rem; }
.map-key .map-to-trains { display: none; align-self: center; white-space: nowrap; }
.map-key i { display: inline-block; width: 10px; height: 10px; }
.key-current { background: var(--current); border-radius: 2px; }
.key-goal { background: var(--goal); border-radius: 1px; transform: rotate(45deg) scale(.86); }
.map-key .key-route { width: 16px; height: 4px; border-radius: 2px; background: #19364c; }
[data-solution] .key-route { background: var(--answer); }
[data-solution] #key-route-label { color: var(--answer); font-weight: 800; }

.dispatch { grid-area: dispatch; min-width: 0; border-inline-start: 1px solid var(--line); }
.dispatch-head p, .result p { margin: 5px 0 0; font-size: .8rem; color: var(--muted); line-height: 1.45; word-break: keep-all; }
.dispatch-head .mission-step { margin: 0 0 3px; color: var(--accent); font-size: .7rem; font-weight: 800; }
.departures { display: grid; gap: 6px; padding: 0 10px 10px; }
.departure {
  display: grid;
  grid-template-columns: 28px minmax(0,1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 51px;
  text-align: left;
  padding: 6px 8px;
  touch-action: manipulation;
}
.line-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--line-color); color: #fff; font-size: .81rem; }
.departure strong, .departure small { display: block; }
.departure small { margin-top: 3px; color: var(--muted); font-size: .67rem; }
.departure .timing { text-align: right; font-variant-numeric: tabular-nums; }
.departure[data-late] .timing small { color: #803b1b; }
.departure:disabled { opacity: .72; }
.departure[data-late] .timing strong { color: #884021; }
.departure .timing strong { white-space: nowrap; }
.result { margin: 0 10px 10px; padding: 12px; border-radius: 8px; background: var(--wash); }
.result h3 { margin: 0; font-size: 1rem; }
.result button { margin-top: 8px; }
.result #solution { border-color: var(--answer); color: var(--answer); background: #fff; }
[data-solution] .result #solution { color: #fff; background: var(--answer); }
.answer-summary { display: grid; gap: 8px; margin-top: 10px; }
.answer-card { min-width: 0; padding: 9px 10px; border: 1px solid #d9c1ed; border-radius: 7px; background: #faf6fd; }
.answer-card h4 { margin: 0 0 5px; color: var(--answer); font-size: .85rem; }
.answer-card strong { color: var(--answer); font-size: .9rem; }
.answer-card p { margin: 4px 0 0; }
.answer-alternative { border-color: var(--line); background: var(--surface); }
.answer-alternative h4 { color: var(--ink); }
.answer-alternative dl { margin: 8px 0 0; font-size: .76rem; }
.answer-alternative dl div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.answer-alternative dd { margin: 0; color: var(--ink); font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; }
.answer-alternative #answer-alternative-reason { color: #803b1b; }
.answer-transfers { margin-top: 10px; padding: 9px 10px; border: 1px solid #d9c1ed; border-radius: 7px; color: var(--answer); background: #faf6fd; }
.answer-transfers h4 { margin: 0; font-size: .85rem; }
.answer-transfers ol { display: grid; gap: 6px; margin: 6px 0 0; padding-inline-start: 1.2em; }
.answer-transfers li { padding: 7px 0 0; border-top: 1px solid #e3d3ef; font-size: .81rem; }
.answer-transfers li::marker { font-weight: 800; }
.answer-transfers small { display: block; margin-top: 3px; color: var(--muted); font-size: .71rem; }
.answer-lines { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.answer-lines span { padding: 2px 6px; border-radius: 4px; color: #fff; background: var(--line-color); font-weight: 760; }
.game-actions { padding: 0 10px 10px; }
.game-actions:has(button[hidden] + button[hidden] + button[hidden]) { padding: 0; }
.ride-history { grid-area: history; padding: 0 14px 4px; border-top: 1px solid var(--line); }
.ride-history ol { margin: 6px 0 0; padding-left: 20px; }
.ride-history li { padding: 4px 0; color: var(--muted); font-size: .79rem; line-height: 1.45; }
.ride-history .line-name { color: var(--line-color); font-weight: 750; }
[data-solution] .ride-history { background: var(--answer-wash); }
[data-solution] .ride-history summary, [data-solution] .ride-history li { color: var(--answer); font-weight: 750; }

.station-last, .other-trains { margin: 0 10px 6px; }
.station-last summary, .other-trains summary, .ride-history summary { padding: 11px 4px; color: var(--accent); font-size: .8rem; cursor: pointer; }
.other-trains .departures { padding: 0 0 5px; }
.station-last ul { list-style: none; padding: 0; margin: 0 0 5px; }
.station-last li { display: flex; justify-content: space-between; gap: 6px; padding: 5px 0; border-top: 1px solid var(--line); font-size: .72rem; }
.station-last li strong { flex: none; font-variant-numeric: tabular-nums; }

.last-trains { margin-top: 20px; }
.last-trains > summary { color: var(--accent); font-weight: 750; cursor: pointer; }
.last-trains[open] > summary { margin-bottom: 12px; }
.lookup-controls {
  display: grid;
  grid-template-columns: minmax(85px,.65fr) minmax(120px,1.3fr) minmax(130px,1fr) auto;
  gap: 8px;
  align-items: end;
  margin: 0;
  padding: 0;
  border: 0;
}
.lookup-controls label { display: grid; gap: 4px; min-width: 0; font-size: .78rem; font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#lookup-status { margin: 11px 0; font-size: .82rem; font-weight: 720; }
.last-results { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.last-results section { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; }
.last-results section h3 { margin: 0; font-size: .81rem; }
.last-results dl { margin: 5px 0 0; }
.last-results dl > div { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); font-size: .76rem; }
.last-results dd { margin: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.last-results [data-last] { color: var(--accent); font-weight: 790; }

@media (max-width: 730px) {
  .lookup-controls { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .last-results { grid-template-columns: minmax(0,1fr); }
  .journey > div { padding-inline: 4px; }
  .journey dd { overflow-wrap: anywhere; }
  .subway-game { grid-template-columns: minmax(0,1fr); grid-template-areas: "journey" "map" "dispatch" "history"; }
  .journey { padding: 8px 4px; }
  .journey > div { padding: 2px 7px; }
  .journey dd { font-size: .9rem; }
  .dispatch { border-inline-start: 0; border-top: 1px solid var(--line); }
  .map-head, .dispatch-head { padding: 9px 10px; }
  .map-key { padding: 8px 10px; }
  .map-key .map-to-trains { display: inline-block; }
}
@media (max-width: 580px) {
  .difficulty-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .difficulty-picker button { grid-column: 1 / -1; }
  .difficulty-picker select { font-size: .82rem; }
  .time-left { font-size: .63rem; }
  [data-expanded-map]:not([data-wide-map]) .map-board { min-width: 535px; }
  [data-expanded-map] .map-swipe { display: block; }
}
