/* NY → San Diego — public site.
   A gallery wall: muted print-like map, one cobalt line for the road, photographs as the hero.

   Readability rules applied at every screen size:
   - body text ≥ 17px, labels and numbers ≥ 14px (0.875rem); no text smaller except map attribution
   - text colours meet WCAG AA contrast on --paper (graphite 4.7:1, cobalt 6.4:1, ink 15:1)
   - every control is ≥ 44 × 44px on touch screens
   - photos are never cropped (object-fit: contain inside a frame shaped like the day's photos)

   Layouts: phone < 700px (stacked) · tablet 700–1099px (stacked, centred 680px column)
            desktop ≥ 1100px (map 50% | journal 40%, margins and gutter share the remaining 10%) */
:root {
  --paper: #f4f5f2;
  --paper-deep: #e8eae5;
  --ink: #1c2220;
  --graphite: #5f6662;
  --hairline: #d9dcd6;
  --numeral: #a3a8a3;
  --cobalt: #2c3fd1;
  --cobalt-wash: #e4e7fb;

  /* Latin faces first; Chinese text falls through to each platform's Traditional Chinese face. */
  --display: 'Archivo', 'Helvetica Neue', Arial, 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
  --text: 'Newsreader', Georgia, 'Songti TC', 'Noto Serif TC', 'Noto Serif CJK TC', 'PMingLiU', serif;

  /* Type scale (rem = 16px) */
  --fs-label: 0.875rem;   /* 14px: dates, counters, small data */
  --fs-data: 0.9375rem;   /* 15px: facts, controls */
  --fs-body: 1.0625rem;   /* 17px: stories */
  --fs-title: 1.1875rem;  /* 19px: day titles */

  --margin: 16px;
  --gap: 0px;
  --tap: 44px;
  --mast: auto;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  /* Keep clear of the notch / home indicator on phones held sideways. */
  padding: 0 max(var(--margin), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--margin), env(safe-area-inset-left));
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 3px;
}

button {
  font: inherit;
  color: inherit;
}

/* --- Masthead --- */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.2rem;
  padding: 1.25rem 0 1rem;
}

.masthead__title {
  width: 100%;
  margin: 0;
  font-family: var(--display);
  font-variation-settings: 'wdth' 68;
  font-weight: 760;
  font-size: clamp(2rem, 1.4rem + 2.2vw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
}

.masthead__facts {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  font-family: var(--display);
  font-size: var(--fs-data);
  color: var(--graphite);
}

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

.unit-toggle {
  display: flex;
  font-family: var(--display);
  font-size: var(--fs-data);
}

.unit-toggle button {
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: none;
  padding: 0 0.5rem;
  color: var(--graphite);
  cursor: pointer;
}

.unit-toggle button[aria-pressed='true'] {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--cobalt);
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

/* --- Page layout (phone first: map on top, journal below) --- */
.layout {
  display: block;
}

.map-frame {
  height: clamp(260px, 48svh, 560px);
  margin-bottom: 1.25rem;
  border: 1px solid var(--hairline);
  background: var(--paper-deep);
}

#map {
  width: 100%;
  height: 100%;
  /* Same grey as the filtered tiles, so tile edges never show during zoom animations. */
  background: #ececea;
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-tabs {
  display: flex;
  gap: 1.5rem;
  font-family: var(--display);
  font-size: var(--fs-data);
  border-bottom: 1px solid var(--hairline);
}

.sidebar-tabs button {
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: none;
  padding: 0;
  color: var(--graphite);
  cursor: pointer;
}

.sidebar-tabs button[aria-selected='true'] {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--cobalt);
}

.day-list,
.numbers {
  padding-bottom: 3rem;
}

/* --- Map styling: a grey print with one cobalt line --- */
.tiles-muted {
  filter: grayscale(1) contrast(0.86) brightness(1.07);
}

/* Overlap tiles by 1px: when Leaflet shows tiles scaled (e.g. half size on a zoomed-out phone map),
   sub-pixel gaps between them would otherwise show as hairlines on 2x/3x screens. */
.tiles-muted img.leaflet-tile {
  width: 257px !important;
  height: 257px !important;
}

.leaflet-container {
  font-family: var(--display);
  font-size: var(--fs-label);
}

.leaflet-control-zoom a,
.leaflet-control-layers {
  border-radius: 0 !important;
  border-color: var(--hairline) !important;
  color: var(--ink) !important;
}

.leaflet-bar {
  border: 1px solid var(--hairline) !important;
  box-shadow: none !important;
}

.leaflet-control-layers {
  box-shadow: none !important;
  border: 1px solid var(--hairline) !important;
  background: var(--paper) !important;
}

.leaflet-control-layers label {
  min-height: 32px;
  display: flex;
  align-items: center;
}

.leaflet-control-attribution {
  background: rgb(244 245 242 / 0.85) !important;
  font-size: 0.6875rem;
}

.route-hit {
  cursor: pointer;
}

.route-tip {
  font-family: var(--display);
  font-size: var(--fs-label);
  border-radius: 0;
  border: 1px solid var(--hairline);
  box-shadow: none;
}

.pin {
  display: block;
  width: 10px;
  height: 10px;
  margin: 2px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  background: var(--graphite);
  box-shadow: 0 0 0 1px rgb(28 34 32 / 0.25);
}

.pin--camp,
.pin--stay,
.pin--host {
  background: var(--ink);
}

.pin--bike_shop,
.pin--sight {
  background: var(--cobalt);
}

.pin--loved {
  box-shadow: 0 0 0 2px var(--cobalt);
}

.pin--legend {
  display: inline-block;
  vertical-align: -1px;
  margin: 0 0.4rem 0 0.2rem;
}

.leaflet-popup-content-wrapper {
  border-radius: 0;
  box-shadow: 0 6px 24px rgb(28 34 32 / 0.12);
}

.leaflet-popup-content {
  font-size: var(--fs-data);
  line-height: 1.4;
}

.popup__type {
  font-size: var(--fs-label);
  color: var(--graphite);
}

.popup__name {
  font-family: var(--display);
  font-variation-settings: 'wdth' 85;
  font-weight: 650;
  font-size: 1.0625rem;
  margin: 2px 0;
}

.popup__comment {
  margin: 6px 0;
  font-family: var(--text);
  font-size: 1rem;
  line-height: 1.45;
}

.popup__cost {
  font-size: var(--fs-label);
}

.stars {
  color: var(--cobalt);
  letter-spacing: 1px;
  font-size: var(--fs-label);
  white-space: nowrap;
}

/* --- Journal: one entry per day, numbered because it is a sequence --- */
.day {
  border-bottom: 1px solid var(--hairline);
}

.day__header {
  width: 100%;
  display: grid;
  grid-template-columns: 3.25rem 1fr;
  align-items: baseline;
  gap: 0.5rem;
  padding: 1rem 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.day__number {
  font-family: var(--display);
  font-variation-settings: 'wdth' 62;
  font-weight: 800;
  font-size: 2.5rem;
  line-height: 0.8;
  color: var(--numeral);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

.day.is-open .day__number {
  color: var(--cobalt);
}

@media (hover: hover) {
  .day__header:hover .day__number {
    color: var(--cobalt);
  }
}

.day__heading {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.day__date {
  font-family: var(--display);
  font-size: var(--fs-label);
  color: var(--graphite);
}

.day__title {
  font-family: var(--display);
  font-variation-settings: 'wdth' 88;
  font-weight: 620;
  font-size: var(--fs-title);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.day__highlight {
  font-style: italic;
  font-size: 1rem;
  color: var(--graphite);
}

.day__body {
  display: none;
  padding: 0.25rem 0 2.5rem;
}

.day.is-open .day__body {
  display: block;
}

.day__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin: 1rem 0 1.25rem;
  font-family: var(--display);
  font-size: var(--fs-data);
  font-variant-numeric: tabular-nums;
}

.day__story p {
  margin: 0 0 1em;
  font-size: var(--fs-body);
  line-height: 1.7;
  max-width: 64ch;
  white-space: pre-line;
  overflow-wrap: break-word;
}

.day__weather {
  margin: 0 0 1rem;
  font-style: italic;
  font-size: 1rem;
  color: var(--graphite);
}

.day__more summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  font-family: var(--display);
  font-size: var(--fs-data);
  color: var(--cobalt);
  cursor: pointer;
  list-style: none;
}

.day__more summary::-webkit-details-marker {
  display: none;
}

.day__more summary::after {
  content: '+';
  margin-left: 0.4em;
}

.day__more[open] summary::after {
  content: '–';
}

.day-spend,
.day-extras {
  margin: 0.75rem 0 0;
  font-family: var(--display);
  font-size: var(--fs-label);
  line-height: 1.5;
  color: var(--graphite);
}

.place-list {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
}

.place-list li + li {
  border-top: 1px solid var(--hairline);
}

.place-link {
  width: 100%;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.25rem 0;
  border: 0;
  background: none;
  font-family: var(--display);
  font-size: var(--fs-data);
  text-align: left;
  cursor: pointer;
}

@media (hover: hover) {
  .place-link:hover span:first-child {
    color: var(--cobalt);
  }
}

.place-list__comment {
  margin: -0.25rem 0 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--graphite);
}

/* --- Slideshow: photographs at their own proportions, crossfading every 8 s --- */
.slideshow__frame {
  position: relative;
  aspect-ratio: var(--ratio, 0.8);
  /* Never taller than the screen: shrink the width instead, keeping the photo's shape. */
  width: min(100%, calc(78svh * var(--ratio, 0.8)));
  margin-inline: auto;
  background: var(--paper-deep);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.slide {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  transition: opacity 1.2s ease;
}

.slide.is-active {
  opacity: 1;
}

.slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  -webkit-user-drag: none;
}

.slide figcaption {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 0.4rem 0.6rem;
  background: rgb(244 245 242 / 0.9);
  font-size: 1rem;
  font-style: italic;
}

.slideshow--empty {
  aspect-ratio: 3 / 2;
  background: var(--paper-deep);
}

.slideshow--empty img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  mix-blend-mode: multiply;
}

.slideshow__arrow {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(244 245 242 / 0.88);
  box-shadow: 0 1px 4px rgb(28 34 32 / 0.18);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s;
}

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

.slideshow__arrow--prev {
  left: 10px;
}

.slideshow__arrow--next {
  right: 10px;
}

@media (hover: hover) {
  .slideshow__arrow:hover {
    background: var(--paper);
    color: var(--cobalt);
  }
}

.slideshow__count {
  margin: 0.5rem 0 0;
  text-align: right;
  font-family: var(--display);
  font-size: var(--fs-label);
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

/* Chinese stories: a touch more line height and no italic (CJK fonts have none). */
.day__story:lang(zh-Hant) p {
  line-height: 1.85;
  letter-spacing: 0.02em;
  line-break: strict;
}

/* --- Instagram vlog: first slide of the carousel --- */
.reel-slide {
  position: absolute;
  inset: 0;
  display: block;
  color: var(--ink);
  text-decoration: none;
  -webkit-user-drag: none;
}

.reel-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* 9:16 cover inside the photos' frame: never cropped */
  display: block;
}

/* "Instagram ↗": where the slide goes, in the corner — not a play button, which would promise playback here. */
.reel-chip {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem 0.45rem 0.55rem;
  border-radius: 999px;
  background: rgb(28 34 32 / 0.72);
  color: #fff;
  font-family: var(--display);
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: background 0.15s;
}

.reel-chip svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reel-chip__logo {
  width: 1.15rem;
  height: 1.15rem;
}

.reel-chip__dot {
  fill: currentColor;
  stroke: none;
}

.reel-chip__arrow {
  width: 0.85rem;
  height: 0.85rem;
  opacity: 0.85;
}

@media (hover: hover) {
  .reel-slide:hover .reel-chip {
    background: rgb(28 34 32 / 0.9);
  }
}

/* --- The numbers --- */
.numbers {
  padding-top: 1.25rem;
}

.numbers-section {
  margin-bottom: 2.5rem;
}

.numbers-section h2 {
  margin: 0 0 1rem;
  font-family: var(--display);
  font-variation-settings: 'wdth' 88;
  font-weight: 620;
  font-size: var(--fs-title);
}

.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem 1rem;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi__value {
  font-family: var(--display);
  font-variation-settings: 'wdth' 62;
  font-weight: 760;
  font-size: clamp(2rem, 1.6rem + 1.2vw, 2.5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi__label {
  font-family: var(--display);
  font-size: var(--fs-label);
  color: var(--graphite);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(8rem, 10rem) 1fr auto;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
  font-family: var(--display);
  font-size: var(--fs-label);
}

.bar-row__track {
  height: 6px;
  background: var(--paper-deep);
}

.bar-row__fill {
  display: block;
  height: 100%;
  background: var(--ink);
}

.bar-row__value {
  min-width: 3.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.numbers-note {
  margin: 0.75rem 0 0;
  font-style: italic;
  font-size: 1rem;
  color: var(--graphite);
}

.chart {
  width: 100%;
  height: auto;
}

.chart-area { fill: var(--cobalt-wash); }
.chart-line { fill: none; stroke: var(--cobalt); stroke-width: 1.6; }
.chart-tick { stroke: var(--hairline); stroke-dasharray: 2 3; }
/* SVG units: the 340-wide chart renders 340–430px wide, so 13 units ≥ 13–16px on screen. */
.chart-label { font-size: 13px; fill: var(--graphite); text-anchor: middle; font-family: var(--display); }
.chart-end { font-size: 14px; fill: var(--ink); text-anchor: end; font-weight: 600; font-family: var(--display); }

.prep-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--display);
  font-size: var(--fs-data);
}

.prep-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--hairline);
}

/* --- Touch screens and phone/tablet widths: larger map controls --- */
@media (pointer: coarse), (max-width: 1099px) {
  .leaflet-bar a,
  .leaflet-touch .leaflet-bar a {
    width: var(--tap);
    height: var(--tap);
    line-height: var(--tap);
  }

  .leaflet-control-layers-toggle,
  .leaflet-touch .leaflet-control-layers-toggle {
    width: var(--tap);
    height: var(--tap);
  }
}

/* --- Tablets: still stacked, with a centred reading column --- */
@media (min-width: 700px) {
  :root {
    --margin: 32px;
  }

  .masthead {
    padding: 1.75rem 0 1.25rem;
  }

  .masthead__title {
    width: auto;
    margin-right: 1rem;
  }

  .unit-toggle {
    margin-left: auto;
  }

  .map-frame {
    height: clamp(320px, 50svh, 620px);
    margin-bottom: 2rem;
  }

  .sidebar {
    max-width: 680px;
    margin-inline: auto;
  }
}

/* --- Desktop: map 50% | journal 40% --- */
@media (min-width: 1100px) {
  :root {
    --margin: 3vw;
    --gap: 4vw;
    --mast: 96px;
  }

  .masthead {
    height: var(--mast);
    flex-wrap: nowrap;
    padding: 0;
    gap: 2.5rem;
  }

  .masthead__title {
    white-space: nowrap;
    margin-right: 0;
  }

  .layout {
    display: grid;
    grid-template-columns: 50fr 40fr;
    column-gap: var(--gap);
    height: calc(100vh - var(--mast) - var(--margin));
    height: calc(100dvh - var(--mast) - var(--margin));
  }

  .map-frame {
    height: auto;
    min-height: 0;
    margin-bottom: 0;
  }

  .sidebar {
    max-width: none;
    margin-inline: 0;
  }

  .day-list,
  .numbers {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--hairline) transparent;
    padding-right: 0.75rem;
  }

  .slideshow__frame {
    /* In the side column, also leave room for the day's heading above the photo. */
    width: min(100%, calc((100dvh - var(--mast) - 12rem) * var(--ratio, 0.8)));
  }
}

/* Short desktop windows (e.g. 1280 × 720 laptops): slimmer masthead. */
@media (min-width: 1100px) and (max-height: 760px) {
  :root {
    --mast: 80px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slide,
  .day__number,
  .slideshow__arrow {
    transition: none;
  }
}
