#trail-panel {
  --map-paper: #f6efdd;
  --map-ink: #2c3e33;
  --map-stroke: #ad9871;
  --map-red: #973e2f;
  --map-shadow: 0 4px 16px #302a2040;
  --map-frame: #20382f;
  --map-edge: #496155;
  --map-inset: 10px;
  position: fixed;
  z-index: 6;
  inset: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) auto auto;
  margin: 0;
  box-sizing: border-box;
  width: clamp(400px, 41vw, 570px);
  height: min(620px, 76dvh);
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  isolation: isolate;
  border: 1px solid #8e9671;
  border-radius: 14px;
  background: var(--map-frame);
  color: var(--map-ink);
  box-shadow: 0 12px 36px #101c16a3;
  -webkit-tap-highlight-color: transparent;
}
#trail-panel[open] { display: grid; }
#minimap[aria-expanded="true"] { border-color: #e3c589; }
body:is(.photographing,.held-inspecting) #trail-panel[open] { visibility: hidden; }

.trail-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 9px 10px 8px 15px;
}
.trail-title-block { min-width: 0; }
#trail-title { margin: 0; color: #f9edce; font: 700 24px/1.1 "Songti SC", "Noto Serif CJK SC", SimSun, serif; }
#trail-location {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #c5d4bf;
  font-size: 12px;
}
#trail-panel button { touch-action: manipulation; }
#trail-panel :is(button, summary, input, #trail-viewport):focus-visible { outline: 2px solid #efba65; outline-offset: -2px; }
#trail-panel .trail-tool {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--map-stroke);
  border-radius: 6px;
  background: var(--map-paper);
  color: var(--map-ink);
  font: 500 23px/1 system-ui, sans-serif;
}
#trail-panel .trail-tool:is(:hover,:focus-visible) { background: #fffaed; }
#trail-panel .trail-tool:disabled { opacity: .58; }
.trail-tool svg, #trail-search svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#trail-panel .trail-heading .trail-tool { border-color: #587063; background: #2d493d; color: #f5eace; }
#trail-panel .trail-heading .trail-tool:is(:hover,:focus-visible,[aria-expanded="true"]) { background: #426153; }

#trail-filters {
  display: grid;
  grid-template-columns: repeat(5,minmax(0,1fr));
  gap: 3px;
  margin: 0 var(--map-inset) 8px;
  padding: 3px;
  border: 1px solid var(--map-edge);
  border-radius: 8px;
  background: #192e26;
}
#trail-filters button { min-height: 32px; padding: 3px; border: 0; border-radius: 5px; background: transparent; color: #deebd9; font-size: 13px; white-space: nowrap; }
#trail-filters button[aria-pressed="false"]:hover { background: #30473d; }
#trail-filters button[aria-pressed="true"] { background: #dfc998; color: #263c30; font-weight: 700; }

#trail-sheet {
  position: relative;
  min-height: 0;
  margin: 0 var(--map-inset) var(--map-inset);
  overflow: hidden;
  border: 1px solid #a89165;
  border-radius: 8px;
  background: #e6dfc8;
}

#trail-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#trail-viewport[data-dragging] { cursor: grabbing; }
#trail-viewport:focus:not(:focus-visible) { outline: none; }
#trail-art {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  display: block;
  max-width: none;
  pointer-events: none;
  outline: 1px solid #64745480;
  box-shadow: 0 4px 28px #4f58492b;
}

#trail-overlay, #trail-pins {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.trail-hit-area {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
  cursor: pointer;
}

.trail-hit-area:hover, .trail-hit-area[data-selected] {
  fill: #fff5d52c;
  stroke: #ffe7af;
  stroke-width: 1.5;
}

.trail-route, .trail-route-halo, .trail-leader { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trail-route-halo { stroke: #fff1c8; stroke-width: 6; }
.trail-route { stroke: var(--map-red); stroke-width: 3; }
.trail-route-end { fill: var(--map-red); stroke: #fff1c8; stroke-width: 2; }
.trail-leader { stroke: #6f573a; stroke-width: 1; }
.trail-anchor { fill: #8c6140; stroke: #f8eccd; stroke-width: 1.15; pointer-events: none; }

#trail-map-controls {
  position: absolute;
  right: 8px;
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(2,auto);
  gap: 3px;
  padding: 3px;
  border-radius: 8px;
  background: #f6efdd;
  box-shadow: var(--map-shadow);
}
#trail-map-controls .trail-tool { width: 34px; height: 34px; }

#trail-search-panel {
  position: absolute;
  z-index: 7;
  inset: 7px 8px auto;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 14px);
}
#trail-search-panel[hidden] { display: none; }
#trail-search { display: flex; flex: none; min-height: 42px; align-items: center; gap: 8px; padding: 0 7px 0 11px; border: 1px solid var(--map-stroke); border-radius: 6px; background: var(--map-paper); box-shadow: var(--map-shadow); }
#trail-search svg { flex: none; width: 17px; height: 17px; color: #6c5b43; }
#trail-query { box-sizing: border-box; min-width: 0; min-height: 40px; flex: 1; padding: 0 2px; background: transparent; border: 0; color: var(--map-ink); font: inherit; font-size: 16px; }
#trail-query::placeholder { color: #6b604c; }
#trail-query::-webkit-search-cancel-button { display: none; }
#trail-search-clear:not([hidden]) { min-width: 36px; min-height: 36px; padding: 0; border: 0; background: transparent; color: var(--map-ink); font-size: 21px; }
.trail-search-popover { margin-top: 4px; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--map-stroke); border-radius: 6px; background: var(--map-paper); box-shadow: var(--map-shadow); }
.trail-search-popover:has(#trail-search-status[hidden]) { display: none; }
#trail-search-status { padding: 7px 12px; margin: 0; color: #645239; font-size: 12px; }
#trail-destinations button { display: flex; width: 100%; justify-content: space-between; align-items: baseline; gap: 8px; min-height: 42px; border: 0; border-top: 1px solid #917b5036; border-radius: 0; padding: 8px 11px; text-align: left; background: none; color: var(--map-ink); }
#trail-destinations button:is(:hover,:focus-visible) { background: #e9dfc3; }
#trail-destinations button small { flex: none; font-size: 11px; color: #645239; }

.trail-compass { position: absolute; top: 9px; right: 11px; display: grid; justify-items: center; width: 24px; color: #4e3d20; font: 700 13px "Songti SC", SimSun, serif; text-shadow: 0 1px #f9ecd3; pointer-events: none; }
.trail-compass svg { width: 16px; height: 22px; stroke: #674b2a; fill: #f3dfac; stroke-width: 1.3; }
.trail-compass svg path + path { fill: #927245; }
#trail-scale { position: absolute; right: 9px; bottom: 94px; display: grid; gap: 1px; padding: 4px 6px; border-radius: 4px; background: #f6efddd9; color: #4e462f; font-size: 11px; text-align: right; pointer-events: none; }
#trail-scale-bar { justify-self: end; height: 4px; box-sizing: border-box; border: solid #71664a; border-width: 0 1px 2px; }
.trail-legend { position: absolute; left: 8px; bottom: 10px; max-height: calc(100% - 20px); overflow: auto; border: 1px solid var(--map-stroke); border-radius: 6px; background: var(--map-paper); font-size: 12px; box-shadow: var(--map-shadow); }
.trail-legend summary { cursor: pointer; padding: 7px 9px; }
.trail-legend dl { margin: 0; padding: 0 13px 10px; }
.trail-legend dl div { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.trail-legend dt { width: 10px; height: 10px; background: #846344; border-radius: 2px; }
.trail-legend dd { margin: 0; white-space: nowrap; }
.trail-legend .trail-legend-here { background: var(--map-red); clip-path: polygon(50% 0,100% 100%,50% 72%,0 100%); }
.trail-legend .trail-legend-peer { border-radius: 50%; background: #36655f; }
.trail-legend .trail-legend-meet { transform: rotate(45deg); background: #b78742; }
.trail-legend .trail-legend-quest { background: #a65345; }
.trail-legend .trail-legend-route { height: 3px; background: var(--map-red); }

#trail-panel .trail-pin {
  position: absolute;
  z-index: 1;
  pointer-events: auto;
  min-height: 27px;
  padding: 3px 8px;
  border: 1px solid #99794e;
  border-radius: 5px;
  background: #f8eed7;
  color: #3f3221;
  box-shadow: 0 2px 5px #3c2e2655;
  white-space: nowrap;
  font: 700 13px/1.2 "Songti SC", "Noto Serif CJK SC", SimSun, serif;
}
#trail-panel .trail-pin[data-kind="region"] { padding-inline: 10px; border-color: #7d8470; background: #edefda; color: #374b39; }
#trail-panel .trail-pin:is([data-map-location="templeCampus"], [data-map-location="marketPlaza"]) { padding: 4px 12px; border-color: #ffe0ad; border-radius: 7px 3px; background: #74382a; color: #fff0c9; font-size: 16px; letter-spacing: .12em; }
#trail-panel .trail-pin[data-category="nature"]:not([data-kind="region"]) { border-color: #6b847b; background: #f0efdbed; color: #344e45; }
#trail-panel .trail-pin[data-category="cultivation"]:not([data-kind="region"]) { border-color: #778173; background: #eae9d5; color: #3f5137; }
#trail-panel .trail-pin:is([data-selected="true"], :focus-visible, :hover) { z-index: 4; border-color: #742a1c; background: #943c2b; color: #fff1d6; }
#trail-here, #trail-meeting-pin, #trail-quest-pin, #trail-guest-pin, .trail-peer { position: absolute; z-index: 5; transform: translate(-50%, -50%); pointer-events: none; }
#trail-here { width: 19px; height: 19px; transform: translate(-50%, -50%) rotate(var(--trail-heading, 0rad)); filter: drop-shadow(0 1px 2px #302716); }
#trail-here::before, #trail-here::after { position: absolute; content: ""; clip-path: polygon(50% 0, 100% 100%, 50% 73%, 0 100%); }
#trail-here::before { inset: -3px; background: #fff4da; }
#trail-here::after { inset: 0; background: #aa3d2c; }
#trail-meeting-pin, #trail-quest-pin, #trail-guest-pin, #trail-panel .trail-peer { box-sizing: border-box; width: 14px; height: 14px; min-height: 0; padding: 0; border: 2px solid #fff1cd; box-shadow: 0 1px 4px #41362cbb; }
#trail-meeting-pin { border-radius: 3px; background: #ac7738; transform: translate(-50%, -50%) rotate(45deg); }
#trail-quest-pin { border-radius: 3px; background: #a04d49; }
#trail-guest-pin, #trail-panel .trail-peer { border-radius: 50%; background: #386f64; }
#trail-panel .trail-peer { pointer-events: auto; }
#trail-panel .trail-peer::after { content: ""; position: absolute; inset: -7px; }

#trail-details:not([hidden]) { display: flex; align-items: center; gap: 8px; margin: -4px var(--map-inset) 7px; color: #f6e7c6; font-size: 12px; }
#trail-active-route { flex: 1; min-width: 0; padding-left: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#trail-cancel-route { min-height: 32px; padding: 3px 9px; border: 1px solid #856051; border-radius: 5px; background: #663c33; color: #fff2d8; white-space: nowrap; font-size: 12px; }
#trail-cancel-route:hover { background: #8c4938; }

#trail-detail, .trail-context > section { box-sizing: border-box; border: 1px solid var(--map-stroke); border-radius: 7px; background: var(--map-paper); box-shadow: var(--map-shadow); }
#trail-detail {
  position: absolute;
  z-index: 6;
  left: 8px;
  bottom: 10px;
  width: min(290px,calc(100% - 102px));
  max-height: calc(100% - 20px);
  padding: 8px;
}
#trail-detail:not([hidden]) { display: grid; grid-template-rows: minmax(0,1fr) auto; gap: 4px; }
#trail-sheet:has(#trail-search-panel:not([hidden])) #trail-detail { display: none; }
#trail-detail-content { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 0 3px; }
#trail-panel #trail-detail-close { position: absolute; right: 7px; top: 7px; width: 32px; height: 32px; font-size: 20px; }
#trail-detail-image:not([hidden]) { display: block; width: 100%; max-height: 82px; aspect-ratio: 3; object-fit: cover; background: #e8dfc7; border-radius: 4px; }
#trail-detail-name { margin: 4px 37px 5px 0; color: #384634; font: 700 19px/1.2 "Songti SC", "Noto Serif CJK SC", SimSun, serif; }
#trail-detail-description, #trail-detail-status { margin: 0 0 6px; color: #504834; font-size: 12px; line-height: 1.45; }
#trail-detail-status { color: #8b3e2c; }
#trail-detail-activities { display: flex; flex-wrap: wrap; gap: 3px; list-style: none; margin: 0 0 4px; padding: 0; }
#trail-detail-activities:empty { display: none; }
#trail-detail-activities li { padding: 1px 5px; border: 1px solid #ac946361; border-radius: 4px; color: #554628; font-size: 11px; }
.trail-detail-actions { display: flex; gap: 5px; }
.trail-detail-actions button { min-height: 38px; padding: 4px 6px; white-space: nowrap; font-size: 12px; }
.trail-detail-actions #trail-detail-navigate { flex: 1; border-color: #435846; background: #395748; color: #fff5d9; }
.trail-detail-actions #trail-detail-navigate:hover { background: #4a6d58; }

.trail-context { position: absolute; top: 8px; left: 8px; display: grid; gap: 4px; max-width: calc(100% - 54px); pointer-events: none; }
.trail-context > section:not([hidden]) { display: flex; align-items: center; gap: 6px; padding: 4px 5px 4px 8px; pointer-events: auto; }
.trail-context p { display: grid; gap: 2px; margin: 0; font-size: 12px; }
.trail-context p :is(small, span) { font-size: 11px; color: #62563e; }
#trail-panel :is(.trail-context button,#trail-detail-preview) {
  min-height: 36px;
  padding: 3px 7px;
  border: 1px solid #a5895f;
  border-radius: 5px;
  background: #ede0bf;
  color: var(--map-ink);
  white-space: nowrap;
  font-size: 12px;
}
#trail-panel :is(.trail-context button,#trail-detail-preview):hover { background: #f7eccc; }
#trail-guest-actions { display: grid; gap: 3px; }

@media (max-width: 680px) and (orientation: portrait) {
  #trail-panel {
    --map-inset: 6px;
    inset: max(8px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) auto max(8px,env(safe-area-inset-left));
    width: auto;
    height: min(420px,52dvh);
    border-radius: 10px;
  }
  body:has(#touch-walk:not([hidden])) #trail-panel { height: min(420px,52dvh,calc(100dvh - 245px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
  .trail-heading { padding: 4px 6px 3px 10px; }
  #trail-title { font-size: 20px; }
  #trail-location { margin-top: 2px; }
  #trail-filters { margin-bottom: 4px; padding: 2px; }
  #trail-panel .trail-pin { padding-inline: 6px; font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 510px) {
  #trail-panel { --map-inset: 6px; inset: max(7px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) auto auto; width: min(440px,49vw); height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  body:has(#touch-walk:not([hidden])) #trail-panel { height: calc(100dvh - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .trail-heading { padding: 3px 6px 2px 10px; }
  #trail-title { font-size: 20px; }
  #trail-location { margin-top: 1px; }
  #trail-filters { margin-bottom: 4px; padding: 1px; }
}
@media (any-pointer: coarse) {
  #trail-panel .trail-heading .trail-tool,#trail-map-controls .trail-tool { width: 44px; height: 44px; }
  #trail-detail { width: min(285px,calc(100% - 118px)); }
  #trail-scale { bottom: 113px; }
  #trail-filters button { min-height: 36px; }
}
