:root {
  --bg: #050510;
  --bg-2: #0a0a1a;
  --fg: #f5f5ff;
  --muted: #8a8aa5;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #7c5cff;
  --accent-2: #00e5ff;
  --accent-3: #ff4ecd;
  --gradient: linear-gradient(135deg, #7c5cff 0%, #00e5ff 50%, #ff4ecd 100%);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  font-family: 'Space Grotesk', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  position: relative;
}
em { font-style: normal; background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* BACKGROUND */
#bg-canvas { position: fixed; inset: 0; z-index: -2; pointer-events: none; }
.grid-overlay {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse at center, rgba(0,0,0,0.9), transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, rgba(0,0,0,0.9), transparent 75%);
}
.noise {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  opacity: 0.04; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* TOPBAR */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding: 22px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: inherit;
  text-decoration: none;
  transition: opacity .3s ease;
}
a.brand:hover { opacity: 0.75; }
.brand-logo {
  width: 26px; height: 26px;
  filter: drop-shadow(0 0 12px rgba(124,92,255,0.6));
}
.legend {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 10, 26, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 11px;
  color: var(--muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.legend-ic {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: var(--accent-2);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* RTL language support (Arabic) */
html[dir="rtl"] .topbar { flex-direction: row-reverse; }
html[dir="rtl"] .topbar-right { flex-direction: row-reverse; }
html[dir="rtl"] .modal-title,
html[dir="rtl"] .modal-desc,
html[dir="rtl"] .modal-child-title,
html[dir="rtl"] .modal-child-desc { text-align: right; direction: rtl; }
html[dir="rtl"] .node-label { direction: rtl; }

/* Language switcher — horizontal scroll row, fits 13+ langs */
.lang-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 10, 26, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 1px;
  max-width: min(440px, 50vw);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.lang-switch::-webkit-scrollbar { display: none; }

.lang-btn {
  padding: 6px 9px;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  transition: all .3s var(--ease);
  min-width: 30px;
  flex-shrink: 0;
}
.lang-btn:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.05);
}
.lang-btn.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.55), rgba(0, 229, 255, 0.35));
  box-shadow: 0 4px 16px rgba(124, 92, 255, 0.35);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: rgba(124, 92, 255, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transform: translateX(20px);
  pointer-events: none;
  transition: all .5s var(--ease);
}
.back-btn.visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
.back-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 8px 30px rgba(124, 92, 255, 0.5);
  transform: translateY(-1px);
}

/* STAGE */
.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.map-canvas {
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  transition: transform 1s var(--ease);
  will-change: transform;
}
.links-svg {
  position: absolute;
  left: 0; top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}
.nodes {
  position: absolute;
  left: 0; top: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.nodes > * { pointer-events: auto; }

/* LINKS (SVG paths) */
.link-path {
  fill: none;
  stroke: url(#link-grad);
  stroke-width: 0.8;
  opacity: 0;
  stroke-linecap: round;
  transition: opacity .5s ease, stroke-dashoffset .9s var(--ease);
  vector-effect: non-scaling-stroke;
}
.link-path.visible { opacity: 0.55; }

/* NODE — common */
.node {
  position: absolute;
  left: 0; top: 0;
  transition:
    transform .9s var(--ease),
    opacity .55s ease;
  will-change: transform, opacity;
}
.node.hidden {
  opacity: 0;
  pointer-events: none;
}
.node-inner {
  position: relative;
  padding: 16px 24px;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 12, 28, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  min-width: 150px;
  text-align: center;
  cursor: pointer;
  transition: all .35s var(--ease);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.node-inner::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: var(--gradient);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity .35s;
}
.node-inner:hover {
  transform: translateY(-2px);
  border-color: transparent;
}
.node-inner:hover::before { opacity: 1; }
.node-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  white-space: nowrap;
}
.node-hint {
  font-size: 9px;
  color: var(--muted);
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.node-hint svg { width: 9px; height: 9px; }

/* Icon buttons on each node */
.node-btn {
  position: absolute;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  color: var(--muted);
  transition: all .3s var(--ease);
  z-index: 2;
}
.node-btn svg { width: 13px; height: 13px; }
.node-btn:hover {
  transform: scale(1.15);
  color: #fff;
  border-color: transparent;
}
.node-btn-zoom {
  top: -10px;
  left: -10px;
}
.node-btn-zoom:hover {
  background: var(--accent-2);
  color: #000;
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.6);
}
.node-btn-speak {
  top: -10px;
  right: -10px;
}
.node-btn-speak:hover {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 18px rgba(124, 92, 255, 0.6);
}
.node-btn-speak.speaking {
  background: var(--accent-2);
  color: #000;
  border-color: var(--accent-2);
  animation: speaking-pulse 1.4s ease-in-out infinite;
}
@keyframes speaking-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.6); }
  50% { box-shadow: 0 0 0 10px rgba(0, 229, 255, 0); }
}

/* ROOT NODE */
.node-root .node-inner {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  padding: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(124, 92, 255, 0.3), rgba(12, 12, 28, 0.9));
  border-color: rgba(124, 92, 255, 0.55);
  box-shadow:
    0 0 100px rgba(124, 92, 255, 0.4),
    inset 0 0 50px rgba(124, 92, 255, 0.18);
}
.node-root .node-inner::before { opacity: 1; }
.root-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.root-logo {
  width: 70px;
  height: 70px;
  filter: drop-shadow(0 0 18px rgba(255,255,255,0.55));
}
.root-label {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.root-sub {
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.node-root::before {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 250px; height: 250px;
  border-radius: 50%;
  border: 1px dashed rgba(255,255,255,0.12);
  animation: rotate-slow 40s linear infinite;
  pointer-events: none;
}
.node-root::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 290px; height: 290px;
  border-radius: 50%;
  border: 1px dashed rgba(255,255,255,0.06);
  animation: rotate-slow 60s linear infinite reverse;
  pointer-events: none;
}
@keyframes rotate-slow {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* L2 NODES */
.node-l2 .node-inner {
  padding: 18px 28px;
  min-width: 175px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.16), rgba(0, 229, 255, 0.06));
  border-color: rgba(124, 92, 255, 0.4);
  box-shadow: 0 12px 44px rgba(124, 92, 255, 0.22);
}
.node-l2 .node-icon {
  font-size: 26px;
  display: block;
  margin-bottom: 6px;
}
.node-l2 .node-label {
  font-size: 15px;
}
.node-l2.active .node-inner {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.36), rgba(0, 229, 255, 0.2));
  border-color: var(--accent);
  box-shadow:
    0 0 70px rgba(124, 92, 255, 0.6),
    0 0 0 3px rgba(124, 92, 255, 0.22);
}

/* L3 NODES */
.node-l3 .node-inner {
  padding: 13px 18px;
  min-width: 140px;
  background: rgba(14, 14, 32, 0.9);
}
.node-l3 .node-label {
  font-size: 12px;
}

/* CRUMBS */
.crumbs {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 10, 26, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.crumb {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  transition: all .3s;
}
.crumb:hover { color: var(--fg); background: rgba(255,255,255,0.06); }
.crumb-active {
  color: var(--fg);
  background: rgba(124, 92, 255, 0.2);
}
.crumb-sep {
  color: var(--muted);
  font-size: 10px;
  opacity: 0.6;
}

/* INITIAL LOAD */
.stage:not(.ready) .node { opacity: 0; transform: scale(0.3); }
.stage:not(.ready) .link-path { opacity: 0; }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(5, 5, 16, 0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s ease;
}
.modal-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  position: relative;
  max-width: 600px;
  width: 100%;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 44px 44px 36px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(22, 22, 44, 0.97), rgba(12, 12, 28, 0.97));
  border: 1px solid rgba(124, 92, 255, 0.4);
  box-shadow:
    0 40px 100px rgba(0, 0, 0, 0.6),
    0 0 100px rgba(124, 92, 255, 0.2);
  transform: translateY(30px) scale(0.94);
  transition: transform .55s var(--ease);
}
.modal-backdrop.visible .modal-card {
  transform: translateY(0) scale(1);
}
.modal-card::-webkit-scrollbar { width: 6px; }
.modal-card::-webkit-scrollbar-track { background: transparent; }
.modal-card::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  transition: all .3s var(--ease);
  background: rgba(0,0,0,0.3);
  z-index: 3;
}
.modal-close:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
  transform: rotate(90deg);
}
.modal-level {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent-2);
  padding: 4px 10px;
  border: 1px solid rgba(0, 229, 255, 0.3);
  border-radius: 999px;
  margin-bottom: 18px;
}
.modal-title {
  font-size: 36px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 18px;
  background: linear-gradient(135deg, #fff 0%, #c6c0ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.modal-desc {
  font-size: 16px;
  line-height: 1.65;
  color: #b8b8d0;
  margin-bottom: 28px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.modal-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 22px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.03);
  font-size: 13px;
  font-weight: 500;
  transition: all .3s var(--ease);
}
.modal-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.08);
  transform: translateY(-1px);
}
.modal-btn:disabled { opacity: 0.5; cursor: default; }
.modal-btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.modal-btn-primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  box-shadow: 0 6px 24px rgba(0, 229, 255, 0.4);
}
.modal-btn-primary.speaking {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #000;
  animation: speaking-pulse 1.4s ease-in-out infinite;
}
.modal-children-wrap {
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.modal-children-wrap.hidden { display: none; }
.modal-children-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-bottom: 14px;
}
.modal-children {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.modal-child {
  position: relative;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.025);
  cursor: pointer;
  transition: all .3s var(--ease);
  text-align: left;
}
.modal-child:hover {
  border-color: var(--accent);
  background: rgba(124, 92, 255, 0.1);
  transform: translateY(-2px);
}
.modal-child-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
}
.modal-child-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============ SPEAKER (PERSON) ============ */
.speaker {
  position: fixed;
  right: -340px;
  bottom: 0;
  z-index: 150;
  width: 280px;
  height: 100vh;
  pointer-events: none;
  transition: right 1.1s var(--ease), opacity .6s ease;
  opacity: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.speaker.visible {
  right: 0;
  opacity: 1;
}

.person-wrap {
  position: relative;
  z-index: 2;
  height: 72vh;
  max-height: 680px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transform-origin: 50% 100%;
  animation: person-idle 4s ease-in-out infinite;
}
.speaker.speaking .person-wrap {
  animation: person-talk 1.8s ease-in-out infinite;
}
@keyframes person-idle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(0.3deg); }
}
@keyframes person-talk {
  0%, 100% { transform: translateY(0) rotate(-0.4deg); }
  25% { transform: translateY(-3px) rotate(0.3deg); }
  50% { transform: translateY(-1px) rotate(-0.2deg); }
  75% { transform: translateY(-4px) rotate(0.5deg); }
}

.person-img,
.figure-robot {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  filter:
    drop-shadow(0 25px 50px rgba(0, 0, 0, 0.6))
    drop-shadow(0 0 40px rgba(124, 92, 255, 0.25));
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity .5s ease, transform .6s var(--ease);
}

/* Mode switching: only show one figure at a time */
.figure-robot { display: none; }
.speaker[data-mode="person"] .figure-person { display: block; }
.speaker[data-mode="person"] .figure-robot { display: none; }
.speaker[data-mode="robot"] .figure-person { display: none; }
.speaker[data-mode="robot"] .figure-robot { display: block; }

/* ===== Robot animations ===== */
.bot-eyes ellipse {
  animation: bot-eye-pulse 2.4s ease-in-out infinite;
}
@keyframes bot-eye-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.bot-core {
  transform-origin: 160px 305px;
  animation: bot-core-pulse 1.8s ease-in-out infinite;
}
@keyframes bot-core-pulse {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}
.bot-led {
  animation: bot-led-blink 2.2s ease-in-out infinite;
}
.bot-led-2 { animation-delay: 0.6s; }
@keyframes bot-led-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.bot-arm-l {
  transform-origin: 62px 248px;
  animation: bot-sway 5s ease-in-out infinite;
}
.bot-arm-r {
  transform-origin: 258px 248px;
  animation: bot-sway 5s ease-in-out infinite reverse;
}
@keyframes bot-sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(1.5deg); }
}
.bot-head {
  transform-origin: 160px 200px;
  animation: bot-head-tilt 6s ease-in-out infinite;
}
@keyframes bot-head-tilt {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-1deg); }
}

/* Mouth dots — animated only when speaking */
.bot-dot {
  transform-origin: center;
  transform-box: fill-box;
  opacity: 0.3;
  animation-duration: 0.6s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
  animation-direction: alternate;
  animation-play-state: paused;
}
.speaker.speaking .bot-dot {
  animation-name: bot-dot-pulse;
  animation-play-state: running;
}
.bot-dot-1 { animation-duration: 0.42s; animation-delay: 0.0s; }
.bot-dot-2 { animation-duration: 0.36s; animation-delay: 0.05s; }
.bot-dot-3 { animation-duration: 0.48s; animation-delay: 0.1s; }
.bot-dot-4 { animation-duration: 0.4s;  animation-delay: 0.15s; }
.bot-dot-5 { animation-duration: 0.44s; animation-delay: 0.05s; }
.bot-dot-6 { animation-duration: 0.5s;  animation-delay: 0.0s; }
@keyframes bot-dot-pulse {
  0%   { opacity: 0.3; transform: scale(0.8); }
  100% { opacity: 1;   transform: scale(1.6); }
}

/* ===== Mode toggle buttons ===== */
.speaker-toggle {
  position: absolute;
  top: 50%;
  left: -16px;
  transform: translate(-100%, calc(-50% + 60px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  opacity: 0;
  transition: opacity .5s ease .5s;
}
.speaker.visible .speaker-toggle { opacity: 1; }
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  transition: all .3s var(--ease);
}
.toggle-btn:hover {
  color: var(--fg);
  border-color: var(--accent);
  transform: translateX(-3px);
}
.toggle-btn.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.5), rgba(0, 229, 255, 0.3));
  border-color: var(--accent);
  box-shadow: 0 6px 24px rgba(124, 92, 255, 0.4);
}
.toggle-btn svg { flex-shrink: 0; }

/* Glow halo behind person */
.speaker-glow {
  position: absolute;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  width: 340px;
  height: 340px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(124, 92, 255, 0.45),
    rgba(0, 229, 255, 0.18) 40%,
    transparent 70%);
  filter: blur(60px);
  z-index: 1;
  animation: glow-pulse 2.4s ease-in-out infinite;
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0.7; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.08); }
}

.speaker-shadow {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.7), transparent 70%);
  z-index: 0;
  animation: shadow-bob 4s ease-in-out infinite;
}
@keyframes shadow-bob {
  0%, 100% { transform: translateX(-50%) scaleX(1); opacity: 0.6; }
  50% { transform: translateX(-50%) scaleX(0.93); opacity: 0.45; }
}

/* ===== Sound waves around mouth area ===== */
.sound-waves {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 0; height: 0;
  pointer-events: none;
}
.wave {
  position: absolute;
  top: 0; left: 0;
  width: 80px; height: 80px;
  border-radius: 50%;
  border: 2px solid rgba(0, 229, 255, 0.7);
  transform: translate(-50%, -50%);
  opacity: 0;
}
.speaker.speaking .wave {
  animation: wave-out 1.6s ease-out infinite;
}
.wave-1 { animation-delay: 0s !important; }
.wave-2 { animation-delay: 0.5s !important; border-color: rgba(124, 92, 255, 0.6); }
.wave-3 { animation-delay: 1s !important; border-color: rgba(255, 78, 205, 0.5); }
@keyframes wave-out {
  0% { width: 30px; height: 30px; opacity: 0.9; border-width: 3px; }
  100% { width: 220px; height: 220px; opacity: 0; border-width: 1px; }
}

/* ===== Equalizer bars in front of body ===== */
.eq {
  position: absolute;
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 50px;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(10, 10, 26, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(124, 92, 255, 0.3);
  box-shadow: 0 8px 30px rgba(124, 92, 255, 0.35);
  opacity: 0;
  transition: opacity .4s ease;
}
.speaker.speaking .eq {
  opacity: 1;
}
.eq-bar {
  width: 4px;
  height: 6px;
  border-radius: 2px;
  background: linear-gradient(180deg, #00e5ff, #7c5cff);
  transform-origin: center bottom;
  animation-duration: 0.5s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
  animation-direction: alternate;
  animation-play-state: paused;
  box-shadow: 0 0 6px rgba(0, 229, 255, 0.6);
}
.speaker.speaking .eq-bar { animation-play-state: running; }
.eq-bar-1 { animation-name: eq-a; animation-duration: 0.42s; }
.eq-bar-2 { animation-name: eq-b; animation-duration: 0.36s; }
.eq-bar-3 { animation-name: eq-c; animation-duration: 0.48s; }
.eq-bar-4 { animation-name: eq-d; animation-duration: 0.32s; }
.eq-bar-5 { animation-name: eq-e; animation-duration: 0.46s; }
.eq-bar-6 { animation-name: eq-f; animation-duration: 0.38s; }
.eq-bar-7 { animation-name: eq-g; animation-duration: 0.44s; }
.eq-bar-8 { animation-name: eq-c; animation-duration: 0.4s; }
.eq-bar-9 { animation-name: eq-a; animation-duration: 0.5s; }
@keyframes eq-a { from { height: 6px; } to { height: 28px; } }
@keyframes eq-b { from { height: 8px; } to { height: 36px; } }
@keyframes eq-c { from { height: 4px; } to { height: 32px; } }
@keyframes eq-d { from { height: 10px; } to { height: 42px; } }
@keyframes eq-e { from { height: 6px; } to { height: 26px; } }
@keyframes eq-f { from { height: 8px; } to { height: 34px; } }
@keyframes eq-g { from { height: 5px; } to { height: 30px; } }

/* ===== Caption badge ===== */
.speaker-caption {
  position: absolute;
  top: 50%;
  left: -16px;
  transform: translate(-100%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(10, 10, 26, 0.88);
  border: 1px solid var(--accent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  box-shadow: 0 10px 40px rgba(124, 92, 255, 0.4);
  opacity: 0;
  transition: opacity .5s ease .3s;
}
.speaker.visible .speaker-caption { opacity: 1; }
.speaker-caption-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00ff9d;
  box-shadow: 0 0 12px #00ff9d;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* MOBILE */
/* ============ TABLET ============ */
@media (max-width: 1024px) {
  .topbar { padding: 18px 22px; gap: 14px; }
  .legend { padding: 8px 14px; gap: 12px; font-size: 12px; }
  .legend-ic { width: 20px; height: 20px; }
}

/* ============ MOBILE ============ */
@media (max-width: 760px) {
  /* Topbar */
  .topbar {
    padding: 12px 14px;
    gap: 8px;
  }
  .brand { font-size: 16px; gap: 8px; }
  .brand-logo { width: 22px; height: 22px; }
  .legend { display: none; }
  .back-btn {
    padding: 9px 14px;
    font-size: 14px;
  }
  .back-btn span { display: none; }
  .topbar-right { gap: 6px; }
  .lang-switch { padding: 2px; gap: 1px; max-width: 60vw; }
  .lang-btn { padding: 7px 9px; font-size: 12px; min-width: 30px; }

  /* Nodes */
  .node-root .node-inner { width: 140px; height: 140px; }
  .root-logo { width: 46px; height: 46px; }
  .root-label { font-size: 16px; }
  .root-sub { font-size: 9px; }
  .node-root::before { width: 170px; height: 170px; }
  .node-root::after { width: 200px; height: 200px; }

  .node-l2 .node-inner {
    padding: 12px 16px;
    min-width: 120px;
  }
  .node-l2 .node-label { font-size: 16px; }
  .node-l2 .node-icon { font-size: 20px; margin-bottom: 3px; }
  .node-l2 .node-hint { font-size: 14px; margin-top: 4px; }

  .node-l3 .node-inner {
    padding: 10px 14px;
    min-width: 100px;
  }
  .node-l3 .node-label { font-size: 15px; }

  /* Node buttons — 32px for easy tapping on mobile */
  .node-btn {
    width: 32px;
    height: 32px;
  }
  .node-btn svg { width: 14px; height: 14px; }
  .node-btn-zoom { top: -10px; left: -10px; }
  .node-btn-speak { top: -10px; right: -10px; }

  /* Crumbs */
  .crumbs {
    bottom: 14px;
    padding: 6px 12px;
    gap: 4px;
  }
  .crumb { font-size: 14px; padding: 5px 10px; }
  .crumb-sep { font-size: 14px; }

  /* Modal */
  .modal-backdrop { padding: 30px 14px; }
  .modal-card {
    padding: 28px 20px 22px;
    border-radius: 18px;
    max-height: calc(100vh - 60px);
  }
  .modal-close { top: 12px; right: 12px; width: 36px; height: 36px; }
  .modal-level { font-size: 11px; padding: 4px 10px; margin-bottom: 14px; }
  .modal-title { font-size: 28px; margin-bottom: 14px; }
  .modal-desc { font-size: 16px; margin-bottom: 22px; }
  .modal-actions {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 22px;
  }
  .modal-btn {
    width: 100%;
    justify-content: center;
    padding: 13px 18px;
    font-size: 14px;
  }
  .modal-children { grid-template-columns: 1fr; gap: 8px; }
  .modal-child { padding: 12px 14px; }
  .modal-child-title { font-size: 15px; }
  .modal-child-desc { font-size: 14px; -webkit-line-clamp: 3; line-clamp: 3; }

  /* Speaker (person/robot) — compact, doesn't dominate the screen */
  .speaker {
    width: 200px;
    right: -260px;
  }
  .person-wrap {
    height: 62vh;
    max-height: 480px;
  }
  .speaker-glow {
    width: 240px;
    height: 240px;
    bottom: -50px;
  }
  .speaker-shadow {
    width: 150px;
    height: 16px;
    bottom: 8px;
  }

  /* Caption above speaker (instead of left side) */
  .speaker-caption {
    top: 14%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    padding: 8px 14px;
    letter-spacing: 0.08em;
  }

  /* Toggle buttons stack horizontally below caption */
  .speaker-toggle {
    top: 14%;
    left: 50%;
    transform: translate(-50%, 42px);
    flex-direction: row;
    gap: 6px;
  }
  .toggle-btn {
    padding: 7px 12px 7px 10px;
    font-size: 12px;
    gap: 5px;
  }
  .toggle-btn svg { width: 13px; height: 13px; }
  .toggle-btn:hover { transform: none; }

  /* Equalizer & sound waves smaller */
  .eq {
    padding: 6px 10px;
    height: 36px;
    gap: 3px;
    bottom: 26%;
  }
  .eq-bar { width: 4px; }
  .wave { width: 60px; height: 60px; }
  @keyframes wave-out {
    0% { width: 24px; height: 24px; opacity: 0.9; border-width: 2px; }
    100% { width: 160px; height: 160px; opacity: 0; border-width: 1px; }
  }
}

/* ============ SMALL PHONES ============ */
@media (max-width: 420px) {
  .topbar { padding: 10px 12px; }
  .brand span { display: none; }
  .back-btn { padding: 9px 12px; font-size: 14px; }

  .node-root .node-inner { width: 120px; height: 120px; }
  .root-logo { width: 40px; height: 40px; }
  .root-label { font-size: 16px; }
  .root-sub { display: none; }
  .node-root::before { width: 146px; height: 146px; }
  .node-root::after { width: 172px; height: 172px; }

  .node-l2 .node-inner { padding: 10px 14px; min-width: 108px; }
  .node-l2 .node-label { font-size: 16px; }
  .node-l2 .node-icon { font-size: 18px; }
  .node-l2 .node-hint { display: none; }

  .node-l3 .node-inner { padding: 9px 12px; min-width: 88px; }
  .node-l3 .node-label { font-size: 15px; }

  .speaker { width: 170px; right: -220px; }
  .person-wrap { height: 56vh; max-height: 400px; }
  .speaker-glow { width: 200px; height: 200px; }

  .modal-card { padding: 24px 16px 18px; }
  .modal-title { font-size: 28px; }
  .modal-desc { font-size: 16px; line-height: 1.6; }
  .modal-child-title { font-size: 15px; }
  .modal-child-desc { font-size: 14px; }
}

/* ============ LANDSCAPE PHONES (low height) ============ */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { padding: 8px 14px; }
  .node-root .node-inner { width: 100px; height: 100px; }
  .root-logo { width: 36px; height: 36px; }
  .root-label { font-size: 16px; }
  .root-sub { display: none; }
  .node-root::before { width: 122px; height: 122px; }
  .node-root::after { width: 142px; height: 142px; }
  .node-l2 .node-inner { padding: 8px 14px; }
  .node-l2 .node-icon { font-size: 16px; margin-bottom: 2px; }
  .node-l2 .node-label { font-size: 16px; }
  .node-l2 .node-hint { display: none; }
  .node-l3 .node-label { font-size: 15px; }
  .crumbs { bottom: 8px; }
  .crumb { font-size: 14px; }
  .speaker { width: 150px; right: -190px; }
  .person-wrap { height: 88vh; max-height: 360px; }
}
