/* =============================================================================
   AUTOMATON TERMINAL — ui_styles.css
   Phase 1: Terminal Shell
   ============================================================================= */

/* --- Custom Properties ------------------------------------------------------- */
:root {
  --color-bg: #000000;
  --color-phosphor: #ccff00;
  --color-phosphor-dim: rgba(204, 255, 0, 0.12);
  --color-phosphor-mid: rgba(204, 255, 0, 0.4);
  --color-white: #ffffff;
  --color-error: #ff3333;
  --font: "Space Mono", "Courier New", monospace;
  --glow-text: 0 0 8px rgba(204, 255, 0, 0.55);
  --glow-spread: 0 0 10px var(--color-phosphor), 0 0 24px var(--color-phosphor);
  --glow-error: 0 0 8px rgba(255, 51, 51, 0.5);
  --term-px: 24px; /* horizontal padding inside terminal */
}

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

/* --- Page -------------------------------------------------------------------- */
html,
body {
  height: 100%;
}

body {
  background-color: var(--color-bg);
  color: var(--color-phosphor);
  font-family: var(--font);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
}

/*
  Global CRT scanlines — applied to the whole viewport.
  A real phosphor screen has horizontal raster lines everywhere.
  Very subtle: 4px pitch, 8% opacity black bands.
*/
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.08) 3px,
    rgba(0, 0, 0, 0.08) 4px
  );
  pointer-events: none;
  z-index: 1000;
}

/* --- Background canvas ------------------------------------------------------- */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* --- Heartbeat radial pulse overlay ------------------------------------------ */
#heartbeat-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(204, 255, 0, 0.07) 0%,
    transparent 65%
  );
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.4s ease-out;
}

/* --- Terminal container ------------------------------------------------------ */
.terminal-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 820px;
  height: 85vh;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
}

/* --- Brand header ------------------------------------------------------------ */
.brand-header {
  text-align: center;
  padding: 0 0 20px;
  flex-shrink: 0;
  animation: breathe 6s ease-in-out infinite;
}

.logo-text {
  font-size: clamp(2.4rem, 7vw, 3.8rem);
  font-weight: 700;
  letter-spacing: -2px;
  text-transform: uppercase;
  /* Static glow; brightness is modulated by breathe on the parent */
  text-shadow: var(--glow-spread);
  line-height: 1;
  user-select: none;
}

.logo-sub {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 3.5px;
  color: rgba(204, 255, 0, 0.42);
  margin-top: 7px;
  text-shadow: none;
  user-select: none;
}

/* --- Terminal window --------------------------------------------------------- */
.terminal-window {
  flex: 1;
  min-height: 0; /* critical: allows flex child to shrink below content size */
  background: rgba(0, 0, 0, 0.94);
  border: 1px solid rgba(204, 255, 0, 0.14);
  border-radius: 0; /* square — more terminal */
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  /* Depth: subtle outer ring + deep inner shadow */
  box-shadow:
    0 0 0 1px rgba(204, 255, 0, 0.03),
    inset 0 0 80px rgba(0, 0, 0, 0.95),
    0 24px 80px rgba(0, 0, 0, 0.75);
  /* CRT border flicker — box-shadow only, never opacity/color of text */
  animation: border-flicker 14s ease-in-out infinite;
}

/*
  Very dim phosphor grid lines on the screen surface — gives depth.
  Not a functional grid, just texture. Kept at 0.05 opacity.
*/
.terminal-window::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(204, 255, 0, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(204, 255, 0, 0.15) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.05;
  pointer-events: none;
  z-index: 1;
}

/* --- Terminal output --------------------------------------------------------- */
.terminal-output {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px var(--term-px) 8px;
  font-size: 13px;
  line-height: 1.65;
  position: relative;
  z-index: 3;
  /* Narrow phosphor-tinted scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(204, 255, 0, 0.18) transparent;
}

.terminal-output::-webkit-scrollbar {
  width: 3px;
}
.terminal-output::-webkit-scrollbar-thumb {
  background: rgba(204, 255, 0, 0.2);
  border-radius: 0;
}
.terminal-output::-webkit-scrollbar-track {
  background: transparent;
}

/* --- Terminal line types ----------------------------------------------------- */

/*
  Base: every line fades in over 120ms.
  animation-fill-mode: both applies the `from` state (opacity:0) during
  any animation-delay period, making staggered boot lines invisible until
  their moment arrives.
*/
.term-line {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 1px;
  animation: line-in 120ms ease both;
}

/* System — default phosphor green with glow */
.term-line.system {
  color: var(--color-phosphor);
  text-shadow: var(--glow-text);
  opacity: 1; /* animation sets this */
}

/* Dim system text — less glow, reduced opacity */
.term-line.system.dim {
  color: rgba(204, 255, 0, 0.48);
  text-shadow: none;
}

/* Bright system text — extra glow for headers and READY */
.term-line.system.bright {
  color: var(--color-phosphor);
  text-shadow: var(--glow-spread);
}

/* User input echo — white, appears instantly */
.term-line.user {
  color: var(--color-white);
  text-shadow: none;
  animation: none;
  opacity: 1;
}

/* Error */
.term-line.error {
  color: var(--color-error);
  text-shadow: var(--glow-error);
}

/* Success confirmation */
.term-line.success {
  color: var(--color-white);
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
}

/* Separator lines — dim phosphor, no glow */
.term-line.separator {
  color: rgba(204, 255, 0, 0.28);
  text-shadow: none;
  letter-spacing: 0;
  animation-duration: 60ms;
}

/* Empty spacer lines — no animation, just height */
.term-line.empty {
  display: block;
  height: 7px;
  animation: none;
  opacity: 1;
  margin-bottom: 0;
}

/* --- Terminal input divider -------------------------------------------------- */
.terminal-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(204, 255, 0, 0.18) 15%,
    rgba(204, 255, 0, 0.18) 85%,
    transparent 100%
  );
  flex-shrink: 0;
  position: relative;
  z-index: 3;
}

/* --- Terminal input row ----------------------------------------------------- */
.terminal-input-row {
  display: flex;
  align-items: center;
  padding: 11px var(--term-px);
  flex-shrink: 0;
  position: relative;
  z-index: 3;
}

/* Follow mode: prompt dims and blinks to signal locked state */
.terminal-input-row.follow-mode .prompt-symbol {
  color: rgba(204, 255, 0, 0.32);
  animation: follow-blink 1.4s step-end infinite;
}

.prompt-symbol {
  color: var(--color-phosphor);
  text-shadow: var(--glow-text);
  font-weight: 700;
  margin-right: 10px;
  user-select: none;
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  transition: color 0.2s;
}

.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--color-white);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.65;
  outline: none;
  caret-color: var(--color-phosphor);
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.18);
}

.terminal-input::placeholder {
  color: rgba(204, 255, 0, 0.16);
  font-style: italic;
}

/* In follow mode, show "q to stop" placeholder */
.terminal-input.follow-placeholder::placeholder {
  content: "";
  color: rgba(204, 255, 0, 0.3);
  font-style: normal;
}

/* --- Status bar ------------------------------------------------------------- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 2px 0;
  font-size: 10px;
  color: rgba(204, 255, 0, 0.36);
  flex-shrink: 0;
  user-select: none;
  letter-spacing: 0.4px;
  line-height: 1;
}

.sb-indicator {
  font-size: 7px;
  color: var(--color-phosphor);
  text-shadow: var(--glow-text);
  animation: indicator-pulse 2.5s ease-in-out infinite;
  line-height: 1;
}

.sb-indicator.offline {
  color: var(--color-error);
  text-shadow: var(--glow-error);
  animation: none;
}

.sb-indicator.idle {
  color: rgba(204, 255, 0, 0.55);
  text-shadow: none;
  animation: indicator-pulse 4s ease-in-out infinite;
}

.sb-sep {
  opacity: 0.2;
}

.sb-spacer {
  margin-left: auto;
}

/* --- Animations -------------------------------------------------------------- */

/*
  breathe: the whole brand header gently pulses in brightness.
  filter:brightness affects the logo glow amplitude visually —
  the text-shadow stays constant but perceived intensity shifts.
*/
@keyframes breathe {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.22);
  }
}

/* Single-line fade-in for all terminal output */
@keyframes line-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Status bar pulse dot */
@keyframes indicator-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.32;
  }
}

/* Follow mode prompt symbol blink */
@keyframes follow-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.12;
  }
}

/*
  CRT border flicker — only touches box-shadow (glow around the terminal
  window border). Text inside is completely unaffected.
  Fires rarely (every ~14s) and lasts only a few frames.
*/
@keyframes border-flicker {
  0%,
  93%,
  100% {
    box-shadow:
      0 0 0 1px rgba(204, 255, 0, 0.03),
      inset 0 0 80px rgba(0, 0, 0, 0.95),
      0 24px 80px rgba(0, 0, 0, 0.75);
  }
  93.8% {
    box-shadow:
      0 0 0 1px rgba(204, 255, 0, 0.11),
      inset 0 0 80px rgba(0, 0, 0, 0.82),
      0 24px 80px rgba(0, 0, 0, 0.75),
      0 0 30px rgba(204, 255, 0, 0.05);
  }
  94.6% {
    box-shadow:
      0 0 0 1px rgba(204, 255, 0, 0.03),
      inset 0 0 80px rgba(0, 0, 0, 0.95),
      0 24px 80px rgba(0, 0, 0, 0.75);
  }
  95.4% {
    box-shadow:
      0 0 0 1px rgba(204, 255, 0, 0.07),
      inset 0 0 80px rgba(0, 0, 0, 0.88),
      0 24px 80px rgba(0, 0, 0, 0.75),
      0 0 20px rgba(204, 255, 0, 0.03);
  }
}

/* --- Responsive tweaks ------------------------------------------------------ */
@media (max-height: 620px) {
  .terminal-container {
    height: 95vh;
  }
  .brand-header {
    padding-bottom: 10px;
  }
  .logo-text {
    font-size: 2rem;
    letter-spacing: -1px;
  }
  .logo-sub {
    display: none;
  }
}

@media (max-width: 600px) {
  .terminal-container {
    padding: 0 8px;
  }
  .terminal-output {
    padding-left: 14px;
    padding-right: 14px;
  }
  .terminal-input-row {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* --- Accessibility: reduced motion ------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}
