:root {
  color-scheme: light;
  --ink: #2f2924;
  --muted: #705f51;
  --cream: #fff8e8;
  --paper: #fffdf5;
  --meadow: #759f5b;
  --meadow-dark: #3e6947;
  --wine: #71364a;
  --wine-dark: #522637;
  --gold: #e4a936;
  --gold-pale: #f9e7b4;
  --red: #9a323a;
  --green: #28643f;
  --line: #cdbf9f;
  --shadow: 0 5px 0 rgb(47 41 36 / 18%);
  --radius: 18px;
  --touch: 48px;
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--meadow-dark); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: linear-gradient(150deg, #88b36b, var(--meadow-dark)); }
button, textarea, select { font: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }

.topbar {
  min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 10px clamp(14px, 2vw, 28px); color: var(--cream); background: var(--wine-dark);
  border-bottom: 4px solid #2f1d25; position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border: 3px solid var(--cream); border-radius: 14px; color: var(--wine-dark); background: var(--gold); font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: clamp(21px, 2vw, 28px); line-height: 1; }
.brand small { margin-top: 3px; letter-spacing: .08em; text-transform: uppercase; font-size: 10px; }
.status-cluster { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.status-chip { min-height: 36px; display: inline-flex; align-items: center; padding: 6px 12px; border: 2px solid var(--cream); border-radius: 999px; background: #5d4a47; color: #fff; font-size: 13px; font-weight: 800; }
.status-chip[data-tone="good"] { background: var(--green); }
.status-chip[data-tone="warn"] { background: #8a601e; }
.status-chip[data-tone="bad"] { background: var(--red); }

.app-shell { width: min(1500px, 100%); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(360px, .8fr); min-height: calc(100vh - 72px); }
.route-board, .control-panel { padding: clamp(14px, 2vw, 26px); }
.route-board { background: rgb(255 248 232 / 8%); color: var(--cream); }
.control-panel { display: flex; flex-direction: column; gap: 14px; background: var(--meadow-dark); border-left: 4px solid rgb(255 255 255 / 18%); }

.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.section-heading h1, .section-heading h2 { margin: 0; line-height: 1.05; }
.section-heading h1 { font-size: clamp(30px, 4vw, 50px); }
.section-heading h2 { font-size: 27px; }
.eyebrow { margin: 0 0 4px; color: inherit; opacity: .72; text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 900; }
.trip-state { padding: 8px 13px; border: 2px solid var(--cream); border-radius: 999px; background: var(--wine); font-weight: 900; text-transform: uppercase; font-size: 12px; white-space: nowrap; }

.wagon-scene { position: relative; height: clamp(200px, 30vh, 320px); overflow: hidden; margin: 18px 0 12px; border: 4px solid var(--ink); border-radius: 28px; background: linear-gradient(#b9dbdc 0 58%, #7eaa61 58%); box-shadow: var(--shadow); }
.hills { position: absolute; left: -5%; right: -5%; bottom: 27%; height: 44%; background: #5e874e; clip-path: polygon(0 100%, 0 65%, 15% 24%, 27% 62%, 45% 18%, 63% 72%, 80% 22%, 100% 58%, 100% 100%); }
.road { position: absolute; left: -4%; right: -4%; bottom: 12%; height: 25%; border: 3px solid var(--ink); background: var(--gold-pale); transform: rotate(-1deg); }
.road::after { content: ""; position: absolute; left: 0; right: 0; top: 48%; border-top: 4px dashed var(--wine); }
.route-progress { --progress: 0%; position: absolute; left: 8%; right: 8%; bottom: 48px; height: 8px; border-radius: 999px; background: linear-gradient(90deg, var(--wine) var(--progress), transparent var(--progress)); z-index: 2; }
.wagon { --progress: 0%; position: absolute; left: clamp(16px, var(--progress), calc(100% - 142px)); bottom: 42px; z-index: 3; width: 126px; min-height: 68px; display: grid; place-items: center; color: var(--cream); background: var(--wine); border: 4px solid var(--ink); border-radius: 20px 20px 10px 10px; box-shadow: 0 7px 0 rgb(47 41 36 / 24%); font-weight: 900; letter-spacing: .1em; transition: left .5s ease; }
.wagon::before, .wagon::after { content: ""; position: absolute; bottom: -13px; width: 25px; height: 25px; border: 4px solid var(--ink); border-radius: 50%; background: var(--cream); }
.wagon::before { left: 14px; } .wagon::after { right: 14px; }
.wagon span + span { font-size: 12px; }

.route-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.route-facts > div { min-height: 72px; padding: 10px 12px; border: 2px solid rgb(255 248 232 / 45%); border-radius: 13px; background: rgb(47 41 36 / 17%); }
.route-facts span, .destination-grid span, .address-block span, .detail-address span, .detail-columns span, .trivia-card span { display: block; margin-bottom: 4px; opacity: .72; text-transform: uppercase; letter-spacing: .1em; font-size: 10px; font-weight: 900; }
.route-facts strong { font-size: 15px; }
.notice { margin: 12px 0; padding: 11px 13px; border: 2px dashed var(--cream); border-radius: 13px; background: rgb(47 41 36 / 18%); line-height: 1.45; }
.trivia-card { padding: 12px 14px; color: var(--ink); background: var(--gold-pale); border: 3px solid var(--ink); border-radius: 15px; box-shadow: var(--shadow); }
.trivia-card p { margin: 0; font-size: 16px; font-weight: 750; }
.lineup-heading { margin-top: 22px; }
.heading-actions, .lineup-presets { display: flex; gap: 7px; flex-wrap: wrap; }

.stop-list { display: grid; gap: 9px; margin: 12px 0 0; padding: 0; list-style: none; counter-reset: stop; }
.stop-item { counter-increment: stop; display: grid; grid-template-columns: 42px 1fr auto; gap: 11px; align-items: center; padding: 10px 11px; color: var(--ink); background: var(--paper); border: 3px solid var(--ink); border-radius: 15px; box-shadow: 0 3px 0 rgb(47 41 36 / 20%); }
.stop-item::before { content: counter(stop); display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--gold); border: 2px solid var(--ink); font-weight: 900; }
.stop-item[data-active="true"] { background: var(--gold-pale); border-width: 4px; }
.stop-item[data-state="completed"]::before { content: "Done"; font-size: 9px; background: #b9d4ac; }
.stop-item[data-state="skipped"] { opacity: .68; }
.stop-main strong, .stop-main small { display: block; }
.stop-main strong { font-size: 16px; line-height: 1.2; }
.stop-main small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.stop-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.destination-card, .actions-card, .route-comparison { padding: 16px; background: var(--cream); border: 4px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); }
.destination-card h2 { margin: 2px 0 5px; font-size: clamp(27px, 3vw, 38px); line-height: 1.05; }
.distance-value { margin: 8px 0 12px; color: var(--wine); font-size: clamp(29px, 4vw, 47px); line-height: 1; font-weight: 900; }
.address-block { padding: 12px; border: 3px solid var(--wine); border-radius: 14px; background: var(--paper); }
.address-block strong, .address-block small { display: block; }
.address-block strong { font-size: 18px; line-height: 1.28; }
.address-block small { margin-top: 5px; color: var(--muted); font-family: ui-monospace, monospace; }
.destination-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.destination-grid > div { padding: 9px 10px; border: 2px dashed var(--line); border-radius: 12px; }
.destination-grid strong { font-size: 14px; line-height: 1.3; }
.evidence { margin-top: 10px; padding: 9px 10px; border-radius: 11px; color: #fff; background: #655c54; font-weight: 800; font-size: 13px; }
.evidence[data-tone="good"] { background: var(--green); }
.evidence[data-tone="warn"] { background: #8a601e; }

.actions-card h2, .route-comparison h2 { margin: 0 0 10px; font-size: 21px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.button { min-height: var(--touch); padding: 9px 13px; border: 3px solid var(--ink); border-radius: 999px; color: var(--ink); background: var(--paper); box-shadow: 0 3px 0 rgb(47 41 36 / 22%); font-weight: 900; cursor: pointer; }
.button:hover { filter: brightness(.97); }
.button:active { transform: translateY(2px); box-shadow: none; }
.button:disabled { cursor: not-allowed; opacity: .45; filter: grayscale(.3); }
.button-primary { color: var(--cream); background: var(--wine); }
.button-secondary { background: var(--gold); }
.button-danger { color: #fff; background: var(--red); }
.button-small { min-height: var(--touch); padding: 6px 12px; font-size: 12px; }
.button-wide { grid-column: 1 / -1; }
.control-note, .route-comparison p { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.route-comparison dl { display: grid; gap: 4px; margin: 0; }
.route-comparison dl > div { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; padding: 7px 0; border-top: 1px dashed var(--line); }
.route-comparison dt { color: var(--muted); }.route-comparison dd { margin: 0; font-weight: 900; text-align: right; }

.dialog { width: min(720px, calc(100% - 24px)); max-height: 92vh; padding: 0; border: 0; border-radius: 22px; background: transparent; }
.dialog::backdrop { background: rgb(31 31 25 / 74%); }
.dialog-card { position: relative; padding: 22px; color: var(--ink); background: var(--cream); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 8px 0 rgb(0 0 0 / 25%); overflow: auto; }
.dialog-card h2 { margin: 0 70px 14px 0; font-size: 29px; }
.dialog-close { position: absolute; top: 12px; right: 12px; min-height: 42px; padding: 6px 12px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); font-weight: 900; }
/* Details and Passport keep their Close control outside the scrolling text.
   Normal flow prevents headings from painting over its touch target. */
.dialog-panel { max-height: min(92vh, calc(100vh - 24px)); max-height: min(92dvh, calc(100dvh - 24px)); overflow: hidden; }
.dialog-panel .dialog-card { display: flex; flex-direction: column; max-height: inherit; padding: 0; overflow: hidden; }
.dialog-header { display: flex; flex: none; justify-content: flex-end; padding: clamp(12px, 2vw, 22px); }
.dialog-panel .dialog-close { position: static; min-width: var(--touch); min-height: var(--touch); border-width: 3px; cursor: pointer; }
.dialog-content { min-height: 0; padding: 0 clamp(12px, 2vw, 22px) clamp(12px, 2vw, 22px); overflow: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.dialog-panel h2 { margin: 0 0 14px; }
.dialog-content > *, .dialog-panel .detail-columns > div { min-width: 0; }
.dialog-panel fieldset { min-inline-size: 0; }
.dialog-panel select { min-width: 0; max-width: 100%; }
.dialog-panel .passport-row { grid-template-columns: minmax(0, 1fr) minmax(0, auto); }
.dialog-panel :focus-visible { outline: 3px solid var(--wine); outline-offset: 3px; }
.detail-address { padding: 11px; border: 3px solid var(--wine); border-radius: 13px; background: var(--paper); }
.detail-address strong, .detail-address small { display: block; }.detail-address small { margin-top: 4px; color: var(--muted); }
.detail-columns { display: grid; grid-template-columns: 1fr 1.5fr; gap: 9px; margin: 10px 0; }
.detail-columns > div { padding: 10px; border: 2px dashed var(--line); border-radius: 12px; }
.detail-columns p { margin: 0; line-height: 1.4; }
.field { display: grid; gap: 5px; font-weight: 900; }
.field textarea { width: 100%; padding: 10px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; resize: vertical; }
#rating-fields { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin: 12px 0 0; padding: 10px; border: 2px dashed var(--line); border-radius: 12px; }
#rating-fields legend { padding: 0 6px; font-weight: 900; }
.rating-field { display: grid; gap: 4px; font-size: 11px; font-weight: 900; }
.rating-field select { min-height: 42px; padding: 5px; border: 2px solid var(--ink); border-radius: 9px; background: #fff; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.history-summary { padding: 10px; border: 2px dashed var(--line); border-radius: 12px; font-weight: 900; }
.dialog-note { color: var(--muted); line-height: 1.45; }
.lineup-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 12px; }
.lineup-option { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 8px; padding: 9px; border: 2px solid var(--line); border-radius: 11px; background: var(--paper); font-weight: 900; }
.lineup-option input { width: 22px; height: 22px; accent-color: var(--wine); }
.passport-list { display: grid; gap: 7px; margin-top: 10px; }
.passport-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 9px 10px; border: 2px solid var(--line); border-radius: 11px; background: var(--paper); }
.passport-row span { color: var(--muted); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 18px; z-index: 30; max-width: min(650px, calc(100% - 28px)); padding: 11px 16px; transform: translate(-50%, 130%); color: #fff; background: var(--ink); border: 3px solid var(--cream); border-radius: 999px; box-shadow: 0 5px 18px rgb(0 0 0 / 35%); font-weight: 900; transition: transform .25s ease; }
.toast[data-show="true"] { transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { border-left: 0; border-top: 4px solid rgb(255 255 255 / 18%); }
  .route-board { min-height: auto; }
}
@media (max-width: 640px) {
  .topbar { align-items: flex-start; }.status-cluster { max-width: 55%; }
  .route-facts, .destination-grid { grid-template-columns: 1fr; }
  .wagon-scene { height: 210px; }
  .stop-item { grid-template-columns: 38px 1fr; }.stop-actions { grid-column: 1 / -1; }
  .detail-columns, #rating-fields { grid-template-columns: 1fr; }
  .dialog-panel .passport-row { grid-template-columns: 1fr; }
  .lineup-options { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
