/* ============================================================
   DAR Portal v3 — mobile-first, rebuild с нуля
   Шаг 2 (центр композиции) + Шаг 2.5 (фон)
   ============================================================ */

/* ---------- Токены ---------- */
:root {
  --neon-cyan:    oklch(0.86 0.16 210);
  --neon-magenta: oklch(0.68 0.28 340);
  --neon-gold:    oklch(0.83 0.16 85);
  --neon-violet:  oklch(0.62 0.24 300);

  --bg-deep: oklch(0.12 0.04 280);
  --bg-haze: oklch(0.18 0.06 285);

  --glow-cyan:    0 0 4px oklch(0.86 0.16 210/0.9), 0 0 12px oklch(0.86 0.16 210/0.7), 0 0 28px oklch(0.86 0.16 210/0.5);
  --glow-magenta: 0 0 4px oklch(0.68 0.28 340/0.9), 0 0 12px oklch(0.68 0.28 340/0.7), 0 0 28px oklch(0.68 0.28 340/0.5);
  --glow-gold:    0 0 4px oklch(0.83 0.16 85/0.9), 0 0 10px oklch(0.83 0.16 85/0.6), 0 0 22px oklch(0.83 0.16 85/0.4);

  --font-display:   "Press Start 2P", "Courier New", monospace;
  --font-terminal:  "VT323", "Courier New", monospace;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* [hidden] ВСЕГДА побеждает display:flex на оверлеях.
   Это осознанная защита от regression "чёрный слой блокирует клики". */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: #fff;
  font-family: var(--font-terminal);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Шаг 2: СЦЕНА + КОМПОЗИЦИЯ (ядро) ---------- */

/* Сцена: намертво привязана к экрану, скролл невозможен */
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* F. Дышащее небо: radial-gradient над дверью + linear.
     Анимация background-size даёт «дыхание» свечения — портал живой. */
  background:
    radial-gradient(ellipse 80% 50% at 50% 30%, oklch(0.22 0.09 300 / 0.7), transparent 70%),
    linear-gradient(180deg, oklch(0.06 0.03 275) 0%, var(--bg-deep) 60%, oklch(0.05 0.03 270) 100%);
  background-size: 100% 100%, 100% 100%;
  animation: breathe-bg 14s ease-in-out infinite;
}
@keyframes breathe-bg {
  0%, 100% { background-size: 100% 100%, 100% 100%; }
  50%      { background-size: 120% 115%, 100% 100%; }
}

/* G. Виньетка-затухание: затемнение по краям пульсирует — камера фокусирует */
.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, oklch(0 0 0 / 0.55) 100%);
  opacity: 0.7;
  animation: vignette-pulse 10s ease-in-out infinite;
}
@keyframes vignette-pulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 0.75; }
}

/* H. CRT-сканлайны: СТАТИЧНЫЕ, без анимации (анимация = эпилепсия).
   Просто тонкая текстура CRT-экрана, неподвижная. */
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 51;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    oklch(0 0 0 / 0.12) 4px,
    transparent 5px
  );
  opacity: 0.4;
}

/* КОМПОЗИЦИЯ: бокс 2:3 высотой ВЫШЕ экрана, сдвинут вниз так,
   что прозрачные нижние края ассета уходят ЗА экран.
   Пол ассета (65-85% высоты) оказывается у самого низа экрана. */
.picture {
  position: absolute;
  left: 50%;
  bottom: -13svh;              /* прозрачный низ ассета уходит за экран */
  transform: translateX(-50%);
  aspect-ratio: 2 / 3;
  z-index: 1;
  height: 113svh;              /* чуть выше экрана, чтобы низ ушёл за край */
  width: auto;
}
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .picture {
    height: 113svh;
    bottom: -13svh;
  }
}

.composition {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- Шаг 2.5: ФОН (атмосфера) ---------- */

/* .sky — контейнер для туманностей/звёзд. z-index 0 → позади composition.
   pointer-events: none → не перехватывает клики.
   overflow:hidden + contain → GPU-cheap. */
.sky {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  contain: strict;
}

/* Туманности — два radial-gradient блоба, медленный drift (transform only).
   Видны сквозь прозрачное небо composition. GPU-cheap: will-change + contain. */
.sky::before,
.sky::after {
  content: "";
  position: absolute;
  width: 90%;
  height: 55%;
  border-radius: 50%;
  filter: blur(8px);
  will-change: transform;
  contain: strict;
}
.sky::before {
  top: -8%; left: -15%;
  background: radial-gradient(circle at 40% 40%, oklch(0.62 0.24 300 / 0.55), transparent 65%);
  animation: drift-a 26s ease-in-out infinite;
}
.sky::after {
  top: -4%; right: -18%;
  background: radial-gradient(circle at 60% 40%, oklch(0.68 0.28 340 / 0.45), transparent 65%);
  animation: drift-b 32s ease-in-out infinite;
}
@keyframes drift-a {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(6%,4%) scale(1.08); }
}
@keyframes drift-b {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(-5%,3%) scale(1.1); }
}

/* Звёзды — генерируются JS ТОЛЬКО на десктопе (matchMedia-гейт).
   1px rects, opacity-only twinkle. На мобайле их нет в DOM. */
.star {
  position: absolute;
  width: 2px; height: 2px;
  background: #fff;
  box-shadow: 0 0 3px #fff;
  opacity: 1;
  will-change: opacity;
  animation: twinkle 6s ease-in-out infinite;
}
.star.cyan { background: oklch(0.86 0.16 210); box-shadow: 0 0 4px oklch(0.86 0.16 210); }
.star.big { width: 3px; height: 3px; box-shadow: 0 0 6px #fff; }
@keyframes twinkle {
  0%,100% { opacity: 0.8; }
  50%     { opacity: 0.4; }
}

/* ---------- ЛОГО (привязан к .scene / экрану, не к боксу) ---------- */
.logo {
  position: absolute;
  left: 50%;
  top: 3vh;
  transform: translateX(-50%);
  width: min(40vw, 240px);
  z-index: 2;
  filter: drop-shadow(0 0 8px oklch(0.78 0.22 280 / 0.7));
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .logo { width: min(18vw, 260px); top: 1vh; }
}

/* ---------- КНОПКА COMING SOON (привязана к .scene, на фасаде арки) ---------- */
.display {
  position: absolute;
  left: 50%;
  top: 38vh;
  transform: translateX(-50%);
  width: min(70vw, 420px);
  padding: 0;
  background: transparent;
  cursor: pointer;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.display-img { width: 100%; height: auto; image-rendering: pixelated; }
.display-text {
  width: 100%;
  min-height: 24px;
  display: none;
  font-family: var(--font-display);
  font-size: clamp(7px, 2.4vw, 11px);
  letter-spacing: 0.12em;
  color: var(--neon-cyan);
  text-align: center;
  padding: 6px 4px;
  background: oklch(0.08 0.04 280 / 0.85);
  border: 2px solid var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
  box-shadow: 0 0 12px oklch(0.86 0.16 210 / 0.5);
  clip-path: polygon(3% 0, 97% 0, 100% 22%, 100% 78%, 97% 100%, 3% 100%, 0 78%, 0 22%);
}
.display[data-state="access-terminal"] .display-text,
.display[data-state="access-granted"] .display-text { display: block; }
.display[data-state="access-terminal"] .display-img,
.display[data-state="access-granted"] .display-img { display: none; }
.display-text .granted-sub {
  display: block;
  font-size: 0.62em;
  opacity: 0.85;
  margin-top: 4px;
}

/* ---------- I. TRON-сетка на горизонте (1 element, CSS only) ---------- */
/* Перспективная неоновая сетка у горизонта — создаёт глубину. */
.grid-horizon {
  position: absolute;
  left: -20%;
  right: -20%;
  bottom: 30%;
  height: 25%;
  z-index: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(90deg, transparent 0, transparent 39px, oklch(0.86 0.16 210 / 0.35) 40px),
    repeating-linear-gradient(0deg, transparent 0, transparent 39px, oklch(0.68 0.28 340 / 0.3) 40px);
  transform: perspective(400px) rotateX(60deg);
  transform-origin: 50% 100%;
  mask-image: linear-gradient(to top, black 10%, transparent 90%);
  -webkit-mask-image: linear-gradient(to top, black 10%, transparent 90%);
  animation: grid-rush 1.5s linear infinite;
  opacity: 0.6;
}
@keyframes grid-rush {
  0%   { background-position-y: 0, 0; }
  100% { background-position-y: 40px, 0; }
}
@media (prefers-reduced-motion: reduce) {
  .grid-horizon { animation: none; }
}

/* ---------- J. Неон-перелив на двери (CSS filter, 0 DOM) ---------- */
/* drop-shadow меняет цвет cyan→violet→magenta — дверь «живая неоновая вывеска». */
.composition {
  animation: neon-shimmer 8s ease-in-out infinite;
}
@keyframes neon-shimmer {
  0%, 100% { filter: drop-shadow(0 0 6px oklch(0.86 0.16 210 / 0.5)); }
  33%      { filter: drop-shadow(0 0 8px oklch(0.62 0.24 300 / 0.55)); }
  66%      { filter: drop-shadow(0 0 7px oklch(0.68 0.28 340 / 0.5)); }
}
@media (prefers-reduced-motion: reduce) {
  .composition { animation: none; }
}

/* ---------- SIGNBOARDS (desktop only, hidden mobile) ---------- */
.signboards { display: none; }

/* ---------- BURGER (mobile only) ---------- */
.burger {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 80;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 42px;
  height: 38px;
  padding: 8px 9px;
  background: oklch(0.08 0.04 280 / 0.85);
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 8px oklch(0.86 0.16 210 / 0.5);
  clip-path: polygon(0 16%,10% 16%,10% 0,90% 0,90% 16%,100% 16%,100% 84%,90% 84%,90% 100%,10% 100%,10% 84%,0 84%);
}
.burger span {
  display: block; height: 2px;
  background: var(--neon-cyan);
  box-shadow: 0 0 4px var(--neon-cyan);
  transition: transform .2s, opacity .2s;
}
.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- MOBILE MENU ---------- */
.menu-backdrop {
  position: fixed; inset: 0; z-index: 75;
  background: oklch(0 0 0 / 0.6); cursor: pointer;
}
.menu {
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 80;
  width: min(82vw, 320px);
  padding: 16px;
  background: linear-gradient(180deg, oklch(0.1 0.05 285), oklch(0.06 0.03 275));
  border-right: 3px solid var(--neon-cyan);
  box-shadow: 0 0 20px oklch(0.86 0.16 210 / 0.4);
  transform: translateX(-105%);
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column;
}
.menu[data-open="true"] { transform: translateX(0); }
.menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px; margin-bottom: 16px;
  border-bottom: 2px solid var(--neon-cyan);
}
.menu-title {
  font-family: var(--font-display);
  font-size: 11px; letter-spacing: 0.18em;
  color: var(--neon-magenta);
  text-shadow: 0 0 6px oklch(0.68 0.28 340 / 0.6);
}
.menu-close {
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: 0.14em;
  color: var(--neon-cyan);
}
.menu-list { display: flex; flex-direction: column; gap: 12px; }
.menu-list .sign {
  display: block; width: 100%;
  padding: 13px 14px;
  font-family: var(--font-display);
  font-size: 11px; letter-spacing: 0.16em; text-align: center;
  background: oklch(0.08 0.04 280 / 0.85);
  border: 2px solid;
  clip-path: polygon(0 14%,8% 14%,8% 0,92% 0,92% 14%,100% 14%,100% 86%,92% 86%,92% 100%,8% 100%,8% 86%,0 86%);
}
.menu-list .sign.cta {
  color: var(--bg-deep);
  background: var(--neon-cyan);
  border-color: var(--neon-cyan);
}

/* ---------- TERMINAL (форма) ---------- */
.terminal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 8px 8px;
  background: oklch(0 0 0 / 0.5);
}
.terminal-panel {
  width: 100%; max-width: 480px;
  background: linear-gradient(180deg, oklch(0.1 0.05 285), oklch(0.06 0.03 275));
  border: 3px solid var(--neon-cyan);
  box-shadow: 0 0 20px oklch(0.86 0.16 210 / 0.4);
  clip-path: polygon(0 4%,3% 4%,3% 0,97% 0,97% 4%,100% 4%,100% 96%,97% 96%,97% 100%,3% 100%,3% 96%,0 96%);
  transform: translateY(110%);
  transition: transform 360ms cubic-bezier(0.16, 1, 0.3, 1);
}
.terminal[data-open="true"] .terminal-panel { transform: translateY(0); }
.terminal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 2px solid var(--neon-cyan);
}
.terminal-title {
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: 0.18em;
  color: var(--neon-magenta);
  text-shadow: 0 0 5px oklch(0.68 0.28 340 / 0.6);
}
.terminal-dots { display: inline-flex; gap: 5px; }
.terminal-dots i { width: 7px; height: 7px; display: inline-block; }
.terminal-dots i:nth-child(1) { background: var(--neon-magenta); }
.terminal-dots i:nth-child(2) { background: var(--neon-gold); }
.terminal-dots i:nth-child(3) { background: var(--neon-cyan); }
.terminal-form { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.terminal-status { font-size: 16px; color: oklch(0.86 0.16 210 / 0.85); }
.caret { animation: blink 1s steps(1) infinite; }
@keyframes blink { 0%,50%{opacity:1} 51%,100%{opacity:0} }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label {
  font-family: var(--font-display);
  font-size: 9px; letter-spacing: 0.18em;
  color: oklch(0.86 0.16 210 / 0.85);
}
.field-label .req { color: var(--neon-magenta); margin-left: 3px; }
.field-input {
  width: 100%;
  font-family: var(--font-terminal);
  font-size: 20px;
  color: var(--neon-cyan);
  background: transparent;
  border: 2px solid oklch(0.86 0.16 210 / 0.5);
  padding: 7px 11px;
  caret-color: var(--neon-cyan);
}
.field-input::placeholder { color: oklch(0.86 0.16 210 / 0.3); }
.field-input:focus {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow: 0 0 10px oklch(0.86 0.16 210 / 0.5);
}
.field-error {
  display: none;
  font-family: var(--font-display);
  font-size: 9px; letter-spacing: 0.16em;
  color: var(--neon-magenta);
  text-shadow: 0 0 4px oklch(0.68 0.28 340 / 0.5);
}
.field-error:not(:empty) { display: block; }
.terminal-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-top: 8px;
}
.btn-abort {
  font-family: var(--font-display);
  font-size: 9px; letter-spacing: 0.16em;
  color: oklch(0.86 0.16 210 / 0.7);
  padding: 6px 8px;
}
.btn-abort:active { color: var(--neon-cyan); }
.btn-submit {
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: 0.16em;
  color: var(--bg-deep);
  background: var(--neon-magenta);
  padding: 11px 16px;
  box-shadow: 0 0 10px oklch(0.68 0.28 340 / 0.5);
  clip-path: polygon(0 18%,9% 18%,9% 0,91% 0,91% 18%,100% 18%,100% 82%,91% 82%,91% 100%,9% 100%,9% 82%,0 82%);
}
.btn-submit:disabled { opacity: 0.55; }

/* ---------- DESKTOP ENHANCEMENT ---------- */
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .burger, .menu, .menu-backdrop { display: none !important; }
  .signboards {
    display: flex; flex-direction: column; gap: 18px;
    position: absolute; left: 24px; top: 50%;
    transform: translateY(-50%);
    z-index: 20; max-width: 170px;
  }
  .signboards .sign {
    display: block; padding: 9px 14px;
    font-family: var(--font-display);
    font-size: 10px; letter-spacing: 0.16em; text-align: center;
    background: oklch(0.08 0.04 280 / 0.85);
    border: 2px solid;
    clip-path: polygon(0 14%,8% 14%,8% 0,92% 0,92% 14%,100% 14%,100% 86%,92% 86%,92% 100%,8% 100%,8% 86%,0 86%);
  }
  .signboards .sign.cta {
    color: var(--bg-deep);
    background: var(--neon-cyan);
    border-color: var(--neon-cyan);
  }
}

/* ---------- Reduced motion: глушим всё ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
