:root {
  --accent: #d94f33;
  --accent-soft: #fdeeea;
  --ink: #23201e;
  --ink-soft: #6d6762;
  --line: #e6e1dc;
  --panel: #fffdfb;
  --sand: #f6f1ea;
  --sidebar-width: 380px;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--sand);
  overflow: hidden;
}

/* ------------------------------------------------------------------ sidebar */

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 18px rgba(35, 32, 30, 0.06);
  z-index: 500;
}

.masthead {
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.app-name {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
}

/* Editable in place: it reads as a heading until you click into it. */
.trip-name {
  display: block;
  width: 100%;
  margin: 0;
  padding: 2px 6px 2px 5px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.trip-name:hover { border-color: var(--line); }

.trip-name:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.masthead-hint {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.start {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-soft);
}

.start label {
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
}

.start input {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: #fff;
}

.start input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.date-range {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.stat {
  background: var(--panel);
  padding: 12px 8px;
  text-align: center;
}

.stat b {
  display: block;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat span {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
}

.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 18px 24px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------- itinerary */

.itinerary {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.stop {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stop:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(217, 79, 51, 0.1);
}

.stop-num {
  flex: 0 0 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stop-body { flex: 1 1 auto; min-width: 0; }

.stop-city {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.stop-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-soft);
}

.no-pass {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: help;
}

.stop-dates {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.nights {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.nights-count {
  min-width: 62px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.nights-btn,
.stop-actions button {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.nights-btn:hover,
.stop-actions button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.stop-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stop-actions button:disabled {
  opacity: 0.35;
  cursor: default;
}

.stop-actions .remove:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.leg {
  margin: 0 0 0 21px;
  padding: 6px 0 6px 22px;
  border-left: 2px dashed var(--accent);
  font-size: 11.5px;
  color: var(--ink-soft);
}

.leg-km {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink);
}

.leg-via {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  opacity: 0.85;
}

.leg-mode {
  display: inline-block;
  margin-top: 4px;
  margin-right: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.leg-trains {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.12s;
}

/* Quiet enough not to clutter the list, present enough to be found. */
.leg:hover .leg-trains,
.leg-trains:focus { opacity: 1; }

.leg-trains:hover { text-decoration: underline; }

.leg-ferry  { background: #e3f0fa; color: #2b7bb9; }
.leg-bus,
.leg-flight { background: #eeedec; color: var(--ink-soft); }

.leg-unknown { border-left-style: dotted; border-left-color: var(--line); }

.empty {
  margin: 0 0 20px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
  text-align: center;
}

/* ------------------------------------------------------------------ picker */

.search {
  width: 100%;
  margin-bottom: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  background: #fff;
}

.search:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.picker {
  display: grid;
  gap: 5px;
}

.picker-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.picker-item strong { font-size: 13px; font-weight: 600; }

.picker-tag {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  opacity: 0.75;
}

.picker-country {
  margin: 10px 0 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  opacity: 0.7;
}

.picker-country:first-child { margin-top: 0; }

.picker-empty {
  margin: 4px 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* Non-capitals sit slightly indented so the country's capital reads first. */
.picker-item:not(.is-capital) strong { font-weight: 500; }

.picker-item:hover {
  background: var(--sand);
  border-color: var(--line);
}

.picker-item.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.picker-item.is-on strong { color: var(--accent); }

/* ---------------------------------------------------------------- controls */

.controls {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.loop {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
}

.loop input { accent-color: var(--accent); }

.buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.buttons button {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.buttons button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.buttons .primary {
  grid-column: 1 / -1;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.buttons .primary:hover {
  background: #c24427;
  border-color: #c24427;
  color: #fff;
}

/* --------------------------------------------------------------------- map */

#map {
  flex: 1 1 auto;
  height: 100%;
  background: #eef1f3;
}

/* ------------------------------------------------------ presentation mode */

.stage {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  pointer-events: none;
}

body.presenting .sidebar { display: none; }
body.presenting .stage { display: block; }

.stage-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 360px;
  max-height: 100%;
  overflow-y: auto;
  pointer-events: auto;
  padding: 30px 28px 26px;
  background: rgba(255, 253, 251, 0.95);
  backdrop-filter: blur(8px);
  box-shadow: 2px 0 40px rgba(35, 32, 30, 0.16);
}

/* A 360px column eats a narrow screen; drop it to a sheet across the top. */
@media (max-width: 900px) {
  .stage-panel {
    width: 100%;
    max-height: 48%;
    padding: 20px 20px 18px;
    box-shadow: 0 2px 30px rgba(35, 32, 30, 0.16);
  }
  .stage-title { font-size: 23px; }
}

.stage-title {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.stage-dates {
  margin: 6px 0 0;
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.stage-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}

.stage-stop {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 0;
}

.stage-num {
  flex: 0 0 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stage-city {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}

.stage-meta {
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* The leg sits on the rail between two stops, like the editing view. */
.stage-leg {
  margin: 3px 0 3px 10px;
  padding: 5px 0 5px 21px;
  border-left: 2px dashed var(--line);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.stage-leg.is-live {
  border-left-color: var(--accent);
  color: var(--ink);
}

.stage-resv {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stage-stats {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

/* The number that decides which pass to buy — give it its own weight. */
.stage-days {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

/* An emoji carries its own colour, so only spacing and size matter here. */
.stage-moon {
  margin-right: 5px;
  font-size: 12px;
  cursor: help;
}

.stage-share {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 14px;
}

.stage-share button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.stage-share button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ------------------------------------------------- times drawn on the line */

.leg-label-wrap { background: none; border: none; }

.leg-label {
  display: inline-block;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 253, 251, 0.96);
  border: 1px solid var(--accent);
  box-shadow: 0 2px 8px rgba(35, 32, 30, 0.18);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.leg-label.is-muted {
  border-color: var(--line);
  color: var(--ink-soft);
  font-weight: 500;
}

/* Dashed outline: the time is real but the timetable behind it is not final. */
.leg-label.is-provisional {
  border-style: dashed;
  border-color: var(--ink-soft);
  color: var(--ink-soft);
}

.stage-prov {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px dashed var(--line);
  border-radius: 4px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: help;
}

.stage-exit {
  position: absolute;
  top: 34px;
  right: 34px;
  pointer-events: auto;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 251, 0.94);
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(35, 32, 30, 0.14);
}

.stage-exit:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.leaflet-container { font: inherit; }

/* Mute the standard OSM tiles into a pale basemap so the route line dominates. */
.leaflet-tile {
  filter: grayscale(0.85) brightness(1.08) contrast(0.92);
}

.city-dot { cursor: pointer; }

.stop-badge-wrap { background: none; border: none; }

.stop-badge {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #23201e;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------- responsive */

/*
 * On narrow screens the panel-and-map split stops paying off: capping the
 * sidebar's height just crushes the itinerary. Let the page scroll normally
 * instead, with the map pinned to the top where it is seen first.
 */
@media (max-width: 820px) {
  html, body { height: auto; }
  body { flex-direction: column; overflow: visible; }

  #map {
    order: -1;
    height: 46vh;
    flex: 0 0 46vh;
    border-bottom: 1px solid var(--line);
  }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    border-right: none;
    box-shadow: none;
  }

  .scroll {
    flex: 0 0 auto;
    overflow: visible;
  }

  .start { flex-wrap: wrap; }
}
