:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #17211b;
  --muted: #5b655f;
  --subtle: #e3e8e1;
  --line: #d5ddd3;
  --accent: #047c75;
  --accent-strong: #075b56;
  --accent-soft: #dff4ef;
  --rail-red: #d13c32;
  --rail-blue: #2e6fbb;
  --rail-green: #3a8b49;
  --rail-amber: #b77818;
  --shadow: 0 18px 50px rgb(23 33 27 / 16%);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
}

.control-panel {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 24px;
  background: color-mix(in srgb, var(--panel) 94%, var(--bg));
  border-right: 1px solid var(--line);
  overflow: auto;
}

.brand-row,
.section-title,
.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-block-start: 0;
}

h1 {
  margin-block-end: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-block-end: 0;
  font-size: 1rem;
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.icon-button svg,
.primary-button svg,
.secondary-button svg,
.status-refresh-button svg,
.date-input-wrap svg,
.search-input-wrap svg {
  width: 19px;
  height: 19px;
  stroke-width: 2.1;
}

.date-box,
.search-box {
  position: relative;
}

.date-box label,
.search-box label,
.sort-row label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.date-input-wrap,
.search-input-wrap {
  min-height: 48px;
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.date-input-wrap:focus-within,
.search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.date-input-wrap svg,
.search-input-wrap svg {
  color: var(--accent-strong);
}

.date-input-wrap input,
.search-input-wrap input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.suggestions {
  position: absolute;
  inset: calc(100% + 6px) 0 auto;
  z-index: 20;
  display: none;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.suggestions.visible {
  display: block;
}

.suggestion {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--subtle);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.suggestion:last-child {
  border-bottom: 0;
}

.suggestion:hover,
.suggestion.active {
  background: var(--accent-soft);
}

.suggestion strong {
  display: block;
  font-size: 0.95rem;
}

.suggestion span {
  color: var(--muted);
  font-size: 0.82rem;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.toggle-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.sort-row select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

.status-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
}

.status-panel.loading {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: var(--accent-soft);
}

.status-panel.cache {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: #f4fbf8;
}

.status-panel.error {
  border-color: color-mix(in srgb, var(--rail-red) 60%, var(--line));
  background: #fff1ef;
}

.status-refresh-button {
  margin-top: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.summary-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.summary-grid span {
  display: block;
  font-size: 1.3rem;
  font-weight: 800;
}

.summary-grid p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.destination-section {
  min-height: 240px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cache-badge {
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
}

.destination-list {
  display: grid;
  gap: 8px;
}

.destination-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.destination-card:hover,
.destination-card.active {
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgb(23 33 27 / 10%);
}

.destination-card strong {
  display: block;
  margin-bottom: 6px;
  line-height: 1.2;
}

.destination-meta,
.destination-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef1ec;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 750;
}

.destination-score {
  align-self: start;
  padding: 5px 7px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.map-stage {
  position: relative;
  min-height: 100vh;
}

.map {
  position: absolute;
  inset: 0;
  background: #e7ece7;
}

.map-legend {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(520px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 8px 24px rgb(23 33 27 / 14%);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 0.8rem;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-legend span[hidden] {
  display: none !important;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

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

.legend-dot.longdistance {
  background: var(--rail-amber);
}

.legend-dot.regional {
  background: var(--rail-green);
}

.legend-dot.suburban {
  background: var(--rail-blue);
}

.station-modal {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.station-modal::backdrop {
  background: rgb(17 24 39 / 46%);
}

.modal-head,
.modal-body,
.modal-actions {
  padding: 18px;
}

.modal-head {
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  font-size: 1.35rem;
}

.modal-body {
  display: grid;
  gap: 14px;
}

.modal-facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.modal-facts div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
}

.modal-facts strong {
  display: block;
  font-size: 1rem;
}

.modal-facts span {
  color: var(--muted);
  font-size: 0.75rem;
}

.line-strip,
.example-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.example-list {
  display: grid;
}

.example-row {
  display: grid;
  grid-template-columns: minmax(72px, auto) 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--subtle);
  font-size: 0.88rem;
}

.example-row:last-child {
  border-bottom: 0;
}

.line-badge {
  display: inline-flex;
  justify-content: center;
  min-width: 44px;
  padding: 4px 7px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 850;
}

.modal-actions {
  border-top: 1px solid var(--line);
}

.primary-button,
.secondary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--accent-strong);
  background: var(--accent-strong);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.leaflet-container {
  font: inherit;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.start-marker {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 2px 10px rgb(0 0 0 / 32%);
}

@media (max-width: 900px) {
  .app-shell {
    height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(330px, 42vh) minmax(0, 1fr);
    overflow: hidden;
  }

  .control-panel {
    height: auto;
    min-height: 0;
    max-height: none;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: auto;
  }

  .map-stage {
    min-height: 0;
  }

  .map {
    position: relative;
    min-height: 100%;
    height: 100%;
  }

  .destination-section {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  .control-panel {
    gap: 14px;
    padding: 14px;
  }

  .brand-row {
    align-items: start;
  }

  .summary-grid,
  .modal-facts {
    grid-template-columns: 1fr;
  }

  .destination-card {
    grid-template-columns: 1fr;
  }

  .destination-score {
    justify-self: start;
  }

  .station-modal {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 8px 8px 0 0;
  }

  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .example-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
