:root {
  --bg: #0a0a0a;
  --bg-warm: #120f0c;
  --ink: #e8e6df;
  --ink-dim: rgba(232, 230, 223, 0.62);
  --ink-mute: rgba(232, 230, 223, 0.28);
  --ink-faint: rgba(232, 230, 223, 0.12);
  --amber: #e6a41f;
  --amber-bright: #ffc960;
  --amber-dim: rgba(230, 164, 31, 0.42);
  --amber-glow: rgba(230, 164, 31, 0.55);

  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 400;
  font-feature-settings: "ss01", "cv02";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  background-image:
    radial-gradient(ellipse 60% 50% at 50% 45%, rgba(230, 164, 31, 0.07), transparent 70%),
    radial-gradient(ellipse 70% 60% at 80% 95%, rgba(110, 72, 28, 0.05), transparent 70%);
}

/* ---------- Stage layout ---------- */
.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "center"
    "bottom";
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  gap: clamp(10px, 2vh, 18px);
  overflow: hidden;
  isolation: isolate;
}

/* ---------- Canvas (cartesian plane + 3D mesh + particles) ---------- */
.plane {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  display: block;
}

/* ============================================================
   BRAND — split layout: logo on top, hero+CTA on bottom,
   (0,0) point breathes in the middle.
   ============================================================ */
.brand {
  grid-area: center;
  align-self: stretch;
  justify-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  z-index: 3;
  pointer-events: none;
  padding: clamp(16px, 4vh, 36px) 16px;
  position: relative;
}

.brand__bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  pointer-events: none;
}

.brand__title {
  display: inline-flex;
  line-height: 0;
  margin: 0;
  font-size: 0;
  position: relative;
}

.brand__logo {
  display: block;
  width: min(56vw, 300px);
  height: auto;
  max-height: 18vh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  transform: translateY(8px);
  filter: contrast(1.05) saturate(1.08);
}

.brand.shown .brand__logo {
  animation: logoReveal 1.4s var(--ease-out) forwards, logoPulse 4.5s 1.6s ease-in-out infinite;
}

@keyframes logoReveal {
  0%   { opacity: 0;   transform: translateY(10px) scale(0.985); filter: contrast(1.05) saturate(1.08) brightness(0.4) blur(2px); }
  10%  { opacity: 0.6; transform: translate(3px, 10px) scale(0.99); filter: contrast(1.4) saturate(1.2) brightness(1.1) blur(0); }
  14%  { opacity: 0.4; transform: translate(-2px, 10px); filter: contrast(1.05) saturate(1.08) brightness(0.7); }
  22%  { opacity: 0.85; transform: translate(1px, 10px); filter: contrast(1.05) saturate(1.08) brightness(1.15); }
  28%  { opacity: 0.5; transform: translate(-3px, 10px); }
  40%  { opacity: 0.9; transform: translate(0, 6px) scale(0.995); }
  100% { opacity: 1;   transform: translateY(0) scale(1); filter: contrast(1.05) saturate(1.08) brightness(1); }
}

@keyframes logoPulse {
  0%, 100% { filter: contrast(1.05) saturate(1.08) brightness(1); }
  50%      { filter: contrast(1.06) saturate(1.1) brightness(1.04); }
}

/* Glitch RGB split copies — over the logo, screen-blended */
.brand__title::before,
.brand__title::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background-image: url("logo.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0;
  mix-blend-mode: screen;
}

.brand.glitching .brand__title::before {
  animation: glitchR 1.4s steps(1, end);
}
.brand.glitching .brand__title::after {
  animation: glitchB 1.4s steps(1, end);
}

@keyframes glitchR {
  0%   { opacity: 0; transform: translate(0, 0); filter: none; }
  6%   { opacity: 0.75; transform: translate(8px, 0); filter: hue-rotate(-25deg) saturate(2) brightness(1.6); }
  12%  { opacity: 0.40; transform: translate(-6px, 2px); filter: hue-rotate(-25deg) saturate(2) brightness(1.3); }
  20%  { opacity: 0.85; transform: translate(5px, -1px); filter: hue-rotate(-25deg) saturate(1.8); }
  28%  { opacity: 0.30; transform: translate(-3px, 0); filter: hue-rotate(-25deg); }
  38%  { opacity: 0.55; transform: translate(7px, 0); filter: hue-rotate(-25deg) brightness(1.4); }
  46%  { opacity: 0.20; transform: translate(0, 1px); filter: hue-rotate(-25deg); }
  100% { opacity: 0; transform: translate(0, 0); filter: none; }
}

@keyframes glitchB {
  0%   { opacity: 0; transform: translate(0, 0); filter: none; }
  6%   { opacity: 0.65; transform: translate(-8px, 0); filter: hue-rotate(60deg) saturate(2) brightness(1.5); }
  14%  { opacity: 0.40; transform: translate(6px, -2px); filter: hue-rotate(60deg) saturate(2) brightness(1.3); }
  22%  { opacity: 0.80; transform: translate(-5px, 1px); filter: hue-rotate(60deg) saturate(1.8); }
  30%  { opacity: 0.25; transform: translate(2px, 0); filter: hue-rotate(60deg); }
  40%  { opacity: 0.50; transform: translate(-7px, 0); filter: hue-rotate(60deg) brightness(1.4); }
  48%  { opacity: 0.18; transform: translate(0, -1px); filter: hue-rotate(60deg); }
  100% { opacity: 0; transform: translate(0, 0); filter: none; }
}

/* Scanlines overlay strictly on the logo */
.brand__title > img {
  position: relative;
  z-index: 1;
}

.brand::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.18) 0px,
    rgba(0, 0, 0, 0.18) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s var(--ease);
}

.brand.shown::after {
  opacity: 0.45;
}

/* Hero line — "сайт в разработке" — single line */
.brand__hero {
  margin-top: 0;
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(20px, 6vw, 56px);
  line-height: 1;
  letter-spacing: 0;
  color: var(--ink);
  text-transform: lowercase;
  white-space: nowrap;
  text-align: center;
  opacity: 0;
  transform: translateY(14px);
  filter: blur(6px);
  text-shadow: 0 0 36px rgba(230, 164, 31, 0.08);
}

.brand__hero > span {
  display: inline-block;
}

.brand__hero-text {
  color: var(--ink);
  min-height: 1em;
}

.brand__hero-cursor {
  color: var(--amber);
  margin-left: 0.05em;
  animation: heroCursor 0.9s steps(2, end) infinite;
  text-shadow: 0 0 12px rgba(230, 164, 31, 0.45);
}

@keyframes heroCursor {
  50% { opacity: 0; }
}

.brand.shown .brand__hero {
  animation: heroIn 1.0s var(--ease-out) 0.65s forwards;
}

@keyframes heroIn {
  0%   { opacity: 0; transform: translateY(14px); filter: blur(6px); }
  60%  { filter: blur(0); }
  100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.brand__sub {
  margin-top: clamp(10px, 1.6vh, 16px);
  font-size: clamp(11px, 2.6vw, 14px);
  font-weight: 400;
  color: var(--ink-dim);
  letter-spacing: 0.18em;
  text-transform: lowercase;
  opacity: 0;
  transform: translateY(6px);
}

.brand.shown .brand__sub {
  animation: subIn 0.8s var(--ease) 1.25s forwards;
}

@keyframes subIn {
  to { opacity: 1; transform: none; }
}

/* ── Primary CTA: «связаться» button + inline expand panel ── */
.cta {
  margin-top: clamp(24px, 4.5vh, 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 2vh, 18px);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
}

.brand.shown .cta {
  animation: ctaIn 0.8s var(--ease) 1.6s forwards;
}

@keyframes ctaIn {
  to { opacity: 1; transform: none; }
}

.cta__main {
  position: relative;
  font-family: var(--mono);
  font-size: clamp(13px, 3.6vw, 17px);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: var(--amber);
  background: rgba(230, 164, 31, 0.06);
  border: 1.5px solid var(--amber);
  padding: clamp(14px, 2.6vh, 18px) clamp(28px, 7vw, 44px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.65em;
  text-shadow: 0 0 12px rgba(230, 164, 31, 0.45);
  transition: background 0.35s var(--ease), color 0.35s var(--ease), letter-spacing 0.35s var(--ease), transform 0.25s var(--ease);
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.cta__main::before,
.cta__main::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 1.5px solid var(--amber);
  pointer-events: none;
}

.cta__main::before {
  animation: ctaRipple 2.4s ease-out infinite;
}

.cta__main::after {
  animation: ctaRipple 2.4s ease-out infinite 1.2s;
}

@keyframes ctaRipple {
  0%   { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.18); }
}

.cta__main:hover,
.cta__main:focus-visible {
  background: rgba(230, 164, 31, 0.16);
  color: var(--amber-bright);
  letter-spacing: 0.16em;
  transform: translateY(-1px);
}

.cta__main:active {
  transform: translateY(0) scale(0.98);
}

.cta__arrow {
  display: inline-block;
  font-weight: 500;
}

/* By default show "closed" labels (связаться), hide "open" (закрыть) */
.cta__arrow--open,
.cta__label--open {
  display: none;
}

/* When panel is open, swap them */
.cta--open .cta__arrow--closed,
.cta--open .cta__label--closed {
  display: none;
}

.cta--open .cta__arrow--open,
.cta--open .cta__label--open {
  display: inline-block;
}

.cta--open .cta__arrow--open {
  font-size: 1.25em;
  line-height: 0.9;
}

.cta--open .cta__main::before,
.cta--open .cta__main::after {
  animation: none;
  opacity: 0;
}

.cta--open .cta__main {
  background: rgba(230, 164, 31, 0.18);
}

/* Expand panel — collapsed by default, slides down on open */
.cta__panel {
  display: grid;
  grid-template-rows: repeat(3, auto);
  gap: 6px;
  width: min(360px, 86vw);
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.45s var(--ease), opacity 0.35s var(--ease), margin 0.35s var(--ease);
  margin-top: 0;
  pointer-events: none;
}

.cta--open .cta__panel {
  max-height: 280px;
  opacity: 1;
  pointer-events: auto;
  margin-top: 4px;
}

.cta__option {
  display: grid;
  grid-template-columns: 50px 1fr;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--ink);
  background: rgba(230, 164, 31, 0.04);
  border: 1px solid var(--amber-dim);
  font-family: var(--mono);
  letter-spacing: 0.05em;
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease), transform 0.3s var(--ease);
  min-height: 48px;
}

.cta__option:hover,
.cta__option:focus-visible {
  background: rgba(230, 164, 31, 0.14);
  border-color: var(--amber);
  transform: translateX(2px);
  outline: none;
}

.cta__opt-key {
  font-size: clamp(13px, 3vw, 15px);
  font-weight: 600;
  color: var(--amber);
  letter-spacing: 0.16em;
  text-transform: lowercase;
}

.cta__opt-val {
  font-size: clamp(12px, 2.8vw, 14px);
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

@media (max-height: 600px) {
  .cta { margin-top: 16px; gap: 10px; }
  .cta__main { padding: 10px 22px; font-size: 12px; }
  .cta__option { padding: 8px 12px; min-height: 40px; }
  .cta--open .cta__panel { max-height: 220px; }
}

@media (min-width: 720px) {
  .brand__logo { width: min(28vw, 360px); max-height: 20vh; }
}

@media (max-height: 560px) {
  .brand__logo { width: min(40vw, 240px); max-height: 22vh; }
}

/* ============================================================
   TERMINAL — bottom strip, full width, always alive
   ============================================================ */
.terminal {
  grid-area: bottom;
  justify-self: stretch;
  align-self: end;
  z-index: 4;
  font-size: clamp(11px, 3vw, 13px);
  line-height: 1.55;
  letter-spacing: 0.02em;
  color: var(--ink);
  pointer-events: none;
  padding: 12px 14px 10px 14px;
  border-top: 1px solid var(--amber-dim);
  background:
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.55) 40%),
    linear-gradient(180deg, rgba(230, 164, 31, 0.04), transparent 30%);
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
  min-height: 140px;
}

.terminal::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 80px;
  height: 3px;
  background: var(--amber);
  box-shadow: 0 0 12px var(--amber-glow);
  animation: scanRun 8s linear infinite;
}

@keyframes scanRun {
  0%   { left: 0; opacity: 0.9; }
  50%  { left: calc(100% - 80px); opacity: 0.6; }
  100% { left: 0; opacity: 0.9; }
}

.terminal__head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--amber);
  font-weight: 500;
  font-size: 0.88em;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
}

.terminal__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
  animation: heartbeat 1.8s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes heartbeat {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.78); }
}

.terminal__sep {
  flex: 1;
  height: 1px;
  min-width: 20px;
  background: repeating-linear-gradient(
    to right, var(--ink-faint) 0 4px, transparent 4px 8px
  );
}

.terminal__meta {
  color: var(--ink-mute);
  font-weight: 400;
  letter-spacing: 0.08em;
  font-size: 0.92em;
  font-variant-numeric: tabular-nums;
}

.terminal__status {
  color: var(--amber);
  font-weight: 500;
  letter-spacing: 0.1em;
  font-size: 0.92em;
  text-transform: lowercase;
  text-shadow: 0 0 8px rgba(230, 164, 31, 0.3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.terminal__log {
  list-style: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  /* No overflow/max-height — JS strictly caps line count via trimLog().
     Avoids flex-end clipping the top line when content slightly overshoots. */
}

.terminal__log li {
  opacity: 0;
  transform: translateX(-4px);
  animation: lineIn 0.42s var(--ease) forwards;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.terminal__log li::before {
  content: "› ";
  color: var(--amber);
  margin-right: 2px;
  opacity: 0.9;
}

.terminal__log li.cur { color: var(--ink); }

.terminal__log li.cur::after {
  content: "▌";
  display: inline-block;
  color: var(--amber);
  margin-left: 2px;
  animation: blink 1s steps(2, end) infinite;
  text-shadow: 0 0 6px var(--amber-glow);
}

.terminal__log li.fade {
  animation: lineOut 0.5s var(--ease) forwards;
}

@keyframes lineIn  { to { opacity: 0.9; transform: none; } }
@keyframes lineOut { to { opacity: 0; transform: translateY(-4px); max-height: 0; } }
@keyframes blink   { 50% { opacity: 0; } }

@media (min-width: 720px) {
  .terminal {
    padding: 10px 22px 8px;
    min-height: 120px;
  }
}

/* ============================================================
   CTA backdrop — dims everything except logo + 4 buttons when open
   ============================================================ */
.cta-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 4, 0.94);
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.45s var(--ease);
}

body.cta-open .cta-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Lift the entire brand block above the backdrop so logo + CTA stay bright */
body.cta-open .brand {
  z-index: 10;
}

/* Hero text fully hidden while panel is open (override the heroIn animation) */
body.cta-open .brand__hero {
  animation: none !important;
  opacity: 0 !important;
  filter: blur(3px);
  transition: opacity 0.35s var(--ease), filter 0.35s var(--ease);
  pointer-events: none;
}

/* ============================================================
   Overlays: scanlines, grain, vignette
   ============================================================ */
.scanlines {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.02) 0px,
    rgba(255, 255, 255, 0.02) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: 0.6;
}

.grain {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0.28;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.45 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grainShift 1.1s steps(3) infinite;
}

@keyframes grainShift {
  0%   { transform: translate(0, 0); }
  33%  { transform: translate(-3px, 2px); }
  66%  { transform: translate(2px, -2px); }
  100% { transform: translate(0, 0); }
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(0, 0, 0, 0.6) 100%);
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .terminal__log li.cur::after { animation: none; opacity: 1; }
  .terminal__dot { animation: none; }
}
