:root {
  --ink: #1b1710;
  --paper: #f3ead8;
  --paper-2: #e7dcc4;
  --forest: #2a4630;
  --moss: #4a6b45;
  --line: rgba(27, 23, 16, 0.12);
  --muted: #6a614f;
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #12100c;
  color: var(--ink);
}

body {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.panel {
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  position: relative;
  z-index: 10;
}

.panel-fixed {
  flex: 0 0 auto;
  padding: 22px 20px 0;
  position: relative;
  z-index: 5;
  pointer-events: auto;
}

#network-filters button,
#diff-filters button {
  pointer-events: auto;
  cursor: pointer;
}

.panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 20px 32px;
}

.brand h1 {
  font-family: Fraunces, Georgia, "Iowan Old Style", serif;
  font-size: 2.05rem;
  line-height: 1.05;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.68rem;
  color: var(--moss);
  font-weight: 700;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.toolbar {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: var(--paper-2);
  border-radius: 10px;
  padding: 3px;
}

.seg-btn,
.chip {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.seg-btn {
  padding: 8px 6px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
}

.seg-btn.is-on,
.chip.is-on {
  background: var(--forest);
  color: #f6f1e4;
}

.toggle,
.exag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
}

.exag input {
  width: 140px;
}

.exag b {
  font-variant-numeric: tabular-nums;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.panel-filters {
  margin-top: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.filter-block + .filter-block {
  margin-top: 10px;
}

.filter-label {
  margin: 0 0 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--moss);
}

.filters-network {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.filters-diff {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--paper-2);
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 36px;
  width: 100%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.filters-diff .chip {
  width: auto;
  border-radius: 999px;
  padding: 6px 11px;
  min-height: 0;
}

.chip[data-network="sleza"] { box-shadow: inset 3px 0 0 #2e7d32; }
.chip[data-network="strefa-mtb-sudety"] { box-shadow: inset 3px 0 0 #ef6c00; }
.chip[data-network="glacensis"] { box-shadow: inset 3px 0 0 #c62828; }
.chip[data-network="singltrek-smrk"] { box-shadow: inset 3px 0 0 #1565c0; }
.chip[data-network="singletrack-szklarska"] { box-shadow: inset 3px 0 0 #6a1b9a; }

.chip.is-on {
  box-shadow: none;
}

.chip:active {
  transform: scale(0.98);
}

.elev-readout {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--line);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.list-tools {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

.search {
  flex: 1;
  display: block;
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: #faf6ec;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.9rem;
}

.search input:focus {
  outline: 2px solid rgba(42, 70, 48, 0.35);
  border-color: var(--moss);
}

.reset-btn {
  border: 1px solid var(--line);
  background: var(--paper-2);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--ink);
}

.reset-btn:hover {
  background: rgba(42, 70, 48, 0.12);
}

.trail-stats {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.saved-block {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.saved-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.saved-head .filter-label {
  margin: 0;
}

.save-view-btn {
  border: 0;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.save-view-btn:hover {
  background: rgba(42, 70, 48, 0.14);
}

.saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.saved-empty {
  font-size: 0.78rem;
  color: var(--muted);
}

.saved-chip {
  border: 0;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 8px 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.saved-chip:hover {
  background: rgba(42, 70, 48, 0.14);
}

.saved-del {
  opacity: 0.55;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 2px;
}

.saved-del:hover {
  opacity: 1;
}

.gpx-block {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.gpx-import-btn {
  position: relative;
  display: inline-flex;
  cursor: pointer;
  overflow: hidden;
}

.gpx-import-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.gpx-hint {
  margin: 0 0 8px;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}

.gpx-list {
  display: grid;
  gap: 6px;
}

.gpx-empty {
  font-size: 0.78rem;
  color: var(--muted);
}

.gpx-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 2px;
  background: var(--paper-2);
  border-radius: 10px;
  padding: 2px 4px 2px 2px;
}

.gpx-item.is-on {
  background: rgba(42, 70, 48, 0.14);
  box-shadow: inset 3px 0 0 #d35400;
}

.gpx-pick {
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  min-width: 0;
}

.gpx-pick strong {
  display: block;
  font-size: 0.86rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gpx-meta {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 1px;
}

.gpx-ico {
  border: 0;
  background: transparent;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.85rem;
  line-height: 1;
}

.gpx-ico:hover {
  background: rgba(42, 70, 48, 0.16);
}

.trail-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.net-section {
  margin-top: 14px;
  list-style: none;
}

.net-section:first-child {
  margin-top: 0;
}

.net-head-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.net-toggle {
  border: 0;
  background: var(--paper-2);
  border-radius: 10px;
  width: 32px;
  cursor: pointer;
  color: var(--ink);
  flex: 0 0 32px;
}

.net-toggle:hover {
  background: rgba(42, 70, 48, 0.16);
}

.net-chevron {
  display: inline-block;
  transition: transform 0.15s ease;
}

.net-section.is-collapsed .net-chevron {
  transform: rotate(-90deg);
}

.net-section.is-collapsed .net-body {
  display: none;
}

.net-body {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}

.net-head {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  background: var(--forest);
  color: #f6f1e4;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.net-head:hover,
.net-head.is-on {
  background: #1e3424;
}

.net-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.loc-group {
  margin-top: 8px;
  padding-left: 4px;
  list-style: none;
}

.net-body .trail {
  padding-left: 12px;
}

.loc-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.loc-head:hover {
  background: rgba(42, 70, 48, 0.16);
}

.loc-count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.trail-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 12px 8px;
}

.trail {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  gap: 2px;
  font: inherit;
  color: inherit;
}

.trail:hover,
.trail.is-on {
  background: rgba(42, 70, 48, 0.1);
}

.trail.is-match .trail-name {
  text-decoration: underline;
  text-decoration-color: rgba(42, 70, 48, 0.35);
}

.trail-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}

.blaze {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 10px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.trail-meta {
  color: var(--muted);
  font-size: 0.8rem;
  padding-left: 18px;
}

.stage {
  position: relative;
  min-height: 100%;
  z-index: 1;
}

#map {
  position: absolute;
  inset: 0;
  background: #c9d6b8;
}

#map .maplibregl-canvas {
  background: #c9d6b8;
}

.boot {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(201, 214, 184, 0.82);
  font-family: Fraunces, Georgia, serif;
  font-size: 1.15rem;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.boot.is-off {
  opacity: 0;
}

.menu-btn {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 3;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--paper);
  font-size: 1.1rem;
  cursor: pointer;
}

.hud {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  max-width: 280px;
}

.hud-card {
  background: rgba(243, 234, 216, 0.92);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.profile {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  background: rgba(243, 234, 216, 0.95);
  border-radius: 12px;
  padding: 10px 12px 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.profile-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.85rem;
}

.profile-head span {
  color: var(--muted);
  flex: 1;
}

#profile-close {
  border: 0;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
}

#profile-canvas {
  width: 100%;
  display: block;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.act-btn {
  border: 0;
  background: var(--forest);
  color: #f6f1e4;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.act-btn:hover {
  background: #1e3424;
}

.act-btn.act-stop {
  background: #6a3b2a;
}

.act-btn.act-avinox {
  background: #1b1710;
  margin-left: auto;
}

.sim-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.sim-speed input {
  width: 92px;
}

.sim-speed b {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.sim-follow-lab {
  font-size: 0.78rem;
  gap: 6px;
}

.sim-scrub {
  width: 100%;
  margin: 8px 0 0;
  accent-color: var(--forest);
}

.rider-mark {
  width: 28px;
  height: 28px;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

.rider-mark svg {
  display: block;
}

.popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.popup-actions button {
  border: 0;
  background: var(--forest);
  color: #f6f1e4;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 9px;
  border-radius: 7px;
  cursor: pointer;
}

.popup-actions .popup-avinox {
  background: #1b1710;
}

.stage.is-drop {
  outline: 3px dashed rgba(42, 70, 48, 0.55);
  outline-offset: -8px;
}

.maplibregl-ctrl-group {
  border-radius: 10px !important;
  overflow: hidden;
}

.maplibregl-popup-content {
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
}

.popup-trail strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.popup-trail p {
  margin: 0 0 4px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
}

.popup-trail .popup-desc {
  font-size: 0.75rem;
  margin-top: 6px;
  color: var(--muted);
}

@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
  }

  .panel {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(92vw, 360px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 30;
  }

  body.panel-open .panel {
    transform: none;
  }

  .menu-btn {
    display: block;
  }
}
