/* Draeda Atlas. Light + dark via tokens; dark follows the device unless the
   viewer picks one (data-theme on <html>). Phone first: the panel is a
   bottom sheet under 760px, a side panel above. */

:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #efe9dd;
  --text: #22201c;
  --muted: #6b655a;
  --line: #d9d1c1;
  --accent: #8a5a1c;
  --accent-text: #ffffff;
  --shadow: 0 6px 24px rgba(40, 30, 10, .18);
  --deed: #b5651d;
  --deed-fill: rgba(181, 101, 29, .12);
  --perim: rgba(181, 101, 29, .9);
  --cover: rgba(46, 125, 220, .16);
  --unfinished: #d62f2f;
  --player: #7b3fe4;
  --bot: #12a39a;
  --warn: #c0392b;
  --map-bg: #2f5e78;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b;
    --surface: #1b2027;
    --surface-2: #242b34;
    --text: #e9e5dc;
    --muted: #9aa3ad;
    --line: #333c47;
    --accent: #e0a458;
    --accent-text: #1b1406;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    --deed: #f0a050;
    --deed-fill: rgba(240, 160, 80, .14);
    --perim: rgba(240, 160, 80, .9);
    --cover: rgba(90, 160, 255, .2);
    --unfinished: #ff5a5a;
    --player: #b98cff;
    --bot: #3fd6c9;
    --warn: #ff7a6a;
    --map-bg: #0d2433;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12161b;
  --surface: #1b2027;
  --surface-2: #242b34;
  --text: #e9e5dc;
  --muted: #9aa3ad;
  --line: #333c47;
  --accent: #e0a458;
  --accent-text: #1b1406;
  --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  --deed: #f0a050;
  --deed-fill: rgba(240, 160, 80, .14);
  --perim: rgba(240, 160, 80, .9);
  --cover: rgba(90, 160, 255, .2);
  --unfinished: #ff5a5a;
  --player: #b98cff;
  --bot: #3fd6c9;
  --warn: #ff7a6a;
  --map-bg: #0d2433;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#map { position: fixed; inset: 0; background: var(--map-bg); }
.leaflet-container { background: var(--map-bg); font: inherit; }
/* Dark mode dims the terrain a little so markers keep contrast. */
:root[data-theme="dark"] .leaflet-tile-pane { filter: brightness(.82) saturate(.9); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: brightness(.82) saturate(.9); }
}

#bar {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; gap: 8px; align-items: center; z-index: 1000;
  padding: 6px 8px; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.logo { color: var(--accent); font-size: 18px; }
.badge {
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  background: var(--accent); color: var(--accent-text);
}
.search { position: relative; flex: 1; min-width: 0; }
#q {
  width: 100%; padding: 8px 10px; border-radius: 8px; font: inherit;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
}
#results {
  position: absolute; top: 40px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  max-height: 50vh; overflow: auto; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
#results li { padding: 8px; border-radius: 6px; cursor: pointer; }
#results li:hover, #results li.on { background: var(--surface-2); }
#results small { color: var(--muted); display: block; }
button.icon {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font-size: 16px; cursor: pointer;
}

#panel {
  position: fixed; z-index: 999; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  top: 70px; right: 10px; bottom: 10px; width: 300px; border-radius: 12px; padding: 4px 14px 14px;
  transition: transform .2s ease;
}
#panel.closed { transform: translateX(calc(100% + 20px)); }
#panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
#panel label { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
#panel ul { list-style: none; margin: 0; padding: 0; }
#panel li { padding: 6px 4px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
#panel li:hover { background: var(--surface-2); }
#panel li small { color: var(--muted); margin-left: auto; text-align: right; }
#panel li > span:not(.swatch) { white-space: nowrap; }
.swatch { width: 14px; height: 4px; border-radius: 2px; flex: none; }
.hint { color: var(--muted); margin: 4px 0; font-size: 13px; }
.route { display: grid; gap: 6px; }
.route select, .route button {
  font: inherit; padding: 7px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); width: 100%;
}
.route button { background: var(--accent); color: var(--accent-text); border: 0; font-weight: 600; cursor: pointer; }
.meta p { color: var(--muted); font-size: 12px; margin: 4px 0; }
.grip { display: none; }
.admin-only { display: none !important; }
body.is-admin .admin-only { display: block !important; }
body.is-admin label.admin-only { display: flex !important; }

#coords {
  position: fixed; left: 10px; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 998;
  padding: 4px 8px; border-radius: 8px; font: 12px/1.3 ui-monospace, monospace;
  background: var(--surface); color: var(--muted); border: 1px solid var(--line);
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 15px; }
.leaflet-popup-content .muted { color: var(--muted); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }
.leaflet-control-attribution { background: var(--surface) !important; color: var(--muted) !important; }
.leaflet-tooltip { background: var(--surface); color: var(--text); border-color: var(--line); }
.deed-label {
  background: transparent; border: 0; box-shadow: none; color: #fff; font-weight: 600;
  text-shadow: 0 0 3px #000, 0 0 2px #000;
}
.deed-label::before { display: none; }

@media (max-width: 760px) {
  .brand #title { display: none; }
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh;
    border-radius: 16px 16px 0 0; padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  #panel.closed { transform: translateY(calc(100% - 28px)); }
  .grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; }
  #coords { display: none; }
  .leaflet-bottom { bottom: 34px; }
}

/* Guard towers: small squares, so they never read as highway nodes. */
.tower { width: 0; height: 0; }
.tower i {
  position: absolute; left: -5px; top: -5px; width: 10px; height: 10px;
  border: 2px solid #fff; border-radius: 2px; box-shadow: 0 0 2px rgba(0,0,0,.6);
}
.zlow .tower i { left: -3px; top: -3px; width: 6px; height: 6px; border-width: 1px; }
.zhigh .tower i { left: -7px; top: -7px; width: 14px; height: 14px; }
.leaflet-overlay-pane path.cover { mix-blend-mode: screen; }

/* Players vs vassals: round purple dots vs small teal diamonds, so a bot never
   reads as a person at a glance. */
.key { width: 12px; height: 12px; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.key-player { border-radius: 50%; background: var(--player); }
.key-bot { width: 10px; height: 10px; transform: rotate(45deg); border-radius: 2px; background: var(--bot); margin: 0 1px; }
#panel label .count { margin-left: auto; color: var(--muted); }
.bot { width: 0; height: 0; }
.bot i {
  position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; transform: rotate(45deg);
  background: var(--bot); border: 2px solid #fff; border-radius: 2px; box-shadow: 0 0 2px rgba(0,0,0,.6);
}
.bot.npc i { background: #8a94a0; }

/* Deed card */
.deed-pop .leaflet-popup-content { margin: 0; width: auto !important; min-width: 240px; }
.card { padding: 12px 14px 10px; }
.card-head h3 { margin: 0; font-size: 16px; line-height: 1.25; padding-right: 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag {
  font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.tag-ally { color: var(--accent); border-color: var(--accent); }
.motto { margin: 8px 0 0; font-style: italic; color: var(--muted); }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 8px;
}
.stats div {
  background: var(--surface-2); border-radius: 8px; padding: 6px 4px; text-align: center;
  display: flex; flex-direction: column;
}
.stats b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
.card dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
.card dd { margin: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card dd.warn { color: var(--warn); font-weight: 600; }
.card dd .swatch { width: 10px; height: 10px; border-radius: 3px; }
.card details { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.card summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.card details p { margin: 6px 0 0; color: var(--muted); font-size: 13px; max-height: 120px; overflow: auto; }
.card-foot {
  margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line);
  font: 11px/1.3 ui-monospace, monospace; color: var(--muted);
}

/* Keep Leaflet's zoom buttons clear of the top bar. */
.leaflet-top { top: 64px; }
