/*
 * ЕДИНАЯ ШАПКА Ecliption — стили (разметка и логика: shared/header.js).
 * Правишь здесь → меняется на всех страницах сайта и внутри лабораторий.
 * Сюда же вынесены стеклянные контролы, окно «Как пользоваться» и тост (часть шапки).
 * Переменные страницы (--accent, --ink, --control-height…) берутся из :root страницы;
 * если их нет (лаборатории) — работают запасные значения в var(--x, запас).
 */

@property --brand-accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #6558ef;
}

@property --brand-accent-2 {
  syntax: "<color>";
  inherits: true;
  initial-value: #50bde7;
}

@property --brand-accent-glow {
  syntax: "<color>";
  inherits: true;
  initial-value: #b8a6ff;
}

.glass-control,
.glass-panel {
  position: relative;
  border: 1px solid var(--glass-line, rgba(255, 255, 255, 0.86));
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(242, 249, 255, 0.42)),
    rgba(220, 239, 255, 0.34);
  box-shadow: var(--shadow-control, 0 8px 22px rgba(33, 64, 125, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.92));
  backdrop-filter: blur(24px) saturate(1.32);
  -webkit-backdrop-filter: blur(24px) saturate(1.32);
}

.glass-control::before,
.glass-panel::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 1px;
  border-radius: inherit;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.55), transparent 28%, transparent 72%, rgba(255, 255, 255, 0.18));
  pointer-events: none;
}

.glass-control > *,
.glass-panel > * {
  position: relative;
  z-index: 1;
}

.topbar {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.topbar__left,
.topbar__actions {
  display: flex;
  align-items: center;
}

.topbar__left {
  gap: 18px;
}

.topbar__actions {
  gap: 9px;
}

.icon-button,
.action-button {
  height: var(--control-height, 42px);
  border-radius: var(--radius-control, 13px);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.icon-button {
  display: grid;
  width: var(--control-height, 42px);
  padding: 0;
  place-items: center;
}

.icon-button svg {
  width: 19px;
  height: 19px;
}

.action-button {
  display: inline-flex;
  min-width: 102px;
  padding: 0 14px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 720;
  letter-spacing: -0.01em;
}

.action-button--wide {
  min-width: 154px;
}

.action-button svg {
  width: 18px;
  height: 18px;
}

.action-button .sound-off {
  display: none;
}

.action-button[aria-pressed="false"] .sound-on {
  display: none;
}

.action-button[aria-pressed="false"] .sound-off {
  display: block;
}

.control-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #45c99a;
  box-shadow: 0 0 0 4px rgba(69, 201, 154, 0.13);
}

.action-button[aria-pressed="false"] .control-dot {
  background: #a8b0c5;
  box-shadow: none;
}

.icon-button:hover,
.action-button:hover,
.language-switch:hover {
  border-color: #fff;
  box-shadow: 0 12px 26px rgba(43, 73, 139, 0.14), inset 0 1px 0 #fff;
  transform: translateY(-1px);
}

.icon-button:active,
.action-button:active {
  transform: translateY(0) scale(0.98);
}

.brand {
  position: relative;
  display: flex;
  height: 34px;
  align-items: center;
}

.brand img {
  display: block;
  width: auto;
  height: 29px;
  object-fit: contain;
}

.brand::before {
  content: "";
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

@supports ((-webkit-mask-image: url("../assets/brand/ecliption-logo.png")) or (mask-image: url("../assets/brand/ecliption-logo.png"))) {
  .brand img {
    opacity: 0;
  }

  .brand::before {
    display: block;
    background:
      linear-gradient(
        102deg,
        color-mix(in srgb, var(--brand-accent, #6558ef) 68%, #0d214f 32%) 0%,
        color-mix(in srgb, var(--brand-accent-2, #50bde7) 62%, #0d214f 38%) 27%,
        color-mix(in srgb, var(--brand-accent-glow, #b8a6ff) 54%, #0d214f 46%) 50%,
        color-mix(in srgb, var(--brand-accent, #6558ef) 66%, #0d214f 34%) 73%,
        color-mix(in srgb, var(--brand-accent-2, #50bde7) 60%, #0d214f 40%) 100%
      );
    background-position: 0% 50%;
    background-size: 240% 100%;
    filter:
      saturate(1.08)
      contrast(1.05)
      drop-shadow(0 1px 1px rgba(8, 22, 57, 0.24))
      drop-shadow(0 3px 9px rgba(16, 32, 78, 0.13));
    -webkit-mask-image: url("../assets/brand/ecliption-logo.png");
    mask-image: url("../assets/brand/ecliption-logo.png");
    -webkit-mask-position: left center;
    mask-position: left center;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
    animation: brand-gradient-flow 8.5s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
    will-change: background-position;
  }
}

@keyframes brand-gradient-flow {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.language-switch {
  isolation: isolate;
  display: grid;
  width: 150px;
  height: var(--control-height, 42px);
  padding: 3px;
  border-radius: var(--radius-control, 13px);
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.language-switch::after {
  content: "";
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 3);
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 5px 14px rgba(43, 74, 143, 0.14);
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.language-switch[data-language="kz"]::after {
  transform: translateX(100%);
}

.language-switch[data-language="en"]::after {
  transform: translateX(200%);
}

.language-switch button {
  position: relative;
  z-index: 2;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #7681a1;
  cursor: pointer;
  font-size: 12px;
  font-weight: 780;
  letter-spacing: 0.04em;
  transition: color 180ms ease;
}

.language-switch button[aria-pressed="true"] {
  color: var(--ink, #10204e);
}

.instruction-modal {
  width: min(590px, calc(100% - 32px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink, #10204e);
  overscroll-behavior: contain;
}

.instruction-modal::backdrop {
  background: rgba(21, 34, 76, 0.28);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  padding: 32px;
  border-radius: 28px;
  box-shadow: 0 32px 90px rgba(27, 47, 100, 0.3), inset 0 1px 0 #fff;
}

.modal-close {
  position: absolute;
  z-index: 3;
  top: 16px;
  right: 16px;
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 11px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  place-items: center;
}

.modal-icon {
  display: grid;
  width: 50px;
  height: 50px;
  margin-bottom: 20px;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--accent, #6558ef), var(--accent-2, #50bde7));
  box-shadow: 0 13px 30px rgba(var(--accent-rgb, 101, 88, 239), 0.28);
  color: #fff;
  font-size: 24px;
  font-weight: 760;
  place-items: center;
}

.modal-card h2 {
  margin: 0 0 22px;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.modal-card ol {
  display: grid;
  margin: 0;
  padding: 0;
  gap: 11px;
  list-style: none;
}

.modal-card li {
  display: grid;
  padding: 13px 14px;
  border: 1px solid rgba(77, 97, 145, 0.1);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.54);
  grid-template-columns: 36px 1fr;
  gap: 12px;
}

.modal-card li > span {
  color: var(--accent, #6558ef);
  font-size: 12px;
  font-weight: 820;
}

.modal-card li p,
.modal-card li strong,
.modal-card li small {
  display: block;
  margin: 0;
}

.modal-card li strong {
  margin-bottom: 3px;
  font-size: 14px;
}

.modal-card li small {
  color: var(--muted, #6b779b);
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  z-index: 500;
  left: 50%;
  bottom: 26px;
  max-width: min(480px, calc(100% - 32px));
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 13px;
  background: rgba(18, 33, 74, 0.9);
  box-shadow: 0 16px 45px rgba(24, 41, 89, 0.28);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 980px) {
  .action-button span:not(.control-dot),
  .action-button--wide span {
    display: none;
  }

  .action-button,
  .action-button--wide {
    min-width: var(--control-height, 42px);
    width: var(--control-height, 42px);
    padding: 0;
  }

  .control-dot {
    position: absolute;
    right: 7px;
    bottom: 7px;
  }

  .language-switch {
    width: 132px;
  }

  .language-switch button {
    font-size: 11px;
  }
}

@media (max-width: 620px) {
  .topbar__left {
    gap: 10px;
  }

  .topbar__actions {
    gap: 6px;
  }

  .brand img {
    width: 108px;
    height: auto;
  }

  .topbar [data-sound] {
    display: none;
  }

  .language-switch {
    width: 116px;
  }

  .language-switch button {
    font-size: 10px;
    letter-spacing: 0.02em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand::before {
    animation: none !important;
    background-position: 50% 50%;
    will-change: auto;
  }
}

@media (forced-colors: active) {
  .brand img {
    opacity: 1;
  }

  .brand::before {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Резерв для страниц без стилей сайта (лаборатории): базовая типографика
   самой шапки. На страницах сайта значения совпадают с глобальными.
   -------------------------------------------------------------------------- */
.topbar,
.topbar *,
.instruction-modal,
.instruction-modal *,
.toast {
  box-sizing: border-box;
}

.topbar a,
.topbar button,
.instruction-modal a,
.instruction-modal button {
  color: inherit;
  font-family: var(--font-head, "Rubik", "Segoe UI", system-ui, sans-serif);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:where(.topbar button, .instruction-modal button) {
  font-size: inherit; /* нулевая специфичность: размеры .action-button/.language-switch button побеждают */
}

.topbar svg,
.instruction-modal svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.topbar button:focus-visible,
.topbar a:focus-visible,
.instruction-modal button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent, #6558ef) 72%, #112958 28%);
  outline-offset: 3px;
}

/* --------------------------------------------------------------------------
   ЛАБОРАТОРИИ (shared/header.js, атрибут data-lab): шапка плавает поверх
   полноэкранной сцены в тех же координатах, что и на страницах сайта
   (ширина min(1740px, 100% − 64px), отступ сверху 16px, высота 48px).
   Высота шапки с отступом — переменная --site-header-h на <html>.
   Цвета предмета передаёт data-accent* на <script>, переменные живут
   только внутри .site-header-lab и не конфликтуют с токенами приложения.
   -------------------------------------------------------------------------- */
html {
  --site-header-h: 0px;
}

html.has-lab-header {
  --site-header-h: 74px;
}

.site-header-lab {
  --ink: #10204e;
  --muted: #6b779b;
  --glass-line: rgba(255, 255, 255, 0.86);
  --shadow-control: 0 8px 22px rgba(33, 64, 125, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.92);
  --control-height: 42px;
  --radius-control: 13px;
  --font-head: "Rubik", "Segoe UI", system-ui, sans-serif;
  --font-body: "Golos Text", "Segoe UI", system-ui, sans-serif;
  position: fixed;
  z-index: 2000;
  top: 0;
  right: 0;
  left: 0;
  padding-top: 16px;
  color: var(--ink);
  font-family: var(--font-body);
  pointer-events: none;
}

.site-header-lab .topbar {
  width: min(1740px, calc(100% - 64px));
  margin: 0 auto;
  pointer-events: none;
}

.site-header-lab .topbar :is(a, button, .language-switch) {
  pointer-events: auto;
}

@media (max-width: 980px) {
  .site-header-lab .topbar {
    width: min(100% - 28px, 900px);
  }
}

@media (max-width: 620px) {
  .site-header-lab {
    padding-top: 10px;
  }

  .site-header-lab .topbar {
    width: calc(100% - 20px);
  }

  html.has-lab-header {
    --site-header-h: 68px;
  }
}

/* «Как пользоваться» в лабораториях: заголовок-эйбрау (в сайте это .eyebrow из common.css) */
.modal-eyebrow {
  display: flex;
  margin: 0 0 8px;
  align-items: center;
  gap: 10px;
  color: var(--accent, #6558ef);
  font-family: var(--font-head, "Rubik", "Segoe UI", system-ui, sans-serif);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.17em;
  line-height: 1.3;
}

.modal-eyebrow > span:first-child {
  width: 28px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.instruction-modal h2 {
  font-family: var(--font-head, "Rubik", "Segoe UI", system-ui, sans-serif);
}

/* Диалог «Как пользоваться» внутри лаборатории: центр экрана и клики (хост шапки — pointer-events:none;
   у приложений бывает глобальный сброс margin, который ломает margin:auto у <dialog>) */
.site-header-lab .instruction-modal {
  inset: 0;
  margin: auto;
  pointer-events: auto;
}

/* Шапка лаборатории — ОДНО фиолетовое полупрозрачное «стекло»: назад + логотип + звук + язык + «как пользоваться»
   в одном окне, без отдельной светлой полосы на всю ширину (как на страницах сайта, где фон шапки — фиолетовый
   градиент страницы). Лаборатория начинается сразу под окном шапки. */
.site-header-lab .topbar {
  min-height: 54px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 20px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 38%),
    linear-gradient(120deg, rgba(176, 156, 255, 0.84), rgba(150, 190, 255, 0.76));
  box-shadow: 0 12px 34px rgba(18, 8, 56, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
  backdrop-filter: blur(22px) saturate(1.35);
}
