:root {
  --bg: #f7f4ec;
  --surface: #fffdf7;
  --ink: #1f2a22;
  --muted: #5d6b61;
  --line: #ddd6c4;
  --accent: #2f6b3f;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --gold: #b7791f;
  --shadow: 0 6px 24px rgba(20, 30, 22, 0.18);

  /* Map colours */
  --guarded: #2f9e44;
  --pending: #f2b01e;
  --unguarded: #d9480f;
  --trail: #1c7ed6;
  --trace: #7048e8;
  --swept: #12b886;
  --position: #1c7ed6;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a16;
    --surface: #1d2620;
    --ink: #e9e6dc;
    --muted: #9aa89e;
    --line: #34413a;
    --accent: #4c9a61;
    --accent-ink: #0d140f;
    --danger: #f97066;
    --gold: #e0a84a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* --- Level / XP header ------------------------------------------------------------ */

#hud {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 12px;
  right: 12px;
  z-index: 500;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-name { flex: 1; min-width: 0; }
.hud-name strong { margin-right: 6px; }

.badge {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-weight: 700;
}

.chip {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--line);
  color: var(--ink);
  white-space: nowrap;
}
.chip.good { background: var(--guarded); color: #fff; }
.chip.poor { background: var(--unguarded); color: #fff; }
.chip.sim { background: var(--trace); color: #fff; }

.xpbar {
  height: 8px;
  margin: 8px 0 4px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}

#hud-xpfill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), #f5c46b);
  transition: width 0.6s ease;
}

/* --- Bottom panel ----------------------------------------------------------------- */

.panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  max-height: 70vh;
  overflow-y: auto;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.panel p { margin: 6px 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.stats.cols-3 { grid-template-columns: repeat(3, 1fr); }

@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
}

.stat {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stat b {
  display: block;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 0.75rem;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

button, .button {
  flex: 1 1 auto;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

label {
  display: block;
  margin: 10px 0 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.error {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 14px;
  height: 4px;
  margin-right: 5px;
  vertical-align: middle;
  border-radius: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
td { padding: 6px 0; border-bottom: 1px solid var(--line); }
td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Login overlay ---------------------------------------------------------------- */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 30% 20%, #3f7a50, #16241b 70%);
}

.card {
  width: 100%;
  max-width: 380px;
  padding: 24px 20px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

/* --- Floating button and toasts --------------------------------------------------- */

.fab {
  position: fixed;
  right: 14px;
  bottom: calc(var(--panel-h, 0px) + 36px);
  z-index: 400;
  flex: none;
  width: 48px;
  height: 48px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.4rem;
}

.fab-second { bottom: calc(var(--panel-h, 0px) + 96px); }

#toasts {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 110px);
  left: 16px;
  right: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 600;
  text-align: center;
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.leaving { opacity: 0; transform: translateY(-8px); }
.toast-error { background: var(--danger); color: #fff; }
.toast-xp { background: var(--gold); color: #fff; }
.toast-big { background: var(--accent); color: var(--accent-ink); font-size: 1.1rem; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  .toast, #hud-xpfill { animation: none; transition: none; }
}

/* Keep the map's bottom controls (the attribution) above the panel. */
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-bottom-left { bottom: var(--panel-h, 0px); }
.maplibregl-ctrl-attrib { font-size: 10px; }
