/* ── Reset & base ─────────────────────────────────────────── */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #e8ecf4;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Segoe UI Mono', Menlo, Monaco, Consolas, monospace;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Viewport shell ───────────────────────────────────────── */

.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewport::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(
      ellipse 68% 52% at 50% 50%,
      rgba(245, 238, 220, 0.12) 0%,
      rgba(170, 195, 255, 0.055) 28%,
      rgba(30, 42, 70, 0.03) 52%,
      transparent 74%
    );
  opacity: 0;
  z-index: 9;
  pointer-events: none;
}

.viewport--power-on::before {
  animation: glass-charge 1.4s ease-out forwards;
}

@keyframes glass-charge {
  0% {
    opacity: 0;
    filter: blur(24px);
  }
  35% {
    opacity: 0.18;
    filter: blur(22px);
  }
  100% {
    opacity: 0;
    filter: blur(28px);
  }
}

/* ── Power-on line ────────────────────────────────────────── */

.power-line {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(100vw, 86rem);
  height: 1px;
  transform: translate(-50%, -50%) scaleX(0.035) scaleY(1);
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(170, 195, 255, 0.42) 16%,
    rgba(255, 246, 220, 0.95) 50%,
    rgba(170, 195, 255, 0.42) 84%,
    transparent 100%
  );
  box-shadow:
    0 0 2px rgba(255, 250, 230, 0.85),
    0 0 12px rgba(230, 236, 255, 0.72),
    0 0 42px rgba(125, 165, 255, 0.32),
    0 0 96px rgba(255, 220, 160, 0.12);
  opacity: 0;
  z-index: 20;
  pointer-events: none;
  will-change: transform, height, opacity, filter;
}

.viewport--power-on .power-line {
  animation: none;
}

/* ── Bloom warm-up ────────────────────────────────────────── */

.bloom {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(
      ellipse 72% 58% at 50% 50%,
      rgba(255, 244, 214, 0.16) 0%,
      rgba(180, 200, 255, 0.08) 28%,
      rgba(80, 110, 180, 0.035) 54%,
      transparent 78%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(255, 255, 255, 0.025) 49%,
      rgba(255, 255, 255, 0.055) 50%,
      rgba(255, 255, 255, 0.025) 51%,
      transparent 100%
    );
  opacity: 0;
  z-index: 15;
  pointer-events: none;
  transform: scale(1.04, 0.12);
  filter: blur(6px);
}

.viewport--bloom .bloom {
  animation: bloom-in 1.4s ease-out forwards;
}

@keyframes bloom-in {
  0% {
    opacity: 0;
    transform: scale(1);
    filter: blur(24px);
  }
  38% {
    opacity: 0.12;
    transform: scale(1);
    filter: blur(26px);
  }
  100% {
    opacity: 0;
    transform: scale(1);
    filter: blur(30px);
  }
}

/* ── CRT container ────────────────────────────────────────── */

.crt {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  opacity: 0;
  filter: brightness(0.3) contrast(1.2) saturate(0.9);
  transition: none;
}

.viewport--ready .crt-glass {
  animation: brightness-drift 9s ease-in-out infinite;
}

@keyframes brightness-drift {
  0%, 100% { filter: brightness(1); }
  33%       { filter: brightness(0.994); }
  66%       { filter: brightness(1.003); }
}

.viewport--alive .crt {
  animation: crt-warm 1.25s ease-out forwards;
}

@keyframes crt-warm {
  0% {
    opacity: 0;
    filter: brightness(0.82) contrast(1.04) saturate(0.96) blur(0.4px);
  }
  55% {
    opacity: 0.88;
    filter: brightness(1.03) contrast(1.02) saturate(1) blur(0.15px);
  }
  100% {
    opacity: 1;
    filter: brightness(1) contrast(1) saturate(1) blur(0);
  }
}

/* ── Glass surface ────────────────────────────────────────── */

.crt-glass {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* ── Content ──────────────────────────────────────────────── */

.content {
  text-align: center;
  opacity: 0;
  user-select: none;
}

.viewport--ready .content {
  animation: content-reveal 1.15s ease-out forwards;
}

@keyframes content-reveal {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}

.terminal {
  display: inline-block;
  text-align: center;
}

.line {
  font-size: clamp(0.75rem, 1.8vw, 0.875rem);
  letter-spacing: 0.06em;
  height: 1.6em;
  line-height: 1.6;
  margin: 0;
}

.line.domain,
.line.message {
  padding-left: 1ch;
}

.line.domain::after,
.line.message::after {
  content: "▌";
  display: inline-block;
  width: 1ch;
  visibility: hidden;
}

.line.domain:has(.cursor),
.line.message:has(.cursor) {
  padding-left: 1ch;
}

.line.domain:has(.cursor)::after,
.line.message:has(.cursor)::after {
  content: "";
  width: 0;
}

.line.domain {
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  letter-spacing: 0.18em;
  text-transform: lowercase;
  color: rgba(232, 236, 244, 0.92);
  margin-bottom: 0.8rem;
  text-shadow:
    -0.4px 0 rgba(255, 80, 80, 0.12),
     0.4px 0 rgba(80, 120, 255, 0.14),
     0 0 12px rgba(180, 200, 255, 0.25),
     0 0 28px rgba(140, 170, 255, 0.12);
}

.line.message {
  color: rgba(220, 228, 240, 0.72);
  margin-bottom: 0.8rem;
  text-shadow:
    -0.3px 0 rgba(255, 80, 80, 0.08),
     0.3px 0 rgba(80, 120, 255, 0.1),
     0 0 8px rgba(180, 200, 255, 0.18);
}

.line.prompt {
  height: 1.6em;
}

.cursor {
  display: inline-block;
  width: 1ch;
  color: rgba(210, 220, 240, 0.85);
  text-shadow:
    0 0 6px rgba(180, 200, 255, 0.3),
    0 0 14px rgba(140, 170, 255, 0.15);
}

.cursor--active {
  opacity: 1;
}

.cursor--idle {
  animation: cursor-blink 1.06s step-end infinite;
}

.line.prompt .cursor {
  visibility: hidden;
}

.content--cursor-visible .line.prompt .cursor--idle {
  visibility: visible;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Effect layers ────────────────────────────────────────── */

.layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.layer--rgb {
  z-index: 2;
  background:
    linear-gradient(90deg, rgba(255, 0, 0, 0.018) 0%, transparent 50%, rgba(0, 0, 255, 0.018) 100%);
  mix-blend-mode: screen;
  opacity: 0;
}

.viewport--ready .layer--rgb {
  animation: layer-fade 1.2s ease-out 0.3s forwards;
}

.layer--scanlines {
  z-index: 11;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 1px,
    rgba(0, 0, 0, 0.12) 1px,
    rgba(0, 0, 0, 0.12) 2px
  );
  opacity: 0;
}

.viewport--power-on .layer--scanlines {
  animation: none;
}

.viewport--ready .layer--scanlines {
  animation: scanlines-in 2.8s ease-out forwards;
}

@keyframes scanlines-in {
  0%   { opacity: 0; }
  100% { opacity: 0.55; }
}

@keyframes layer-fade {
  to { opacity: 1; }
}

.layer--vignette {
  z-index: 12;
  background: radial-gradient(
    ellipse 75% 70% at 50% 48%,
    transparent 30%,
    rgba(0, 0, 0, 0.25) 70%,
    rgba(0, 0, 0, 0.55) 100%
  );
  opacity: 0;
}

.viewport--alive .layer--vignette {
  animation: layer-fade 1s ease-out 0.2s forwards;
}

.layer--curve {
  z-index: 13;
  box-shadow:
    inset 0 0 80px rgba(0, 0, 0, 0.45),
    inset 0 0 200px rgba(0, 0, 0, 0.2);
  border-radius: 3% / 4%;
  opacity: 0;
}

.viewport--alive .layer--curve {
  animation: layer-fade 1s ease-out 0.1s forwards;
}

.layer--flicker {
  z-index: 14;
  background: transparent;
  opacity: 0;
  animation: micro-flicker 0.15s steps(3) infinite;
}

.viewport--ready .layer--flicker {
  animation: micro-flicker 0.15s steps(3) infinite;
}

@keyframes micro-flicker {
  0%, 100% { background: transparent; }
  33%       { background: rgba(255, 255, 255, 0.006); }
  66%       { background: rgba(0, 0, 0, 0.008); }
}

.layer--hsync {
  z-index: 15;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 48%,
    rgba(255, 255, 255, 0.025) 49.5%,
    rgba(255, 255, 255, 0.04) 50%,
    rgba(255, 255, 255, 0.025) 50.5%,
    transparent 52%,
    transparent 100%
  );
  opacity: 0;
  transform: translateY(-100%);
}

.layer--hsync.active {
  animation: hsync-shimmer 0.35s ease-out forwards;
}

@keyframes hsync-shimmer {
  0% {
    opacity: 0;
    transform: translateY(-20%);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(120%);
  }
}

.layer--noise {
  z-index: 16;
  opacity: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: overlay;
}

.viewport--ready .layer--noise {
  animation: noise-in 2s ease-out forwards;
}

@keyframes noise-in {
  to { opacity: 0.35; }
}

/* ── Reduced motion ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .viewport::before,
  .power-line,
  .bloom,
  .crt,
  .content,
  .layer--scanlines,
  .layer--flicker,
  .layer--hsync,
  .layer--noise,
  .layer--rgb,
  .layer--vignette,
  .layer--curve {
    animation: none !important;
    transition: none !important;
  }

  .viewport--power-on .power-line,
  .viewport--alive .crt,
  .viewport--ready .content {
    opacity: 1;
    filter: none;
    transform: none;
  }

  .viewport--ready .crt-glass {
    animation: none;
    filter: none;
  }

  .layer--vignette,
  .layer--curve,
  .layer--rgb,
  .layer--noise {
    opacity: 1;
  }
}
