/* ─── Tellus Styles ────────────────────────────────────────────────────── */

:root {
  --bg: #0a0a0f;
  --bg-elevated: #11111a;
  --bg-panel: #0f0f1a;
  --fg: #e8e8f0;
  --fg-muted: #8888a0;
  --fg-subtle: #555570;
  --accent: #4f46e5;      /* indigo */
  --accent-glow: #6366f1;
  --amber: #f59e0b;
  --amber-glow: #fbbf24;
  --border: #222233;
  --border-bright: #333350;
  --card: #161622;
  --card-hover: #1c1c2e;
  --danger: #ef4444;
  --ok: #22c55e;
  --font-ui: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --panel-w: 420px;
  --header-h: 72px;
}

@media (prefers-reduced-motion: reduce) {
  :root { --transition: 0ms; }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  overflow: hidden;
  min-height: 100vh;
}

/* ─── Globe Canvas ────────────────────────────────────────────────────── */
#globe {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  background: var(--bg);
}

/* ─── Masthead ────────────────────────────────────────────────────────── */
.masthead {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  pointer-events: auto;
}
.brand-mark { width: 28px; height: 28px; color: var(--accent); flex-shrink: 0; }
.brand h1 {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--fg) 0%, var(--amber) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline {
  font-size: 0.875rem; color: var(--fg-muted);
  margin-left: 38px; max-width: 400px;
  pointer-events: auto;
}
.meta {
  display: flex; gap: 12px; font-size: 0.75rem; color: var(--fg-subtle);
  margin-left: 38px; pointer-events: auto;
}
.meta-sep { opacity: 0.4; }

/* ─── Search Overlay ──────────────────────────────────────────────────── */
.search-overlay {
  position: fixed;
  top: calc(var(--header-h) + 16px);
  left: 24px; right: 24px;
  z-index: 60;
  pointer-events: none;
  opacity: 0; visibility: hidden; transform: translateY(-8px);
  transition: opacity var(--transition), visibility var(--transition), transform var(--transition);
}
.search-overlay.open { opacity: 1; visibility: visible; transform: translateY(0); pointer-events: auto; }
.search-overlay .search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--fg-subtle); pointer-events: none;
}
#search-input {
  width: 100%; padding: 12px 16px 12px 44px;
  font: inherit; font-size: 1rem;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--fg);
  box-shadow: var(--shadow);
  outline: none;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,0.2); }
.search-results {
  list-style: none; margin-top: 6px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); max-height: 320px; overflow-y: auto;
}
.search-results li {
  padding: 10px 16px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  transition: background var(--transition);
}
.search-results li:hover,
.search-results li[aria-selected="true"] { background: var(--card-hover); }
.search-results .flag { font-size: 1.25rem; }
.search-results .name { font-weight: 500; }
.search-results .meta { font-size: 0.75rem; color: var(--fg-muted); margin-left: auto; }
.search-hint { font-size: 0.65rem; color: var(--fg-subtle); margin-top: 6px; display: block; }

/* ─── Panel ───────────────────────────────────────────────────────────── */
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  max-width: 100vw;
  z-index: 100;
  background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-elevated) 100%);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform var(--transition);
  box-shadow: var(--shadow);
}
.panel.open { transform: translateX(0); }
@media (max-width: 640px) {
  .panel { width: 100vw; max-height: 70vh; bottom: 0; top: auto; border-left: none; border-top: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
}

.panel-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-country { display: flex; gap: 12px; min-width: 0; }
.flag { font-size: 2rem; line-height: 1; }
.panel-country h2 { font-size: 1.125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-meta { font-size: 0.75rem; color: var(--fg-muted); }
.panel-close {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--border);
  color: var(--fg-muted); font-size: 1.5rem; line-height: 1;
  cursor: pointer; transition: all var(--transition);
  flex-shrink: 0;
}
.panel-close:hover { background: var(--card); border-color: var(--border-bright); color: var(--fg); }

.panel-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.panel-tab {
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent;
  color: var(--fg-muted); font-size: 0.75rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: all var(--transition);
}
.panel-tab:hover { background: var(--card); color: var(--fg); }
.panel-tab[aria-selected="true"] {
  background: var(--accent); color: #fff; border-color: var(--accent-glow);
  box-shadow: 0 0 16px rgba(79,70,229,0.3);
}

.panel-content {
  flex: 1; overflow-y: auto; padding: 16px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.panel-section { display: none; }
.panel-section.active { display: block; animation: fadeIn var(--transition); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Metric Grid */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .metric-grid { grid-template-columns: 1fr; } }
.metric-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  transition: all var(--transition);
}
.metric-card:hover { border-color: var(--border-bright); background: var(--card-hover); }
.metric-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-subtle); margin-bottom: 4px; }
.metric-value { font-family: var(--font-mono); font-size: 1.125rem; font-weight: 600; color: var(--fg); }
.metric-unit { font-size: 0.7rem; color: var(--fg-muted); margin-left: 4px; }
.metric-sparkline { width: 100%; height: 28px; margin-top: 8px; display: block; }
.metric-rank { display: inline-flex; gap: 4px; margin-top: 6px; font-size: 0.65rem; }
.rank-badge {
  padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.6rem;
  background: var(--bg); border: 1px solid var(--border);
}
.rank-badge.top10 { background: rgba(245,158,11,0.15); border-color: var(--amber); color: var(--amber); }
.rank-badge.top25 { background: rgba(79,70,229,0.15); border-color: var(--accent); color: var(--accent); }
.metric-source { font-size: 0.6rem; color: var(--fg-subtle); margin-top: 4px; display: block; }

.panel-actions {
  display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}
.btn {
  padding: 8px 14px; border-radius: var(--radius-sm);
  font: inherit; font-size: 0.75rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  border: 1px solid var(--border); background: var(--card); color: var(--fg);
}
.btn:hover { background: var(--card-hover); border-color: var(--border-bright); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-glow); }
.btn.ghost { background: transparent; }

/* ─── Compare Bar ─────────────────────────────────────────────────────── */
.compare-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 80; padding: 10px 24px;
  background: linear-gradient(0deg, var(--bg-panel) 0%, rgba(17,17,26,0.95) 100%);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 0.875rem; color: var(--fg);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
  animation: slideUp var(--transition);
}
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: none; opacity: 1; } }
.compare-sep { color: var(--fg-muted); }
#compare-exit { margin-left: 8px; padding: 4px 10px; font-size: 0.75rem; }

/* ─── Colophon ────────────────────────────────────────────────────────── */
.colophon {
  position: fixed; bottom: 0; left: 24px; right: 24px;
  z-index: 40; padding: 12px 0; pointer-events: none;
  font-size: 0.7rem; color: var(--fg-subtle); text-align: center;
}
.colophon a { color: var(--fg-muted); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color var(--transition); }
.colophon a:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Scrollbars ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* ─── Focus Visible ───────────────────────────────────────────────────── */
*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Reduced Motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
