:root {
  --bg: #eef3f4;
  --surface: #ffffff;
  --ocean: #d6e4e9;
  --land: #fbfaf6;
  --land-hover: #f1ede2;
  --border: #a7bbc3;
  --ink: #14252e;
  --muted: #5a6f79;
  --line: #dde6e9;
  --visited: #d2344b;
  --visited-soft: #fbe3e6;
  --other: #1b8a84;
  --other-soft: #dcf1ef;
  --wish: #f2b8c0;
  --wish-ink: #b8862a;
  --gold: #c9971c;
  --whatsapp: #1fa855;
  --shadow: 0 10px 30px rgba(20, 37, 46, .14);
  --radius: 14px;
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b161c;
    --surface: #13232b;
    --ocean: #0f1e26;
    --land: #283a43;
    --land-hover: #33484f;
    --border: #3f5763;
    --ink: #e6eef1;
    --muted: #93a8b1;
    --line: #22363f;
    --visited: #ff5c70;
    --visited-soft: #3b1d25;
    --other: #3cc4bb;
    --other-soft: #173a3a;
    --wish: #6b3340;
    --wish-ink: #e6b84a;
    --gold: #e6b84a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--visited); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  border: 0; background: none; padding: 4px 6px 4px 0; text-align: left; border-radius: 10px;
}
.brand-text { display: flex; flex-direction: column; }
.caret { font-size: 16px; color: var(--muted); margin-left: 6px; }
.mark {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--visited);
  background: radial-gradient(circle, var(--visited) 0 5px, transparent 6px);
  transform: rotate(-12deg);
}
.brand-text { min-width: 0; }
.brand .title {
  margin: 0; font: 800 19px/1.1 var(--display); letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#groupSub { display: block; margin: 2px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 10px 18px;
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--visited); color: #fff; }
.btn-whatsapp { background: var(--whatsapp); color: #fff; }
.btn-ghost { background: transparent; border: 1.5px solid var(--border); color: var(--ink); }
.btn-text { background: none; color: var(--muted); }
.btn-small { padding: 7px 14px; font-size: 13.5px; }
.btn-danger { background: var(--visited); color: #fff; }
.btn-wide { width: 100%; padding: 13px 18px; }
.btn:disabled { opacity: .6; cursor: default; }

/* Layout */
main {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-rows: minmax(260px, 50%) 1fr;
}
@media (min-width: 900px) {
  main { grid-template-rows: none; grid-template-columns: 1fr 380px; }
}

/* Map */
#mapWrap { position: relative; background: var(--ocean); overflow: hidden; min-height: 0; }
#map {
  width: 100%; height: 100%; display: block; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.sphere { fill: var(--ocean); }
.country {
  fill: var(--land); stroke: var(--border); stroke-width: .6px;
  vector-effect: non-scaling-stroke; cursor: pointer;
  transition: fill .18s ease;
}
@media (hover: hover) { .country:hover { fill: var(--land-hover); } }
.country.on { fill: var(--visited); stroke: color-mix(in srgb, var(--visited) 70%, #000); }
.country.wish { fill: var(--wish); }
.viewing-other .country.on { fill: var(--other); stroke: color-mix(in srgb, var(--other) 70%, #000); }
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }

.zoom {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; flex-direction: column; border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow); background: var(--surface);
}
.zoom button {
  width: 40px; height: 40px; border: 0; background: var(--surface);
  font-size: 20px; line-height: 1; color: var(--ink);
}
.zoom button + button { border-top: 1px solid var(--line); }

.chip {
  position: absolute; left: 12px; top: 12px; right: 64px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  width: max-content; max-width: calc(100% - 24px);
  padding: 8px 8px 8px 14px; border-radius: 999px;
  background: var(--other); color: #fff; font-weight: 600; font-size: 13.5px;
  box-shadow: var(--shadow);
}
.chip button { border: 0; border-radius: 999px; padding: 5px 12px; background: rgba(255,255,255,.22); color: #fff; font-weight: 600; font-size: 13px; }

#toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  max-width: calc(100% - 120px);
  padding: 8px 14px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: var(--shadow); pointer-events: none;
}

/* Panel */
#panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-top: 1px solid var(--line);
}
@media (min-width: 900px) { #panel { border-top: 0; border-left: 1px solid var(--line); } }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: none; padding: 10px 6px 12px;
  font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--visited); }
.pill {
  min-width: 22px; padding: 1px 7px; border-radius: 999px;
  background: var(--line); color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums;
}
.tabpanel {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 12px;
}

.score { display: flex; flex-direction: column; gap: 8px; }
.score-num { display: flex; align-items: baseline; gap: 8px; }
.score-num b { font: 800 40px/1 var(--display); color: var(--visited); font-variant-numeric: tabular-nums; }
.score-num span { color: var(--muted); font-weight: 500; }
.meter { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--visited); border-radius: inherit; transition: width .3s ease; }
.score-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.me-name button { border: 0; background: none; padding: 0; color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.save-state.err { color: var(--visited); }

.search input {
  width: 100%; padding: 11px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg);
  font-size: 16px; /* stops iOS zoom on focus */
}
.search input:focus { border-color: var(--border); outline: none; }
.only-mine { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.only-mine input { accent-color: var(--visited); width: 17px; height: 17px; }

.country-list { list-style: none; margin: 0; padding: 0; }
.country-list li + li { border-top: 1px solid var(--line); }
.country-list li { display: flex; align-items: center; }
.country-list label {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px; padding: 11px 4px; cursor: pointer;
}
.wish-btn {
  flex: none; width: 40px; height: 40px; border: 0; background: none;
  font-size: 20px; color: var(--border);
}
.wish-btn.active { color: var(--wish-ink); }
.country-list input { accent-color: var(--visited); width: 20px; height: 20px; flex: none; }
.country-list .on { font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; margin: 0; }

.hint { margin: 0; font-size: 13px; color: var(--muted); }
.hint b { color: var(--ink); font-weight: 600; }
.wish-count { display: block; margin-top: 4px; color: var(--wish-ink); font-weight: 600; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.stat { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; font-size: 13px; }
.stat .mini { grid-column: 1 / -1; }
.stat-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.zero { color: var(--muted); }
.leave { margin-top: 8px; font-size: 13.5px; }
.maps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.maps-list a {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px; background: var(--bg);
  color: var(--ink); font-weight: 600; text-decoration: none;
}
.maps-list a[aria-current] { border: 1.5px solid var(--visited); }
.maps-list a span { font-size: 12px; color: var(--visited); font-weight: 700; }
.passport-img { width: 100%; max-height: 55vh; object-fit: contain; border-radius: 12px; background: #14252e; }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.board li { display: flex; align-items: center; gap: 6px; }
.board .row {
  flex: 1; min-width: 0; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1.5px solid transparent; border-radius: 12px;
  background: var(--bg); text-align: left;
}
.remove-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: none; color: var(--muted); font-size: 22px; line-height: 1;
}
.remove-btn:hover { background: var(--bg); color: var(--visited); }
.board .active .row { border-color: var(--other); background: var(--other-soft); }
.board .rank {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font: 800 14px/1 var(--display); background: var(--line); color: var(--ink);
}
.board li:nth-child(1) .rank.r1 { background: var(--gold); color: #fff; }
.board .who { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.board .who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board .you { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--visited); margin-left: 6px; }
.mini { height: 5px; border-radius: 999px; background: var(--line); overflow: hidden; display: block; }
.mini i { display: block; height: 100%; background: var(--visited); border-radius: inherit; }
.board .mini { height: 5px; border-radius: 999px; background: var(--line); overflow: hidden; }
.board .mini i { display: block; height: 100%; background: var(--visited); border-radius: inherit; }
.board .num { font: 800 22px/1 var(--display); font-variant-numeric: tabular-nums; }

/* Dialogs */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 20, 26, .55);
  backdrop-filter: blur(3px);
}
.dialog {
  width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 24px 20px 20px; border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow);
}
.dialog h2 { margin: 0; font: 800 24px/1.15 var(--display); letter-spacing: -.01em; text-wrap: balance; }
.dialog p { margin: 0; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); font-size: 16px; font-weight: 500; color: var(--ink);
}
.field input:focus { border-color: var(--visited); outline: none; }
.error { color: var(--visited) !important; font-size: 13.5px; font-weight: 600; }
.recent { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.recent span { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.recent a { color: var(--ink); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Install + transfer */
.install-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 14px; border-radius: 12px;
  background: var(--visited-soft); font-size: 13.5px; font-weight: 600;
}
.install-banner span { flex: 1; min-width: 0; }
.install-x { border: 0; background: none; width: 30px; height: 30px; font-size: 20px; color: var(--muted); }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
.steps b { color: var(--ink); }
.move-code {
  margin: 0; padding: 14px; border-radius: 12px; background: var(--bg); text-align: center;
  font: 800 34px/1 var(--display); letter-spacing: .08em; color: var(--ink) !important;
  font-variant-numeric: tabular-nums; user-select: all;
}
#codeInput { text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }

/* Done selecting */
.done-bar {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.done-tick {
  display: inline-grid; place-items: center;
  width: 17px; height: 17px; margin-left: 6px; border-radius: 50%;
  background: var(--other); color: #fff; font-size: 11px; font-weight: 800; vertical-align: 1px;
}
.legal-links { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
.legal-links a { color: var(--muted); }
