
:root {
  --page-bg: #f2f4f1;
  --story-bg: #ffffff;
  --ink: #181b1f;
  --muted: #646b65;
  --accent: #13786f;
  --map-bg: #e8ede8;
  --map-panel: rgba(255, 255, 255, 0.94);
  --route-recorded: #e25438;
  --route-photo: #147f88;
  --timeline-bg: #171a1f;
  color: var(--ink);
  background: var(--page-bg);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--page-bg); }
button { font: inherit; letter-spacing: 0; }

.viewer-shell {
  display: grid;
  grid-template-columns: minmax(0, 64fr) minmax(340px, 36fr);
  min-height: 100dvh;
}

.story-pane {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  padding: 46px clamp(24px, 5vw, 76px) 68px;
  color: var(--ink);
  background: var(--story-bg);
}

.story-header,
.cover,
.sequence-heading,
.photo-sequence {
  width: 100%;
  max-width: 900px;
  margin-right: auto;
  margin-left: auto;
}

.story-header { margin-bottom: 28px; }
.story-kicker {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 9px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
}
.story-kicker::before {
  width: 22px;
  height: 2px;
  background: currentColor;
  content: "";
}
.story-header h1 {
  max-width: 820px;
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  overflow-wrap: anywhere;
  font-size: 52px;
  font-weight: 500;
  line-height: 1.08;
}
.story-description {
  max-width: 720px;
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
  overflow-wrap: anywhere;
  white-space: pre-line;
}
.story-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 11px;
}
.story-meta span { position: relative; }
.story-meta span + span::before {
  position: absolute;
  top: 50%;
  left: -10px;
  width: 3px;
  height: 3px;
  background: #a2aaa3;
  border-radius: 50%;
  content: "";
}

.cover {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  margin-bottom: 32px;
  padding: 0;
  overflow: hidden;
  background: var(--map-bg);
  border: 0;
  border-radius: 5px;
  box-shadow: 0 16px 44px rgba(26, 34, 29, 0.09);
  cursor: zoom-in;
}
.cover img { width: 100%; height: 100%; object-fit: cover; transition: transform 280ms ease; }
.cover-meta {
  position: absolute;
  right: 14px;
  bottom: 14px;
  left: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 13px;
  color: #ffffff;
  background: rgba(18, 21, 19, 0.76);
  border-radius: 4px;
  text-align: left;
}
.cover-meta strong { font-size: 12px; line-height: 1.45; }
.cover-meta small { flex: 0 0 auto; color: #dbe3dc; font-size: 10px; }

.sequence-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 13px;
}
.sequence-heading h2 { margin: 0; font-size: 16px; }
.sequence-heading span { color: #747c75; font-size: 10px; }
.photo-sequence {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.photo-card {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  background: var(--map-bg);
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}
.photo-card.active { border-color: var(--accent); }
.photo-card:focus-visible { outline: 2px solid #181b1f; outline-offset: 2px; }
.photo-card img { width: 100%; height: 100%; object-fit: cover; transition: transform 220ms ease; }
.photo-card-meta {
  position: absolute;
  right: 6px;
  bottom: 6px;
  left: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 5px 7px;
  color: #ffffff;
  background: rgba(18, 21, 19, 0.76);
  border-radius: 3px;
}
.photo-card-meta strong { font-size: 9px; }
.photo-card-meta small {
  overflow: hidden;
  color: #dfe5df;
  font-size: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-pane {
  position: sticky;
  top: 0;
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--map-bg);
  border-left: 1px solid #d6dbd5;
}
.route-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--map-bg);
}
.route-stage svg { position: relative; z-index: 1; width: 100%; height: 100%; }
.amap-host {
  position: absolute;
  z-index: 0;
  inset: 0;
  visibility: hidden;
}
.route-stage.amap-enabled .amap-host { visibility: visible; }
.route-stage.amap-enabled > svg { visibility: hidden; }
.amap-viewer-marker {
  display: block;
  width: 16px;
  height: 16px;
  background: #ffffff;
  border: 2px solid #171a1f;
  border-radius: 50%;
}
.amap-viewer-marker.active {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border: 3px solid #ffffff;
}
.amap-error {
  position: absolute;
  z-index: 3;
  right: 14px;
  bottom: 14px;
  padding: 7px 9px;
  color: #6f392e;
  background: rgba(255, 244, 240, 0.96);
  border: 1px solid #e4b8ad;
  border-radius: 4px;
  font-size: 9px;
}
.map-tile { opacity: 0.76; }
.route-line,
.route-casing,
.route-photo-gps,
.route-photo-gps-casing,
.route-inferred,
.route-inferred-casing {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.route-casing { stroke: #ffffff; stroke-width: 10; }
.route-line { stroke: var(--route-recorded); stroke-width: 5; }
.route-photo-gps-casing { stroke: rgba(255, 255, 255, 0.96); stroke-width: 11; }
.route-photo-gps { stroke: var(--route-photo); stroke-width: 6; }
.photo-gps-node {
  fill: #ffffff;
  stroke: var(--route-photo);
  stroke-width: 2;
}
.route-inferred-casing { stroke: rgba(255, 255, 255, 0.92); stroke-width: 9; }
.route-inferred {
  stroke: #287f89;
  stroke-width: 4;
  stroke-dasharray: 10 11;
}
.route-point {
  fill: #ffffff;
  stroke: #181b1f;
  stroke-width: 3;
  cursor: pointer;
}
.route-point.active { fill: var(--accent); stroke: #ffffff; stroke-width: 4; }
.route-point:focus { outline: none; stroke: #e25438; stroke-width: 5; }
.route-end-label {
  fill: #48514a;
  stroke: rgba(255, 255, 255, 0.94);
  stroke-width: 5px;
  paint-order: stroke;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 24px;
  font-weight: 750;
}
.route-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: #707871;
  text-align: center;
  font-size: 12px;
}
.map-legend {
  position: absolute;
  z-index: 2;
  top: 16px;
  left: 16px;
  padding: 8px 10px;
  color: #343a35;
  background: var(--map-panel);
  border: 1px solid #d1d7d1;
  border-radius: 4px;
  font-size: 9px;
}
.map-legend,
.legend-row { display: grid; }
.map-legend { gap: 6px; }
.legend-row {
  grid-template-columns: 22px auto;
  align-items: center;
  gap: 6px;
}
.map-legend i {
  display: inline-block;
  width: 22px;
  height: 3px;
  margin-right: 0;
  background: var(--route-recorded);
  vertical-align: middle;
}
.map-legend i.photo-gps { background: var(--route-photo); }
.map-legend i.recorded { background: var(--route-recorded); }
.map-legend i.inferred {
  height: 0;
  background: transparent;
  border-top: 3px dashed #287f89;
}
.map-summary {
  position: absolute;
  z-index: 2;
  top: 16px;
  right: 16px;
  padding: 8px 10px;
  color: #343a35;
  background: var(--map-panel);
  border: 1px solid #d1d7d1;
  border-radius: 4px;
  text-align: right;
}
.map-summary strong,
.map-summary span { display: block; }
.map-summary strong { font-size: 15px; }
.map-summary span { margin-top: 2px; color: #6c746d; font-size: 8px; }
.map-attribution {
  position: absolute;
  z-index: 2;
  right: 8px;
  bottom: 7px;
  color: #6e756f;
  background: rgba(255, 255, 255, 0.82);
  font-size: 8px;
}

.viewer-timeline { padding: 15px 16px 16px; background: var(--timeline-bg); color: #ffffff; }
.timeline-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 11px;
}
.timeline-heading strong { font-size: 11px; }
.timeline-heading span { color: #aeb6af; font-size: 9px; }
.timeline-controls {
  display: grid;
  grid-template-columns: 34px 34px 34px minmax(120px, 1fr) 104px;
  align-items: center;
  gap: 7px;
}
.timeline-controls button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #ffffff;
  background: #2c312d;
  border: 1px solid #454c46;
  border-radius: 4px;
  cursor: pointer;
}
.timeline-controls button:disabled { opacity: 0.35; cursor: not-allowed; }
.timeline-progress { display: flex; align-items: center; height: 34px; }
.timeline-progress input {
  width: 100%;
  height: 18px;
  margin: 0;
  cursor: pointer;
  appearance: none;
  background: transparent;
}
.timeline-progress input:disabled { cursor: default; }
.timeline-progress input::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(to right, #6bc0b5 0 var(--progress, 0%), #59615a var(--progress, 0%) 100%);
  border-radius: 2px;
}
.timeline-progress input::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  appearance: none;
  background: #ffffff;
  border: 3px solid #17877c;
  border-radius: 50%;
}
.timeline-progress input::-moz-range-track { height: 4px; background: #59615a; border-radius: 2px; }
.timeline-progress input::-moz-range-progress { height: 4px; background: #6bc0b5; border-radius: 2px; }
.timeline-progress input::-moz-range-thumb { width: 10px; height: 10px; background: #ffffff; border: 3px solid #17877c; border-radius: 50%; }
.timeline-current {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.timeline-current img { width: 32px; height: 32px; object-fit: cover; border-radius: 3px; }
.timeline-current span { min-width: 0; }
.timeline-current strong,
.timeline-current small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-current strong { font-size: 9px; }
.timeline-current small { margin-top: 3px; color: #aeb6af; font-size: 7px; }

.viewer-dialog {
  width: min(1040px, 94vw);
  max-width: none;
  padding: 0;
  overflow: hidden;
  background: #111411;
  border: 0;
  border-radius: 5px;
}
.viewer-dialog::backdrop { background: rgba(0, 0, 0, 0.82); }
.dialog-media { display: grid; min-height: 70dvh; place-items: center; }
.dialog-media img { display: block; max-width: 100%; max-height: 86dvh; }
.dialog-close,
.dialog-previous,
.dialog-next {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  cursor: pointer;
}
.dialog-close { top: 10px; right: 10px; font-size: 20px; }
.dialog-previous,
.dialog-next { top: 50%; transform: translateY(-50%); font-size: 24px; }
.dialog-previous { left: 10px; }
.dialog-next { right: 10px; }
.dialog-previous:disabled,
.dialog-next:disabled { opacity: 0.3; cursor: not-allowed; }

.error-state {
  display: grid;
  min-height: 100dvh;
  padding: 24px;
  place-content: center;
  text-align: center;
}
.error-state strong { font-size: 18px; }
.error-state span {
  max-width: 480px;
  margin-top: 8px;
  color: #6a716b;
  font-size: 13px;
  line-height: 1.6;
}

:root[data-theme="nocturne"] {
  --page-bg: #10120f;
  --story-bg: #181b17;
  --ink: #f2f0e8;
  --muted: #a6aaa2;
  --accent: #efb45d;
  --map-bg: #242a25;
  --map-panel: rgba(20, 23, 20, 0.92);
  --route-recorded: #f07752;
  --route-photo: #63c2b8;
  --timeline-bg: #090b09;
  color-scheme: dark;
}

:root[data-theme="nocturne"] .story-header h1 {
  color: #f7f3e8;
}

:root[data-theme="nocturne"] .cover,
:root[data-theme="nocturne"] .photo-card {
  border-color: #343a34;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

:root[data-theme="nocturne"] .cover-meta,
:root[data-theme="nocturne"] .photo-card-meta {
  background: rgba(7, 9, 7, 0.82);
}

:root[data-theme="nocturne"] .photo-sequence {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

:root[data-theme="nocturne"] .photo-card:nth-child(3n + 1) {
  grid-column: span 2;
  aspect-ratio: 16 / 9;
}

:root[data-theme="nocturne"] .sequence-heading span,
:root[data-theme="nocturne"] .route-empty,
:root[data-theme="nocturne"] .map-attribution,
:root[data-theme="nocturne"] .map-summary span {
  color: #a6aaa2;
}

:root[data-theme="nocturne"] .map-pane {
  border-color: #323832;
}

:root[data-theme="nocturne"] .map-tile {
  opacity: 0.45;
  filter: grayscale(0.8) brightness(0.68) contrast(1.18);
}

:root[data-theme="nocturne"] .map-legend,
:root[data-theme="nocturne"] .map-summary {
  color: #ebece5;
  border-color: #424942;
}

:root[data-theme="nocturne"] .route-end-label {
  fill: #eff0e8;
  stroke: rgba(25, 28, 25, 0.95);
}

:root[data-theme="nocturne"] .map-attribution {
  background: rgba(20, 23, 20, 0.82);
}

:root[data-theme="postcard"] {
  --page-bg: #e9f0ed;
  --story-bg: #ffffff;
  --ink: #19201e;
  --muted: #596762;
  --accent: #e63f3b;
  --map-bg: #cfe5e0;
  --map-panel: rgba(255, 255, 255, 0.94);
  --route-recorded: #e63f3b;
  --route-photo: #087d76;
  --timeline-bg: #14201e;
}

:root[data-theme="postcard"] .story-pane {
  border-top: 6px solid #e63f3b;
}

:root[data-theme="postcard"] .story-header h1 {
  font-family: "Arial Black", "Microsoft YaHei", sans-serif;
  font-size: 50px;
  font-weight: 800;
  line-height: 1.12;
}

:root[data-theme="postcard"] .story-kicker::before {
  width: 8px;
  height: 8px;
  background: #f1bd35;
}

:root[data-theme="postcard"] .cover {
  aspect-ratio: 3 / 2;
  border: 7px solid #ffffff;
  border-radius: 0;
  outline: 1px solid #d9dedb;
  box-shadow: 8px 10px 0 #f1bd35;
}

:root[data-theme="postcard"] .photo-sequence {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

:root[data-theme="postcard"] .photo-card {
  border: 0;
  border-radius: 0;
  box-shadow: 4px 5px 0 #b9deda;
}

:root[data-theme="postcard"] .photo-card:nth-child(5n + 1) {
  grid-column: span 2;
  aspect-ratio: 16 / 9;
}

:root[data-theme="postcard"] .photo-card.active {
  outline: 3px solid #e63f3b;
  outline-offset: 2px;
}

:root[data-theme="postcard"] .map-tile {
  opacity: 0.58;
  filter: saturate(0.75) contrast(0.9);
}

@media (hover: hover) {
  .cover:hover img,
  .photo-card:hover img {
    transform: scale(1.025);
  }
}

@media (max-width: 1080px) {
  .photo-sequence { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .viewer-shell { display: block; }
  .story-pane { padding: 27px 16px 48px; }
  .story-header { margin-bottom: 20px; }
  .story-header h1 { font-size: 34px; }
  .cover { margin-bottom: 25px; }
  .cover-meta { right: 8px; bottom: 8px; left: 8px; padding: 8px 9px; }
  .sequence-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .photo-sequence { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .map-pane {
    position: sticky;
    z-index: 3;
    top: 0;
    display: block;
    width: 100%;
    min-height: 230px;
    height: 34dvh;
    border-right: 0;
    border-bottom: 1px solid #d5dad4;
    border-left: 0;
  }
  .route-stage { height: 100%; }
  .map-legend { top: 9px; left: 9px; }
  .map-summary { top: 9px; right: 9px; }
  .map-attribution { right: 10px; bottom: 74px; }
  .viewer-timeline {
    position: absolute;
    right: 8px;
    bottom: 8px;
    left: 8px;
    padding: 9px;
    border-radius: 4px;
  }
  .timeline-heading { display: none; }
  .timeline-controls { grid-template-columns: 30px 30px 30px minmax(70px, 1fr) 48px; gap: 5px; }
  .timeline-controls button { width: 30px; height: 30px; }
  .timeline-current { display: block; text-align: right; }
  .timeline-current img,
  .timeline-current small { display: none; }
  .dialog-previous { left: 6px; }
  .dialog-next { right: 6px; }
}

@media (max-width: 390px) {
  .photo-sequence { grid-template-columns: 1fr; }
  :root[data-theme="nocturne"] .photo-sequence,
  :root[data-theme="postcard"] .photo-sequence { grid-template-columns: 1fr; }
  :root[data-theme="nocturne"] .photo-card:nth-child(3n + 1),
  :root[data-theme="postcard"] .photo-card:nth-child(5n + 1) { grid-column: span 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
