:root {
  color-scheme: dark;
  --bg: #080808;
  --panel: #0d0d0d;
  --panel-2: #121212;
  --border: #2b2b2b;
  --text: #f0f0f0;
  --muted: #a6a6a6;
  --subtle: #777777;
  --accent: #d9d9d9;
  --accent-rgb: 217, 217, 217;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; }
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, .globe-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell {
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 38% 42%, rgba(255, 255, 255, 0.025), transparent 38%),
    linear-gradient(145deg, #070707 0%, #0a0a0a 55%, #050505 100%);
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 3vw, 42px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(8, 8, 8, 0.88);
}

.brand-block { display: grid; gap: 3px; }
.brand-block strong { font-size: 1rem; letter-spacing: 0.01em; }
.eyebrow, .panel-kicker { color: var(--muted); font-size: 0.68rem; letter-spacing: 0.18em; font-weight: 700; }

.control-dock {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: min(720px, 64vw);
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(18, 18, 18, 0.86);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
}
.search { position: relative; flex: 1 1 420px; min-width: 260px; display: flex; gap: 8px; }
.search input {
  min-width: 0;
  flex: 1;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 13px;
  background: #101010;
  color: var(--text);
}
.search input::placeholder { color: #707070; }
.search button, .globe-controls button, .clear-selection {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #121212;
  color: var(--text);
  padding: 0 15px;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}
.search button:hover, .globe-controls button:hover, .clear-selection:hover { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.08); }
.search-results {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: min(380px, calc(100vh - 120px));
  overflow-x: hidden;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(11, 11, 11, 0.98);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.42);
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--accent-rgb), 0.58) rgba(255, 255, 255, 0.06);
}
.search-results::-webkit-scrollbar { width: 8px; }
.search-results::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.06); }
.search-results::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.58);
}
.search-option {
  width: 100%;
  min-height: 46px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 7px;
  padding: 7px 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.search-option:hover,
.search-option.is-active {
  background: rgba(var(--accent-rgb), 0.1);
}
.search-option img {
  width: 34px;
  height: 24px;
  object-fit: contain;
  filter: saturate(0.92) contrast(1.02);
}
.search-option strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-option span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--subtle);
  font-size: 0.68rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-option code {
  color: var(--muted);
  font: 700 0.68rem/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
}
.search-empty {
  padding: 13px 12px;
  color: var(--muted);
  font-size: 0.82rem;
}
.globe-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}
.globe-controls button { min-width: 44px; padding: 0 13px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 370px);
  height: calc(100vh - 77px);
  min-height: 0;
}

.globe-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(16px, 2.6vw, 36px);
  overflow: hidden;
  background: #030303;
}

.globe-stage {
  position: relative;
  width: 100%;
  min-height: min(72vw, 760px);
  max-height: calc(100vh - 190px);
  aspect-ratio: 1.25 / 1;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.globe-stage.is-dragging { cursor: grabbing; }
.globe-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#space-canvas { z-index: 0; }
#webgl-canvas { z-index: 1; }
#map-canvas { z-index: 2; }

.globe-status {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}
.globe-status.ready { opacity: 0; transition: opacity 300ms ease; }

.country-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(12px, 12px);
  padding: 7px 10px;
  border: 1px solid rgba(var(--accent-rgb), 0.5);
  border-radius: 6px;
  background: rgba(10, 10, 10, 0.95);
  color: var(--text);
  font-size: 0.78rem;
  box-shadow: 0 0 20px rgba(var(--accent-rgb), 0.12);
}

.interaction-help { max-width: 820px; margin: 12px auto 0; text-align: center; color: var(--subtle); font-size: 0.76rem; line-height: 1.55; }

.country-panel {
  position: relative;
  isolation: isolate;
  border-left: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(16, 16, 16, 0.97), rgba(9, 9, 9, 0.99));
  padding: clamp(26px, 4vw, 48px) clamp(22px, 3vw, 34px);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--accent-rgb), 0.55) rgba(255, 255, 255, 0.06);
}
.country-panel::-webkit-scrollbar { width: 8px; }
.country-panel::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.06); }
.country-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.55);
}
.country-panel::-webkit-scrollbar-thumb:hover { background: rgba(var(--accent-rgb), 0.76); }
.country-panel::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 1px;
  background: var(--accent);
  box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.72);
  opacity: 0.28;
}
.empty-state, .country-details { position: relative; z-index: 1; }
.country-details {
  min-height: calc(100vh - 77px - clamp(52px, 8vw, 96px));
}
.panel-watermark {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 0;
  width: 100%;
  height: auto;
  max-height: 62%;
  object-fit: contain;
  object-position: center bottom;
  opacity: 0.46;
  pointer-events: none;
  filter: saturate(1.12) contrast(1.05);
  -webkit-mask-image: radial-gradient(ellipse at 100% 100%, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.82) 30%, rgba(0, 0, 0, 0.26) 58%, transparent 82%);
  mask-image: radial-gradient(ellipse at 100% 100%, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.82) 30%, rgba(0, 0, 0, 0.26) 58%, transparent 82%);
}
.empty-state {
  min-height: calc(100vh - 77px - clamp(52px, 8vw, 96px));
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.empty-state h1, .country-details h1 { margin: 9px 0 12px; font-size: 2.35rem; line-height: 1.04; }
.country-details h1 {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
}
.country-details h1.long-name { font-size: 2rem; line-height: 1.08; }
.country-details h1.extra-long-name { font-size: 1.68rem; line-height: 1.12; }
.empty-state p, .about-entity p { color: var(--muted); line-height: 1.65; }
.overview-heading { text-align: center; }
.overview-heading h1 { margin-top: 12px; }
.overview-heading p { margin: 0 auto; max-width: 31rem; font-size: 0.9rem; }
.overview-stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.overview-stats div {
  min-width: 0;
  padding: 14px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}
.overview-stats dt, .overview-section h2 {
  color: var(--subtle);
  text-transform: uppercase;
  font-size: 0.67rem;
  letter-spacing: 0.11em;
}
.overview-stats dd {
  margin: 6px 0 0;
  color: var(--text);
  font-size: 1.28rem;
  line-height: 1;
  font-weight: 800;
}
.overview-section { margin-top: 24px; }
.overview-section h2 { margin: 0 0 10px; }
.overview-section p { margin: 0; font-size: 0.86rem; }
.overview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.overview-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.24);
  background: rgba(var(--accent-rgb), 0.06);
  color: #d7d7d7;
  font-size: 0.76rem;
  white-space: nowrap;
}
.country-heading { display: block; min-width: 0; text-align: center; }
.country-heading > div:last-child { min-width: 0; }
.flag-card {
  width: 96px;
  flex: 0 0 96px;
  position: relative;
  margin: 0 auto 12px;
}
.flag {
  display: block;
  width: 88px;
  height: 62px;
  object-fit: contain;
  filter: saturate(0.92) contrast(1.02);
  transform: translateZ(0);
}
.parent-flag {
  position: absolute;
  right: 0;
  bottom: -6px;
  width: 34px;
  height: 24px;
  object-fit: contain;
  background: transparent;
  border: 0;
  filter: saturate(0.92) contrast(1.02) drop-shadow(0 0 7px rgba(var(--accent-rgb), 0.24));
  transform: translateZ(0);
}
.accent-rule { height: 2px; margin: 24px 0 28px; background: linear-gradient(90deg, var(--accent), transparent); box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.45); }
.stats-grid { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 20px 16px; }
.stats-grid div { min-width: 0; }
.stats-grid dt { color: var(--subtle); text-transform: uppercase; font-size: 0.67rem; letter-spacing: 0.11em; }
.stats-grid dd { margin: 5px 0 0; color: var(--text); font-size: 0.98rem; overflow-wrap: anywhere; }
.about-entity { margin: 28px 0 22px; }
.about-entity h2 { margin: 0 0 8px; color: var(--subtle); text-transform: uppercase; font-size: 0.67rem; letter-spacing: 0.11em; }
.about-entity p { margin: 0; font-size: 0.86rem; }
.clear-selection { width: 100%; }

@media (max-width: 840px) {
  .app-shell { height: auto; min-height: 100vh; overflow: visible; }
  .topbar { align-items: stretch; flex-direction: column; gap: 12px; }
  .control-dock { min-width: 0; width: 100%; }
  .search { min-width: 0; }
  .workspace { grid-template-columns: 1fr; height: auto; }
  .globe-panel { padding-bottom: 18px; }
  .globe-stage { min-height: min(96vw, 640px); max-height: none; aspect-ratio: 1 / 0.88; }
  .country-panel { border-left: 0; border-top: 1px solid var(--border); min-height: 300px; }
  .country-panel::before { inset: 0 0 auto 0; width: auto; height: 1px; }
  .country-details { min-height: 0; }
  .empty-state { min-height: 0; justify-content: flex-start; }
}

@media (max-width: 520px) {
  .topbar { padding: 14px; }
  .control-dock { flex-direction: column; align-items: stretch; }
  .search { flex: 1 1 auto; flex-wrap: wrap; }
  .search input { flex-basis: 100%; }
  .search button { width: 100%; }
  .search-results { top: 94px; max-height: min(360px, calc(100vh - 170px)); }
  .globe-controls {
    justify-content: stretch;
    padding-left: 0;
    padding-top: 8px;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
  .globe-controls button { flex: 1; }
  .globe-panel { padding: 10px; }
  .globe-stage { min-height: 350px; }
  .interaction-help { padding-inline: 8px; }
  .country-panel { padding: 26px 18px; }
  .panel-watermark {
    right: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: 56%;
    opacity: 0.32;
  }
  .flag-card { width: 82px; flex-basis: 82px; }
  .flag { width: 76px; height: 54px; }
  .parent-flag { width: 30px; height: 21px; }
  .country-details h1 { font-size: 1.85rem; }
  .country-details h1.long-name { font-size: 1.45rem; }
  .country-details h1.extra-long-name { font-size: 1.25rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .overview-stats { grid-template-columns: 1fr; }
  .overview-tags span { white-space: normal; }
}

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