:root {
  --bark: #4b3b2a;
  --soil: #36291d;
  --moss: #3d5a3e;
  --lichen: #7a9e7e;
  --sage: #b8cfba;
  --cream: #f8f3e8;
  --amber: #d4892a;
  --ember: #e85d2f;
  --line: rgba(255, 255, 255, 0.18);
  --line-soft: rgba(255, 255, 255, 0.12);
  --ink-soft: rgba(244, 239, 227, 0.76);
  --ink-muted: rgba(244, 239, 227, 0.5);
  --origin: #56a6ff;
  --access: #cf4259;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Lora", Georgia, serif;
  color: var(--cream);
  background:
    radial-gradient(circle at 8% 5%, rgba(212, 137, 42, 0.1) 0%, rgba(212, 137, 42, 0) 32%),
    linear-gradient(180deg, #62503b 0%, #52412f 56%, #453626 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.32;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.07'/%3E%3C/svg%3E");
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 16px 24px;
}

.masthead {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 22px 24px 20px;
  background:
    radial-gradient(circle at 88% 12%, rgba(122, 158, 126, 0.2) 0%, rgba(122, 158, 126, 0) 38%),
    linear-gradient(132deg, rgba(76, 57, 37, 0.95) 0%, rgba(63, 47, 31, 0.95) 55%, rgba(58, 42, 28, 0.96) 100%);
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.35);
}

.masthead-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  font-family: "DM Mono", monospace;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--lichen);
}

.masthead h1 {
  margin: 0;
  font-family: "Playfair Display", serif;
  font-size: clamp(2.1rem, 4.6vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 0.92;
  color: var(--cream);
}

.masthead-graphic {
  width: min(220px, 34vw);
  min-width: 130px;
  flex: 0 0 auto;
}

.masthead-graphic svg {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.masthead p {
  margin: 12px 0 0;
  max-width: 780px;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.search-panel {
  --header-offset: 180px;
  --score-panel-width: 150px;
  margin-top: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(72, 54, 35, 0.92), rgba(62, 46, 31, 0.95));
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
}

.search-form {
  margin-right: calc(var(--score-panel-width) + 12px);
}

.search-form label {
  display: inline-block;
  margin: 0 0 8px;
  font-family: "DM Mono", monospace;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--lichen);
}

.search-row {
  display: flex;
  gap: 10px;
}

.control-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: var(--header-offset) minmax(0, 360px) auto;
  gap: 12px 14px;
  align-items: center;
}

.count-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: var(--header-offset) 1fr;
  gap: 12px;
  align-items: center;
}

.result-count-toggle {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(0, 70px));
  gap: 7px;
  justify-content: start;
}

.result-count-btn {
  font-family: "DM Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-soft);
  padding: 6px 8px;
}

.result-count-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.result-count-btn.is-active {
  border-color: rgba(212, 137, 42, 0.7);
  background: rgba(212, 137, 42, 0.2);
  color: var(--cream);
}

.score-row {
  margin-top: 0;
  display: flex;
  position: absolute;
  right: 14px;
  top: 14px;
  bottom: 14px;
  width: var(--score-panel-width);
}

.trail-score-card {
  width: 100%;
  height: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.trail-score-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.trail-score-label {
  font-family: "DM Mono", monospace;
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.info-dot {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "DM Mono", monospace;
  font-size: 0.64rem;
  border: 1px solid rgba(255, 255, 255, 0.38);
  color: var(--cream);
  cursor: help;
}

.info-tooltip {
  position: absolute;
  right: 0;
  top: 20px;
  min-width: 220px;
  max-width: 250px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(25, 18, 11, 0.96);
  color: var(--cream);
  font-family: "DM Mono", monospace;
  font-size: 0.62rem;
  line-height: 1.45;
  letter-spacing: 0.03em;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 200;
}

.info-dot:hover .info-tooltip,
.info-dot:focus .info-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.trail-score-gauge {
  --score-angle: 0deg;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 128px;
  max-height: 128px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(65, 49, 31, 0.96) 57%, transparent 58%),
    conic-gradient(from -90deg, var(--amber) var(--score-angle), rgba(255, 255, 255, 0.12) 0deg);
}

#trail-score-value {
  font-family: "Playfair Display", serif;
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1;
  color: var(--cream);
}

.inline-label {
  margin: 0;
  white-space: nowrap;
  font-family: "DM Mono", monospace;
  font-size: 0.67rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 11px 12px;
  font-family: "Lora", Georgia, serif;
  font-size: 0.93rem;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.09);
}

input[type="text"]::placeholder {
  color: rgba(244, 239, 227, 0.44);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--amber);
  background: rgba(255, 255, 255, 0.14);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--moss);
}

.slider-value {
  min-width: 160px;
  font-family: "DM Mono", monospace;
  font-size: 0.73rem;
  color: var(--ink-soft);
}

button {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 10px 14px;
  font-family: "Playfair Display", serif;
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--cream);
  background: var(--moss);
  cursor: pointer;
  transition: background-color 0.18s ease, transform 0.08s ease, border-color 0.18s ease;
}

button:hover {
  background: #4b6c4d;
}

button:active {
  transform: scale(0.985);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.progress-wrap {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: calc(var(--score-panel-width) + 12px);
}

.progress-track {
  width: 100%;
  max-width: 220px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.17);
  overflow: hidden;
}

#progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--moss), var(--lichen));
  transition: width 260ms ease;
}

#progress-label {
  min-width: 32px;
  text-align: right;
  font-family: "DM Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--lichen);
}

.status-row {
  margin-right: calc(var(--score-panel-width) + 12px);
  min-height: 1.2em;
  margin-top: 10px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#status {
  flex: 1;
  min-width: 0;
  min-height: 1.2em;
  margin: 0;
  font-family: "DM Mono", monospace;
  font-size: 0.72rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.status-source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(184, 207, 186, 0.44);
  background: rgba(61, 90, 62, 0.28);
  color: var(--sage);
  padding: 2px 7px;
  font-family: "DM Mono", monospace;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.2;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 14px;
  margin-right: calc(var(--score-panel-width) + 12px);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "DM Mono", monospace;
  font-size: 0.7rem;
  color: var(--ink-soft);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-origin {
  background: var(--origin);
}

.dot-access {
  background: var(--access);
}

.content {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 2.25fr) minmax(260px, 0.96fr) minmax(300px, 1.08fr);
  gap: 12px;
}

.map-frame {
  position: relative;
}

#map {
  height: 72vh;
  min-height: 470px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.33);
  background: #5d4a35;
}

.map-action {
  position: absolute;
  top: 52px;
  right: 12px;
  z-index: 550;
  font-family: "DM Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 10px;
  background: #2f6a41;
  border: 1px solid rgba(184, 207, 186, 0.28);
}

.map-action:hover {
  background: #3f7e52;
}

.side-panel {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(73, 55, 35, 0.93), rgba(62, 47, 31, 0.95));
  padding: 14px;
  max-height: 72vh;
  overflow: auto;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28);
}

.side-panel::-webkit-scrollbar {
  width: 5px;
}

.side-panel::-webkit-scrollbar-thumb {
  background: var(--moss);
  border-radius: 3px;
}

.history-panel h3,
.results-panel h2 {
  margin: 0;
  font-family: "Playfair Display", serif;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--cream);
}

.history-panel h3 {
  font-size: 1.45rem;
}

.results-panel h2 {
  font-size: 1.8rem;
}

.directions-toggle {
  margin: 8px 0 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.map-directions {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 550;
  margin: 0;
  width: auto;
  grid-template-columns: auto auto;
}

.direction-mode-btn {
  font-family: "DM Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid rgba(75, 59, 42, 0.6);
  background: var(--soil);
  color: var(--cream);
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.direction-mode-btn:hover {
  background: var(--bark);
}

.direction-mode-btn.is-active {
  border-color: var(--amber);
  background: var(--amber);
  color: var(--soil);
  font-weight: 500;
}

#history-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: grid;
  gap: 3px;
}

.history-button {
  width: 100%;
  text-align: left;
  border-radius: 4px;
  padding: 8px 10px;
  font-family: "Lora", Georgia, serif;
  font-size: 0.86rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--line);
  color: var(--cream);
}

.history-button:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(212, 137, 42, 0.46);
}

.history-meta {
  margin-left: 2px;
  font-family: "DM Mono", monospace;
  font-size: 0.64rem;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.history-empty {
  color: var(--ink-muted);
  font-family: "DM Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}

.results-subtitle {
  margin: 4px 0 12px;
  color: var(--ink-muted);
  font-size: 0.84rem;
}

#results-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

#results-list li {
  margin-bottom: 12px;
  line-height: 1.5;
  color: var(--cream);
}

.result-item {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 8px 7px;
  margin-left: 0;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.result-item.is-active {
  border-color: rgba(212, 137, 42, 0.72);
  background: rgba(212, 137, 42, 0.13);
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-link {
  border: 0;
  background: transparent;
  padding: 0;
  font-family: "Playfair Display", serif;
  font-size: 1.04rem;
  font-weight: 600;
  color: var(--sage);
  box-shadow: none;
  text-decoration: none;
}

.result-link:hover {
  color: #d1e4d2;
  text-decoration: underline;
}

.copy-point-btn {
  font-family: "DM Mono", monospace;
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 6px 10px;
  border: 1px solid rgba(184, 207, 186, 0.45);
  background: rgba(61, 90, 62, 0.45);
  color: var(--cream);
  white-space: nowrap;
}

.copy-point-btn:hover {
  background: rgba(61, 90, 62, 0.62);
}

.result-meta {
  display: block;
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #1f150b;
  color: var(--cream);
  border: 1px solid var(--line);
}

.leaflet-popup-content {
  font-family: "Lora", Georgia, serif;
}

@media (max-width: 1240px) {
  .content {
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr);
  }

  .history-panel {
    grid-column: 1 / -1;
    max-height: 230px;
  }

  .results-panel {
    max-height: none;
  }
}

@media (max-width: 940px) {
  .app-shell {
    padding: 14px 10px 16px;
  }

  .masthead {
    padding: 16px 14px;
  }

  .masthead-title {
    align-items: flex-start;
  }

  .masthead-graphic {
    width: min(165px, 42vw);
    min-width: 100px;
  }

  .search-row {
    flex-direction: column;
  }

  .search-row button {
    width: 100%;
  }

  .control-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .count-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .search-form {
    margin-right: 0;
  }

  .score-row {
    position: static;
    width: 100%;
    top: auto;
    right: auto;
    bottom: auto;
    margin-top: 12px;
    justify-content: flex-start;
  }

  .trail-score-card {
    width: 150px;
    height: auto;
  }

  .trail-score-gauge {
    max-width: 124px;
    max-height: 124px;
  }

  .progress-wrap {
    margin-right: 0;
  }

  .status-row {
    margin-right: 0;
  }

  .legend-row {
    margin-right: 0;
  }

  .result-count-toggle {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .slider-value {
    min-width: 0;
  }

  .content {
    grid-template-columns: 1fr;
  }

  #map {
    height: 56vh;
    min-height: 340px;
  }

  .history-panel,
  .results-panel {
    max-height: none;
  }
}
