/* Language Families Explorer — base styles */
:root {
  --bg: #F6F3EC;
  --paper: #FBF8F1;
  --ink: #1D2333;
  --ink-soft: #4A5169;
  --line: #1D2333;
  --muted: #8A8B93;
  --accent-sky: #3B82F6;
  --accent-coral: #F97A4D;
  --accent-violet: #8B5CF6;
  --accent-moss: #4C9A68;
  --accent-sun: #E8B83A;
  --accent-rose: #E45A84;
  --shadow-sm: 0 1px 0 rgba(29,35,51,0.06);
  --shadow-md: 0 4px 14px rgba(29,35,51,0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: 'Geist', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 1.5; }
body { min-height: 100vh; overflow-x: hidden; }

h1,h2,h3,h4 { font-family: 'Fraunces', 'Georgia', serif; font-weight: 500; letter-spacing: -0.01em; color: var(--ink); margin: 0; text-wrap: balance; }
h1 { font-size: 34px; line-height: 1.05; }
h2 { font-size: 26px; line-height: 1.1; }
h3 { font-size: 20px; line-height: 1.2; }
p  { margin: 0; text-wrap: pretty; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }
a { color: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px 56px;
}

/* ----- Top bar ----- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 22px 0 18px;
  border-bottom: 1px solid rgba(29,35,51,0.08);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, var(--accent-sky) 70%, #1e4dbe);
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.15);
  position: relative;
  flex-shrink: 0;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 6px 10px 18px 8px;
  border-radius: 50%;
  background: var(--accent-moss);
  opacity: 0.6;
  filter: blur(1.5px);
}
.tabs {
  display: flex; gap: 4px; margin-left: auto;
  flex-wrap: wrap;
}
.tab {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--ink-soft);
  transition: background .15s, color .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: rgba(29,35,51,0.06); color: var(--ink); }
.tab.active {
  background: var(--ink);
  color: var(--paper);
}
.tab-dot {
  width: 8px; height: 8px; border-radius: 50%;
}

/* ----- Search ----- */
.search-wrap { position: relative; }
.search-input {
  font: inherit;
  padding: 8px 12px 8px 34px;
  border: 1px solid rgba(29,35,51,0.15);
  background: var(--paper);
  border-radius: 999px;
  width: 220px;
  outline: none;
  transition: border-color .15s, width .2s;
}
.search-input:focus { border-color: var(--ink); width: 260px; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.12);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  max-height: 340px; overflow-y: auto;
  z-index: 20;
}
.search-result {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(29,35,51,0.05);
  cursor: pointer;
  transition: background .1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: rgba(59,130,246,0.08); }
.search-result-flag { font-size: 20px; }
.search-result-name { font-weight: 500; }
.search-result-native { font-size: 12px; color: var(--muted); margin-left: auto; font-style: italic; }

/* ----- Content frame ----- */
.content { padding: 28px 0; }
.view-header {
  display: flex; align-items: end; justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.view-header .sub {
  color: var(--ink-soft);
  font-size: 15px;
  max-width: 520px;
  margin-top: 6px;
}
.view-header .meta {
  font-size: 12px; color: var(--muted);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ----- Map ----- */
.map-stage {
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.1);
  border-radius: 22px;
  position: relative;
  overflow: hidden;
  aspect-ratio: 1000 / 560;
  box-shadow: var(--shadow-md);
}
.map-svg { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.map-svg:active { cursor: grabbing; }
.map-bg-sea {
  fill: #EAF2FB;
}
.map-grid line { stroke: rgba(59,130,246,0.08); stroke-width: 1; }
.map-region {
  stroke: var(--ink);
  stroke-width: 1.5;
  transition: fill .2s, transform .2s;
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
}
.map-region:hover { filter: brightness(1.05); }
.map-region.selected { stroke-width: 2.5; }
.map-label {
  font-size: 12px;
  font-family: 'Geist', sans-serif;
  font-weight: 500;
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
}
.map-controls {
  position: absolute; right: 16px; top: 16px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.12);
  border-radius: 12px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.map-controls button {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--ink);
  transition: background .15s;
}
.map-controls button:hover { background: rgba(29,35,51,0.06); }
.map-legend {
  position: absolute; left: 16px; bottom: 16px;
  background: rgba(251,248,241,0.94);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(29,35,51,0.1);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 12px;
  max-width: 320px;
}
.map-legend-title {
  font-family: 'Fraunces', serif;
  font-size: 15px;
  margin-bottom: 6px;
}
.map-legend-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0;
}
.swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ----- Tree ----- */
.tree-stage {
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.1);
  border-radius: 22px;
  padding: 12px;
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: hidden;
  max-height: 720px;
  box-shadow: var(--shadow-md);
}
.tree-svg { width: 100%; height: 100%; display: block; }
.tree-node { cursor: pointer; transition: transform .2s; transform-box: fill-box; transform-origin: center; }
.tree-node:hover { transform: scale(1.08); }
.tree-label {
  font-size: 11px;
  font-family: 'Geist', sans-serif;
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
}
.tree-link {
  fill: none;
  stroke-width: 1.5;
  transition: stroke-width .2s, opacity .2s;
}
.tree-branch-label {
  font-family: 'Fraunces', serif;
  font-size: 14px;
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
}

.tree-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
}
@media (max-width: 900px) {
  .tree-layout { grid-template-columns: 1fr; }
}
.tree-side {
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.1);
  border-radius: 22px;
  padding: 20px;
  font-size: 14px;
  max-height: 720px;
  overflow-y: auto;
}
.tree-side h3 { margin-bottom: 8px; }
.tree-side p { color: var(--ink-soft); margin-bottom: 14px; }
.tree-side .hint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  display: block;
}
.branch-list { display: flex; flex-wrap: wrap; gap: 6px; }
.branch-chip {
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  border: 1px solid rgba(29,35,51,0.15);
  background: var(--paper);
  transition: all .15s;
}
.branch-chip:hover { border-color: var(--ink); }
.branch-chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.branch-chip .swatch { display: inline-block; margin-right: 6px; vertical-align: middle; }

/* ----- Info panel ----- */
.panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(29,35,51,0.35);
  backdrop-filter: blur(3px);
  z-index: 100;
  opacity: 0;
  animation: fadeIn .2s forwards;
}
@keyframes fadeIn { to { opacity: 1; } }
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 96vw);
  background: var(--paper);
  box-shadow: -12px 0 30px rgba(29,35,51,0.15);
  z-index: 101;
  overflow-y: auto;
  transform: translateX(100%);
  animation: slideIn .28s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes slideIn { to { transform: translateX(0); } }
.panel-head {
  padding: 22px 24px 16px;
  border-bottom: 1px solid rgba(29,35,51,0.08);
  position: sticky; top: 0; background: var(--paper); z-index: 2;
}
.panel-close {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(29,35,51,0.06);
  transition: background .15s;
}
.panel-close:hover { background: rgba(29,35,51,0.12); }
.panel-flag { font-size: 42px; line-height: 1; margin-bottom: 8px; }
.panel-native {
  font-family: 'Fraunces', serif;
  font-size: 20px;
  color: var(--ink-soft);
  font-style: italic;
}
.panel-meta {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.panel-meta .tag {
  padding: 3px 8px; border-radius: 999px;
  background: rgba(29,35,51,0.05);
  color: var(--ink-soft);
}
.panel-body { padding: 18px 24px 32px; display: flex; flex-direction: column; gap: 20px; }
.panel-hello {
  border-radius: 16px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(59,130,246,0.10), rgba(139,92,246,0.10));
  border: 1px solid rgba(59,130,246,0.18);
  display: flex; gap: 14px; align-items: center;
}
.panel-hello-text {
  flex: 1;
  font-family: 'Fraunces', serif;
  font-size: 26px;
  line-height: 1.1;
  font-feature-settings: "ss01";
}
.panel-hello-ipa {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}
.tts-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  display: grid; place-items: center;
  transition: transform .15s, background .15s;
  flex-shrink: 0;
}
.tts-btn:hover { transform: scale(1.05); }
.tts-btn.speaking { background: var(--accent-coral); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(249,122,77,0.5);} 50% { box-shadow: 0 0 0 10px rgba(249,122,77,0);} }

.panel-section h4 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.fact-list { display: flex; flex-direction: column; gap: 8px; }
.fact-item {
  display: flex; gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(29,35,51,0.03);
}
.fact-bullet {
  flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-sky);
  color: white;
  font-size: 12px; font-weight: 600;
  font-family: 'Fraunces', serif;
}
.culture-card {
  padding: 14px;
  border-radius: 14px;
  background: #FFF4E8;
  border: 1px dashed rgba(249,122,77,0.35);
  font-size: 14px;
  line-height: 1.5;
}
.didyouknow {
  padding: 14px 16px;
  border-radius: 14px;
  background: #FFF9DD;
  border: 1px solid rgba(232,184,58,0.4);
  position: relative;
  font-size: 14px;
}
.didyouknow::before {
  content: "Did you know?";
  display: block;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 13px;
  color: var(--accent-coral);
  margin-bottom: 4px;
}

/* ----- External links ----- */
.links-list { display: flex; flex-direction: column; gap: 6px; }
.ext-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(29,35,51,0.1);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
  transition: border-color .15s, background .15s, transform .1s;
}
.ext-link:hover {
  border-color: var(--ink);
  background: rgba(59,130,246,0.05);
}
.ext-link:active { transform: translateY(1px); }
.ext-link span { flex: 1; }
.ext-link .ext-arrow { color: var(--muted); transition: color .15s, transform .15s; }
.ext-link:hover .ext-arrow { color: var(--accent-sky); transform: translate(2px, -2px); }

/* ----- Timeline ----- */
.timeline-wrap {
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.1);
  border-radius: 22px;
  padding: 28px 28px 18px;
  box-shadow: var(--shadow-md);
}
.timeline-year-display {
  font-family: 'Fraunces', serif;
  font-size: 54px;
  line-height: 1;
  margin-bottom: 6px;
}
.timeline-year-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 24px;
}
.timeline-track-wrap {
  position: relative;
  margin: 30px 4px 16px;
}
.timeline-track {
  height: 6px;
  background: rgba(29,35,51,0.08);
  border-radius: 999px;
  position: relative;
}
.timeline-fill {
  position: absolute; top: 0; bottom: 0; left: 0;
  background: linear-gradient(90deg, var(--accent-coral), var(--accent-sky));
  border-radius: 999px;
  transition: width .1s linear;
}
.timeline-handle {
  position: absolute; top: 50%;
  transform: translate(-50%, -50%);
  width: 22px; height: 22px;
  background: var(--ink);
  border: 3px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(29,35,51,0.25);
  cursor: grab;
}
.timeline-handle:active { cursor: grabbing; }
.timeline-ticks {
  display: flex; justify-content: space-between;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}
.timeline-lane-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid rgba(29,35,51,0.06);
}
.timeline-lane-label {
  font-family: 'Fraunces', serif;
  font-size: 15px;
  display: flex; align-items: center; gap: 8px;
}
.timeline-lane-label .flag { font-size: 18px; }
.timeline-lane-track {
  position: relative;
  height: 18px;
}
.timeline-lane-bar {
  position: absolute;
  top: 4px;
  height: 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity .2s, filter .2s;
}
.timeline-lane-bar.inactive { opacity: 0.25; filter: grayscale(0.4); }
.timeline-lane-bar:hover { filter: brightness(1.08); }
.timeline-cursor {
  position: absolute; top: -6px; bottom: -6px;
  width: 2px;
  background: var(--ink);
  border-radius: 1px;
  pointer-events: none;
}
.timeline-legend {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid rgba(29,35,51,0.06);
  display: flex; gap: 18px; flex-wrap: wrap;
}

/* Region popover (when family blob in map is tapped) */
.region-pop {
  position: absolute;
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.12);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow-md);
  min-width: 200px;
  max-width: 260px;
  z-index: 5;
  font-size: 13px;
}
.region-pop h3 { font-size: 16px; margin-bottom: 8px; }
.region-fam {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  border-top: 1px solid rgba(29,35,51,0.06);
  cursor: pointer;
  transition: color .1s;
}
.region-fam:first-of-type { border-top: none; padding-top: 8px; }
.region-fam:hover { color: var(--accent-sky); }
.region-fam-count {
  margin-left: auto;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
}

/* Progress / unlocks */
.progress-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(76,154,104,0.12);
  color: var(--accent-moss);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.04em;
}
.progress-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-moss);
  animation: breathe 2s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }
.unlock-toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  z-index: 200;
  opacity: 0;
  transition: transform .3s cubic-bezier(0.22,1,0.36,1), opacity .2s;
  box-shadow: 0 10px 30px rgba(29,35,51,0.3);
}
.unlock-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.unlock-star { color: var(--accent-sun); }

/* Welcome / home */
.home-hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 32px;
  padding: 28px 0 0;
}
@media (max-width: 820px) {
  .home-hero { grid-template-columns: 1fr; }
}
.home-title {
  font-size: clamp(42px, 6vw, 68px);
  line-height: 0.98;
  letter-spacing: -0.02em;
}
.home-title em {
  font-style: italic;
  color: var(--accent-coral);
}
.home-lead {
  color: var(--ink-soft);
  font-size: 17px;
  max-width: 480px;
  margin-top: 18px;
}
.home-ctas {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 22px;
}
.btn {
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: transform .15s, background .15s;
  border: 1px solid transparent;
  display: inline-flex; gap: 8px; align-items: center;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { transform: translateY(-1px); background: #000; }
.btn.ghost { border-color: rgba(29,35,51,0.2); background: transparent; }
.btn.ghost:hover { border-color: var(--ink); }

.home-stats {
  background: var(--paper);
  border: 1px solid rgba(29,35,51,0.08);
  border-radius: 22px;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  position: relative;
  box-shadow: var(--shadow-md);
}
.home-stat .num {
  font-family: 'Fraunces', serif;
  font-size: 42px;
  line-height: 1;
  color: var(--ink);
}
.home-stat .lbl {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.home-globes {
  position: absolute;
  right: -20px;
  top: -30px;
  display: flex; gap: -10px;
}

/* Decorative sky illustration */
.home-sky {
  grid-column: 1 / -1;
  margin-top: 32px;
  border-radius: 22px;
  overflow: hidden;
  position: relative;
  aspect-ratio: 24 / 7;
  background: linear-gradient(180deg, #DFEDFD, #EFF7FF);
  border: 1px solid rgba(29,35,51,0.08);
}

/* Loading shimmer */
.shimmer {
  background: linear-gradient(90deg, rgba(29,35,51,0.04), rgba(29,35,51,0.08), rgba(29,35,51,0.04));
  background-size: 200% 100%;
  animation: shim 1.6s linear infinite;
}
@keyframes shim { to { background-position: -200% 0; } }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(29,35,51,0.15); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(29,35,51,0.25); }
