:root {
  --paper: #f7f4ec;
  --surface: #fffdf8;
  --line: #dfd8cb;
  --ink: #142119;
  --muted: #5c675e;
  --sage: #38562d;
  --sage-2: #587549;
  --rust: #b55232;
  --river: #28708f;
  --gold: #bd8b35;
  --shadow: 0 14px 34px rgba(42, 36, 25, .12);
  --radius: 8px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(56, 86, 45, .035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(56, 86, 45, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

button, input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 18px calc(82px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, .76);
  box-shadow: 0 0 0 1px rgba(223, 216, 203, .7);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 10px 0;
  background: rgba(255, 253, 248, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 5vw, 2rem);
  font-weight: 700;
  line-height: 1;
}

.brand span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
}

.brand-mark svg {
  width: 40px;
  height: 40px;
  fill: var(--sage);
  stroke: var(--surface);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(42, 36, 25, .06);
  cursor: pointer;
}

.icon-button svg,
.tab svg,
.search-box svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.search-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .22s ease;
}

.search-panel.is-open {
  grid-template-rows: 1fr;
}

.search-box {
  display: flex;
  min-height: 0;
  overflow: hidden;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  border-bottom: 1px solid transparent;
}

.search-panel.is-open .search-box {
  padding: 12px 0;
  border-color: var(--line);
}

.search-box input {
  width: 100%;
  min-width: 0;
  height: 44px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  padding: 0 12px;
}

.chips {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 18px 0 16px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  min-width: 58px;
  min-height: 42px;
  padding: 0 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.chip.is-active {
  color: white;
  background: var(--sage);
  border-color: var(--sage);
  box-shadow: 0 8px 18px rgba(56, 86, 45, .24);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(42, 36, 25, .06);
}

.stats div {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: "icon value" "icon label";
  align-items: center;
  justify-content: center;
  column-gap: 9px;
  min-height: 88px;
  padding: 10px;
}

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

.stats strong {
  grid-area: value;
  font-size: clamp(1.25rem, 5vw, 1.8rem);
  line-height: 1;
}

.stats small {
  grid-area: label;
  color: var(--ink);
  font-size: .82rem;
}

.stat-icon {
  grid-area: icon;
  width: 26px;
  height: 26px;
  background: currentColor;
  color: var(--sage-2);
  clip-path: polygon(0 8%, 30% 0, 30% 92%, 0 100%);
  box-shadow: 10px 0 0 currentColor, 20px 0 0 currentColor;
}

.stat-icon.flag {
  color: var(--rust);
  clip-path: polygon(10% 0, 80% 12%, 80% 52%, 18% 42%, 18% 100%, 10% 100%);
  box-shadow: none;
}

.stat-icon.water {
  color: var(--river);
  clip-path: none;
  box-shadow: none;
  background:
    radial-gradient(12px 7px at 7px 8px, transparent 60%, currentColor 62% 78%, transparent 80%),
    radial-gradient(12px 7px at 19px 8px, transparent 60%, currentColor 62% 78%, transparent 80%),
    radial-gradient(12px 7px at 7px 18px, transparent 60%, currentColor 62% 78%, transparent 80%),
    radial-gradient(12px 7px at 19px 18px, transparent 60%, currentColor 62% 78%, transparent 80%);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 12px;
}

.section-head h1,
.section-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.28rem, 5vw, 1.8rem);
  line-height: 1.05;
}

.section-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .88rem;
}

.view { display: none; }
.view.is-active { display: block; }

.trail-grid {
  display: grid;
  gap: 12px;
}

.trail-card {
  position: relative;
  display: grid;
  grid-template-columns: 58px 1fr 28px;
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 148px;
  padding: 16px 12px;
  text-align: left;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(42, 36, 25, .055);
  cursor: pointer;
}

.trail-card:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.icon-button:focus-visible,
.save-button:focus-visible {
  outline: 3px solid rgba(40, 112, 143, .42);
  outline-offset: 2px;
}

.trail-badge {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  color: white;
  background: var(--badge);
  border-radius: 50%;
  box-shadow: inset 0 -10px 16px rgba(20, 33, 25, .15);
}

.trail-badge svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.trail-copy {
  min-width: 0;
}

.trail-copy h3 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.18rem;
  line-height: 1.16;
}

.states,
.tag {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.35;
}

.miles {
  display: inline-block;
  margin-top: 12px;
  color: #0f5c88;
  font-size: .98rem;
  font-weight: 750;
}

.chevron {
  color: var(--muted);
  font-size: 2rem;
  line-height: 1;
}

.map-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.map-canvas {
  position: relative;
  min-height: 430px;
  overflow: hidden;
  background:
    linear-gradient(165deg, rgba(88, 117, 73, .13), transparent 52%),
    linear-gradient(20deg, rgba(40, 112, 143, .12), transparent 50%),
    #fbfaf5;
}

.map-canvas::before {
  position: absolute;
  inset: 12% 7% 17%;
  content: "";
  background: rgba(56, 86, 45, .1);
  border: 2px solid rgba(56, 86, 45, .18);
  clip-path: polygon(8% 39%, 20% 23%, 35% 20%, 48% 27%, 61% 20%, 76% 29%, 93% 30%, 88% 50%, 74% 55%, 67% 72%, 49% 68%, 34% 78%, 22% 65%, 12% 60%);
}

.route-pin {
  position: absolute;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: white;
  background: var(--badge);
  border: 3px solid var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.route-pin svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.empty {
  display: grid;
  min-height: 240px;
  place-items: center;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.3rem;
}

.tabbar {
  position: fixed;
  right: max(18px, calc((100vw - 980px) / 2 + 18px));
  bottom: 0;
  left: max(18px, calc((100vw - 980px) / 2 + 18px));
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(68px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 253, 248, .94);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -12px 32px rgba(42, 36, 25, .12);
  backdrop-filter: blur(18px);
}

.tab {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
}

.tab span {
  font-size: .76rem;
}

.tab.is-active {
  color: var(--sage);
}

.tab.is-active::after {
  position: absolute;
  bottom: env(safe-area-inset-bottom);
  width: 42px;
  height: 3px;
  content: "";
  background: var(--sage);
  border-radius: 999px 999px 0 0;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
}

.sheet.is-open {
  display: block;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 33, 25, .36);
  border: 0;
}

.sheet-panel {
  position: absolute;
  right: max(0px, calc((100vw - 980px) / 2));
  bottom: 0;
  left: max(0px, calc((100vw - 980px) / 2));
  max-height: min(84vh, 720px);
  overflow: auto;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -20px 50px rgba(20, 33, 25, .24);
}

.grabber {
  width: 42px;
  height: 5px;
  margin: 0 auto 16px;
  background: #c9c0b0;
  border-radius: 999px;
}

.sheet-title {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 14px;
  align-items: center;
}

.sheet-title h2 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 6vw, 2.1rem);
  line-height: 1.08;
}

.save-button {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  color: var(--sage);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.save-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.save-button.is-saved svg {
  fill: currentColor;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.detail-stats div,
.mini-panel {
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.detail-stats small,
.mini-panel small {
  display: block;
  color: var(--muted);
  font-size: .76rem;
}

.detail-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
}

.mini-panel {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.mini-panel strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
}

.source-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: .78rem;
}

.source-note a {
  color: var(--river);
}

.noscript-list {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

@media (min-width: 740px) {
  .app-shell {
    padding-right: 28px;
    padding-left: 28px;
  }

  .trail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trail-card {
    min-height: 170px;
    grid-template-columns: 64px 1fr 28px;
    padding: 18px;
  }

  .trail-badge {
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .brand {
    gap: 9px;
    font-size: 1.22rem;
  }

  .brand-mark,
  .brand-mark svg {
    width: 35px;
    height: 35px;
  }

  .trail-card {
    grid-template-columns: 52px 1fr 20px;
    gap: 10px;
    padding: 14px 10px;
  }

  .trail-badge {
    width: 52px;
    height: 52px;
  }

  .trail-badge svg {
    width: 29px;
    height: 29px;
  }

  .trail-copy h3 {
    font-size: 1.05rem;
  }

  .detail-stats {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
