:root {
  --bg: #f5f7fb;
  --bg-elevated: #ffffff;
  --bg-soft: #f8fbff;
  --text: #172132;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
  --primary: #6ea8fe;
  --primary-2: #8b5cf6;
  --accent: #22d3ee;
  --success: #10b981;
  --danger: #ef4444;
  --gold: #f59e0b;
  --surface-grad: linear-gradient(160deg, #ffffff 0%, #f7fbff 100%);
  --hero-grad: linear-gradient(140deg, rgba(110, 168, 254, 0.18), rgba(139, 92, 246, 0.12));
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --max-width: 1180px;
}

body.theme-dark {
  --bg: #07101e;
  --bg-elevated: #0f1729;
  --bg-soft: #111b30;
  --text: #eef4ff;
  --muted: #a7b4ca;
  --border: rgba(255, 255, 255, 0.09);
  --shadow: 0 22px 46px rgba(0, 0, 0, 0.35);
  --surface-grad: linear-gradient(160deg, #111b30 0%, #0b1221 100%);
  --hero-grad: linear-gradient(140deg, rgba(110, 168, 254, 0.18), rgba(139, 92, 246, 0.18));
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(34, 211, 238, 0.10), transparent 24%),
    radial-gradient(circle at top right, rgba(139, 92, 246, 0.09), transparent 22%),
    var(--bg);
}
body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.muted-text { color: var(--muted); }
.success-text { color: var(--success); font-weight: 700; }
.error-text { color: var(--danger); font-weight: 700; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
  background: rgba(255, 255, 255, 0.74);
  border-bottom: 1px solid var(--border);
}
body.theme-dark .site-header { background: rgba(7, 16, 30, 0.8); }
.header-inner {
  width: min(var(--max-width), calc(100% - 24px));
  margin: 0 auto;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  box-shadow: 0 12px 30px rgba(110, 168, 254, 0.25);
}
.desktop-nav {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-weight: 600;
}
.desktop-nav a:hover, .footer-links a:hover { color: var(--text); }
.icon-btn, .account-btn, .primary-btn, .secondary-btn, .danger-btn, .mode-btn, .difficulty-btn, .answer-btn, .btn {
  border: 0;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
}
.icon-btn:hover, .account-btn:hover, .primary-btn:hover, .secondary-btn:hover, .danger-btn:hover, .mode-btn:hover, .difficulty-btn:hover, .answer-btn:hover, .btn:hover { transform: translateY(-2px); }
.icon-btn, .account-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  min-height: 44px;
  padding: 0 14px;
}
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  padding: 8px 14px;
}
.account-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.account-meta { display: grid; line-height: 1.1; }
.account-mode { color: var(--muted); font-size: .78rem; font-weight: 600; }

.page-shell {
  width: min(var(--max-width), calc(100% - 24px));
  margin: 0 auto;
  padding: 28px 0 56px;
}
.surface-card, .intro-hero, .info-box, .summary-card, .challenge-grid a, .surface-mini {
  background: var(--surface-grad);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
}
.page-hero, .surface-card.page-hero, .intro-hero {
  background-image: var(--hero-grad);
}
.surface-card, .page-hero { padding: 24px; }
.surface-card.tight { padding: 18px; }
.surface-mini {
  padding: 18px;
  border-radius: var(--radius-md);
}
.intro-hero {
  padding: 34px;
  display: grid;
  grid-template-columns: 1.3fr .9fr;
  gap: 24px;
}
.intro-side { display: grid; gap: 16px; }
.hero-stat {
  padding: 22px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.66);
}
body.theme-dark .hero-stat { background: rgba(255, 255, 255, 0.03); }
.hero-stat strong { display: block; font-size: 1.8rem; margin-bottom: 6px; }
.hero-stat span { color: var(--muted); }

.eyebrow {
  display: inline-block;
  color: var(--accent);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 800;
}
h1, h2, h3, h4, p { margin-top: 0; }
h1 { font-size: clamp(2.2rem, 4vw, 4.2rem); line-height: 1.05; margin-bottom: 14px; }
h2 { font-size: clamp(1.4rem, 2vw, 2rem); }
.lead, .hero-text, .surface-card p, .summary-card p, .info-box p { color: var(--muted); line-height: 1.7; }
.hero-actions, .action-row, .pill-row, .mode-switcher, .difficulty-switcher, .compact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.title-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
}
.btn, .primary-btn, .secondary-btn, .danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 800;
}
.btn, .primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 30px rgba(110, 168, 254, .28);
}
.secondary-btn, .mode-btn, .difficulty-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}
.danger-btn {
  background: #fff1f2;
  color: #b91c1c;
  border: 1px solid #fecdd3;
}
body.theme-dark .danger-btn { background: rgba(239, 68, 68, .15); color: #fecaca; border-color: rgba(239, 68, 68, .35); }
.full { width: 100%; }

.section-head { margin: 36px 0 20px; }
.info-box { padding: 24px; }
.info-box.wide { width: 100%; }
.summary-card { padding: 22px; }
.summary-card.muted { background: rgba(255, 255, 255, .55); }
body.theme-dark .summary-card.muted { background: rgba(255, 255, 255, .03); }
.challenge-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.challenge-grid a { padding: 22px; }
.challenge-grid a p { min-height: 72px; }
.challenge-grid .icon { font-size: 1.9rem; margin-bottom: 12px; }
.summary-grid, .stats-inline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.summary-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.summary-grid div, .stats-inline div {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, .55);
}
body.theme-dark .summary-grid div, body.theme-dark .stats-inline div { background: rgba(255, 255, 255, .03); }
.summary-grid strong, .stats-inline strong { display: block; font-size: 1.2rem; }
.summary-grid span, .stats-inline span { color: var(--muted); font-size: .92rem; }

.quiz-topbar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .55);
  font-weight: 700;
  color: var(--muted);
}
body.theme-dark .pill { background: rgba(255, 255, 255, .03); }
.pill.accent { color: var(--accent); }
.pill.gold { color: var(--gold); }
.progress-bar {
  height: 10px;
  margin: 18px 0 20px;
  border-radius: 999px;
  background: rgba(100, 116, 139, .15);
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--primary), var(--primary-2));
}
.quiz-question { margin-bottom: 18px; }
.quiz-visual {
  min-height: 160px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(255, 255, 255, .55);
}
body.theme-dark .quiz-visual { background: rgba(255, 255, 255, .03); }
.flag-large { width: 132px; height: 92px; object-fit: cover; border-radius: 18px; box-shadow: var(--shadow); }
.flag-small { width: 70px; height: 48px; object-fit: cover; border-radius: 12px; }
.visual-inline, .visual-stack { display: flex; align-items: center; gap: 16px; }
.visual-stack { flex-direction: column; }
.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.answer-btn {
  min-height: 62px;
  text-align: left;
  border-radius: 18px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
}
.answer-btn.correct { border-color: rgba(16, 185, 129, .5); background: rgba(16, 185, 129, .14); }
.answer-btn.wrong { border-color: rgba(239, 68, 68, .5); background: rgba(239, 68, 68, .14); }
.feedback { min-height: 70px; margin-top: 18px; color: var(--muted); }
.feedback strong { display: block; margin-bottom: 6px; color: var(--text); }
.feedback.good strong { color: var(--success); }
.feedback.bad strong { color: var(--danger); }
.action-row.right { justify-content: flex-end; }
.action-row.center { justify-content: center; }
.result-card { text-align: center; }
.result-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(110, 168, 254, .15), rgba(139, 92, 246, .12));
  border: 1px solid var(--border);
}
.result-ring strong { display: block; font-size: 2rem; }
.result-ring span { color: var(--muted); }
.analysis-panel {
  text-align: left;
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .55);
}
body.theme-dark .analysis-panel { background: rgba(255, 255, 255, .03); }

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(330px, calc(100vw - 30px));
  transform: translateX(-104%);
  transition: transform .25s ease;
  z-index: 40;
}
html[dir='rtl'] .drawer {
  inset: 0 0 0 auto;
  transform: translateX(104%);
}
.drawer.open { transform: translateX(0); }
html[dir='rtl'] .drawer.open { transform: translateX(0); }
body.drawer-open { overflow: hidden; }
.drawer-panel {
  height: 100%;
  max-height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
}
html[dir='rtl'] .drawer-panel { border-right: 0; border-left: 1px solid var(--border); }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 35;
}
.drawer-backdrop.show { opacity: 1; pointer-events: auto; }
.drawer-top, .modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}
.drawer-eyebrow { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; font-size: .76rem; letter-spacing: .12em; }
.drawer-nav { display: grid; gap: 10px; margin-top: 24px; padding-bottom: 12px; }
.drawer-nav a {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .45);
  font-weight: 700;
}
body.theme-dark .drawer-nav a { background: rgba(255, 255, 255, .03); }
.drawer-footer { margin-top: auto; padding-top: 20px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}
.modal-card {
  width: min(760px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  overflow-y: auto;
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
}
.account-grid, .settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 18px;
}
.stack-form { display: grid; gap: 16px; margin-top: 12px; }
.stack-form label, .settings-grid label { display: grid; gap: 8px; font-weight: 700; }
input, select, textarea {
  min-height: 46px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 0 14px;
}
textarea {
  min-height: 140px;
  padding: 14px;
  resize: vertical;
}
.toggle-row {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, .45);
}
body.theme-dark .toggle-row { background: rgba(255, 255, 255, .03); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; margin-top: 20px; }
.inline-note {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(110, 168, 254, .12);
  border: 1px solid rgba(110, 168, 254, .22);
  color: var(--muted);
}
.inline-note.success { background: rgba(16, 185, 129, .12); border-color: rgba(16, 185, 129, .28); color: var(--success); }
.inline-note.error { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .28); color: var(--danger); }

.split-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.map-card { overflow: hidden; }
.map-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.map-stage {
  position: relative;
  min-height: 560px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #cdeeff, #edf7ff);
}
body.theme-dark .map-stage { background: linear-gradient(180deg, #11304d, #081624); }
.map-stage.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
}
body.theme-dark .map-stage.loading::after { background: rgba(0, 0, 0, 0.2); }
.leaflet-map { width: 100%; min-height: 560px; }
.map-loading {
  position: absolute;
  inset: 18px auto auto 18px;
  z-index: 500;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .88);
  box-shadow: var(--shadow);
  color: var(--text);
}
body.theme-dark .map-loading { background: rgba(15, 23, 42, .85); }
.map-status { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.map-legend { margin-top: 18px; }
.leaflet-container { font: inherit; }
body.theme-dark .leaflet-control-zoom a,
body.theme-dark .leaflet-bar a { background: #0f1729; color: #eef4ff; border-bottom-color: rgba(255, 255, 255, .08); }
.used-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.used-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(110, 168, 254, .12);
  border: 1px solid rgba(110, 168, 254, .25);
  font-weight: 700;
}

.legal-grid {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 18px;
}
.legal-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.8;
}
.contact-grid {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 18px;
}
.contact-card, .legal-card { height: 100%; }
.contact-meta { display: grid; gap: 12px; }
.contact-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .55);
}
body.theme-dark .contact-pill { background: rgba(255, 255, 255, .03); }
.form-success {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(16, 185, 129, .12);
  border: 1px solid rgba(16, 185, 129, .28);
  color: var(--success);
}

.ad-slot {
  margin-top: 18px;
  border-radius: 20px;
  border: 1px dashed rgba(110, 168, 254, .35);
  background: rgba(110, 168, 254, .06);
  padding: 14px;
  text-align: center;
}
body.theme-dark .ad-slot { background: rgba(110, 168, 254, .08); }
.ad-slot-label {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 800;
}
.ad-slot-body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 58px;
}
.ad-frame-shell {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  max-width: 100%;
  overflow: auto;
}

.site-footer {
  width: min(var(--max-width), calc(100% - 24px));
  margin: 0 auto 28px;
  color: var(--muted);
}
.footer-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  padding: 18px 0 6px;
}
.footer-links { display: flex; flex-wrap: wrap; gap: 14px; }
.app-toast {
  position: fixed;
  inset: auto 18px 18px auto;
  z-index: 70;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--text);
  color: white;
  box-shadow: var(--shadow);
}
html[dir='rtl'] .app-toast {
  inset: auto auto 18px 18px;
}

@media (max-width: 980px) {
  .intro-hero,
  .challenge-grid,
  .summary-grid,
  .stats-inline,
  .split-layout,
  .legal-grid,
  .contact-grid,
  .account-grid,
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }
  .desktop-nav { display: none; }
}

@media (max-width: 760px) {
  .page-shell { padding-top: 18px; }
  .drawer { width: min(360px, calc(100vw - 18px)); }
  .intro-hero,
  .challenge-grid,
  .summary-grid,
  .stats-inline,
  .answer-grid,
  .split-layout,
  .legal-grid,
  .contact-grid,
  .account-grid,
  .settings-grid,
  .footer-grid {
    grid-template-columns: 1fr;
  }
  .surface-card, .page-hero, .intro-hero { padding: 20px; }
  .header-inner { min-height: 68px; }
  .action-row.right, .action-row.center { justify-content: stretch; }
  .leaflet-map, .map-stage { min-height: 420px; }
}

html[dir='rtl'] .challenge-grid a,
html[dir='rtl'] .answer-btn,
html[dir='rtl'] .analysis-panel,
html[dir='rtl'] .surface-card,
html[dir='rtl'] .modal-card {
  text-align: right;
}


.ad-slot.compact {
  padding: 10px 12px;
}
.ad-inline-anchor {
  margin-top: 22px;
}
.compact-anchor .ad-slot {
  margin-top: 0;
}
.ad-script-holder {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.ad-mobile-sticky-host {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 42;
  width: min(340px, calc(100vw - 24px));
  display: none;
}
.ad-mobile-sticky-host .ad-slot {
  margin-top: 0;
  padding: 8px 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.16);
}
body.theme-dark .ad-mobile-sticky-host .ad-slot {
  background: rgba(15, 23, 42, 0.95);
}
@media (max-width: 760px) {
  body { padding-bottom: 94px; }
  .ad-mobile-sticky-host { display: block; }
}

