/* ── Design System: chmod-x ──
   Palette: Cyberpunk Terminal Dark
   BG: #0a0a0f  |  Surface: #0d1117
   Primary: #a78bfa (violet)  |  Accent: #22d3ee (cyan)
   Text: #e2e8f0  |  Muted: #64748b
   Success: #4ade80  |  Error: #f87171  |  Warn: #fbbf24
   Font: JetBrains Mono (mono) / IBM Plex Sans (sans)
*/

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

:root {
  --bg: #0a0a0f;
  --surface: #0d1117;
  --surface-light: #161b22;
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --primary: #a78bfa;
  --primary-dim: rgba(167, 139, 250, 0.15);
  --accent: #22d3ee;
  --accent-dim: rgba(34, 211, 238, 0.1);
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --font-sans: 'IBM Plex Sans', -apple-system, system-ui, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-mono);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Logo ── */
.logo {
  position: fixed;
  top: 24px;
  left: 28px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  transition: opacity 0.3s ease;
}

.logo:hover {
  opacity: 0.8;
}

.logo__icon {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 0 8px rgba(167, 139, 250, 0.3));
  transition: filter 0.3s ease;
}

.logo:hover .logo__icon {
  filter: drop-shadow(0 0 12px rgba(167, 139, 250, 0.5));
}

.logo__text {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.logo:hover .logo__text {
  opacity: 1;
}

/* ── Music Toggle ── */
.music-toggle {
  position: fixed;
  top: 24px;
  right: 28px;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.6);
  border: 1px solid rgba(167, 139, 250, 0.15);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.music-toggle:hover {
  color: var(--text);
  border-color: rgba(167, 139, 250, 0.35);
  box-shadow: 0 0 16px rgba(167, 139, 250, 0.15);
}

.music-toggle__icon {
  width: 18px;
  height: 18px;
  display: none;
}

.music-toggle__icon--off {
  display: block;
}

.music-toggle.playing .music-toggle__icon--off {
  display: none;
}

.music-toggle.playing .music-toggle__icon--on {
  display: block;
}

.music-toggle.playing {
  color: var(--primary);
  border-color: rgba(167, 139, 250, 0.3);
  animation: musicPulse 3s ease-in-out infinite;
}

@keyframes musicPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(167, 139, 250, 0.1); }
  50% { box-shadow: 0 0 18px rgba(167, 139, 250, 0.25); }
}

/* ── Abstract Background ── */
canvas#particles {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* Aurora nebula layer */
.aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.aurora__ribbon {
  position: absolute;
  width: 200%;
  height: 60%;
  left: -50%;
  filter: blur(60px);
  opacity: 0;
  mix-blend-mode: screen;
  will-change: transform, opacity;
}

.aurora__ribbon--1 {
  top: -10%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(139, 92, 246, 0.25) 20%,
    rgba(34, 211, 238, 0.2) 40%,
    rgba(167, 139, 250, 0.3) 60%,
    rgba(236, 72, 153, 0.15) 80%,
    transparent 100%
  );
  animation: aurora1 12s ease-in-out infinite;
}

.aurora__ribbon--2 {
  bottom: -20%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(34, 211, 238, 0.2) 25%,
    rgba(139, 92, 246, 0.25) 50%,
    rgba(74, 222, 128, 0.1) 75%,
    transparent 100%
  );
  animation: aurora2 16s ease-in-out 3s infinite;
}

.aurora__ribbon--3 {
  top: 20%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(236, 72, 153, 0.15) 30%,
    rgba(167, 139, 250, 0.2) 50%,
    rgba(34, 211, 238, 0.15) 70%,
    transparent 100%
  );
  animation: aurora3 20s ease-in-out 6s infinite;
}

@keyframes aurora1 {
  0%, 100% { transform: translateX(-10%) rotate(-3deg) scaleY(0.8); opacity: 0; }
  15% { opacity: 0.7; }
  50% { transform: translateX(10%) rotate(2deg) scaleY(1.2); opacity: 0.9; }
  85% { opacity: 0.5; }
}

@keyframes aurora2 {
  0%, 100% { transform: translateX(5%) rotate(2deg) scaleY(0.6); opacity: 0; }
  20% { opacity: 0.6; }
  50% { transform: translateX(-15%) rotate(-4deg) scaleY(1.1); opacity: 0.8; }
  80% { opacity: 0.4; }
}

@keyframes aurora3 {
  0%, 100% { transform: translateX(8%) rotate(1deg) scaleY(0.7); opacity: 0; }
  30% { opacity: 0.5; }
  60% { transform: translateX(-8%) rotate(-2deg) scaleY(1.3); opacity: 0.7; }
  90% { opacity: 0.3; }
}

/* Orbs - bigger and brighter */
.orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  will-change: transform;
}

.orb--1 {
  width: 800px;
  height: 800px;
  background: radial-gradient(circle, rgba(167, 139, 250, 0.25), rgba(139, 92, 246, 0.08) 50%, transparent 70%);
  top: -20%;
  left: -15%;
  filter: blur(60px);
  animation: drift1 22s ease-in-out infinite;
}

.orb--2 {
  width: 700px;
  height: 700px;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.2), rgba(6, 182, 212, 0.06) 50%, transparent 70%);
  bottom: -20%;
  right: -15%;
  filter: blur(70px);
  animation: drift2 28s ease-in-out infinite;
}

.orb--3 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(236, 72, 153, 0.18), transparent 70%);
  top: 30%;
  left: 50%;
  filter: blur(80px);
  animation: drift3 18s ease-in-out infinite;
}

.orb--4 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(74, 222, 128, 0.12), transparent 70%);
  top: 60%;
  left: 10%;
  filter: blur(90px);
  animation: drift4 24s ease-in-out infinite;
}

.orb--5 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.1), transparent 70%);
  top: 10%;
  right: 10%;
  filter: blur(70px);
  animation: drift5 20s ease-in-out infinite;
}

@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(80px, 60px) scale(1.15); }
  66% { transform: translate(-50px, 100px) scale(0.9); }
}

@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(-70px, -80px) scale(1.2); }
  66% { transform: translate(40px, -40px) scale(0.85); }
}

@keyframes drift3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(60px, -50px) scale(1.15); }
  66% { transform: translate(-80px, 40px) scale(0.9); }
}

@keyframes drift4 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(100px, -60px) scale(1.1); }
}

@keyframes drift5 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  40% { transform: translate(-50px, 70px) scale(1.2); }
  70% { transform: translate(30px, -30px) scale(0.95); }
}

/* Perspective grid floor */
.grid-floor {
  position: fixed;
  bottom: 0;
  left: -50%;
  width: 200%;
  height: 50%;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(transparent 0%, rgba(167, 139, 250, 0.03) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 79px,
      rgba(167, 139, 250, 0.06) 79px,
      rgba(167, 139, 250, 0.06) 80px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 79px,
      rgba(167, 139, 250, 0.06) 79px,
      rgba(167, 139, 250, 0.06) 80px
    );
  background-size: 100% 100%, 80px 80px, 80px 80px;
  transform: perspective(500px) rotateX(60deg);
  transform-origin: center top;
  mask-image: linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 80%);
  -webkit-mask-image: linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 80%);
}

/* Floating code fragments */
.code-fragments {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.code-frag {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(167, 139, 250, 0.08);
  white-space: nowrap;
  user-select: none;
  animation: floatUp linear infinite;
}

@keyframes floatUp {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(-110vh) rotate(3deg); opacity: 0; }
}

/* Scanlines */
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.025) 2px,
    rgba(0, 0, 0, 0.025) 4px
  );
}

/* Vignette */
.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    transparent 40%,
    rgba(0, 0, 0, 0.4) 100%
  );
}

/* ── Terminal ── */
.terminal-container {
  position: fixed;
  z-index: 10;
  width: 700px;
  max-width: 94vw;
  opacity: 0;
  /* JS triggers the boot sequence */
}

/* Phase 1: CRT power-on — thin horizontal line expands */
.terminal-container.boot-line {
  opacity: 1;
  clip-path: inset(50% 0 50% 0);
  animation: crtLine 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes crtLine {
  0% { clip-path: inset(50% 0 50% 0); }
  100% { clip-path: inset(0% 0 0% 0); }
}

/* Phase 2: Flicker on */
.terminal-container.boot-flicker {
  animation: flicker 0.3s steps(4) forwards;
}

@keyframes flicker {
  0% { opacity: 1; }
  20% { opacity: 0.4; }
  40% { opacity: 0.9; }
  60% { opacity: 0.3; }
  80% { opacity: 0.85; }
  100% { opacity: 1; }
}

/* Phase 3: Settle — subtle scale bounce */
.terminal-container.boot-ready {
  opacity: 1;
  clip-path: none;
  animation: settle 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes settle {
  0% { transform: scale(1.01); filter: brightness(1.3); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Boot text styling */
.boot-line-text {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
  opacity: 0.6;
  white-space: pre;
}

.boot-line-text.ok {
  color: var(--green);
  opacity: 0.8;
}

.boot-line-text.highlight {
  color: var(--accent);
  opacity: 0.9;
}

.boot-line-text.brand {
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  opacity: 1;
}

/* Neon glow aura behind terminal */
.terminal-container::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 14px;
  background: linear-gradient(
    135deg,
    rgba(167, 139, 250, 0.5),
    rgba(34, 211, 238, 0.4),
    rgba(236, 72, 153, 0.35),
    rgba(139, 92, 246, 0.5)
  );
  background-size: 300% 300%;
  animation: neonShift 8s ease-in-out infinite;
  filter: blur(18px);
  opacity: 0.6;
  z-index: -1;
}

/* Sharper inner border glow */
.terminal-container::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 13px;
  background: linear-gradient(
    135deg,
    rgba(167, 139, 250, 0.6),
    rgba(34, 211, 238, 0.5),
    rgba(236, 72, 153, 0.4),
    rgba(139, 92, 246, 0.6)
  );
  background-size: 300% 300%;
  animation: neonShift 8s ease-in-out infinite;
  z-index: -1;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  padding: 1px;
}

@keyframes neonShift {
  0%, 100% { background-position: 0% 50%; }
  25% { background-position: 100% 0%; }
  50% { background-position: 100% 100%; }
  75% { background-position: 0% 100%; }
}

/* Terminal light cast — JS controls the color via CSS custom property */
.terminal-light {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 900px;
  height: 900px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(100px);
  opacity: 0.25;
  background: radial-gradient(circle, var(--neon-color, rgba(167,139,250,0.4)) 0%, transparent 70%);
  transition: background 0.6s ease, left 0.15s ease-out, top 0.15s ease-out;
  will-change: background, left, top;
}

/* Floor reflection under terminal */
.terminal-reflection {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 700px;
  height: 350px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 0;
  filter: blur(60px);
  opacity: 0.2;
  background: radial-gradient(ellipse at top center, var(--neon-color, rgba(167,139,250,0.4)) 0%, transparent 70%);
  transition: background 0.6s ease, left 0.15s ease-out;
  will-change: background, left;
}

.terminal {
  position: relative;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid rgba(167, 139, 250, 0.12);
  border-radius: 12px;
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(167, 139, 250, 0.06),
    0 0 15px rgba(167, 139, 250, 0.08),
    0 0 45px rgba(139, 92, 246, 0.06),
    0 0 80px rgba(34, 211, 238, 0.04),
    0 4px 24px rgba(0, 0, 0, 0.4),
    0 24px 80px rgba(0, 0, 0, 0.5);
}

/* Title bar */
.terminal__titlebar {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

@media (min-width: 541px) {
  .terminal__titlebar {
    cursor: grab;
  }
  .terminal__titlebar:active {
    cursor: grabbing;
  }
}

.terminal__dots {
  display: flex;
  gap: 8px;
}

.terminal__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.terminal__dot--close { background: #ff5f57; }
.terminal__dot--min { background: #febc2e; }
.terminal__dot--max { background: #28c840; }

.terminal__title {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  font-family: var(--font-sans);
  font-weight: 400;
  margin-right: 52px;
}

/* Body */
.terminal__body {
  padding: 20px 22px 24px;
  height: 420px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  scrollbar-width: thin;
  scrollbar-color: var(--surface-light) transparent;
}

.terminal__body::-webkit-scrollbar {
  width: 6px;
}

.terminal__body::-webkit-scrollbar-track {
  background: transparent;
}

.terminal__body::-webkit-scrollbar-thumb {
  background: var(--surface-light);
  border-radius: 3px;
}

/* Lines */
.line {
  display: flex;
  align-items: baseline;
  min-height: 1.75em;
}

.prompt {
  color: var(--primary);
  white-space: pre;
  user-select: none;
  flex-shrink: 0;
}

.prompt__arrow {
  color: var(--accent);
}

.cmd {
  color: var(--accent);
  white-space: pre;
}

.arg {
  color: var(--yellow);
  white-space: pre;
}

.flag {
  color: var(--green);
  white-space: pre;
}

.path {
  color: var(--primary);
  white-space: pre;
}

/* Cursor */
.cursor {
  display: inline-block;
  width: 8px;
  height: 17px;
  background: var(--text);
  vertical-align: text-bottom;
  margin-left: 1px;
}

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

.cursor--solid {
  animation: none;
  opacity: 1;
}

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

/* Interactive input */
.input-row {
  display: flex;
  align-items: baseline;
  position: relative;
}

.input-mirror {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.75;
  white-space: pre;
}

.input-field {
  position: absolute;
  left: -9999px;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Output */
.output {
  color: var(--text-muted);
  font-size: 13px;
  padding: 1px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.output--success { color: var(--green); }
.output--error { color: var(--red); }
.output--info { color: var(--accent); }
.output--primary { color: var(--primary); }
.output--dim { color: var(--text-muted); opacity: 0.7; }
.output--bright { color: var(--text); }

/* ── Watermark ── */
.watermark {
  position: fixed;
  bottom: 20px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 10;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: rgba(167, 139, 250, 0.25);
  letter-spacing: 3px;
  text-transform: uppercase;
  user-select: none;
  transition: color 0.3s ease, text-shadow 0.3s ease;
  text-shadow: 0 0 20px rgba(167, 139, 250, 0.1);
}

.watermark:hover {
  color: rgba(167, 139, 250, 0.5);
  text-shadow: 0 0 30px rgba(167, 139, 250, 0.2);
}

/* ── rm -rf Glitch Effect ── */
.terminal--glitch {
  animation: termShake 0.08s linear infinite;
}

.terminal--glitch .terminal__body {
  animation: glitchFlicker 0.15s steps(2) infinite;
}

.terminal--glitch::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(248, 113, 113, 0.03) 2px,
    rgba(248, 113, 113, 0.03) 4px
  );
  pointer-events: none;
  z-index: 100;
  mix-blend-mode: screen;
}

@keyframes termShake {
  0%  { transform: translate(0, 0); }
  10% { transform: translate(-3px, 1px); }
  20% { transform: translate(2px, -2px); }
  30% { transform: translate(-1px, 3px); }
  40% { transform: translate(3px, -1px); }
  50% { transform: translate(-2px, -2px); }
  60% { transform: translate(1px, 2px); }
  70% { transform: translate(-3px, -1px); }
  80% { transform: translate(2px, 1px); }
  90% { transform: translate(-1px, -3px); }
  100% { transform: translate(0, 0); }
}

@keyframes glitchFlicker {
  0%   { opacity: 1; }
  25%  { opacity: 0.85; }
  50%  { opacity: 1; }
  75%  { opacity: 0.9; filter: hue-rotate(20deg); }
  100% { opacity: 1; }
}

.glitch-text {
  display: inline;
  position: relative;
  color: var(--red) !important;
  opacity: 0.8;
  text-shadow: 1px 0 var(--accent), -1px 0 var(--primary);
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .orb,
  .terminal-container,
  .terminal-container.boot-line,
  .terminal-container.boot-flicker,
  .terminal-container.boot-ready,
  .terminal-container::before,
  .terminal-container::after,
  .aurora__ribbon,
  .code-frag {
    animation: none;
  }

  .terminal-container,
  .terminal-container.boot-line,
  .terminal-container.boot-flicker,
  .terminal-container.boot-ready {
    opacity: 1;
    transform: none;
    clip-path: none;
    filter: none;
  }

  .aurora__ribbon {
    opacity: 0.3;
  }

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

  .code-fragments {
    display: none;
  }
}

/* ── Responsive ── */
@media (max-width: 540px) {
  .terminal__body {
    padding: 16px 14px 20px;
    font-size: 12px;
    height: 320px;
  }

  .input-field {
    font-size: 12px;
  }

  .terminal__title {
    font-size: 11px;
  }

  .output {
    font-size: 11px;
  }

  /* ── Mobile performance: reduce GPU-heavy blur layers ── */
  .orb--4, .orb--5 { display: none; }
  .orb--1 { width: 500px; height: 500px; filter: blur(40px); }
  .orb--2 { width: 400px; height: 400px; filter: blur(40px); }
  .orb--3 { width: 350px; height: 350px; filter: blur(50px); }

  .aurora__ribbon { filter: blur(40px); }

  .terminal-light {
    width: 500px;
    height: 500px;
    filter: blur(60px);
  }

  .terminal-reflection {
    width: 400px;
    height: 200px;
    filter: blur(40px);
  }

  .terminal-container::before { filter: blur(12px); }

  .terminal {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .code-fragments { display: none; }
}
