/* =========================================================
   Namae — Design tokens + base
   ========================================================= */

:root {
  /* Surfaces */
  --bg: #ffffff;
  --bg-elev: #f8f9fb;
  --bg-elev-2: #f1f3f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  /* Text */
  --text: #0a0a0a;
  --text-sub: #4b5563;
  --text-mute: #9ca3af;
  --text-inverse: #ffffff;

  /* Brand */
  --brand: #0a0a0a;
  --accent: #22c55e;
  --accent-2: #16a34a;

  /* Score colors */
  --score-bad: #ef4444;
  --score-mid: #eab308;
  --score-good: #22c55e;

  /* Grade chip colours — distinct hue + per-grade text for readable contrast
     (color-independent: grade letter is the primary signal, colour is secondary). */
  --grade-s-bg: linear-gradient(135deg, #34d399, #10b981); --grade-s-fg: #053321;
  --grade-a-bg: #15803d; --grade-a-fg: #ffffff;
  --grade-b-bg: #84cc16; --grade-b-fg: #1a2e05;
  --grade-c-bg: #facc15; --grade-c-fg: #422006;
  --grade-d-bg: #fb923c; --grade-d-fg: #431407;
  --grade-f-bg: #dc2626; --grade-f-fg: #ffffff;

  /* Map */
  --map-land: #e5e7eb;
  --map-land-stroke: #ffffff;
  --map-ocean: transparent;
  --map-hover: #cbd5e1;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.10);
  --shadow-popover: 0 8px 32px rgba(0,0,0,.18);
  --blur: saturate(180%) blur(20px);

  /* Geometry */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Typography */
  --font-sans: "Inter", "Noto Sans KR", "Noto Sans JP", "Noto Sans SC", "Noto Sans Arabic", "Noto Sans Devanagari", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-display: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Motion — four canonical curves of the design system */
  --ease-spring: cubic-bezier(.4, 1.6, .6, 1);   /* The Reveal: overshoot + settle */
  --ease-breath: cubic-bezier(.4, 0, .6, 1);     /* The Pulse: sine-like inhale/exhale */
  --ease-drift:  cubic-bezier(.65, 0, .35, 1);   /* The Atmosphere: slow ambient */
  --ease-snap:   cubic-bezier(.2, 0, .2, 1);     /* UI: instant feedback */
  /* Legacy aliases */
  --ease: var(--ease-snap);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  /* Duration scale — only four steps used across the system */
  --dur-instant:   120ms;
  --dur-quick:     280ms;
  --dur-cinematic: 1500ms;
  --dur-breath:    4000ms;
  /* Legacy aliases */
  --dur-1: var(--dur-instant);
  --dur-2: 200ms;
  --dur-3: 320ms;

  /* Luminous accents — The Bridge beams */
  --beam-cyan:   #22d3ee;
  --beam-violet: #a78bfa;
  --beam-rose:   #fb7185;

  /* Atmospheric inks — The Atmosphere calligraphy */
  --ink-1: rgba(34, 197, 94, 0.10);
  --ink-2: rgba(167, 139, 250, 0.08);
  --ink-3: rgba(251, 113, 133, 0.06);

  /* Stage — The Reveal cinematic background */
  --stage-bg:   #050608;
  --stage-haze: rgba(255, 255, 255, 0.04);

  /* Layout */
  --header-h: 56px;
  --control-h: 72px;
  --sidebar-ad-w: 320px;
  --lang-strip-h: 92px;
  --footer-ad-h: 110px;
  --max-w: 1440px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --bg-elev: #121212;
    --bg-elev-2: #1a1a1a;
    --surface: #131313;
    --border: #262626;
    --border-strong: #3a3a3a;

    --text: #f5f5f5;
    --text-sub: #b3b3b3;
    --text-mute: #6b7280;
    --text-inverse: #0a0a0a;

    --brand: #f5f5f5;
    --map-land: #2a2a2a;
    --map-land-stroke: #0a0a0a;
    --map-hover: #3a3a3a;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
    --shadow-popover: 0 8px 32px rgba(0,0,0,.6);
  }
}

/* Manual theme override */
:root[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-elev: #121212;
  --bg-elev-2: #1a1a1a;
  --surface: #131313;
  --border: #262626;
  --border-strong: #3a3a3a;
  --text: #f5f5f5;
  --text-sub: #b3b3b3;
  --text-mute: #6b7280;
  --text-inverse: #0a0a0a;
  --brand: #f5f5f5;
  --map-land: #2a2a2a;
  --map-land-stroke: #0a0a0a;
  --map-hover: #3a3a3a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  --shadow-popover: 0 8px 32px rgba(0,0,0,.6);
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f8f9fb;
  --bg-elev-2: #f1f3f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0a0a0a;
  --text-sub: #4b5563;
  --text-mute: #9ca3af;
  --text-inverse: #ffffff;
  --brand: #0a0a0a;
  --map-land: #e5e7eb;
  --map-land-stroke: #ffffff;
  --map-hover: #cbd5e1;
}

/* =========================================================
   Reset / Base
   ========================================================= */

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  font-size: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
}

input {
  font-family: inherit;
  font-size: inherit;
  background: none;
  border: none;
  color: inherit;
  outline: none;
}

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-elev);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-sub);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: -9999px;
}
.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
  z-index: 1000;
  background: var(--surface);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

/* =========================================================
   Flag — self-hosted SVG (replaces emoji; default size = lang card)
   ========================================================= */
.flag {
  display: inline-block;
  width: 24px;
  height: 18px;
  object-fit: cover;
  border-radius: 2px;
  vertical-align: middle;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.10);
}

/* =========================================================
   Header
   ========================================================= */

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, var(--score-good) 0 6px, transparent 7px),
    radial-gradient(circle at 70% 35%, var(--score-mid) 0 5px, transparent 6px),
    radial-gradient(circle at 40% 70%, var(--score-bad) 0 5px, transparent 6px),
    radial-gradient(circle at 75% 70%, var(--score-good) 0 5px, transparent 6px),
    var(--brand);
}

.brand-name {
  font-size: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-sub);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.icon-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}
.icon-btn.ghost { background: transparent; }

/* =========================================================
   App layout
   ========================================================= */

.app {
  display: grid;
  grid-template-rows: var(--control-h) 1fr auto var(--footer-ad-h);
  grid-template-columns: minmax(0, 1fr);
  min-height: calc(100dvh - var(--header-h));
  min-width: 0;
}

/* =========================================================
   Control bar (input + spin + score)
   ========================================================= */

.control-bar {
  height: var(--control-h);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.input-wrap {
  flex: 1 1 auto;
  max-width: 480px;
  position: relative;
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 var(--space-4);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.input-wrap:focus-within {
  border-color: var(--text-sub);
  background: var(--surface);
}

#name-input {
  flex: 1;
  width: 100%;
  height: 100%;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}
#name-input::placeholder {
  color: var(--text-mute);
  font-weight: 400;
}

.spin-btn {
  flex: 0 0 auto;
  height: 48px;
  padding: 0 var(--space-5);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--brand);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 15px;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), opacity var(--dur-1) var(--ease);
}
.spin-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.spin-btn:active { transform: translateY(0) scale(.98); }

.spin-btn.spinning .spin-icon {
  animation: spin 600ms var(--ease-out);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.score-display {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  min-width: 220px;
}

.score-meter {
  width: 80px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-elev-2);
  overflow: hidden;
}
.score-meter-fill {
  height: 100%;
  width: 0;
  background: var(--score-bad);
  transition: width var(--dur-3) var(--ease-out), background var(--dur-3) var(--ease-out);
  border-radius: var(--radius-pill);
}

.score-text {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.score-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.score-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  font-variation-settings: "opsz" 48, "SOFT" 30;
  color: var(--text);
}
.score-grade {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sub);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
}
.score-grade[data-grade="S"] { color: var(--grade-s-fg); background: var(--grade-s-bg); }
.score-grade[data-grade="A"] { color: var(--grade-a-fg); background: var(--grade-a-bg); }
.score-grade[data-grade="B"] { color: var(--grade-b-fg); background: var(--grade-b-bg); }
.score-grade[data-grade="C"] { color: var(--grade-c-fg); background: var(--grade-c-bg); }
.score-grade[data-grade="D"] { color: var(--grade-d-fg); background: var(--grade-d-bg); }
.score-grade[data-grade="F"] { color: var(--grade-f-fg); background: var(--grade-f-bg); }

/* Subtle ring for chip definition against card backgrounds (figure/ground). */
.score-grade, .panel-grade, .detail-card-grade, .detail-score-grade {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

/* =========================================================
   Map row
   ========================================================= */

.map-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-ad-w);
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  min-height: 0;
  min-width: 0;
}

.map-container {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 360px;
  /* Equal Earth projection ratio ~ 2.05:1. Pinning the container prevents the SVG's
     intrinsic sizing from forming a feedback loop that blows the grid row vertical. */
  aspect-ratio: 2.05 / 1;
  max-height: calc(100dvh - var(--header-h) - var(--control-h) - var(--lang-strip-h) - var(--footer-ad-h) - 40px);
}

#map {
  width: 100%;
  height: 100%;
  display: block;
}

#map svg {
  display: block;
  width: 100%;
  height: 100%;
}

#map .country {
  fill: var(--country-fill, var(--map-land));
  stroke: var(--map-land-stroke);
  stroke-width: 0.5;
  transition: fill var(--dur-2) var(--ease-out), opacity var(--dur-1) var(--ease);
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
  will-change: transform;
}
#map .country:hover {
  fill: var(--map-hover);
  opacity: 0.85;
}
#map .country.country-selected {
  stroke: var(--text);
  stroke-width: 1.5;
}
#map .country.no-data {
  fill: var(--map-land);
  cursor: default;
}
#map .country.no-data:hover {
  opacity: 1;
}

/* The Pulse — breathing animation, BPM driven by score */
@keyframes country-pulse-low {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.006); }
}
@keyframes country-pulse-high {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.012); }
}
#map .country.pulse-band-1 { animation: country-pulse-low  var(--bpm, 5000ms) cubic-bezier(.4,0,.6,1) infinite; }
#map .country.pulse-band-2 { animation: country-pulse-low  var(--bpm, 5000ms) cubic-bezier(.4,0,.6,1) infinite; }
#map .country.pulse-band-3 { animation: country-pulse-high var(--bpm, 5000ms) cubic-bezier(.4,0,.6,1) infinite; }
#map .country.pulse-band-4 { animation: country-pulse-high var(--bpm, 5000ms) cubic-bezier(.4,0,.6,1) infinite; }

body.reveal-running #map .country { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  #map .country { animation: none !important; }
}

.map-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: var(--text-mute);
  font-size: 15px;
  transition: opacity var(--dur-3) var(--ease);
}
.map-empty.hidden { opacity: 0; }

.map-empty-inner {
  text-align: center;
  max-width: 440px;
  padding: 0 var(--space-4);
}
.map-empty-text {
  margin: 0 0 var(--space-3);
  color: var(--text-sub);
  font-size: 15px;
  line-height: 1.5;
}
.map-empty-text strong { color: var(--text); font-weight: 600; }
.map-empty-examples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  pointer-events: auto;
}
.map-empty.hidden .map-empty-examples { pointer-events: none; }
.example-chip {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 500;
  transition: transform var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.example-chip:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface);
}

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev);
  z-index: 2;
}
.map-loading.hidden { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  animation: spinner 700ms linear infinite;
}
@keyframes spinner {
  to { transform: rotate(360deg); }
}

.map-popover {
  position: fixed;
  z-index: 80;
  min-width: 180px;
  max-width: 240px;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
  font-size: 13px;
}
.map-popover .pop-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.map-popover .pop-flag { display: inline-flex; line-height: 0; }
.map-popover .pop-flag .flag { width: 20px; height: 15px; }
.map-popover .pop-score {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.map-popover .pop-score-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.map-popover .pop-meaning {
  margin-top: var(--space-2);
  color: var(--text-sub);
  font-size: 12px;
  line-height: 1.4;
}

/* =========================================================
   Sidebar ad
   ========================================================= */

.sidebar-ad {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: var(--space-2);
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  color: var(--text-mute);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ad-slot[data-ad-size="300x600"] { width: 300px; height: 600px; max-height: 70vh; }
.ad-slot[data-ad-size="728x90"]  { width: 100%; max-width: 728px; height: 90px; margin: 0 auto; }
.ad-slot[data-ad-size="responsive"] { width: 100%; min-height: 90px; }
.ad-slot[data-ad-size="320x100"] { width: 320px; height: 100px; }
.ad-slot[data-ad-size="in-feed"] { width: 100%; min-height: 120px; }
/* Pre-AdSense: keep the slot's reserved size (no CLS) but don't show a placeholder
   label or dashed box that could be mistaken for broken/unfinished content. */
.ad-placeholder { display: none; }

/* =========================================================
   Language strip
   ========================================================= */

/* Language section = region tabs + scroll strip */
.lang-section {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--bg);
  min-width: 0;
  overflow: hidden;
}

.region-tabs {
  display: flex;
  gap: 2px;
  padding: var(--space-2) var(--space-5);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.region-tabs::-webkit-scrollbar { display: none; }

.region-tab {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.region-tab:hover { background: var(--bg-elev); color: var(--text); }
.region-tab.active { background: var(--text); color: var(--text-inverse); }
.region-count {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-elev-2);
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}
.region-tab.active .region-count {
  background: rgba(255,255,255,.18);
  color: rgba(255,255,255,.95);
}

.lang-strip {
  padding: var(--space-3) 0;
  background: var(--bg);
  overflow: hidden;
}

.lang-strip-track {
  display: flex;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  height: 100%;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  -webkit-overflow-scrolling: touch;
  /* Right-edge fade hints there are more cards to scroll to. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
}
.lang-strip-track::-webkit-scrollbar { height: 6px; }
.lang-strip-track::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.lang-card {
  flex: 0 0 auto;
  min-width: 138px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-3);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
  position: relative;
}
.lang-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}
.lang-card.active {
  border-color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.lang-card-tier2::after {
  content: "T2";
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-mute);
  background: var(--bg-elev-2);
  padding: 1px 4px;
  border-radius: 3px;
}

.lang-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.lang-card-flag {
  display: inline-flex;
  line-height: 0;
}
.lang-card-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  letter-spacing: 0.05em;
}
.lang-card-name {
  font-size: 13px;
  color: var(--text-sub);
  margin: 4px 0 8px;
}
.lang-card-score {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.lang-card-bar {
  margin-top: 4px;
  height: 4px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.lang-card-bar-fill {
  height: 100%;
  width: 0;
  background: var(--score-good);
  border-radius: var(--radius-pill);
  transition: width var(--dur-3) var(--ease-out), background var(--dur-3) var(--ease-out);
}

/* =========================================================
   Detail panel (desktop side) / bottom sheet (mobile)
   ========================================================= */

.detail-panel {
  position: fixed;
  z-index: 90;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);

  /* Desktop default: right-side drawer */
  top: var(--header-h);
  right: 0;
  bottom: 0;
  width: 380px;
  transform: translateX(100%);
  transition: transform var(--dur-3) var(--ease-out);
  display: flex;
  flex-direction: column;
}
.detail-panel.open {
  transform: translateX(0);
}

.panel-handle {
  display: none;
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  margin: var(--space-2) auto var(--space-1);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.panel-flag {
  display: inline-flex;
  line-height: 0;
}
.panel-flag .flag { width: 34px; height: 26px; }
.panel-country {
  flex: 1;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.panel-score-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.panel-score {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.panel-grade {
  font-size: 16px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text-sub);
}
.panel-grade[data-grade="S"] { color: var(--grade-s-fg); background: var(--grade-s-bg); }
.panel-grade[data-grade="A"] { color: var(--grade-a-fg); background: var(--grade-a-bg); }
.panel-grade[data-grade="B"] { color: var(--grade-b-fg); background: var(--grade-b-bg); }
.panel-grade[data-grade="C"] { color: var(--grade-c-fg); background: var(--grade-c-bg); }
.panel-grade[data-grade="D"] { color: var(--grade-d-fg); background: var(--grade-d-bg); }
.panel-grade[data-grade="F"] { color: var(--grade-f-fg); background: var(--grade-f-bg); }

.panel-axes {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-5);
  display: grid;
  gap: var(--space-3);
}
.panel-axes li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-3);
  font-size: 14px;
  color: var(--text-sub);
}
.panel-axes .axis-bar {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.panel-axes .axis-bar-fill {
  height: 100%;
  width: 0;
  background: var(--score-good);
  border-radius: var(--radius-pill);
  transition: width var(--dur-3) var(--ease-out);
}
.panel-axes .axis-value {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
}

.panel-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0 0 var(--space-5);
  font-size: 14px;
}
.panel-meta dt {
  color: var(--text-mute);
  font-weight: 500;
}
.panel-meta dd {
  margin: 0;
  color: var(--text);
}
.panel-meta dd.rtl {
  direction: rtl;
  text-align: left;
}

.panel-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--brand);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  transition: transform var(--dur-1) var(--ease);
}
.panel-link:hover { transform: translateY(-1px); }

.panel-flag-row {
  padding: var(--space-3);
  margin: 0 0 var(--space-4);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--score-bad);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.panel-flag-message {
  margin: 0;
  font-size: 13px;
  color: var(--text-sub);
}
.panel-flag-message b {
  color: var(--text);
  font-weight: 600;
}
.panel-report {
  align-self: flex-start;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease);
}
.panel-report:hover { background: var(--bg-elev-2); }
.panel-report.reported {
  background: var(--score-good);
  color: #fff;
  border-color: var(--score-good);
  cursor: default;
}

/* =========================================================
   Backdrop (mobile)
   ========================================================= */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 80;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease);
}
.backdrop.show {
  opacity: 1;
}

/* =========================================================
   Footer ad + footer
   ========================================================= */

.footer-ad {
  height: var(--footer-ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.site-footer {
  padding: var(--space-5);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-mute);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  text-align: center;
}
.site-footer nav {
  display: flex;
  gap: var(--space-4);
}
.site-footer nav a:hover { color: var(--text); }

/* =========================================================
   Content pages (about / methodology / privacy)
   ========================================================= */
.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5);
}
.doc h1 {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 800;
  font-variation-settings: "opsz" 144, "SOFT" 30;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-4);
}
.doc .doc-lead { font-size: 18px; color: var(--text); }
.doc h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: var(--space-6) 0 var(--space-3);
}
.doc p, .doc li {
  color: var(--text-sub);
  font-size: 16px;
  line-height: 1.7;
}
.doc ul { padding-left: var(--space-5); margin: var(--space-3) 0; }
.doc li { margin-bottom: var(--space-2); }
.doc strong { color: var(--text); font-weight: 600; }
.doc a { color: var(--accent-2); text-decoration: underline; }
.doc-updated { color: var(--text-mute); font-size: 13px; margin-top: var(--space-7); }

/* =========================================================
   Mobile responsive
   ========================================================= */

@media (max-width: 880px) {
  :root {
    --control-h: auto;
    --lang-strip-h: 80px;
    --footer-ad-h: 100px;
  }

  .app {
    grid-template-rows: auto 1fr auto auto;
  }

  .control-bar {
    padding: var(--space-3) var(--space-4);
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .input-wrap {
    flex: 1 1 100%;
    max-width: none;
    height: 44px;
    order: 1;
  }

  .spin-btn {
    flex: 1 1 auto;
    height: 44px;
    order: 2;
  }

  .score-display {
    margin-left: 0;
    height: 44px;
    flex: 2 1 auto;
    min-width: 0;
    order: 3;
  }

  .score-meter { width: 40px; }
  .score-value { font-size: 18px; }

  .map-row {
    grid-template-columns: 1fr;
    padding: var(--space-3) var(--space-3);
  }

  .sidebar-ad { display: none; }

  .map-container {
    min-height: 55vh;
    border-radius: var(--radius-md);
  }

  .lang-strip {
    padding: var(--space-2) 0;
  }

  .lang-card {
    min-width: 120px;
    padding: var(--space-2) var(--space-3);
  }
  .lang-card-score { font-size: 18px; }

  /* Detail panel becomes bottom sheet */
  .detail-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 70dvh;
    border-left: none;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    transform: translateY(100%);
  }
  .detail-panel.open {
    transform: translateY(0);
  }
  .panel-handle { display: block; }
  .panel-header { padding: var(--space-3) var(--space-4); }
  .panel-body { padding: var(--space-4); }
  .panel-score { font-size: 40px; }

  .footer-ad { padding: 0 var(--space-3); }
}

@media (max-width: 480px) {
  .site-header {
    padding: 0 var(--space-3);
  }
  .control-bar {
    padding: var(--space-2) var(--space-3);
  }
  .spin-btn { padding: 0 var(--space-3); }
  .score-display { padding: 0 var(--space-3); gap: var(--space-2); }
}

/* =========================================================
   The Bridge — Canvas particle + bezier beam overlay
   ========================================================= */

.bridge-canvas {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  /* Slight mix-blend to integrate with map colours below */
  mix-blend-mode: screen;
}

/* In light mode use a softer blend mode so beams don't overpower content */
:root[data-theme="light"] .bridge-canvas { mix-blend-mode: multiply; opacity: 0.65; }

@media (prefers-reduced-motion: reduce) {
  .bridge-canvas { display: none; }
}

/* Performance auto-degradation — applied by scripts/performance.js on sustained low FPS.
   Tier 1 stops The Pulse; Tier 2 also removes The Bridge canvas. */
body.perf-degraded #map .country { animation: none !important; }
body.perf-min .bridge-canvas { display: none !important; }

/* The Pulse — 3D globe mode (lazy-loaded via scripts/globe.js; desktop only) */
.globe-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.globe-canvas:active { cursor: grabbing; }
body.globe-mode #map,
body.globe-mode .map-empty,
body.globe-mode .map-popover,
body.globe-mode .bridge-canvas { display: none !important; }
.globe-toggle.active { background: var(--bg-elev); color: var(--text); }
@media (max-width: 880px) { .globe-toggle { display: none; } }

/* =========================================================
   The Atmosphere — generative calligraphy background
   ========================================================= */

.atmosphere-layer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0.7;
}

/* In dark mode use screen-blend for additive glow against the dark bg */
@media (prefers-color-scheme: dark) {
  .atmosphere-layer { mix-blend-mode: screen; opacity: 0.45; }
}
:root[data-theme="dark"] .atmosphere-layer { mix-blend-mode: screen; opacity: 0.45; }
:root[data-theme="light"] .atmosphere-layer { mix-blend-mode: multiply; opacity: 0.7; }

.atmosphere-stroke { will-change: opacity, transform; }

/* Pause atmosphere during reveal */
body.reveal-running .atmosphere-layer { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .atmosphere-stroke { animation: none !important; }
}

/* =========================================================
   The Reveal — 1.5s cinematic sequence
   ========================================================= */

body.reveal-running {
  /* Block UI interaction during the reveal */
  pointer-events: none;
}
body.reveal-running .site-header,
body.reveal-running .reveal-falling-stage,
body.reveal-running .reveal-dot,
body.reveal-running .reveal-sweep {
  pointer-events: auto;
}

.reveal-dot {
  position: fixed;
  z-index: 95;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--beam-cyan);
  box-shadow:
    0 0 16px var(--beam-cyan),
    0 0 48px rgba(34, 211, 238, 0.6),
    0 0 96px rgba(34, 211, 238, 0.3);
  pointer-events: none;
}

.reveal-falling-stage {
  position: fixed;
  z-index: 94;
  left: 0; right: 0;
  top: 40%;
  transform: translateY(-50%);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  text-align: center;
}

.reveal-letter {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 800;
  font-variation-settings: "opsz" 144, "SOFT" 30;
  font-size: clamp(48px, 9vw, 124px);
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
  text-shadow:
    0 0 24px rgba(34, 211, 238, 0.25),
    0 4px 24px rgba(0, 0, 0, 0.35);
  will-change: transform, opacity, filter;
}

.reveal-sweep {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent 0%,
    transparent 40%,
    rgba(34, 211, 238, 0.22) 48%,
    rgba(167, 139, 250, 0.30) 50%,
    rgba(34, 211, 238, 0.22) 52%,
    transparent 60%,
    transparent 100%
  );
  mix-blend-mode: screen;
  transform: translateX(-110%);
  will-change: transform, opacity;
}

@media (prefers-reduced-motion: reduce) {
  .reveal-dot,
  .reveal-falling-stage,
  .reveal-sweep {
    display: none !important;
  }
}

/* =========================================================
   Reduced motion
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* =========================================================
   Consent banner — analytics opt-in (Consent Mode)
   Injected by scripts/analytics.js only when GA4 is configured.
   ========================================================= */

.consent-banner {
  position: fixed;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-4);
  width: min(640px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: consent-rise var(--dur-quick) var(--ease-out);
}

@keyframes consent-rise {
  from { opacity: 0; transform: translate(-50%, var(--space-4)); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.consent-banner__text {
  flex: 1 1 260px;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-sub);
}

.consent-banner__link {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.consent-banner__actions {
  display: flex;
  flex: 0 0 auto;
  gap: var(--space-2);
}

.consent-banner__btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--dur-instant) var(--ease-snap),
              border-color var(--dur-instant) var(--ease-snap),
              opacity var(--dur-instant) var(--ease-snap);
}

.consent-banner__btn--solid {
  background: var(--brand);
  color: var(--text-inverse);
}
.consent-banner__btn--solid:hover {
  opacity: 0.88;
}

.consent-banner__btn--ghost {
  border: 1px solid var(--border-strong);
  color: var(--text-sub);
}
.consent-banner__btn--ghost:hover {
  border-color: var(--text-sub);
  color: var(--text);
}

@media (max-width: 480px) {
  .consent-banner {
    flex-direction: column;
    align-items: stretch;
  }
  .consent-banner__actions {
    justify-content: flex-end;
  }
}
