:root {
  --bg: #eef3ec;
  --surface: #ffffff;
  --fg: #1f2a20;
  --muted: #66746a;
  --line: #dde6da;
  --accent: #2e7d32;
  --accent-strong: #1b5e20;
  --accent-soft: #e3f1e3;
  --sun: #ffca28;
  --danger: #d32f2f;
  --danger-soft: #fdecea;
  --shadow: 0 2px 10px rgba(27, 60, 30, .08), 0 1px 2px rgba(27, 60, 30, .06);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .22);
  --radius: 16px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101510;
    --surface: #1a221b;
    --fg: #e7eee6;
    --muted: #9aa99d;
    --line: #2b382c;
    --accent: #66bb6a;
    --accent-strong: #2e7d32;
    --accent-soft: #1f3321;
    --danger: #ef5350;
    --danger-soft: #3a1f1f;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
h2 { font-size: 1.05rem; font-weight: 800; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
h2 > i { color: var(--accent); width: 1.2em; text-align: center; }
.muted { color: var(--muted); font-size: .88rem; margin: 6px 0; }
.error { color: var(--danger); }
ul, ol { padding: 0; margin: 0; list-style: none; }
code { font-size: .85em; }

/* ---------- header ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--accent-strong), #388e3c);
  color: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: rgba(255, 255, 255, .18); color: var(--sun); font-size: 1.05rem;
}
#topbar h1 { font-size: 1.2rem; font-weight: 900; margin: 0; letter-spacing: .2px; white-space: nowrap; }
#role-box { display: flex; align-items: center; gap: 8px; }
.role-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, .16); white-space: nowrap;
}
button.ghost {
  background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .35);
  display: inline-flex; align-items: center; gap: 6px;
}
button.ghost:hover { background: rgba(255, 255, 255, .24); border-color: #fff; }
#demo-banner {
  background: #fff3cd; color: #5c4400; padding: 6px 16px; font-size: .85rem;
}

/* ---------- layout ---------- */
#layout { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; min-height: 300px; background: #dfe8dc; }
#map.adding { cursor: crosshair; }
#panel {
  width: 380px; overflow-y: auto; padding: 14px 14px 28px;
  background: var(--bg); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
}
#panel > section[hidden], #admin-panel[hidden] { display: none; }
#admin-panel { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}

/* ---------- hero image ---------- */
.hero {
  position: relative; border-radius: var(--radius); overflow: hidden; min-height: 132px;
  box-shadow: var(--shadow); color: #0d2b10; flex: none;
}
.hero-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-text { position: relative; padding: 14px 16px; }
.hero-text h2 { font-size: 1.25rem; font-weight: 900; margin: 0 0 4px; color: #0d2b10; }
#free-count {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  background: rgba(255, 255, 255, .85); padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700;
}

/* ---------- scoreboard ---------- */
#scoreboard { display: flex; flex-direction: column; gap: 8px; }
#scoreboard li {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 14px; background: var(--bg);
  border-left: 6px solid var(--team, #9e9e9e);
}
#scoreboard li.leader { background: var(--accent-soft); }
.rank {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; font-size: .95rem; color: var(--muted); background: var(--surface);
}
.rank.gold { color: #fff; background: linear-gradient(135deg, #ffd54f, #f9a825); }
.rank.silver { color: #fff; background: linear-gradient(135deg, #cfd8dc, #90a4ae); }
.rank.bronze { color: #fff; background: linear-gradient(135deg, #ffb380, #d17a3b); }
.team-info { min-width: 0; }
#scoreboard .team-name { font-weight: 800; font-size: 1.05rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 7px; border-radius: 999px; background: var(--line); margin-top: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--team); transition: width .5s ease; }
#scoreboard .score { font-weight: 900; font-size: 1.6rem; font-variant-numeric: tabular-nums; line-height: 1; }
.swatch {
  width: 16px; height: 16px; border-radius: 50%; flex: none; display: inline-block;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px rgba(0, 0, 0, .15);
}

/* ---------- controls ---------- */
button, .file-btn {
  font: inherit; font-size: .92rem; font-weight: 700; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
button:hover, .file-btn:hover { border-color: var(--muted); }
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary, button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
button.small { padding: 5px 9px; }
button.link {
  border: none; background: none; padding: 2px 0; font-weight: 700; color: var(--fg);
}
button.link:hover { color: var(--accent); }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; flex: none; }
input, select {
  font: inherit; font-size: .95rem; padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type=color] { padding: 2px; width: 40px; height: 40px; flex: none; border-radius: 50%; cursor: pointer; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 50%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }
.btn-col > * { justify-content: flex-start; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input:not([type=color]) { flex: 1; }
#team-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-list li {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px;
  border-radius: 999px; background: var(--bg);
}
#player-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
#player-list li:last-child { border-bottom: none; }
.me-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#gps-me { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0; font-size: 1rem; }

/* toggle switch */
.switch { position: relative; display: flex; gap: 10px; align-items: center; font-weight: 700; cursor: pointer; }
/* The real checkbox sits invisibly over the switch, inside the scrolling panel. If it were positioned
   relative to anything outside the panel, focusing it on click would scroll the whole page. */
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.slider {
  width: 48px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none;
  transition: background .2s ease;
}
.slider::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s ease;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- map markers ---------- */
.pt {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 14px; border: 3px solid #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .35), 0 0 0 1px rgba(0, 0, 0, .15);
}
.pt.free { color: rgba(255, 255, 255, .9); }
.hiker { background: none; border: none; }
.hiker .pin {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 3px solid #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
}
.hiker i {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff;
  font-size: 15px; text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.hiker.me i { font-size: 19px; }
.hiker .pulse {
  position: absolute; left: 50%; top: 121%; width: 26px; height: 10px; margin: -5px 0 0 -13px;
  border-radius: 50%; opacity: .5; z-index: -1; animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(.6); opacity: .7; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ---------- popups ---------- */
.leaflet-popup-content-wrapper { border-radius: 16px; box-shadow: var(--shadow-lg); }
.leaflet-popup-content { margin: 14px 16px; font-family: "Nunito", system-ui, sans-serif; font-size: .95rem; }
.popup { min-width: 210px; }
.popup strong { font-size: 1.1rem; font-weight: 900; display: block; }
.popup .owner { display: flex; align-items: center; gap: 6px; color: #5f6b62; margin: 2px 0 6px; }
.popup .muted { color: #5f6b62; }
.popup button { background: #fff; color: #1f2a20; border-color: #dde6da; }
.team-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.team-picker button, .popup button.capture, .join-teams button {
  color: #fff; border: 2px solid transparent; text-shadow: 0 1px 2px rgba(0, 0, 0, .45); font-weight: 800;
}
.team-picker button.selected { box-shadow: 0 0 0 2px #fff inset, 0 0 0 2px #1f2a20; }
.team-picker button.nobody { background: #9e9e9e; }
.admin-edit { margin-top: 10px; padding-top: 10px; border-top: 1px solid #e5ebe3; }
.admin-edit input { width: 100%; background: #fff; color: #000; border-color: #ccd6c9; }
.popup button.danger { color: #d32f2f; }

/* ---------- dialogs ---------- */
dialog {
  border: none; border-radius: 22px; padding: 22px 20px 18px; box-shadow: var(--shadow-lg);
  background: var(--surface); color: var(--fg); width: min(360px, calc(100% - 32px));
}
dialog h2 { justify-content: center; font-size: 1.25rem; margin-bottom: 6px; }
dialog .muted { text-align: center; }
dialog input { width: 100%; margin: 8px 0; }
dialog .btn-row { justify-content: center; }
dialog::backdrop { background: rgba(10, 30, 12, .45); backdrop-filter: blur(2px); }
.dialog-icon {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 18px; display: grid; place-items: center;
  font-size: 1.5rem; color: var(--accent); background: var(--accent-soft);
}
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: .9rem; font-weight: 700; }
.field select, .field input { width: 100%; margin: 0; }
.join-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.join-teams button { font-size: 1.05rem; padding: 18px 8px; border-radius: 16px; flex-direction: column; gap: 4px; }
.join-teams button i { font-size: 1.4rem; }

/* ---------- floating GPS controls ---------- */
#gps-float {
  /* Kept above the bottom of the map so the Mapy.com logo stays visible. */
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 1500;
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: calc(100% - 32px);
}
#gps-float[hidden], #gps-capture[hidden], #gps-join[hidden], #gps-pill[hidden], #gps-sync[hidden] { display: none; }
#gps-capture, #gps-join {
  font-size: 1.2rem; font-weight: 900; padding: 15px 26px; border-radius: 999px;
  color: #fff; border: 3px solid #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .45);
  box-shadow: var(--shadow-lg);
}
#gps-join { background: linear-gradient(135deg, #43a047, var(--accent-strong)); }
#gps-capture { animation: bounce-in .35s ease-out; }
@keyframes bounce-in {
  0% { transform: scale(.6); opacity: 0; }
  70% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}
#gps-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(20, 30, 22, .86); color: #fff; padding: 8px 16px; border-radius: 999px;
  font-size: .9rem; font-weight: 700; text-align: center; backdrop-filter: blur(4px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
}
#gps-sync {
  background: rgba(20, 30, 22, .72); color: #c8e6c9; padding: 3px 12px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; display: flex; align-items: center; gap: 6px;
}
#gps-sync.error { color: #fff; background: rgba(198, 40, 40, .92); }

#toast {
  position: fixed; left: 50%; top: 76px; transform: translateX(-50%);
  background: #1f2a20; color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 2000;
  font-weight: 700; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px); text-align: center;
}

/* ---------- point lock ---------- */
.pt { position: relative; }
.lock-badge {
  position: absolute; right: -8px; top: -8px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; background: #263238; color: #fff; font-size: 9px;
  border: 2px solid #fff;
}
.lock-note {
  white-space: nowrap;
  margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #fff3e0; color: #7a3500; font-weight: 700;
}
.lock-note strong { font-variant-numeric: tabular-nums; }
#lock-minutes { width: 90px; flex: none !important; }
.unit { color: var(--muted); font-weight: 700; margin-right: auto; }

/* ---------- countdown ---------- */
#countdown {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 7px 16px; background: #fff8e1; color: #5d4300; font-weight: 800; font-size: .95rem;
  border-bottom: 1px solid #ffe082; z-index: 1000;
}
#countdown strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
#countdown.soon { background: #ffe0b2; color: #7a3500; border-color: #ffb74d; }
#countdown.soon i { animation: pulse-icon 1s ease-in-out infinite; }
#countdown.over { background: #263238; color: #fff; border-color: #263238; }
@keyframes pulse-icon { 50% { transform: scale(1.25); } }
.deadline-form { margin: 10px 0 4px; }
.game-over-note {
  margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #eceff1; color: #263238; font-weight: 700;
}

/* ---------- tab bar (phones) ---------- */
#tabbar { display: none; }
@media (max-width: 760px) {
  body { height: 100vh; height: 100dvh; overflow: hidden; }
  #layout { flex-direction: column; position: relative; }
  #map { flex: 1; min-height: 0; }
  #panel { width: 100%; border-left: none; flex: 1; }
  body[data-tab="map"] #panel, body[data-tab="score"] #map { display: none; }
  body[data-tab="score"] #gps-float { display: none; }
  #role-box .ghost span { display: none; }
  #tabbar {
    display: flex; gap: 8px; padding: 8px 16px; padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--surface); box-shadow: 0 -2px 12px rgba(0, 0, 0, .1); z-index: 1001;
  }
  #tabbar button {
    flex: 1; flex-direction: column; gap: 2px; border: none; border-radius: 14px; background: none;
    padding: 6px 0; font-size: .78rem; font-weight: 800; color: var(--muted);
  }
  #tabbar button i { font-size: 1.25rem; }
  #tabbar button.active { color: var(--accent); background: var(--accent-soft); }
  #gps-float { bottom: calc(var(--tabbar-h) + 44px + env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) {
  #topbar h1 { font-size: 1.05rem; }
  .role-chip { padding: 4px 8px; }
}
