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

.hud-switcher {
  position: fixed;
  top: max(14px, env(safe-area-inset-top, 0px));
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 2px;
  box-sizing: border-box;
  width: min(488px, calc(100vw - 40px));
  max-width: calc(100vw - 40px);
  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;
  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: 12.5px;
}

.hud-btn {
  box-sizing: border-box;
  position: relative;
  flex: 1 1 0;
  color: rgba(226, 238, 239, 0.72);
  text-decoration: none;
  padding: 8px 10px;
  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.07em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 8px rgba(238, 250, 244, 0.05);
}

.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: 900;
  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: 50%;
  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%);
}

.hud-btn-brief {
  color: rgba(226, 238, 239, 0.72);
  border-color: transparent;
  background: transparent;
}

.hud-btn-lab {
  color: rgba(244, 247, 251, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(148, 163, 184, 0.04);
}

.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: 12px;
    right: 12px;
    top: max(10px, env(safe-area-inset-top, 0px));
    bottom: auto;
    transform: none;
    width: auto;
    max-width: none;
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 24px;
    overflow: hidden;
  }
  .hud-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 5px 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    text-align: center;
    font-size: clamp(0.48rem, 1.7vw, 0.58rem);
    letter-spacing: 0.015em;
    border-radius: 999px;
  }
  .hud-btn {
    font-size: 0;
  }
  .hud-btn::after {
    content: attr(data-short);
    font-size: clamp(0.66rem, 2.5vw, 0.76rem);
    line-height: 1;
  }
}

@media (max-height: 620px) {
  .hud-switcher {
    top: max(8px, env(safe-area-inset-top, 0px));
    bottom: auto;
    width: 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: 16px;
    right: 16px;
  }
}

@media (max-width: 380px) {
  .hud-switcher {
    left: 10px;
    right: 10px;
  }
  .hud-btn { font-size: 0.45rem; letter-spacing: 0.01em; }
}

/* ── 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); }
}
