:root {
  --paper: #f3eee3;
  --paper-deep: #e8dfce;
  --ink: #17201d;
  --ink-soft: #53605b;
  --line: rgba(23, 32, 29, 0.14);
  --accent: #d95336;
  --accent-dark: #a43a25;
  --teal: #266b61;
  --gold: #d8a134;
  --white: #fffdf8;
  --shadow: 0 18px 55px rgba(31, 37, 33, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family:
    "Noto Sans CJK SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei",
    sans-serif;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(350px, 420px) 1fr;
  width: 100%;
  height: 100%;
}

.sidebar {
  position: relative;
  z-index: 500;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background:
    radial-gradient(circle at 12% 4%, rgba(216, 161, 52, 0.16), transparent 25%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.55), transparent 45%),
    var(--paper);
  box-shadow: 16px 0 40px rgba(26, 31, 28, 0.08);
}

.sidebar::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(23, 32, 29, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 29, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  content: "";
}

.hero {
  padding: 34px 32px 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-family: "Courier New", monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: clamp(42px, 4vw, 62px);
  font-weight: 800;
  letter-spacing: -0.07em;
  line-height: 0.96;
}

.subtitle {
  margin: 10px 0 14px;
  color: var(--teal);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.13em;
}

.intro {
  max-width: 32em;
  margin: 0;
  color: var(--ink-soft);
  font-family: "Songti SC", "STSong", serif;
  font-size: 14px;
  line-height: 1.7;
}

.route-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.stat {
  padding: 18px 16px;
  text-align: center;
}

.stat + .stat {
  border-left: 1px solid var(--line);
}

.stat strong {
  display: block;
  font-family: "DIN Alternate", "Arial Narrow", sans-serif;
  font-size: 25px;
  letter-spacing: -0.04em;
}

.stat span {
  display: block;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}

.controls {
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.control-heading,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.control-heading > span,
.section-title h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.control-heading button {
  padding: 0;
  border: 0;
  color: var(--accent-dark);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.segment-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px;
  margin-top: 12px;
}

.segment-button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.52);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  transition:
    color 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.segment-button:hover {
  border-color: rgba(38, 107, 97, 0.5);
}

.segment-button[aria-pressed="true"] {
  border-color: var(--teal);
  color: var(--white);
  background: var(--teal);
}

.filter-heading {
  margin-top: 16px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.filter-button {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  font-size: 11px;
  transition:
    color 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.filter-button:hover {
  transform: translateY(-1px);
}

.filter-button[aria-pressed="true"] {
  border-color: var(--ink);
  color: var(--white);
  background: var(--ink);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 12px;
}

.layer-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.place-section {
  min-height: 0;
  padding: 18px 16px 0 24px;
  overflow: hidden;
}

.section-title {
  padding-right: 8px;
}

.section-title span {
  color: var(--ink-soft);
  font-size: 11px;
}

.place-list {
  height: calc(100% - 30px);
  padding: 12px 8px 34px 0;
  overflow-y: auto;
  scrollbar-color: rgba(38, 107, 97, 0.35) transparent;
}

.place-group {
  margin-bottom: 20px;
}

.place-group h3 {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 0 7px;
  padding: 6px 0;
  color: var(--teal);
  background: linear-gradient(var(--paper) 75%, transparent);
  font-size: 11px;
  letter-spacing: 0.12em;
}

.place-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-top: 1px solid var(--line);
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.place-item:hover,
.place-item:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.62);
  transform: translateX(3px);
}

.place-index {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(217, 83, 54, 0.35);
  border-radius: 50%;
  color: var(--accent-dark);
  background: rgba(217, 83, 54, 0.08);
  font-family: "Courier New", monospace;
  font-size: 10px;
  font-weight: 700;
}

.place-copy strong {
  display: block;
  overflow: hidden;
  font-family: "Songti SC", "STSong", serif;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-copy span {
  display: block;
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 11px;
}

.priority {
  align-self: center;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
}

.sidebar-footer {
  padding: 13px 24px 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  background: rgba(243, 238, 227, 0.96);
  font-size: 10px;
  line-height: 1.5;
}

.sidebar-footer p {
  margin: 0;
}

.sidebar-footer p + p {
  margin-top: 4px;
}

.map-stage {
  position: relative;
  min-width: 0;
  background: #d9ddd3;
}

#map {
  width: 100%;
  height: 100%;
  background: #d9ddd3;
}

.leaflet-container {
  background-color: #dce2d8;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(38, 107, 97, 0.08), transparent 18%),
    radial-gradient(circle at 78% 62%, rgba(216, 161, 52, 0.08), transparent 20%),
    repeating-radial-gradient(
      ellipse at 50% 50%,
      transparent 0 19px,
      rgba(23, 32, 29, 0.035) 20px 21px
    );
}

.map-title {
  position: absolute;
  top: 24px;
  left: 28px;
  z-index: 450;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 13px 16px;
  border-left: 4px solid var(--accent);
  color: var(--ink);
  background: rgba(255, 253, 248, 0.93);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.map-title span {
  color: var(--ink-soft);
  font-family: "Courier New", monospace;
  font-size: 9px;
  letter-spacing: 0.16em;
}

.map-title strong {
  margin-top: 2px;
  font-family: "Songti SC", "STSong", serif;
  font-size: 20px;
}

.map-legend {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 450;
  display: flex;
  gap: 14px;
  padding: 10px 13px;
  border: 1px solid rgba(23, 32, 29, 0.1);
  border-radius: 4px;
  color: var(--ink-soft);
  background: rgba(255, 253, 248, 0.93);
  box-shadow: var(--shadow);
  font-size: 10px;
  backdrop-filter: blur(8px);
}

.map-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.map-legend i {
  display: inline-block;
  width: 20px;
  height: 3px;
}

.legend-route {
  background: var(--accent);
}

.legend-section {
  background: #286b81;
}

.legend-road {
  border-top: 2px dashed var(--ink-soft);
}

.legend-place {
  width: 9px !important;
  height: 9px !important;
  border-radius: 50%;
  background: var(--teal);
}

.loading-card {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 600;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
  font-size: 12px;
  transform: translate(-50%, -50%);
}

.loading-card.is-error {
  color: #8f2b1a;
}

.tile-warning {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 450;
  max-width: 280px;
  padding: 9px 12px;
  border: 1px solid rgba(217, 83, 54, 0.24);
  color: var(--accent-dark);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  font-size: 10px;
  line-height: 1.5;
}

.place-marker {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--white);
  border-radius: 50% 50% 50% 6px;
  color: var(--white);
  background: var(--teal);
  box-shadow: 0 4px 12px rgba(23, 32, 29, 0.28);
  font-family: "Courier New", monospace;
  font-size: 9px;
  font-weight: 800;
  transform: rotate(-45deg);
}

.place-marker span {
  transform: rotate(45deg);
}

.place-marker[data-priority="核心"] {
  color: var(--white);
  background: var(--accent);
}

.place-marker[data-priority="季节"],
.place-marker[data-priority="深度"] {
  color: var(--ink);
  background: var(--gold);
}

.place-marker[data-segment="taoping-dujiangyan"] {
  color: var(--white);
  background: #286b81;
}

.place-marker[data-segment-role="绕行支线"] {
  color: var(--ink);
  background: var(--gold);
}

.place-marker[data-segment-endpoint="start"],
.place-marker[data-segment-endpoint="end"] {
  color: var(--white);
  background: var(--accent);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  color: var(--ink);
  background: var(--white);
}

.leaflet-popup-content-wrapper {
  border-radius: 3px;
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  width: min(330px, 72vw) !important;
  margin: 16px 18px;
}

.popup-kicker {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-family: "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.popup-title {
  margin: 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: 20px;
  line-height: 1.25;
}

.popup-meta {
  margin: 8px 0;
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
}

.popup-section {
  margin: 0 0 8px;
  padding: 6px 8px;
  border-left: 3px solid #286b81;
  color: #205c70;
  background: rgba(40, 107, 129, 0.08);
  font-size: 11px;
  font-weight: 700;
}

.popup-description,
.popup-tip {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.popup-tip {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.popup-links {
  display: flex;
  gap: 12px;
  margin-top: 11px;
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 58vh) auto;
    height: auto;
    min-height: 100%;
  }

  .map-stage {
    grid-row: 1;
    min-height: 58vh;
  }

  .sidebar {
    grid-row: 2;
    max-height: none;
    overflow: visible;
    border-top: 1px solid var(--line);
    border-right: 0;
    box-shadow: 0 -16px 40px rgba(26, 31, 28, 0.08);
  }

  .hero {
    padding: 26px 22px 18px;
  }

  h1 {
    font-size: 46px;
  }

  .place-section {
    overflow: visible;
  }

  .place-list {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .map-title {
    top: 14px;
    left: 14px;
  }

  .map-legend {
    right: 12px;
    bottom: 14px;
  }

  .tile-warning {
    top: auto;
    right: 14px;
    bottom: 42px;
    max-width: 190px;
  }
}

@media (max-width: 520px) {
  .route-summary .stat {
    padding: 14px 8px;
  }

  .stat strong {
    font-size: 21px;
  }

  .controls {
    padding-inline: 18px;
  }

  .place-section {
    padding-left: 18px;
  }

  .map-legend {
    display: none;
  }
}
