/*
  Universal HUD (Mode Switcher)
  Injected or placed manually into every mode
*/

:root {
  --hud-safe-top: max(82px, calc(env(safe-area-inset-top, 0px) + 82px));
  --hud-top-offset: max(14px, env(safe-area-inset-top, 0px));
  --hud-label-gap: clamp(18px, 2.2vw, 32px);
}

.hud-switcher {
  position: fixed;
  top: var(--hud-top-offset);
  bottom: auto;
  left: 50vw;
  transform: translateX(-50%);
  z-index: 9999;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 0;
  box-sizing: border-box;
  width: min(400px, calc(100vw - 18px));
  max-width: calc(100vw - 18px);
  background:
    linear-gradient(180deg, rgba(4, 10, 13, 0.34), rgba(1, 4, 7, 0.50)),
    radial-gradient(circle at 50% 0%, rgba(57, 255, 20, 0.028), transparent 62%);
  border: 1px solid rgba(154, 255, 168, 0.13);
  padding: 3px 14px;
  border-radius: 28px;
  backdrop-filter: blur(6px) saturate(106%);
  -webkit-backdrop-filter: blur(6px) saturate(106%);
  box-shadow:
    0 8px 28px rgba(0,0,0,0.26),
    0 0 10px rgba(57,255,20,0.028),
    inset 0 1px 0 rgba(255,255,255,0.06);
  font-family: 'SF Mono', monospace;
  font-size: 12px;
}

.hud-btn {
  box-sizing: border-box;
  position: relative;
  width: 100%;
  min-width: 0;
  font-weight: 700;
  color: rgba(226, 238, 239, 0.72);
  text-decoration: none;
  padding: 8px 2px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 24px;
  transition: color 0.22s ease, background 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease, text-shadow 0.22s ease;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 8px rgba(238, 250, 244, 0.05);
  --hud-label-shift: 0px;
}

.hud-label {
  display: inline-block;
  transform: translateX(var(--hud-label-shift));
}

.hud-btn[data-route="research"] { --hud-label-shift: 11px; }
.hud-btn[data-route="media"] { --hud-label-shift: 15px; }
.hud-btn[data-route="brief"] { --hud-label-shift: -9px; }
}

.hud-btn:hover {
  color: #f5fff2;
  background: rgba(57,255,20,0.018);
  border-color: transparent;
  text-shadow: 0 0 10px rgba(57,255,20,0.22);
}

.hud-btn:focus-visible {
  outline: 2px solid #39ff14;
  outline-offset: 2px;
  color: #fff;
}

.hud-btn:active {
  transform: scale(0.95);
}

.hud-btn.active {
  color: #f4fff1;
  background: transparent;
  font-weight: 700;
  border-color: transparent;
  box-shadow: none;
  text-shadow: 0 0 10px rgba(57,255,20,0.28);
}

.hud-btn.active::before {
  content: "";
  position: absolute;
  left: calc(50% + var(--hud-label-shift));
  bottom: 7px;
  width: 3px;
  height: 4px;
  border-radius: 999px;
  background: #39ff14;
  box-shadow: 0 0 10px rgba(57,255,20,0.55);
  transform: translateX(-50%);
}

.audio-btn {
  position: fixed;
  top: max(18px, env(safe-area-inset-top, 0px));
  right: max(28px, env(safe-area-inset-right, 0px));
  z-index: 260;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid rgba(248, 213, 140, 0.24);
  border-radius: 999px;
  background: rgba(3, 7, 12, 0.44);
  color: rgba(244, 247, 251, 0.74);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.audio-btn:hover,
.audio-btn.on {
  color: #f8d58c;
  border-color: rgba(248, 213, 140, 0.48);
  background: rgba(3, 7, 12, 0.58);
}

.audio-btn.queued:not(.on) {
  color: rgba(248, 213, 140, 0.86);
  border-color: rgba(248, 213, 140, 0.34);
}

.audio-btn.loading {
  opacity: 0.62;
  cursor: wait;
}

.audio-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #f8d58c;
  box-shadow: 0 0 10px rgba(248, 213, 140, 0.7);
  flex: 0 0 auto;
}

.audio-btn.on .audio-dot {
  background: #39ff14;
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.72);
}

.lab-cosmos-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 1;
  pointer-events: none;
  opacity: 0.22;
  mix-blend-mode: screen;
}

/* Узкие экраны: pill не должен вылезать за вьюпорт, но подписи остаются понятными. */
@media (max-width: 900px) {
  .hud-switcher {
    left: 50vw;
    right: auto;
    top: var(--hud-top-offset);
    bottom: auto;
    transform: translateX(-50%);
    width: min(360px, calc(100vw - 18px));
    max-width: calc(100vw - 18px);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    padding: 3px 12px;
    border-radius: 24px;
    overflow: hidden;
  }
  .hud-btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 5px 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    text-align: center;
    font-size: clamp(0.52rem, 2.12vw, 0.66rem);
    letter-spacing: 0;
    border-radius: 999px;
  }
  .hud-btn[data-route="research"] { --hud-label-shift: 5px; }
  .hud-btn[data-route="media"] { --hud-label-shift: 5px; }
  .hud-btn[data-route="brief"] { --hud-label-shift: -12px; }
}

@media (max-width: 760px) {
  .audio-btn {
    top: max(62px, calc(env(safe-area-inset-top, 0px) + 62px));
    right: max(12px, env(safe-area-inset-right, 0px));
    min-height: 34px;
    padding: 6px 11px;
    font-size: 0.58rem;
    opacity: 0.82;
  }
}

@media (max-height: 620px) {
  .hud-switcher {
    top: var(--hud-top-offset);
    bottom: auto;
    opacity: 0.94;
  }

  .hud-btn {
    min-height: 40px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
}

@media (min-width: 421px) and (max-width: 900px) {
  .hud-switcher {
    left: 50vw;
    right: auto;
    width: min(360px, calc(100vw - 24px));
    transform: translateX(-50%);
  }
}

@media (max-width: 380px) {
  .hud-switcher {
    left: 50vw;
    right: auto;
    transform: translateX(-50%);
    width: calc(100vw - 12px);
    padding-left: 8px;
    padding-right: 8px;
    gap: 0;
  }
  .hud-btn { font-size: 0.50rem; letter-spacing: 0; }
}

@media (max-device-width: 900px) {
  .hud-switcher {
    left: 50vw;
    right: auto;
    transform: translateX(-50%);
    width: min(360px, calc(100vw - 18px));
    max-width: calc(100vw - 18px);
  }

  .hud-btn {
    padding-left: 2px;
    padding-right: 2px;
    font-size: clamp(0.50rem, 2.08vw, 0.62rem);
    letter-spacing: 0;
  }
}

@media (max-width: 520px) {
  .hud-switcher {
    left: 50vw;
    right: auto;
    transform: translateX(-50%);
    width: min(360px, calc(100vw - 12px));
  }
}

/* ── Global Article Overlay (Modal) ── */
.art-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(4, 12, 9, 0.92);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(16px);
}
.art-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.art-modal {
  background: rgba(6, 18, 14, 0.95);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 16px;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(16, 185, 129, 0.1);
  overflow: hidden;
  position: relative;
}
.art-header {
  padding: 24px 32px;
  border-bottom: 1px solid rgba(16, 185, 129, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.art-header h2 {
  font-size: 1.8rem;
  color: #fff;
  margin: 0;
  font-weight: 700;
}
.art-close-btn {
  background: transparent;
  border: none;
  color: rgba(226, 232, 240, 0.4);
  font-size: 2rem;
  cursor: pointer;
  transition: color 0.2s, transform 0.2s;
  line-height: 1;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.art-close-btn:hover {
  color: #ef4444;
  transform: scale(1.1);
}
.art-body {
  padding: 32px;
  overflow-y: auto;
  color: #a7f3d0;
  line-height: 1.8;
  font-size: 1.05rem;
}
.art-body h1, .art-body h2, .art-body h3 {
  color: #fff;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
}
.art-body p {
  margin-bottom: 1.2em;
}
.art-body strong {
  color: #34d399;
}
.art-body a {
  color: #34d399;
  text-decoration: underline;
  transition: color 0.2s;
}
.art-body a:hover {
  color: #6ee7b7;
}
.art-body .experiment-card, .art-body .formula, .art-body .quote-card, .art-body .comparison-card {
  background: rgba(16, 185, 129, 0.05);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 12px;
  padding: 24px;
  margin: 24px 0;
}
.art-body .quote-card {
  border-left: 4px solid #fbbf24;
  background: rgba(251, 191, 36, 0.04);
}
.art-body .formula {
  text-align: center;
  background: rgba(0, 0, 0, 0.4);
}
.art-body .formula-text {
  font-size: 2.2rem;
  color: #34d399;
  font-family: serif;
  margin-bottom: 12px;
}
.art-body .comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin: 20px 0;
}
.art-body .comparison-card {
  margin: 0;
}
.art-body ul, .art-body ol {
  padding-left: 24px;
  margin-bottom: 1.2em;
}
.art-body li {
  margin-bottom: 0.5em;
}
.art-body .badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: bold;
  margin: 4px;
}
.art-body .badge-proven { background: rgba(16,185,129,0.2); color: #34d399; }
.art-body .badge-nobel { background: rgba(251,191,36,0.2); color: #fbbf24; }
.art-body header {
  display: none;
}

/* ── SPA Transition Overlay ── */
.spa-transition-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 38%, rgba(16,185,129,0.07), transparent 60%),
    radial-gradient(ellipse 60% 45% at 50% 72%, rgba(239,68,68,0.05), transparent 65%),
    #050505;
  z-index: 9998; /* Below HUD (z-index 9999) so the switcher remains visible above darkness */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.spa-transition-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── SPA Loader (inside overlay) ── */
.spa-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  opacity: 0;
  transition: opacity 0.25s ease 0.08s;
}
.spa-transition-overlay.active .spa-loader {
  opacity: 1;
}
.spa-loader-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #10b981 0%,
    rgba(16,185,129,0.06) 38%,
    #ef4444 55%,
    rgba(239,68,68,0.06) 78%,
    #10b981 100%
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  animation: spaLoaderSpin 1s linear infinite;
  filter:
    drop-shadow(0 0 10px rgba(16,185,129,0.5))
    drop-shadow(0 0 20px rgba(239,68,68,0.22));
}
@keyframes spaLoaderSpin {
  to { transform: rotate(360deg); }
}
.spa-loader-text {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(167,243,208,0.78);
  text-shadow: 0 0 12px rgba(16,185,129,0.45);
  animation: spaLoaderPulse 2.2s ease-in-out infinite;
}
@keyframes spaLoaderPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ── Универсальный смысловой глитч (редкий rgb-split на ключевых словах) ──
   Используется точечно: слово-другое на режим, не «гирлянда». */
.dv-glitch-word {
  position: relative;
  display: inline-block;
  animation: dvWordGlitch 9s steps(1) infinite;
}
@keyframes dvWordGlitch {
  0%, 93%, 100% { text-shadow: none; transform: none; opacity: 1; }
  93.8% { text-shadow: -2px 0 rgba(239,68,68,0.85), 2px 0 rgba(34,211,238,0.7); transform: translateX(1px) skewX(-3deg); }
  95%   { text-shadow: 2px 0 rgba(239,68,68,0.85), -2px 0 rgba(16,185,129,0.7); transform: translateX(-1px); opacity: 0.85; }
  96.2% { text-shadow: none; transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .spa-loader-ring,
  .spa-loader-text,
  .hud-switcher.hud-loading,
  .hud-switcher.hud-same,
  .dv-glitch-word {
    animation: none;
  }
  .spa-transition-overlay,
  .spa-loader,
  .hud-btn {
    transition: none;
  }
  .hud-btn:active {
    transform: none;
  }
}

/* ── Same-route click feedback (уже здесь) ── */
.hud-switcher.hud-same {
  animation: hudSamePulse 0.38s ease;
}
@keyframes hudSamePulse {
  0% { box-shadow: 0 12px 34px rgba(0,0,0,0.42), 0 0 0 rgba(16,185,129,0); }
  40% { box-shadow: 0 12px 34px rgba(0,0,0,0.42), 0 0 14px rgba(16,185,129,0.32); }
  100% { box-shadow: 0 12px 34px rgba(0,0,0,0.42), 0 0 0 rgba(16,185,129,0); }
}

/* ── HUD Switcher Loading Feedback ── */
.hud-switcher.hud-loading {
  opacity: 0.75;
  pointer-events: none;
  border-color: #2bff6a;
  box-shadow: 0 0 16px rgba(43, 255, 106, 0.32);
  animation: hudSwitcherPulse 1s infinite alternate;
}
@keyframes hudSwitcherPulse {
  from { box-shadow: 0 0 8px rgba(43, 255, 106, 0.18); }
  to { box-shadow: 0 0 18px rgba(43, 255, 106, 0.42); }
}
