:root {
  --bg: #0d1720;
  --surface: rgba(16, 26, 36, 0.92);
  --surface-solid: #111c27;
  --line: rgba(160, 200, 220, 0.16);
  --text: #e8f1f5;
  --muted: #9db0bb;
  --accent: #5fd3c6;
  --accent-ink: #062521;
  --magic: #b48cff;
  --warn: #ffcf6b;
  --bad: #ff7a7a;
  --done: #6b7d88;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#map { position: fixed; inset: 0; background: #0e3a42; }
.leaflet-container { background: #0e3a42; font: inherit; }
.leaflet-control-zoom a { background: var(--surface-solid); color: var(--text); border-color: var(--line) !important; }
.leaflet-control-zoom a:hover { background: #1b2a37; }
.leaflet-bottom.leaflet-right { margin-bottom: 26px; }

/* top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.spacer { flex: 1; pointer-events: none; }
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-weight: 600; letter-spacing: 0.02em; white-space: nowrap;
}
.brand b { color: var(--accent); font-weight: 700; }
.brand-mark { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, var(--magic), #4b2b8a); box-shadow: 0 0 10px rgba(180, 140, 255, 0.6); }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.pill::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill[data-state="live"]::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 2s infinite; }
.pill[data-state="connecting"]::before { background: var(--warn); }
.pill[data-state="error"]::before { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.45; } }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.small { width: 30px; height: 30px; box-shadow: none; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn:hover, .pill:hover { border-color: rgba(95, 211, 198, 0.5); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* progress panel */
.panel {
  position: fixed; z-index: 1000; top: 64px; right: 16px; width: 330px; max-height: calc(100% - 110px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; padding: 14px 14px 8px; }
.panel-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.panel h2 { margin: 2px 0 0; font-size: 18px; overflow-wrap: anywhere; }
.panel h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.panel-body { overflow: auto; padding: 0 14px 14px; }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed #panelToggle svg { transform: rotate(180deg); }
.counts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.count { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.count b { font-size: 16px; }
.count span:last-child { grid-column: 2; color: var(--muted); font-size: 12px; }
.count-icon { grid-row: span 2; width: 22px; height: 22px; background: center / contain no-repeat; }
.count-icon.chest { background-image: url(/icons/chest.svg); }
.count-icon.satchel { background-image: url(/icons/satchel.svg); }
.note { margin: 10px 0 0; color: var(--muted); }
.quests { display: grid; gap: 8px; }
.quest { padding: 9px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.quest-cat { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--magic); }
.quest-name { font-weight: 600; margin: 1px 0 4px; }
.quest.complete .quest-name::after { content: " ✓"; color: var(--accent); }
.objective { display: flex; justify-content: space-between; gap: 10px; color: var(--text); font-size: 13px; padding: 2px 0; }
.objective.complete { color: var(--done); text-decoration: line-through; }
.objective .amt { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* settings dialog */
.dialog {
  width: min(460px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0;
  color: var(--text); background: var(--surface-solid); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(3, 8, 12, 0.6); }
.dialog form { padding: 16px 18px 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field > span { font-weight: 600; }
.field small { color: var(--muted); }
.field input, .field select {
  width: 100%; padding: 9px 10px; border-radius: 8px;
  background: #0b131b; border: 1px solid var(--line);
}
.field input:focus, .field select:focus { border-color: var(--accent); outline: none; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.btn { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #1a2733; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: default; }

.disclaimer {
  position: fixed; left: 0; bottom: 0; z-index: 900; max-width: 100%;
  padding: 3px 10px calc(3px + env(safe-area-inset-bottom)); font-size: 11px; color: var(--muted);
  background: rgba(13, 23, 32, 0.7); border-top-right-radius: 8px;
}

/* map markers */
.mk { width: 22px !important; height: 22px !important; margin: -11px 0 0 -11px !important; background: center / contain no-repeat; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7)); }
.mk.chest { background-image: url(/icons/chest.svg); }
.mk.satchel { background-image: url(/icons/satchel.svg); width: 18px !important; height: 18px !important; margin: -9px 0 0 -9px !important; }
.mk.landmark { background-image: url(/icons/landmark.svg); width: 18px !important; height: 18px !important; margin: -9px 0 0 -9px !important; }
.mk.landmark.undiscovered { opacity: 0.45; }
.mk.underground { border-radius: 50%; box-shadow: 0 0 0 2px rgba(180, 140, 255, 0.85), 0 0 8px rgba(180, 140, 255, 0.6); background-color: rgba(27, 13, 51, 0.6); }
.mk.done { opacity: 0.4; filter: grayscale(1); }
.mk.done::after { content: ""; position: absolute; right: -4px; bottom: -4px; width: 12px; height: 12px; background: url(/icons/check.svg) center / contain no-repeat; }
.mk.cooldown::after { background-image: url(/icons/clock.svg); }
.hide-done .mk.done { display: none; }
/* zoomed out: smaller markers so islands stay readable */
.zoom-far .mk.chest { width: 12px !important; height: 12px !important; margin: -6px 0 0 -6px !important; }
.zoom-far .mk.satchel, .zoom-far .mk.landmark { width: 11px !important; height: 11px !important; margin: -5px 0 0 -5px !important; }
.zoom-far .mk.done::after { width: 7px; height: 7px; right: -2px; bottom: -2px; }

.player-mk { width: 0 !important; height: 0 !important; }
.player-mk .arrow {
  position: absolute; left: -12px; top: -12px; width: 24px; height: 24px;
  background: url(/icons/player.svg) center / contain no-repeat;
  filter: drop-shadow(0 0 6px rgba(180, 140, 255, 0.9));
}
.player-mk.selected .arrow { filter: drop-shadow(0 0 8px rgba(95, 211, 198, 1)); }
.player-mk .label {
  position: absolute; left: 0; top: 14px; transform: translateX(-50%);
  padding: 1px 7px; border-radius: 999px; white-space: nowrap; font-size: 12px; font-weight: 600;
  background: rgba(13, 23, 32, 0.85); border: 1px solid rgba(180, 140, 255, 0.5);
}
.leaflet-tooltip { background: var(--surface-solid); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-tooltip-top::before { border-top-color: var(--surface-solid); }

@media (max-width: 700px) {
  .brand { display: none; }
  .pill { max-width: calc(100vw - 90px); }
  .panel { top: auto; bottom: 30px; left: 8px; right: 8px; width: auto; max-height: 45%; }
  .leaflet-control-zoom { display: none; }
  .disclaimer { font-size: 10px; border-top-right-radius: 0; right: 0; text-align: center; }
  .toggles { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .pill[data-state="live"]::before { animation: none; }
}
