/* ============================================================
   MapRivals design system
   Palette from the logo: ocean navy, land green, bolt amber.
   Logical properties throughout → RTL (ar, ur) mirrors for free.
   ============================================================ */

:root {
  --ocean-deep: #0A1628;
  --ocean: #12233F;
  --ocean-raised: #182E52;
  --ocean-mist: #2A4470;
  --land: #7BC950;
  --land-deep: #4E9A2E;
  --bolt: #FFC53D;
  --bolt-deep: #E8A200;
  --danger: #E5484D;
  --ink: #F2F6FC;
  --silver: #9BAFCA;
  --silver-dim: #64789B;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(3, 8, 18, .45);
  --bg-glow: #14294b;
  --bar-bg: rgba(10, 22, 40, .85);
  --map-ocean: #0C2140;
  --map-land: #22405F;
  --map-stroke: #0A1628;
  --cov-0: #1B2F4F;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans",
          "Noto Sans Arabic", "Noto Sans Devanagari", "Noto Sans Bengali", sans-serif;
}

/* light theme (MapRivals Pro perk; toggle in the top bar) */
html[data-theme="light"] {
  --ocean-deep: #EDF2F9;
  --ocean: #FFFFFF;
  --ocean-raised: #F2F6FC;
  --ocean-mist: #C4D2E8;
  --land-deep: #3F821F;
  --bolt-deep: #D89500;
  --ink: #14243D;
  --silver: #4A6183;
  --silver-dim: #7C8DA6;
  --shadow: 0 8px 24px rgba(30, 50, 90, .14);
  --bg-glow: #DCE7F5;
  --bar-bg: rgba(255, 255, 255, .88);
  --map-ocean: #C9DCF0;
  --map-land: #FFFFFF;
  --map-stroke: #9FB4D0;
  --cov-0: #E3EAF4;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--bg-glow) 0%, transparent 60%),
    var(--ocean-deep);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}
main { flex: 1; width: 100%; max-width: 1100px; margin-inline: auto; padding: 24px 20px 64px; }
a { color: var(--bolt); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.15; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--bolt); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--bar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--ocean-mist);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 900; font-size: 1.15rem; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand img { width: 36px; height: 36px; }
.brand .riv { color: var(--bolt); }
.topnav { display: flex; gap: 4px; margin-inline-start: 8px; }
.topnav a {
  color: var(--silver); padding: 8px 12px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: .95rem;
}
.topnav a:hover { color: var(--ink); background: var(--ocean); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--ink); background: var(--ocean); }
.topbar-spacer { flex: 1; }
.streak-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--ocean); border: 1px solid var(--ocean-mist);
  color: var(--bolt); font-weight: 700; font-size: .9rem;
  padding: 5px 12px; border-radius: 999px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff; font-size: .95rem; flex: none;
  border: 2px solid var(--ocean-mist);
}

/* language switcher */
.lang-switch { position: relative; }
.lang-switch > button {
  background: var(--ocean); color: var(--ink); border: 1px solid var(--ocean-mist);
  border-radius: var(--radius-sm); padding: 7px 10px; cursor: pointer; font-size: .9rem;
}
.lang-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px);
  background: var(--ocean-raised); border: 1px solid var(--ocean-mist);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto; min-width: 210px; z-index: 60;
  padding: 6px;
}
.lang-menu button {
  display: flex; width: 100%; gap: 10px; align-items: center;
  background: none; border: 0; color: var(--ink); padding: 8px 10px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: .95rem; text-align: start;
}
.lang-menu button:hover { background: var(--ocean-mist); }
.lang-menu button.active { color: var(--bolt); font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: var(--radius-sm); cursor: pointer;
  font-weight: 700; font-size: 1rem; padding: 12px 22px;
  transition: transform .08s ease, filter .15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-bolt { background: linear-gradient(180deg, var(--bolt), var(--bolt-deep)); color: #241a00; }
.btn-ghost { background: var(--ocean); color: var(--ink); border: 1px solid var(--ocean-mist); }
.btn-land { background: linear-gradient(180deg, var(--land), var(--land-deep)); color: #0d2402; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; }
.btn-lg { font-size: 1.15rem; padding: 15px 30px; }

/* ---------- cards / layout ---------- */
.card {
  background: var(--ocean); border: 1px solid rgba(42, 68, 112, .55);
  border-radius: var(--radius); padding: 24px;
}
.grid { display: grid; gap: 16px; }
.eyebrow {
  color: var(--bolt); font-size: .78rem; font-weight: 800;
  letter-spacing: .14em; text-transform: uppercase;
}
.muted { color: var(--silver); }
.small { font-size: .85rem; }

/* ---------- hero (landing) ---------- */
.hero { display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center; padding-block: 48px 32px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 900; margin: 8px 0 12px; letter-spacing: -.02em; }
.hero h1 .riv { color: var(--bolt); }
.hero p.lead { color: var(--silver); font-size: 1.15rem; margin: 0 0 24px; max-width: 46ch; }
.hero-demo { position: relative; }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 40px; }
.mode-card { text-align: center; padding: 20px 16px; transition: border-color .2s; }
.mode-card:hover { border-color: var(--bolt); }
.mode-card .mode-ico { font-size: 2rem; }
.mode-card h3 { margin: 10px 0 4px; font-size: 1.05rem; }
.mode-card p { margin: 0; font-size: .88rem; color: var(--silver); }
.mode-card .lock { color: var(--bolt); font-size: .8rem; font-weight: 700; }

/* ---------- game ---------- */
.game-wrap { max-width: 640px; margin-inline: auto; }
.game-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--silver); font-weight: 600; }
.timer-track { height: 6px; background: var(--ocean); border-radius: 3px; overflow: hidden; margin-bottom: 20px; }
.timer-bar { height: 100%; background: var(--bolt); width: 100%; transform-origin: left; }
[dir="rtl"] .timer-bar { transform-origin: right; }
.q-visual {
  display: flex; align-items: center; justify-content: center;
  min-height: 240px; padding: 16px; margin-bottom: 12px;
}
.q-visual .shape { width: 220px; height: 220px; color: var(--land); filter: drop-shadow(0 6px 18px rgba(0,0,0,.4)); }

/* ---------- regional map (worldmap.js) ---------- */
.mapwrap { width: 100%; }
.q-visual .mapwrap { max-width: 480px; }
.mr-map {
  display: block; width: 100%; aspect-ratio: 4 / 3;
  background: var(--map-ocean); border-radius: var(--radius-sm);
  border: 1px solid rgba(42, 68, 112, .5);
}
.mr-map .mr-land { fill: var(--map-land); stroke: var(--map-stroke); stroke-width: .7; }
.mr-map .mr-target {
  fill: var(--land); stroke: var(--bolt); stroke-width: 1.6;
  filter: drop-shadow(0 0 6px rgba(123, 201, 80, .55));
}

/* world coverage map: deeper green = identified more often */
.mr-covmap { aspect-ratio: auto; }
.mr-cov { stroke: var(--map-stroke); stroke-width: .5; }
.mr-cov-0 { fill: var(--cov-0); }
.mr-cov-1 { fill: #3E5A34; }
.mr-cov-2 { fill: #4E7A38; }
.mr-cov-3 { fill: #63A344; }
.mr-cov-4 { fill: var(--land); }
.cov-legend { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--silver); margin-top: 10px; }
.cov-legend .sw { width: 18px; height: 12px; border-radius: 3px; display: inline-block; }

/* percentile chips */
.pct-chips { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.pct-chip {
  background: var(--ocean-raised); border: 1px solid rgba(42, 68, 112, .55);
  border-radius: var(--radius-sm); padding: 10px 16px; text-align: center; min-width: 110px;
}
.pct-chip .v { font-size: 1.25rem; font-weight: 900; color: var(--bolt); }
.pct-chip .l { font-size: .78rem; color: var(--silver); }
.q-visual .flag { width: 280px; max-width: 80%; border-radius: 6px; box-shadow: var(--shadow); border: 1px solid var(--ocean-mist); }
.q-visual .bigname { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 900; text-align: center; }
.q-prompt { text-align: center; font-size: 1.15rem; font-weight: 700; margin: 0 0 20px; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer {
  background: var(--ocean); border: 1px solid var(--ocean-mist); color: var(--ink);
  border-radius: var(--radius-sm); padding: 14px 16px; font-size: 1rem; font-weight: 600;
  cursor: pointer; text-align: center; transition: border-color .12s, background .12s;
}
.answer:hover { border-color: var(--bolt); }
.answer.correct { background: var(--land-deep); border-color: var(--land); color: #fff; }
.answer.wrong { background: #7e2b2e; border-color: var(--danger); color: #fff; animation: shake .3s; }
.answer[disabled] { cursor: default; }
@keyframes shake { 25% { translate: -5px 0; } 50% { translate: 5px 0; } 75% { translate: -3px 0; } }

.summary-score { font-size: clamp(2.6rem, 8vw, 4rem); font-weight: 900; color: var(--bolt); margin: 4px 0; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 20px 0; }
.stat-tile { background: var(--ocean-raised); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.stat-tile .v { font-size: 1.5rem; font-weight: 800; }
.stat-tile .l { font-size: .78rem; color: var(--silver); text-transform: uppercase; letter-spacing: .08em; }

/* ---------- leaderboard ---------- */
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th { text-align: start; color: var(--silver); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; padding: 10px 12px; }
.lb-table td { padding: 10px 12px; border-top: 1px solid rgba(42,68,112,.4); }
.lb-table tr.me { background: rgba(255, 197, 61, .08); outline: 1px solid rgba(255,197,61,.35); }
.lb-rank { font-weight: 800; color: var(--silver); width: 60px; }
.lb-rank.top { color: var(--bolt); }
.lb-user { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.lb-user a { color: var(--ink); }
.pro-badge {
  background: var(--bolt); color: #241a00; font-size: .65rem; font-weight: 900;
  padding: 2px 6px; border-radius: 4px; letter-spacing: .06em; vertical-align: middle;
}
.lb-score { font-variant-numeric: tabular-nums; font-weight: 700; text-align: end; }

/* ---------- ads (free users only; JS removes them for Pro) ---------- */
.ad-slot {
  background: #FF0000; color: #fff; font-weight: 900; letter-spacing: .1em;
  display: flex; align-items: center; justify-content: center;
  margin: 20px auto; text-transform: uppercase; font-size: .9rem;
  width: 100%; max-width: 728px; height: 90px;
}
.ad-slot.ad-rect { max-width: 300px; height: 250px; }
@media (max-width: 760px) { .ad-slot:not(.ad-rect) { max-width: 320px; height: 50px; } }
body.is-pro .ad-slot { display: none !important; }

/* ---------- forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; font-size: .95rem; }
.field input {
  width: 100%; background: var(--ocean-deep); color: var(--ink);
  border: 1px solid var(--ocean-mist); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 1rem; font-family: inherit;
}
.field input:focus { outline: 2px solid var(--bolt); border-color: transparent; }
.form-msg { font-size: .9rem; margin-top: 8px; }
.form-msg.err { color: var(--danger); }
.form-msg.ok { color: var(--land); }

/* ---------- pricing ---------- */
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.plan { position: relative; text-align: center; }
.plan .price { font-size: 2.2rem; font-weight: 900; }
.plan .per { color: var(--silver); font-size: .9rem; }
.plan.best { border-color: var(--bolt); }
.plan .save {
  position: absolute; top: -12px; inset-inline-end: 14px;
  background: var(--land); color: #0d2402; font-weight: 800; font-size: .75rem;
  padding: 3px 10px; border-radius: 999px;
}
.benefits { list-style: none; padding: 0; margin: 16px 0; text-align: start; }
.benefits li { padding: 6px 0; padding-inline-start: 28px; position: relative; }
.benefits li::before { content: "⚡"; position: absolute; inset-inline-start: 0; color: var(--bolt); }

/* ---------- profile ---------- */
.profile-head { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.profile-head .avatar { width: 84px; height: 84px; font-size: 2rem; }
.profile-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 24px; }

/* ---------- stats bars ---------- */
.bar-row { display: grid; grid-template-columns: 140px 1fr 64px; align-items: center; gap: 12px; padding: 8px 0; }
.bar-track { height: 10px; background: var(--ocean-deep); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--land-deep), var(--land)); }
.bar-fill.low { background: linear-gradient(90deg, #8a3538, var(--danger)); }
.bar-val { text-align: end; font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---------- footer ---------- */
footer {
  border-top: 1px solid var(--ocean);
  padding: 28px 20px; text-align: center; color: var(--silver-dim); font-size: .85rem;
}
footer a { color: var(--silver); margin-inline: 10px; }
footer .attribution { margin-top: 10px; font-size: .75rem; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 9, 18, .7);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal { max-width: 480px; width: 100%; box-shadow: var(--shadow); }

/* ---------- misc ---------- */
.spinner {
  width: 28px; height: 28px; border-radius: 50%; margin: 40px auto;
  border: 3px solid var(--ocean-mist); border-top-color: var(--bolt);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }

/* ---------- mobile bottom navigation (injected by app.js) ---------- */
.bottomnav { display: none; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 24px; padding-block: 24px 16px; }
  .hero h1 { font-size: clamp(1.8rem, 8vw, 2.6rem); }
  .mode-cards { grid-template-columns: 1fr; }
  .plans { grid-template-columns: 1fr; }
  .topnav { display: none; }
  .answers { grid-template-columns: 1fr 1fr; }
  main { padding: 16px 14px 48px; }

  .bottomnav {
    position: fixed; bottom: 0; inset-inline: 0; z-index: 60;
    display: flex;
    background: var(--bar-bg); backdrop-filter: blur(8px);
    border-top: 1px solid var(--ocean-mist);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 4px 10px; color: var(--silver);
    font-size: .68rem; font-weight: 700; text-decoration: none;
  }
  .bottomnav a:hover { text-decoration: none; }
  .bottomnav a .ico { font-size: 1.3rem; line-height: 1.1; }
  .bottomnav a[aria-current="page"] { color: var(--bolt); }
  body { padding-bottom: 76px; }
  .lang-switch .lang-name { display: none; }
  footer { padding-bottom: 20px; }
}

@media (max-width: 480px) {
  .answers { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 84px 1fr 52px; }
  .card { padding: 16px; }
  .profile-head .avatar { width: 64px; height: 64px; font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Pro leaderboard flair ---------- */
.flair-flag { width: 20px; height: 15px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
.lb-table tr[data-flair] { outline-offset: -1px; }
.lb-table tr[data-flair] .lb-user a { color: inherit; }
.flair-font-serif, .flair-font-serif .lb-user a { font-family: Georgia, 'Times New Roman', serif; }
.flair-font-mono, .flair-font-mono .lb-user a { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; }
.flair-font-hand, .flair-font-hand .lb-user a { font-family: 'Segoe Print', 'Comic Sans MS', 'Bradley Hand', cursive; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 14px; }
.swatch {
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent; padding: 0;
}
.swatch.sel { border-color: var(--bolt); box-shadow: 0 0 0 2px rgba(255,197,61,.35); }
.flair-preview {
  display: flex; align-items: center; gap: 10px; font-weight: 700;
  padding: 12px 14px; border-radius: var(--radius-sm); margin: 12px 0;
}

.mr-select {
  width: 100%; background: var(--ocean-deep); color: var(--ink);
  border: 1px solid var(--ocean-mist); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 1rem; font-family: inherit;
}

/* ---------- theme toggle (Pro) ---------- */
.theme-toggle {
  background: var(--ocean); color: var(--ink); border: 1px solid var(--ocean-mist);
  border-radius: var(--radius-sm); padding: 7px 10px; cursor: pointer; font-size: .95rem;
}

/* ---------- zen mode ---------- */
.zen-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(123, 201, 80, .12); border: 1px solid var(--land);
  color: var(--land); font-weight: 700; font-size: .85rem;
  padding: 4px 12px; border-radius: 999px;
}
