:root { color-scheme: dark; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e0e0e; font: 14px/1.4 system-ui, sans-serif; color: #e8e6e0; }   /* overflow: ruler labels and panes poke past the edge, which made page scrollbars flicker and resize the map */
#stage { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #7c6850; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.leaflet-popup { -webkit-user-select: text; user-select: text; }
.sheethead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.headbtns { display: flex; gap: 6px; }
#sheetToggle, #clearQuick { display: none; padding: 4px 12px; font-size: 13px; }
#mapHint .touch { display: none; }
#panel {
  position: absolute; top: 12px; left: 12px; z-index: 1000; width: 300px; box-sizing: border-box;
  padding: 12px 14px; background: rgba(22, 24, 20, .92); border: 1px solid #3a3d34; border-radius: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
h1 { margin: 0; font-size: 18px; }
h1 small { color: #ffd27a; font-weight: 500; font-size: 13px; margin-left: 6px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #b9b6aa; }
input, select, button {
  font: inherit; color: inherit; background: #2a2d26; border: 1px solid #4a4e43; border-radius: 6px; padding: 6px 8px;
}
button { cursor: pointer; }
button:hover { border-color: #ffd27a; }
#go { background: #ffd27a; color: #141614; font-weight: 700; border-color: #ffd27a; flex: 1; }
.row { display: flex; gap: 6px; }
.hint { color: #8d8b80; font-size: 12px; margin: 0; }
.big { font-size: 20px; font-weight: 700; color: #ffd27a; }
#breakdown { width: 100%; border-collapse: collapse; margin-top: 4px; }
#breakdown td { padding: 1px 0; }
#breakdown td:last-child { text-align: right; color: #b9b6aa; }
#error { color: #ff8a80; }
.pin {   /* dark ring inside a yellow ring: readable on satellite, paper and topographic alike */
  width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 3px solid #141614;
  box-shadow: 0 0 0 2px #ffd27a, 0 2px 6px rgba(0, 0, 0, .6); text-align: center; font: 700 12px/16px system-ui;
}
.pin.a { background: #ffd27a; color: #141614; }
.pin.b { background: #141614; color: #ffd27a; }

#panel { max-height: calc(100% - 24px); overflow-y: auto; }
#panel > * { flex-shrink: 0; }                                  /* the panel scrolls; never squash a child (the search list collapsed to 2px) */
.row.opts { align-items: center; flex-wrap: wrap; }
.row.opts select { flex: 1; }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: #e8e6e0; }
#steps { list-style: none; margin: 6px 0 0; padding: 0; counter-reset: s; }
#steps li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: baseline;
  padding: 5px 4px; border-top: 1px solid #33362e; cursor: pointer; font-size: 13px;
}
#steps li:hover, #steps li.on { background: #2a2d26; }
#steps .arrow { color: #ffd27a; font-size: 16px; text-align: center; }
#steps .d { color: #8d8b80; white-space: nowrap; }
.ruler { position: absolute; z-index: 850; pointer-events: none; font: 11px/14px system-ui, sans-serif; color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000; }
.ruler span { position: absolute; }
.ruler.h { left: 0; right: 0; bottom: 0; height: 16px; }
.ruler.h span { transform: translateX(2px); bottom: 1px; }
.ruler.v { top: 0; bottom: 0; right: 0; width: 30px; }
.ruler.v span { right: 3px; transform: translateY(2px); }

.topo-label {
  white-space: nowrap; transform: translate(-50%, -50%); pointer-events: none; color: #3a3328;
  text-shadow: 0 0 3px #ece6d6, 0 0 3px #ece6d6, 0 0 3px #ece6d6, 0 0 2px #ece6d6; font-weight: 600;
}
.topo-label.t-city { font-size: 17px; font-weight: 800; }
.topo-label.t-town { font-size: 14px; }
.topo-label.t-village { font-size: 12px; }
.topo-label.t-military { font-size: 12px; color: #6b2b2b; }
.topo-label.t-landmark { font-size: 11px; font-weight: 500; color: #55503f; }
/* satellite and paper: light text with a dark halo (the defaults above are for the pale topographic map) */
body:not(.topo) .topo-label { color: #f3efe3; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 4px #000, 0 1px 2px #000; }
body:not(.topo) .topo-label.t-military { color: #ff9a8f; }
body:not(.topo) .topo-label.t-landmark { color: #d9d4c0; }

body.topo .ruler { color: #2b2410; text-shadow: 0 0 3px #ece6d6, 0 0 3px #ece6d6; }

details#lootDetails { border-top: 1px solid #33362e; padding-top: 6px; }
details#lootDetails summary { cursor: pointer; font-size: 12px; color: #b9b6aa; }
#lootFilters { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; margin-top: 6px; }
#lootFilters .chk { font-size: 12px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.6); }
.lootpop { font: 13px/1.4 system-ui, sans-serif; color: #e8e6e0; }
.lootpop .muted { color: #8d8b80; font-size: 12px; }
.lootpop .row { margin-top: 6px; display: flex; gap: 6px; }
.lootpop button { background: #ffd27a; color: #141614; font-weight: 600; border: 1px solid #ffd27a; border-radius: 6px; padding: 4px 9px; font-size: 13px; }
.lootpop button:hover { background: #ffe19c; border-color: #ffe19c; }

#search { width: 100%; box-sizing: border-box; }
#searchResults { list-style: none; margin: -2px 0 0; padding: 0; max-height: 260px; overflow-y: auto;
  background: #1d201a; border: 1px solid #4a4e43; border-radius: 6px; }
#searchResults li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; cursor: pointer; font-size: 13px; }
#searchResults li small { color: #8d8b80; white-space: nowrap; }
#searchResults li:hover, #searchResults li.on { background: #2f3328; }

details#savedDetails { border-top: 1px solid #33362e; padding-top: 6px; }
details#savedDetails summary { cursor: pointer; font-size: 12px; color: #b9b6aa; }
#savedFilter { width: 100%; margin-top: 6px; }
#savedList { list-style: none; margin: 6px 0 0; padding: 0; max-height: 170px; overflow-y: auto; }
#savedList li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; padding: 4px 2px; cursor: pointer; font-size: 13px; border-top: 1px solid #2c2f27; }
#savedList li:hover { background: #2a2d26; }
#savedList li.empty { display: block; color: #8d8b80; cursor: default; font-size: 12px; }
#savedList li.empty:hover { background: none; }
#savedList small { color: #8d8b80; white-space: nowrap; }
.savedpin { width: 26px; height: 32px; position: relative; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.savedpin::before { content: ""; position: absolute; left: 3px; top: 0; width: 20px; height: 20px; background: var(--c);
  border: 2px solid #fff; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); box-sizing: border-box; }
.savedpin i { position: absolute; left: 9px; top: 6px; width: 8px; height: 8px; background: #fff; border-radius: 50%; }
.savedtip { background: rgba(20, 22, 18, .85); color: #fff; border: 0; box-shadow: none; font: 600 12px system-ui, sans-serif; padding: 2px 6px; }
.savedtip::before { display: none; }
.lowzoom .savedtip { display: none; }
.savededit { display: flex; flex-direction: column; gap: 6px; }
.savededit label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: #b9b6aa; }
.savededit input, .savededit textarea { font: inherit; padding: 6px 8px; background: #2a2d26; color: #e8e6e0; border: 1px solid #4a4e43; border-radius: 6px; }
.savededit input:focus, .savededit textarea:focus { outline: none; border-color: #ffd27a; }
.savededit .colors { display: flex; gap: 5px; }
.savededit .colors button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; padding: 0; cursor: pointer; }
.savededit .colors button.on { border-color: #fff; }
.lootpop .row { flex-wrap: wrap; }
.lootpop button.danger { background: #4a2622; color: #ffb4a8; border-color: #6e3730; }

/* popup chrome matches the side panel */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: rgba(22, 24, 20, .96); color: #e8e6e0; border: 1px solid #3a3d34; box-shadow: 0 4px 14px rgba(0, 0, 0, .55);
}
.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-container a.leaflet-popup-close-button { color: #b9b6aa; }
.leaflet-container a.leaflet-popup-close-button:hover { color: #fff; }
.leaflet-popup-content a { color: #ffd27a; }

/* ---------- motion ---------- */
@keyframes drop {
  0% { transform: translateY(-36px) scale(.85); opacity: 0; }
  55% { transform: translateY(0) scale(1.1); opacity: 1; }
  75% { transform: translateY(-8px) scale(1); }
  100% { transform: translateY(0) scale(1); }
}
.pin.drop, .savedpin.drop { animation: drop .6s cubic-bezier(.2, .8, .3, 1); }
@keyframes slidein { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: none; } }
#steps li { animation: slidein .3s ease-out both; animation-delay: calc(var(--i, 0) * 30ms); }
@keyframes ring { to { box-shadow: 0 0 0 18px rgba(255, 210, 122, 0); } }
.carDot { width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: #141614; border: 4px solid #ffd27a;
  box-shadow: 0 0 0 0 rgba(255, 210, 122, .6); animation: ring 1.2s ease-out infinite; }

/* step tooltips match the panel */
.leaflet-tooltip.steptip {
  background: rgba(22, 24, 20, .96); color: #e8e6e0; border: 1px solid #3a3d34; border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .55); font: 600 12px system-ui, sans-serif; padding: 3px 8px;
}
.leaflet-tooltip-top.steptip::before { border-top-color: #3a3d34; }
.leaflet-tooltip-bottom.steptip::before { border-bottom-color: #3a3d34; }
.leaflet-tooltip-left.steptip::before { border-left-color: #3a3d34; }
.leaflet-tooltip-right.steptip::before { border-right-color: #3a3d34; }
#drive { align-self: flex-start; margin: 2px 0; font-size: 13px; }
#steps li.on { transition: background .2s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- saved routes ---------- */
details#routesDetails { border-top: 1px solid #33362e; padding-top: 6px; }
details#routesDetails summary { cursor: pointer; font-size: 12px; color: #b9b6aa; }
#routesFilter { width: 100%; margin-top: 6px; }
#routesList { list-style: none; margin: 6px 0 0; padding: 0; max-height: 200px; overflow-y: auto; }
#routesList > li { border-top: 1px solid #2c2f27; padding: 4px 2px; font-size: 13px; }
#routesList li.empty { color: #8d8b80; font-size: 12px; }
#routesList .rrow { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
#routesList .nm { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#routesList .nm:hover { color: #ffd27a; }
#routesList small { color: #8d8b80; white-space: nowrap; }
#routesList .rnote { color: #8d8b80; font-size: 12px; margin-top: 2px; }
#routesList .iconbtn { padding: 1px 6px; font-size: 12px; }

/* modal dialog (route save / edit) */
dialog.modal { padding: 0; border: 1px solid #3a3d34; border-radius: 12px; background: #1d201a; color: #e8e6e0;
  width: min(380px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0, 0, 0, .6); }
dialog.modal::backdrop { background: rgba(8, 9, 7, .62); }
dialog.modal[open] { animation: modalin .18s ease-out; }
dialog#helpModal { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
#helpBody { display: flex; flex-direction: column; }
#helpBody section { order: 1; }
#helpBody section.mine { order: 0; }
#helpBody .privacy { order: 2; border-top: 1px solid #33362e; padding-top: 8px; }
#helpBody .row { order: 3; }
#helpBody h3 { margin: 4px 0; font-size: 13px; color: #ffd27a; }
#helpBody ul { margin: 0 0 8px; padding-left: 18px; }
#helpBody li { margin: 3px 0; font-size: 13px; }
#helpBody kbd { background: #2a2d26; border: 1px solid #4a4e43; border-radius: 4px; padding: 0 4px; font: 12px system-ui; }
#helpBtn { padding: 4px 10px; font-size: 13px; }
@keyframes modalin { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modalbody { display: flex; flex-direction: column; gap: 10px; padding: 18px 20px; }
.modalbody h2 { margin: 0; font-size: 18px; }
.modalbody label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #b9b6aa; }
.modalbody input, .modalbody textarea { font: inherit; padding: 7px 9px; background: #2a2d26; color: #e8e6e0; border: 1px solid #4a4e43; border-radius: 6px; resize: vertical; }
.modalbody input:focus, .modalbody textarea:focus { outline: none; border-color: #ffd27a; }
.modalbody .row { display: flex; gap: 8px; margin-top: 4px; }
.modalbody button.primary { background: #ffd27a; color: #141614; font-weight: 700; border-color: #ffd27a; }
.modalbody button.danger { margin-left: auto; background: #4a2622; color: #ffb4a8; border-color: #6e3730; }
#result .row { gap: 6px; }

/* ---------- touch screens ---------- */
@media (pointer: coarse) {
  #mapHint .mouse { display: none; }
  #mapHint .touch { display: inline; }
  input, select, textarea { font-size: 16px; }                 /* below 16px iOS zooms the page when a field is focused */
  button { font-size: 15px; }
  button, select, input:not([type=checkbox]) { min-height: 40px; }
  input[type=checkbox] { width: 20px; height: 20px; margin: 0; }
  label.chk { min-height: 32px; font-size: 14px; }
  #lootFilters { gap: 4px 8px; }
  #lootFilters .chk { font-size: 14px; }
  details summary { padding: 6px 0; }
  #steps li { padding: 10px 4px; }
  #savedList li, #searchResults li { padding: 10px 6px; }
  #savedList, #routesList { max-height: 240px; }
  #routesList > li { padding: 8px 2px; }
  #routesList .iconbtn { min-height: 36px; min-width: 36px; }
  .lootpop button { min-height: 38px; padding: 4px 12px; font-size: 14px; }
  .savededit .colors { gap: 10px; }
  .savededit .colors button { min-height: 0; width: 30px; height: 30px; }
  .leaflet-container a.leaflet-popup-close-button { width: 34px; height: 34px; font-size: 24px; line-height: 32px; }
}

/* ---------- phones: the panel becomes a bottom sheet under the map ---------- */
@media (max-width: 700px) {
  html, body { height: 100dvh; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
  body { display: flex; flex-direction: column; }
  #stage { position: relative; inset: auto; flex: 1 1 0; min-height: 140px; }
  #panel {
    position: static; flex: 0 0 auto; width: auto; max-height: 55dvh; overscroll-behavior: contain;
    border-width: 1px 0 0; border-radius: 14px 14px 0 0; background: #161814; gap: 10px;
    padding: 8px calc(14px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }
  #sheetToggle { display: block; min-width: 64px; }
  #panel.collapsed #clearQuick { display: block; }                              /* folded: Clear stays reachable next to Menu */
  #panel.collapsed > :not(.sheethead):not(#result) { display: none; }          /* collapsed: title bar plus the route summary */
  #panel.collapsed #result > :not(.big) { display: none; }
  .row.opts { flex-wrap: wrap; }
  .row.opts label.chk { flex: 1 1 40%; }
  .modalbody { padding: 16px; }
}

/* On phones the results list is portaled to body so the scrollable bottom
   sheet cannot clip it, including when the virtual keyboard opens. */
@media (max-width: 700px) {
  body > #searchResults {
    position: fixed;
    z-index: 2000;
    box-sizing: border-box;
    margin: 0;
    overscroll-behavior: contain;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .55);
  }
}
