:root {
  color-scheme: light dark;
  --bg: #0b1120;
  --bg-elevated: #111a2e;
  --surface: #16213a;
  --surface-2: #1c2942;
  --text: #eef2f9;
  --text-muted: #9aa7c2;
  --border: #263354;
  --accent: #f5b942;
  --accent-2: #ff7a59;
  --success: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 20px 45px -20px rgba(0, 0, 0, .55);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }

img { max-width: 100%; }

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

/* ---------- Header / Footer ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 17, 32, .82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; }
.brand-mark { font-size: 1.4rem; }

.site-nav { display: flex; gap: 1.4rem; }
.site-nav a { color: var(--text-muted); font-weight: 600; font-size: .95rem; transition: color .15s; }
.site-nav a:hover { color: var(--text); }

main { flex: 1; }

.site-footer {
  padding: 2.5rem 1.5rem 3rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  border-top: 1px solid var(--border);
}
.site-footer p { margin: .3rem 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .7rem 1.3rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); background: var(--surface-2); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1000;
  border: none;
  box-shadow: 0 10px 25px -10px rgba(245, 185, 66, .6);
}
.btn-primary:hover { box-shadow: 0 14px 30px -10px rgba(245, 185, 66, .75); }

.btn-lg { padding: .95rem 1.8rem; font-size: 1.05rem; }
.btn-sm { padding: .4rem .8rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(248, 113, 113, .4); }
.btn-danger:hover { background: rgba(248, 113, 113, .1); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---------- Hero (home) ---------- */

.hero {
  padding: 6rem 1.5rem 5rem;
  text-align: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(245, 185, 66, .18), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(255, 122, 89, .16), transparent 40%),
    var(--bg);
}
.hero-inner { max-width: 760px; margin: 0 auto; }
.eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .04em; margin-bottom: .6rem; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.15; margin: 0 0 1rem; }
.hero-sub { color: var(--text-muted); font-size: 1.1rem; line-height: 1.6; margin-bottom: 2rem; }

/* ---------- Sections ---------- */

.section { max-width: 1120px; margin: 0 auto; padding: 3.5rem 1.5rem; }
.section-tight { padding-top: 0; padding-bottom: 1.5rem; }
.section-title { font-size: 1.6rem; margin-bottom: 1.6rem; text-align: center; }

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

/* ---------- Country grid (home) ---------- */

.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.country-card {
  position: relative;
  border-radius: var(--radius);
  padding: 1.8rem 1.4rem;
  background: linear-gradient(160deg, var(--from, #0f172a), var(--to, #1e3a8a));
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.country-card:hover { transform: translateY(-4px); box-shadow: 0 26px 50px -18px rgba(0, 0, 0, .6); }
.country-card-flag { font-size: 2.2rem; }
.country-card h3 { margin: 0; font-size: 1.25rem; }
.country-card-meta { color: rgba(255, 255, 255, .78); font-size: .9rem; margin: 0; }
.country-card-cta { margin-top: .6rem; font-weight: 700; font-size: .9rem; }

.progress { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .18); overflow: hidden; margin: .3rem 0; }
.progress-bar { height: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- Aportes recientes ---------- */

.recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; max-width: 640px; margin: 0 auto; }
.recent-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .92rem;
}
.recent-flag { margin-right: .4rem; }

/* ---------- Steps ---------- */

.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  text-align: center;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1000;
  font-weight: 800;
  margin-bottom: .8rem;
}
.step h3 { margin: .2rem 0; }
.step p { color: var(--text-muted); font-size: .92rem; margin: 0; }

.disclaimer { text-align: center; color: var(--text-muted); font-size: .82rem; max-width: 620px; margin: 0 auto; }

/* ---------- Country page ---------- */

.country-hero {
  padding: 4rem 1.5rem 3rem;
  text-align: center;
  background: linear-gradient(160deg, var(--from, #0f172a), var(--to, #1e3a8a));
  color: #fff;
}
.country-hero-inner { max-width: 720px; margin: 0 auto; }
.back-link { display: inline-block; margin-bottom: 1.2rem; color: rgba(255, 255, 255, .8); font-size: .9rem; }
.country-hero-flag { font-size: 3rem; }
.country-hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: .2rem 0 .6rem; }
.country-hero .hero-sub { color: rgba(255, 255, 255, .85); }
.country-hero-stats { font-weight: 700; color: rgba(255, 255, 255, .92); }

.map-wrap { max-width: 720px; margin: 0 auto 2.5rem; text-align: center; }
.map-wrap svg { width: 100%; height: auto; }
.map-loading { padding: 2rem; }
.map-wrap svg [data-province] { cursor: pointer; transition: opacity .15s ease, filter .15s ease; stroke: var(--bg); stroke-width: 1; }
.map-wrap svg [data-province]:hover { opacity: .85; filter: brightness(1.15); }

.province-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.province-card {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1.1rem 1rem;
  text-align: left;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
  color: var(--text);
  font-family: inherit;
}
.province-card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--accent); }
.province-card h4 { margin: 0 0 .3rem; font-size: 1.05rem; }
.province-card .status-line { font-size: .82rem; color: var(--text-muted); }
.province-card.is-unclaimed .status-line { color: var(--success); }
.province-card.is-claimed { border-style: dashed; }
.province-card.is-claimed .status-line { color: var(--danger); font-weight: 700; }
.province-card .owner { display: block; margin-top: .3rem; font-size: .8rem; color: var(--accent); font-weight: 700; }

/* ---------- Barra de estadísticas del país ---------- */

.stats-bar {
  display: flex;
  justify-content: center;
  gap: .8rem;
  flex-wrap: wrap;
  margin: -1.6rem auto 2rem;
  padding: 0 1.5rem;
  position: relative;
  z-index: 5;
}
.stat-pill {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .55rem 1.1rem;
  font-size: .88rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.stat-pill-accent { color: var(--accent); border-color: rgba(245, 185, 66, .4); }

/* ---------- Lista de provincias (página de país) ---------- */

.province-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .8rem;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.province-list-item {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
  transition: border-color .15s ease, transform .15s ease;
}
.province-list-item:hover { border-color: var(--accent); transform: translateY(-1px); }

/* ---------- Chips de filtro por provincia (mapa de país) ---------- */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
  max-width: 1120px;
  margin: 0 auto 1.5rem;
  padding: 0 1.5rem;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: .4rem .9rem;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); color: #1a1000; border-color: var(--accent); }

.canton-province-tag {
  display: inline-block;
  font-size: .72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: .2rem;
}

/* ---------- Panel lateral de provincia ---------- */

.side-panel { position: fixed; inset: 0; z-index: 50; }
.side-panel[hidden] { display: none; }
.side-panel-backdrop { position: absolute; inset: 0; background: rgba(4, 7, 16, .72); backdrop-filter: blur(2px); }
.side-panel-body {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  padding: 2rem 1.6rem 1.6rem;
  overflow-y: auto;
  box-shadow: -20px 0 45px -20px rgba(0, 0, 0, .55);
  animation: slide-in .2s ease;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.modal-close {
  position: absolute;
  top: .8rem;
  right: .8rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.modal-price { color: var(--accent); font-weight: 800; font-size: 1.3rem; margin-top: -.3rem; }

.territory-badge {
  display: inline-block;
  padding: .3rem .7rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .03em;
  margin-bottom: .8rem;
}
.territory-badge.is-claimed { background: rgba(248, 113, 113, .16); color: var(--danger); }
.territory-badge.is-unclaimed { background: rgba(52, 211, 153, .16); color: var(--success); }

.leader-card {
  display: flex;
  align-items: center;
  gap: .7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem .9rem;
  margin: 1rem 0;
}
.leader-flag { font-size: 1.3rem; }
.leader-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.leader-info strong { font-size: .95rem; }
.leader-info span { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-amount { font-weight: 800; color: var(--accent); white-space: nowrap; }

.global-rank { font-size: .88rem; font-weight: 700; color: var(--text); margin: .3rem 0 1.1rem; }

.btn-cta {
  background: linear-gradient(135deg, var(--danger), #b91c1c);
  color: #fff;
  border: none;
  font-size: 1rem;
  padding: .9rem 1rem;
  box-shadow: 0 10px 25px -10px rgba(239, 68, 68, .55);
}
.btn-cta:hover { box-shadow: 0 14px 30px -10px rgba(239, 68, 68, .7); }

.center-text { text-align: center; }

.panel-link { display: block; text-align: center; margin: .6rem 0 1.4rem; font-size: .88rem; font-weight: 600; color: var(--accent); }

.history-block { border-top: 1px solid var(--border); padding-top: 1rem; }
.history-toggle {
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 700;
  font-size: .88rem;
  cursor: pointer;
  padding: 0;
}
.history-list { list-style: none; margin: .8rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.history-list[hidden] { display: none; }
.history-list li { font-size: .84rem; color: var(--text-muted); border-bottom: 1px dashed var(--border); padding-bottom: .5rem; }
.history-list li strong { color: var(--text); }

.back-link-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 1rem;
}

#contribution-form label, .admin-form label {
  display: block;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .9rem;
  font-weight: 600;
}
#contribution-form input, #contribution-form textarea {
  display: block;
  width: 100%;
  margin-top: .35rem;
  padding: .6rem .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
#contribution-form input:focus, #contribution-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.form-error {
  background: rgba(248, 113, 113, .12);
  border: 1px solid rgba(248, 113, 113, .4);
  color: #fecaca;
  padding: .6rem .8rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  margin: .6rem 0;
}
.form-success {
  background: rgba(52, 211, 153, .12);
  border: 1px solid rgba(52, 211, 153, .4);
  color: #bbf7d0;
  padding: .6rem .8rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  margin: .6rem 0;
}

#panel-success { text-align: center; padding-top: .5rem; }
.confetti-emoji { font-size: 3rem; animation: bounce .6s ease; }
@keyframes bounce { 0% { transform: scale(.5); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

@media (max-width: 640px) {
  .site-nav { display: none; }
  .hero { padding: 4rem 1.2rem 3rem; }
}
