/* Night map with white sheets; neon lime is the single action colour. */
:root {
  --lime: #45f03a;
  --lime-soft: #c8f9c2;
  --ink: #0f140f;
  --sheet: #ffffff;
  --surface: #f2f3f5;
  --line: #e3e5e8;
  --muted: #7b8089;
  --map: #2a2e33;
  --danger: #e5484d;
  --radius-sheet: 28px;
  --tabbar-h: 64px;
  --font: Vazirmatn, Tahoma, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--map);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

.num { font-variant-numeric: tabular-nums; }
.display { font-weight: 900; }

main { flex: 1; position: relative; overflow: hidden; }

.view { display: none; position: absolute; inset: 0; overflow-y: auto; }
.view.active { display: block; }
#view-play { overflow: hidden; }
#map { position: absolute; inset: 0; }

/* ---------- Top bar ---------- */

.topbar {
  position: absolute;
  inset: 0 0 auto;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: var(--sheet);
  border-radius: 0 0 22px 22px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.badge {
  width: 40px;
  height: 46px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 20px;
  color: #fff;
  background: var(--user-color, #e5484d);
  clip-path: polygon(0 0, 100% 0, 100% 72%, 50% 100%, 0 72%);
  border: 0;
}

.wordmark {
  font-weight: 900;
  font-size: 26px;
  line-height: 1;
  position: relative;
}
.wordmark::after {
  content: "";
  position: absolute;
  inset-inline-start: 6px;
  bottom: -5px;
  width: 16px;
  height: 4px;
  background: var(--lime);
  border-radius: 2px;
}

.topbar-end { margin-inline-start: auto; display: flex; gap: 8px; }

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
}
.caret { font-size: 11px; color: var(--muted); }

.menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 16px;
  background: var(--sheet);
  border-radius: 18px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  min-width: 200px;
}
.menu button { text-align: start; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.menu button.active { background: var(--lime-soft); }

.plan-head { justify-content: space-between; }
.back { font-weight: 800; padding: 8px 4px; }
.plan-metrics { display: flex; gap: 18px; }
.plan-metrics span { display: flex; align-items: baseline; gap: 6px; }
.plan-metrics small { color: var(--muted); font-size: 12px; }
.plan-metrics b { font-size: 18px; font-weight: 900; white-space: nowrap; }

/* ---------- Map overlay ---------- */

.map-overlay {
  position: absolute;
  top: calc(84px + env(safe-area-inset-top));
  inset-inline: 16px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.map-overlay > * { pointer-events: auto; }

.chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--sheet);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.chip b { font-size: 17px; font-weight: 800; }
.chip small { font-size: 12px; color: var(--muted); }
.chip-icon { color: var(--user-color, var(--danger)); }

.round {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sheet);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  font-size: 20px;
}
.round.light { background: var(--surface); box-shadow: none; }

.toast {
  position: absolute;
  top: calc(140px + env(safe-area-inset-top));
  inset-inline: 16px;
  z-index: 6;
  background: #15191d;
  color: #fff;
  padding: 14px 18px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-line;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.toast.error { background: var(--danger); }

/* ---------- Bottom dock ---------- */

.dock {
  position: absolute;
  inset-inline: 12px;
  bottom: 12px;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.dock-side, .dock-start {
  border-radius: 22px;
  font-weight: 800;
  font-size: 17px;
  padding: 16px 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.dock-side { background: var(--sheet); }
.dock-start { background: var(--lime); color: var(--ink); }

.ruler {
  background: var(--sheet);
  border-radius: 22px;
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.ruler-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ruler-name b { font-weight: 800; }
.ruler small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Sheets ---------- */

.sheet {
  position: absolute;
  inset: auto 0 0;
  z-index: 5;
  background: var(--sheet);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 22px 20px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
}
.sheet.tall { max-height: 88%; overflow-y: auto; }

.big-area { display: flex; align-items: baseline; gap: 6px; line-height: 1; }
.big-area span { font-size: 64px; font-weight: 900; }
.big-area small { font-size: 16px; font-weight: 800; }

.status {
  padding: 6px 14px;
  border-radius: 999px;
  background: #dfe8ff;
  color: #1f4fd6;
  font-size: 13px;
  font-weight: 700;
}
.status.ready { background: var(--lime-soft); color: #1d6b16; }
.status.paused { background: #ffe7c2; color: #8a5300; }

.stats3 {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  gap: 8px;
}
.stats3 small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.stats3 b { font-size: 26px; font-weight: 800; }
.stats3 i { display: block; font-style: normal; font-size: 11px; color: var(--muted); }

.sheet-actions { width: 100%; display: flex; gap: 10px; align-items: center; }
.sheet-actions .btn { flex: 1; }

.btn {
  border-radius: 999px;
  padding: 16px 18px;
  font-weight: 800;
  font-size: 16px;
  text-align: center;
}
.btn.wide { width: 100%; }
.btn-lime { background: var(--lime); color: var(--ink); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-light { background: var(--surface); }
.btn-ghost { color: var(--muted); padding-inline: 10px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; }

.title-field {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-block: 6px;
}
.title-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  background: none;
}
.title-field span { color: var(--muted); }

textarea {
  width: 100%;
  font: inherit;
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  padding: 12px 14px;
  resize: none;
}

.confirm {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: #fff1f1;
  border-radius: 16px;
  padding: 12px;
  font-size: 14px;
}
.confirm span { flex-basis: 100%; }
.confirm .btn { flex: 1; padding-block: 10px; }

.hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.8; text-align: center; }

/* ---------- Rankings ---------- */

#view-ranks, #view-me { background: var(--sheet); padding: calc(16px + env(safe-area-inset-top)) 16px 24px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-head h2 { margin: 0; font-size: 28px; font-weight: 900; }

.segmented { display: flex; background: var(--surface); border-radius: 999px; padding: 4px; }
.segmented button { padding: 8px 16px; border-radius: 999px; font-weight: 700; color: var(--muted); }
.segmented button.active { background: var(--lime-soft); color: var(--ink); }

.podium {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr;
  align-items: end;
  gap: 8px;
  margin-top: 22px;
}
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.podium-col .crown { font-size: 26px; height: 30px; }
.podium-col .name { font-weight: 800; font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-col .area { font-size: 13px; color: var(--muted); }
.podium-col .block {
  width: 100%;
  border-radius: 20px 20px 0 0;
  display: grid;
  place-items: start center;
  padding-top: 10px;
  font-weight: 900;
  font-size: 28px;
  color: #fff;
}
.podium-badge { width: 44px; height: 50px; font-size: 20px; }

.ranklist { list-style: none; padding: 0; margin: 16px 0 0; }
.ranklist li, .you-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.rank-no { font-weight: 900; font-size: 22px; width: 40px; }
.rank-badge { width: 34px; height: 39px; font-size: 15px; flex: none; }
.rank-name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-area { margin-inline-start: auto; font-weight: 700; white-space: nowrap; }
.you-row { background: var(--lime-soft); border-radius: 16px; padding-inline: 12px; margin-top: 10px; border: 0; }

h3 { font-size: 18px; font-weight: 900; margin: 28px 0 8px; }
.feed { list-style: none; padding: 0; margin: 0; }
.feed li { display: flex; gap: 10px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed time { margin-inline-start: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }

/* ---------- Me ---------- */

.me-head { display: flex; align-items: center; gap: 14px; }
.me-head .badge { width: 60px; height: 70px; font-size: 28px; }
.me-head h2 { margin: 0; font-size: 26px; font-weight: 900; }
.me-head p { margin: 2px 0 0; color: var(--muted); }

.me-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 20px; }
.me-stats div { background: var(--surface); border-radius: 18px; padding: 14px 10px; text-align: center; }
.me-stats b { display: block; font-size: 20px; font-weight: 900; }
.me-stats small { color: var(--muted); font-size: 12px; }

.activity { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.activity .act-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--surface); display: grid; place-items: center; }
.activity .act-main { min-width: 0; }
.activity .act-main b { display: block; }
.activity .act-main small { color: var(--muted); }
.activity .act-area { margin-inline-start: auto; font-weight: 800; white-space: nowrap; }

.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-block: 8px 4px; }
.swatch-btn {
  aspect-ratio: 1;
  border-radius: 18px;
  border: 3px solid transparent;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.swatch-btn.active { border-color: var(--ink); box-shadow: 0 0 0 3px var(--lime), inset 0 0 0 3px rgba(255, 255, 255, 0.35); }

/* ---------- Dialogs ---------- */

.sheet-dialog {
  border: 0;
  border-radius: var(--radius-sheet);
  padding: 26px 22px;
  width: min(420px, calc(100vw - 24px));
  margin: auto auto 12px;
}
.sheet-dialog::backdrop { background: rgba(10, 12, 14, 0.6); }
.sheet-dialog form { display: flex; flex-direction: column; gap: 14px; }
.sheet-dialog h2 { margin: 0; font-size: 28px; text-align: center; }
.sheet-dialog p { margin: 0; text-align: center; color: #3c4148; line-height: 1.8; }
.sheet-dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.sheet-dialog input {
  font: inherit;
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
}
.error { color: var(--danger); font-size: 14px; }

.intro-art {
  height: 170px;
  border-radius: 20px;
  background: var(--map);
  overflow: hidden;
}
.intro-art svg { width: 100%; height: 100%; display: block; }
.dots { display: flex; justify-content: center; gap: 6px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--lime); }

/* ---------- Tab bar ---------- */

.tabbar {
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 6px 12px env(safe-area-inset-bottom);
  background: var(--sheet);
  border-top: 1px solid var(--line);
  position: relative;
  z-index: 6;
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--ink); }
.tabbar button.active .tab-icon {
  background: var(--lime-soft);
  padding: 4px 18px;
  border-radius: 12px;
}

/* MapLibre */
.maplibregl-map { font-family: var(--font); }
.maplibregl-popup-content { font-family: var(--font); text-align: right; border-radius: 14px; padding: 12px 14px; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: 84px; }
.me-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #2f6bff;
  border: 3px solid #fff;
  box-shadow: 0 0 0 8px rgba(47, 107, 255, 0.25);
}

@media (prefers-reduced-motion: no-preference) {
  .sheet, .toast { animation: rise 0.25s ease-out; }
  @keyframes rise { from { transform: translateY(16px); opacity: 0; } }
}
