:root {
  color-scheme: light;
  --ink: #15202b;
  --muted: #667386;
  --line: #d9e0ea;
  --panel: #ffffff;
  --soft: #f4f7fb;
  --blue: #005eb8;
  --blue-dark: #004281;
  --teal: #007c89;
  --red: #d62828;
  --amber: #f6c343;
  --shadow: 0 16px 40px rgba(21, 32, 43, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(0, 94, 184, 0.1), transparent 320px),
    var(--soft);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.25rem);
  line-height: 0.95;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-tab {
  min-height: 40px;
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 900;
}

.nav-tab.active {
  color: #fff;
  background: var(--blue);
}

.nav-tab:focus-visible {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 94, 184, 0.16);
}

.icon-button,
.primary-button,
.secondary-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 44px;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.icon-button:active,
.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  background: var(--panel);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.controls {
  display: grid;
  grid-template-columns: auto minmax(220px, 0.7fr) 1fr;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 16px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: #aebacf;
}

.manual-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.display-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(100px, 1fr));
  gap: 12px;
}

.select-controls {
  display: grid;
  grid-template-columns: minmax(180px, 0.45fr) 1fr;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.select-search-form {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 12px) 19px;
  background-repeat: no-repeat;
  background-size:
    6px 6px,
    6px 6px;
  padding-right: 34px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 94, 184, 0.16);
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: #eaf3ff;
  border: 1px solid #c7ddf8;
  border-radius: 8px;
}

.status-panel > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-panel p {
  margin: 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  background: var(--amber);
  border-radius: 50%;
}

.status-dot.ready {
  background: #0a8f53;
}

.status-dot.error {
  background: var(--red);
}

.last-updated {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.status-times {
  display: grid;
  gap: 3px;
  text-align: right;
}

.refresh-countdown {
  margin: 0;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.result-section {
  margin-top: 20px;
}

.map-preview {
  margin-top: 20px;
}

.mini-map {
  width: 100%;
  min-height: 280px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: block;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  text-decoration: none;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.legend-dot.current {
  background: var(--ink);
}

.legend-dot.bus {
  background: var(--red);
}

.legend-dot.train {
  background: var(--teal);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.section-heading h2,
.section-heading p {
  margin: 0;
}

.section-heading h2 {
  font-size: 1.18rem;
}

.section-heading p {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-grid {
  display: grid;
  gap: 16px;
}

.bus-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.station-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.selected-stop-panel,
.selected-train-panel {
  display: grid;
  max-width: 720px;
}

.line-status-panel {
  max-width: 720px;
  margin-bottom: 12px;
}

.line-status {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  align-items: center;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.line-status strong {
  font-size: 1rem;
}

.line-status span {
  justify-self: end;
  padding: 4px 9px;
  color: #fff;
  background: var(--teal);
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 900;
}

.line-status.notice span {
  background: var(--amber);
  color: var(--ink);
}

.line-status p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stop-card {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.stop-card:hover {
  border-color: #aebacf;
  box-shadow: 0 20px 46px rgba(21, 32, 43, 0.14);
  transform: translateY(-1px);
}

.stop-card:focus-visible {
  border-color: var(--blue);
  box-shadow:
    0 0 0 3px rgba(0, 94, 184, 0.18),
    var(--shadow);
  outline: none;
}

.stop-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.stop-header h2 {
  margin: 4px 0 0;
  font-size: 1.16rem;
  line-height: 1.2;
}

.stop-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.stop-letter {
  display: inline-grid;
  min-width: 42px;
  height: 42px;
  place-items: center;
  padding: 0 10px;
  color: #fff;
  background: var(--red);
  border-radius: 8px;
  font-weight: 900;
}

.station-card .stop-letter,
.station-card .route {
  background: var(--teal);
}

.arrival-list {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--line);
}

.arrival {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 74px;
  padding: 14px 18px;
  background: #fff;
}

.route {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 34px;
  padding: 0 8px;
  color: #fff;
  background: var(--blue);
  border-radius: 6px;
  font-weight: 900;
}

.destination {
  min-width: 0;
}

.destination strong,
.destination span {
  display: block;
  overflow-wrap: anywhere;
}

.destination span {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 3px;
}

.eta {
  font-size: 1.55rem;
  font-weight: 900;
  white-space: nowrap;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  background: #fff;
}

.skeleton {
  position: relative;
  min-height: 260px;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent, rgba(0, 94, 184, 0.08), transparent);
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(100%);
  }
}

@media (max-width: 900px) {
  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .display-controls,
  .manual-form {
    grid-column: 1 / -1;
  }

  .bus-grid,
  .station-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 16px;
  }

  .topbar,
  .status-panel,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-end;
  }

  .controls,
  .manual-form,
  .select-search-form,
  .select-controls {
    grid-template-columns: 1fr;
  }

  .line-status {
    grid-template-columns: 1fr;
  }

  .line-status span {
    justify-self: start;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .last-updated {
    white-space: normal;
  }

  .status-times {
    text-align: left;
  }

  .refresh-countdown {
    white-space: normal;
  }

  .mini-map {
    min-height: 220px;
  }
}
