*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --pulse: #f78166;
  --ocean: #0d1117;
  --graticule: #1e2630;
  --country-empty: #1e2630;
}

:root.light {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --green: #1a7f37;
  --pulse: #cf222e;
  --ocean: #ddeeff;
  --graticule: #c8d8e8;
  --country-empty: #e2e8f0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  transition: background 0.25s, color 0.25s;
}

/* ── Header ─────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
header h1 span { color: var(--accent); }
header h1 em {
  font-style: normal;
  font-weight: 400;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#btn-share {
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
  flex-shrink: 0;
}
#btn-share:hover { background: var(--accent); color: var(--bg); }

#btn-theme {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  touch-action: manipulation;
}
#btn-theme:hover { border-color: var(--accent); color: var(--text); }

#user-country {
  font-size: 13px;
  color: var(--muted);
}
#user-country strong { color: var(--text); }

#btn-locate {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}
#btn-locate:hover { border-color: var(--accent); color: var(--text); }

/* ── Referral banner ─────────────────────────────────────── */
#referral-banner {
  width: 100%;
  background: linear-gradient(90deg, #1a3a1a, #0d2a1a);
  border-bottom: 1px solid var(--green);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: #7ee8a2;
  position: relative;
}
#referral-banner.hidden { display: none; }
#referral-banner strong { color: #3fb950; }
#btn-close-referral {
  background: transparent;
  border: none;
  color: #7ee8a2;
  font-size: 15px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  position: absolute;
  right: 16px;
}
#btn-close-referral:hover { color: #fff; }

/* ── Share modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
#btn-close-modal {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s;
}
#btn-close-modal:hover { color: var(--text); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-body h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.modal-body ol {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-body ol li {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}
.modal-body ol li strong { color: var(--accent); }

.share-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.share-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
#share-url-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  min-width: 0;
  font-family: inherit;
}
#btn-copy-url {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
#btn-copy-url:hover { opacity: 0.85; }

.copy-feedback {
  font-size: 12px;
  color: var(--green);
  font-weight: 600;
  margin: 0;
}
.copy-feedback.hidden { display: none; }

.share-status {
  font-size: 12px;
  font-weight: 600;
  margin: 0;
}
.share-status.hidden { display: none; }
.share-status.ready { color: var(--green); }
.share-status.used  { color: var(--pulse); }

/* ── Main layout ─────────────────────────────────────────── */
main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  gap: 32px;
  min-height: calc(100vh - 57px);
}

/* ── Info box ────────────────────────────────────────────── */
#info-box {
  width: 100%;
  max-width: 1100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
#info-box.hidden { display: none; }

#info-box-content {
  flex: 1;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}
#info-box-content strong { color: var(--text); }

#btn-close-info {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}
#btn-close-info:hover { color: var(--text); }

/* ── Map container ───────────────────────────────────────── */
#map-wrap {
  width: 100%;
  max-width: 1100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

#map-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
}

/* Country paths */
.country {
  stroke: #30363d;
  stroke-width: 0.4px;
  transition: fill 0.4s ease;
  cursor: pointer;
}
.country:hover {
  stroke: var(--accent);
  stroke-width: 1px;
}
.country.my-location {
  stroke: var(--pulse);
  stroke-width: 1.5px;
}

/* Bars drawn on map */
.country-bar {
  pointer-events: none;
  opacity: 0.85;
}
.bar-rect {
  rx: 1;
  ry: 1;
}

/* Click-blocked flash */
.country.blocked {
  animation: flash-blocked 0.4s ease;
}
@keyframes flash-blocked {
  0%   { stroke: var(--pulse); stroke-width: 2px; }
  100% { stroke: #30363d;       stroke-width: 0.4px; }
}

/* ── Tooltip ─────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  background: rgba(13,17,23,.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  pointer-events: none;
  font-size: 13px;
  z-index: 100;
  max-width: 200px;
  opacity: 0;
  transition: opacity 0.15s;
}
#tooltip.visible { opacity: 1; }
#tooltip .tt-name { font-weight: 700; margin-bottom: 4px; color: var(--text); }
#tooltip .tt-count { color: var(--muted); }
#tooltip .tt-cooldown { color: var(--pulse); font-size: 12px; margin-top: 4px; }
#tooltip .tt-bonus    { color: var(--green);  font-size: 12px; margin-top: 4px; }

/* ── Stats panel ─────────────────────────────────────────── */
#stats-panel {
  width: 100%;
  max-width: 1100px;
}

#stats-panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

#leaderboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-row {
  display: grid;
  grid-template-columns: 28px 24px 1fr 60px;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  transition: border-color 0.2s;
}
.lb-row:hover { border-color: var(--accent); }

.lb-rank {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
}
.lb-rank.gold   { color: #f0c040; }
.lb-rank.silver { color: #9e9e9e; }
.lb-rank.bronze { color: #cd7f32; }

.lb-flag { font-size: 20px; line-height: 1; }

.lb-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.lb-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 100px;
}
.lb-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.lb-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 3px;
  transition: width 0.5s ease;
}

.lb-count {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-align: right;
}

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  max-width: 280px;
  animation: slide-in 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
.toast.ok    { border-color: var(--green); }
.toast.error { border-color: var(--pulse); }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes fade-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* ── Loading overlay ─────────────────────────────────────── */
#loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  font-size: 16px;
  color: var(--muted);
  transition: opacity 0.4s;
}
#loader.hidden { opacity: 0; pointer-events: none; }

/* ── Zoom controls ───────────────────────────────────────── */
#zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}
#zoom-controls button {
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#zoom-controls button:hover  { background: #21262d; border-color: var(--accent); }
#zoom-controls button:active { background: #30363d; }

/* ── Mobile info card (replaces tooltip on touch) ────────── */
#map-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(13,17,23,0.92);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
#map-info[hidden] { display: none; }
#map-info-name {
  font-weight: 700;
  font-size: 14px;
  flex: 1;
}
#map-info-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Legend ──────────────────────────────────────────────── */
#legend {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: center;
}
.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 4px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 16px;
  }
  header h1 em { display: none; }
  #header-right { gap: 8px; }
  #btn-share { font-size: 12px; padding: 5px 10px; }
  #referral-banner { padding: 10px 40px 10px 16px; font-size: 12px; text-align: center; }

  main {
    padding: 12px 10px;
    gap: 20px;
  }

  #map-wrap {
    border-radius: 8px;
  }

  /* Bigger zoom buttons on mobile */
  #zoom-controls button {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }

  .lb-row {
    grid-template-columns: 24px 22px 1fr 48px;
    gap: 8px;
    padding: 8px 10px;
  }

  .lb-name {
    min-width: 60px;
    font-size: 12px;
  }

  .lb-bar-bg { display: none; }

  .lb-count { font-size: 13px; }

  #legend { gap: 10px; font-size: 11px; }

  #toast-container {
    bottom: 12px;
    right: 8px;
    left: 8px;
  }
  .toast { max-width: 100%; font-size: 13px; }
}

/* ── Report error bar ────────────────────────────────────── */
#report-bar {
  width: 100%;
  padding: 8px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: center;
}
#btn-report-error {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}
#btn-report-error:hover { color: var(--accent); text-decoration: underline; }

/* ── Privacy footer ──────────────────────────────────────── */
#privacy-footer {
  width: 100%;
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  background: var(--surface);
}

#privacy-footer details {
  max-width: 1100px;
  margin: 0 auto;
}

#privacy-footer summary {
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
#privacy-footer summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.2s;
}
#privacy-footer details[open] summary::before {
  transform: rotate(90deg);
}
#privacy-footer summary:hover { color: var(--text); }

.privacy-content {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.privacy-content strong { color: var(--text); }
.privacy-content ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.privacy-content p { margin: 0; }

/* Hide cursor tooltip on touch devices */
@media (hover: none) {
  #tooltip { display: none !important; }
}
