:root {
  --paper: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1c2624;
  --muted: #66706d;
  --line: #d8d7cf;
  --red: #df3b32;
  --green: #17745d;
  --yellow: #e6b744;
  --blue: #2874a6;
  --shadow: 0 12px 30px rgba(28, 38, 36, .09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}
button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: 58px;
  padding: 0 max(18px, calc((100vw - 1240px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(244, 241, 234, .94);
  border-bottom: 1px solid rgba(28, 38, 36, .1);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 750; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--red);
  font-size: 13px;
  font-weight: 900;
}
.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 21px;
}
.icon-button:hover { border-color: var(--ink); }

main { min-height: calc(100vh - 160px); }
.trip-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 50px 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 36px;
}
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 12px; font-weight: 800; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; max-width: 760px; font-size: clamp(38px, 6vw, 72px); line-height: 1.02; letter-spacing: 0; }
.intro { max-width: 680px; margin: 18px 0 0; color: var(--muted); font-size: 17px; }
.trip-controls { min-width: 270px; display: grid; gap: 12px; }
.trip-controls label {
  min-height: 50px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.trip-controls label > span { color: var(--muted); font-size: 13px; font-weight: 700; }
input[type="date"] { max-width: 145px; border: 0; background: transparent; color: var(--ink); }
input[type="checkbox"] { width: 38px; height: 22px; accent-color: var(--red); }

.status-strip {
  max-width: 1192px;
  margin: 0 auto 28px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--ink);
  color: white;
}
.status-strip div { padding: 15px 18px; display: flex; align-items: baseline; gap: 10px; border-right: 1px solid rgba(255,255,255,.17); }
.status-strip div:last-child { border: 0; }
.status-strip strong { font-size: 20px; }
.status-strip span { color: #c8cfcc; font-size: 12px; }

.view-tabs {
  position: sticky;
  top: 58px;
  z-index: 900;
  max-width: 1192px;
  margin: 0 auto;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 234, .96);
  backdrop-filter: blur(12px);
}
.tab { padding: 14px; border: 0; border-bottom: 3px solid transparent; background: transparent; cursor: pointer; font-weight: 750; }
.tab.active { border-bottom-color: var(--red); color: var(--red); }
.view { display: none; }
.view.active { display: block; }

.plan-layout { max-width: 1240px; margin: 0 auto; padding: 28px 24px 60px; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr); gap: 28px; }
.map-panel { position: sticky; top: 82px; align-self: start; }
.section-heading { min-height: 56px; margin-bottom: 18px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; font-size: 25px; line-height: 1.18; }
.map-tools { display: flex; align-items: center; gap: 8px; }
.locate-button {
  min-height: 38px;
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}
.locate-button:hover { border-color: var(--ink); }
.locate-button:disabled { cursor: wait; opacity: .65; }
#map, #mapLarge { width: 100%; background: #d9e0dc; }
#map { height: min(610px, calc(100vh - 200px)); min-height: 460px; box-shadow: var(--shadow); }
#mapLarge { height: calc(100vh - 158px); min-height: 560px; }
.map-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.leaflet-popup-content-wrapper { border-radius: 4px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; }
.map-popup strong { display: block; font-size: 14px; }
.map-popup span { color: var(--muted); font-size: 12px; }
.map-marker {
  width: 28px !important;
  height: 28px !important;
  margin-left: -14px !important;
  margin-top: -14px !important;
  display: grid !important;
  place-items: center;
  border: 3px solid white;
  border-radius: 50%;
  color: white;
  background: var(--red);
  box-shadow: 0 3px 12px rgba(0,0,0,.25);
  font-size: 11px;
  font-weight: 900;
}
.map-marker.used { background: var(--green); }
.map-marker.transit { background: var(--blue); }

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filter { min-height: 36px; padding: 7px 13px; border: 1px solid var(--line); border-radius: 5px; background: transparent; cursor: pointer; }
.filter.active { color: white; border-color: var(--ink); background: var(--ink); }
.timeline { display: grid; gap: 14px; }
.stop-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: transform .18s ease, border-color .18s ease;
}
.stop-card:hover { transform: translateY(-2px); border-color: #aaa99f; }
.stop-card.done { opacity: .62; }
.stop-card.hidden { display: none; }
.stop-time { padding: 17px 10px; text-align: center; border-right: 1px solid var(--line); }
.stop-time strong { display: block; font-size: 17px; }
.stop-time span { color: var(--muted); font-size: 11px; }
.stop-body { min-width: 0; padding: 16px; }
.stop-top { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.stop-top h3 { margin: 0; font-size: 18px; }
.stop-meta { margin: 5px 0 9px; display: flex; flex-wrap: wrap; gap: 6px; }
.badge { padding: 3px 7px; border-radius: 3px; background: #ecebe5; color: var(--muted); font-size: 11px; font-weight: 750; }
.badge.must { color: #a52019; background: #f9dedb; }
.badge.used { color: #0d654f; background: #d9efe8; }
.stop-summary { margin: 0; color: var(--muted); font-size: 14px; }
.stop-actions { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 8px; }
.text-button, .primary-button {
  min-height: 35px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}
.primary-button { color: white; border-color: var(--red); background: var(--red); }
.visit-check { width: 24px; height: 24px; flex: 0 0 auto; accent-color: var(--green); }

.full-map-wrap { position: relative; }
.map-locate-floating { position: absolute; z-index: 500; top: 18px; right: 18px; box-shadow: var(--shadow); }
.map-legend { position: absolute; z-index: 500; left: 24px; bottom: 24px; padding: 10px 12px; display: flex; gap: 14px; background: rgba(255,253,248,.94); box-shadow: var(--shadow); font-size: 12px; }
.dot { width: 9px; height: 9px; display: inline-block; margin-right: 5px; border-radius: 50%; background: var(--red); }
.dot.used { background: var(--green); }
.dot.transit { background: var(--blue); }

.content-width { max-width: 1050px; margin: 0 auto; padding: 38px 24px 70px; }
.metro-routes { display: grid; gap: 18px; }
.metro-card { border-top: 1px solid var(--ink); padding-top: 18px; }
.metro-card-head { display: flex; justify-content: space-between; gap: 20px; }
.metro-card h3 { margin: 0; font-size: 20px; }
.metro-card-head span { color: var(--muted); font-size: 13px; }
.metro-steps { margin: 18px 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metro-step { min-height: 112px; padding: 14px; border-left: 6px solid var(--blue); background: var(--surface); }
.metro-step.east { border-color: #53b7c8; }
.metro-step.kwun { border-color: #249a44; }
.metro-step.tsuen { border-color: #e5252a; }
.metro-step.island { border-color: #196bb5; }
.metro-step strong { display: block; margin-bottom: 6px; font-size: 14px; }
.metro-step span, .metro-tip { color: var(--muted); font-size: 13px; }
.metro-basics { margin-top: 44px; }
.metro-basics h3, .carry-list h3 { margin: 0 0 15px; font-size: 20px; }
.basic-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.basic-grid article { min-height: 120px; padding: 18px; display: flex; gap: 14px; align-items: flex-start; border: 1px solid var(--line); background: var(--surface); }
.basic-grid strong { color: var(--red); font-size: 28px; line-height: 1; }

.scenario-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.scenario { min-height: 170px; padding: 20px; border: 1px solid var(--line); background: var(--surface); }
.scenario-icon { width: 38px; height: 38px; display: grid; place-items: center; margin-bottom: 18px; color: white; background: var(--ink); font-size: 17px; font-weight: 900; }
.scenario h3 { margin: 0 0 8px; font-size: 17px; }
.scenario p { margin: 0; color: var(--muted); font-size: 14px; }
.carry-list { margin-top: 44px; }
.check-grid { display: grid; grid-template-columns: repeat(2, 1fr); border-top: 1px solid var(--line); }
.carry-item { padding: 13px 3px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.carry-item input { width: 20px; height: 20px; accent-color: var(--green); }

dialog { width: min(720px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; background: var(--surface); box-shadow: 0 22px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(17, 27, 24, .72); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; top: 10px; right: 10px; z-index: 2; }
.place-photo { width: 100%; aspect-ratio: 16 / 8; display: block; object-fit: cover; background: #ddd; }
.place-detail { padding: 24px; }
.place-detail h2 { margin: 0 0 4px; font-size: 29px; }
.detail-area { color: var(--red); font-size: 13px; font-weight: 750; }
.detail-grid { margin: 22px 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 24px; }
.detail-grid div { border-top: 1px solid var(--line); padding-top: 10px; }
.detail-grid strong { display: block; margin-bottom: 4px; font-size: 12px; }
.detail-grid span { color: var(--muted); font-size: 13px; }
.place-detail h3 { margin: 24px 0 9px; font-size: 17px; }
.task-list { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.subplace-list { display: grid; gap: 8px; }
.subplace { padding: 11px 0; display: grid; grid-template-columns: minmax(130px, .8fr) minmax(130px, .7fr) minmax(0, 1.6fr); gap: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.subplace span { color: var(--muted); }
.status-label { color: var(--green) !important; font-weight: 750; }
.dialog-actions { margin-top: 22px; display: flex; flex-wrap: wrap; gap: 9px; }

footer { padding: 28px 24px 36px; color: var(--muted); border-top: 1px solid var(--line); text-align: center; font-size: 11px; }
footer p { margin: 4px; }

@media (max-width: 900px) {
  .trip-header { align-items: stretch; flex-direction: column; }
  .trip-controls { min-width: 0; grid-template-columns: 1fr 1fr; }
  .plan-layout { grid-template-columns: 1fr; }
  .map-panel { position: static; }
  #map { height: 430px; min-height: 0; }
  .metro-steps { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .topbar { height: 54px; padding: 0 14px; }
  .trip-header { padding: 32px 16px 22px; gap: 22px; }
  h1 { font-size: 42px; }
  .intro { font-size: 15px; }
  .trip-controls { grid-template-columns: 1fr; }
  .status-strip { margin: 0 16px 20px; grid-template-columns: repeat(2, 1fr); }
  .status-strip div:nth-child(2) { border-right: 0; }
  .status-strip div:nth-child(-n+2) { border-bottom: 1px solid rgba(255,255,255,.17); }
  .view-tabs { margin: 0 16px; }
  .view-tabs { top: 54px; }
  .tab { padding: 12px 5px; font-size: 13px; }
  .plan-layout, .content-width { padding: 24px 16px 48px; }
  .map-heading { align-items: center; }
  .map-heading .locate-button { max-width: 126px; line-height: 1.2; }
  #map { height: 330px; }
  #mapLarge { height: calc(100vh - 130px); min-height: 500px; }
  .stop-card { grid-template-columns: 62px minmax(0, 1fr); }
  .stop-body { padding: 14px 12px; }
  .stop-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .stop-actions > * { text-align: center; }
  .metro-card-head { display: block; }
  .metro-card-head span { display: block; margin-top: 5px; }
  .metro-steps, .basic-grid, .scenario-grid, .check-grid, .detail-grid { grid-template-columns: 1fr; }
  .subplace { grid-template-columns: 1fr; gap: 3px; }
  .place-photo { aspect-ratio: 4 / 3; }
  .place-detail { padding: 20px 16px; }
  .map-legend { right: 14px; left: 14px; bottom: 14px; justify-content: center; }
  .map-locate-floating { top: 12px; right: 12px; }
}

@media print {
  .topbar, .view-tabs, .trip-controls, .map-panel, .stop-actions, footer { display: none !important; }
  body { background: white; }
  .trip-header, .plan-layout { padding: 16px 0; }
  .view, #view-plan { display: block !important; }
  .plan-layout { display: block; }
  .stop-card { break-inside: avoid; margin-bottom: 10px; }
}
