@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

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

html, body, #root {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050505;
  font-family: 'VT323', 'Courier New', monospace;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #1a3a1a; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #33ff33; }

/* Scanlines overlay */
.scanlines::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.12) 2px,
    rgba(0, 0, 0, 0.12) 4px
  );
  pointer-events: none;
  z-index: 100;
  animation: scanlineShift 0.1s steps(2) infinite;
}

@keyframes scanlineShift {
  0% { transform: translateY(0); }
  100% { transform: translateY(4px); }
}

/* CRT curvature vignette */
.crt-vignette::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.7) 100%);
  pointer-events: none;
  z-index: 101;
}

/* Screen flicker */
.crt-flicker {
  animation: flicker 8s infinite;
}

@keyframes flicker {
  0%, 96%, 98%, 100% { opacity: 1; }
  97% { opacity: 0.95; }
  99% { opacity: 0.97; }
}

/* Noise overlay */
.noise-overlay {
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  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.9' 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");
  pointer-events: none;
  z-index: 99;
  animation: noiseMove 0.5s steps(10) infinite;
  opacity: 0.5;
}

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

/* Phosphor glow text */
.glow-green {
  color: #33ff33;
  text-shadow: 0 0 5px #33ff33, 0 0 10px rgba(51, 255, 51, 0.4);
}

.glow-amber {
  color: #ffaa00;
  text-shadow: 0 0 5px #ffaa00, 0 0 10px rgba(255, 170, 0, 0.4);
}

.glow-cyan {
  color: #00ffff;
  text-shadow: 0 0 5px #00ffff, 0 0 10px rgba(0, 255, 255, 0.4);
}

.glow-red {
  color: #ff0033;
  text-shadow: 0 0 5px #ff0033, 0 0 10px rgba(255, 0, 51, 0.4);
}

/* REC blink */
@keyframes recBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.rec-blink {
  animation: recBlink 1s steps(1) infinite;
}

/* Glitch effect */
.glitch-active {
  animation: glitchTrigger 0.3s ease-out;
}

@keyframes glitchTrigger {
  0% { filter: none; }
  10% { filter: hue-rotate(90deg) saturate(2); transform: translateX(-3px); }
  20% { filter: hue-rotate(-90deg) saturate(3); transform: translateX(3px); }
  30% { filter: hue-rotate(45deg); transform: translateX(-1px) skewX(-1deg); }
  40% { filter: none; transform: translateX(2px) skewX(1deg); }
  50% { filter: hue-rotate(-30deg); transform: translateX(0); }
  100% { filter: none; transform: translateX(0); }
}

/* Typewriter cursor */
@keyframes cursorBlink {
  0%, 49% { border-color: #33ff33; }
  50%, 100% { border-color: transparent; }
}

.typing-cursor {
  border-right: 2px solid #33ff33;
  animation: cursorBlink 0.7s steps(1) infinite;
  padding-right: 2px;
}

/* Input pulse */
@keyframes inputPulse {
  0%, 100% { box-shadow: 0 0 5px rgba(51, 255, 51, 0.3), inset 0 0 5px rgba(51, 255, 51, 0.1); }
  50% { box-shadow: 0 0 15px rgba(51, 255, 51, 0.5), inset 0 0 10px rgba(51, 255, 51, 0.15); }
}

.input-pulse {
  animation: inputPulse 2s ease-in-out infinite;
}

/* VHS tracking bar */
@keyframes trackingBar {
  0% { top: -10%; }
  100% { top: 110%; }
}

.tracking-bar {
  position: absolute;
  left: 0; right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  filter: blur(1px);
  z-index: 98;
  pointer-events: none;
  animation: trackingBar 4s linear infinite;
}

/* Portrait distortion */
.portrait-distort {
  filter: contrast(1.1) saturate(1.2);
  transition: filter 0.3s;
}

.portrait-distort:hover {
  filter: contrast(1.3) saturate(1.5) hue-rotate(10deg);
}

/* Tape label styling */
.tape-item {
  border: 1px solid #1a3a1a;
  transition: all 0.2s;
}

.tape-item:hover {
  border-color: #33ff33;
  background: rgba(51, 255, 51, 0.05) !important;
}

/* CRT power-on effect */
@keyframes powerOn {
  0% { transform: scaleY(0.01) scaleX(0.5); filter: brightness(10); }
  20% { transform: scaleY(0.01) scaleX(1); filter: brightness(5); }
  40% { transform: scaleY(1) scaleX(1); filter: brightness(2); }
  60% { transform: scaleY(1) scaleX(1); filter: brightness(1.5); }
  100% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
}

.power-on {
  animation: powerOn 0.8s ease-out;
}

/* Static burst */
@keyframes staticBurst {
  0% { opacity: 0.8; }
  50% { opacity: 0.4; }
  100% { opacity: 0; }
}

.static-burst {
  animation: staticBurst 0.3s ease-out forwards;
}

/* Signal meter */
.signal-bar {
  display: inline-block;
  width: 8px;
  height: 12px;
  margin-right: 1px;
  background: #1a3a1a;
  opacity: 0.3;
}

.signal-bar.active {
  background: #33ff33;
  opacity: 1;
  box-shadow: 0 0 3px #33ff33;
}

/* ====== LAYOUT ====== */

/* Main app container */
.app-outer {
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #050505;
  padding: 8px;
  overflow: hidden;
}

/* CRT Housing */
.crt-housing {
  width: 100%;
  max-width: 1200px;
  flex: 1;
  min-height: 0;
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a, #222);
  border-radius: 16px;
  padding: 10px;
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.8), inset 0 1px 0 rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
}

/* Bezel top */
.bezel-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 6px 6px 6px;
  flex-shrink: 0;
}

.bezel-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #33ff33;
  box-shadow: 0 0 6px #33ff33, 0 0 12px rgba(51,255,51,0.5);
  animation: recBlink 2s infinite;
}

.bezel-label {
  color: #555;
  font-size: 11px;
  font-family: Arial, sans-serif;
  letter-spacing: 1px;
}

.bezel-knob {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #333, #1a1a1a);
  border: 1px solid #2a2a2a;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
}

/* Screen */
.crt-screen-wrap {
  flex: 1;
  min-height: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #111;
  position: relative;
  box-shadow: inset 0 0 60px rgba(0,255,0,0.02), 0 0 2px #000;
}

.crt-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #080a08;
  overflow: hidden;
}

/* Bottom bezel */
.bezel-bottom {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0 0 0;
  gap: 20px;
  flex-shrink: 0;
}

.bezel-slider {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: #1a1a1a;
  border: 1px solid #222;
}

/* VHS HUD top bar */
.vhs-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid #1a3a1a;
  background: rgba(0,0,0,0.5);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
  gap: 6px;
  flex-wrap: nowrap;
  min-height: 36px;
}

.vhs-hud-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.vhs-hud-center {
  font-size: 16px;
  letter-spacing: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vhs-hud-right {
  font-size: 14px;
  letter-spacing: 1px;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-tapes {
  background: none;
  border: 1px solid #1a3a1a;
  color: #33ff33;
  font-family: 'VT323', monospace;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  text-shadow: 0 0 5px #33ff33;
  white-space: nowrap;
  min-height: 28px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Main content area */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ===== DESKTOP: Portrait on left, chat on right ===== */
.portrait-panel {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-right: 1px solid #1a3a1a;
  background: rgba(0,5,0,0.3);
  overflow: hidden;
}

.portrait-frame {
  width: 210px;
  height: 230px;
  border: 2px solid #1a3a1a;
  overflow: hidden;
  position: relative;
  background: #050505;
  box-shadow: inset 0 0 20px rgba(0,255,0,0.05), 0 0 8px rgba(0,255,0,0.1);
  flex-shrink: 0;
}

.portrait-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portrait-name {
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  white-space: nowrap;
}

.portrait-status {
  font-size: 12px;
  opacity: 0.5;
  text-align: center;
}

/* Chat panel */
.chat-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: rgba(0,2,0,0.5);
  min-height: 0;
}

/* Chat message */
.chat-msg {
  padding: 6px 10px;
  margin-bottom: 6px;
  word-break: break-word;
}

.chat-msg-user {
  border-left: 2px solid #33ff33;
  background: rgba(51,255,51,0.03);
}

.chat-msg-ai {
  border-left: 2px solid #ffaa00;
  background: rgba(255,170,0,0.03);
}

.chat-msg-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.chat-msg-label {
  font-size: 13px;
  opacity: 0.6;
}

.chat-msg-time {
  font-size: 11px;
  opacity: 0.3;
}

.chat-msg-body {
  font-size: 16px;
  line-height: 1.4;
}

/* Input area */
.input-area {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #1a3a1a;
  background: rgba(0,0,0,0.5);
  align-items: center;
  flex-shrink: 0;
}

.input-label {
  font-size: 14px;
  white-space: nowrap;
  flex-shrink: 0;
}

.input-field {
  flex: 1;
  background: rgba(0,10,0,0.5);
  border: 1px solid #1a3a1a;
  color: #33ff33;
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 8px 10px;
  outline: none;
  border-radius: 0;
  text-shadow: 0 0 5px #33ff33;
  min-width: 0;
  min-height: 40px;
}

.btn-transmit {
  background: #1a3a1a;
  border: 2px solid #33ff33;
  color: #33ff33;
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 8px 12px;
  cursor: pointer;
  text-shadow: 0 0 5px #33ff33;
  white-space: nowrap;
  letter-spacing: 1px;
  min-height: 40px;
  min-width: 44px;
}

.btn-transmit:disabled {
  background: #0a1a0a;
  border-color: #0a1a0a;
  color: #1a3a1a;
  cursor: not-allowed;
  text-shadow: none;
}

/* Tape Library */
.tape-library {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid #1a3a1a;
  background: rgba(0,5,0,0.9);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
}

.tape-library-header {
  padding: 10px;
  border-bottom: 1px solid #1a3a1a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.tape-library-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.btn-new-tape {
  width: 100%;
  background: rgba(51,255,51,0.1);
  border: 1px dashed #33ff33;
  color: #33ff33;
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
  text-shadow: 0 0 5px #33ff33;
  letter-spacing: 2px;
  margin: 6px 0;
  min-height: 40px;
}

.btn-close-tapes {
  background: none;
  border: none;
  color: #ff0033;
  font-family: 'VT323', monospace;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 36px;
  min-height: 36px;
}

.tape-entry {
  padding: 8px;
  margin-bottom: 4px;
  cursor: pointer;
}

.tape-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
}

.tape-entry-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.tape-entry-label {
  font-size: 13px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tape-entry-preview {
  font-size: 11px;
  opacity: 0.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tape-entry-count {
  font-size: 10px;
  opacity: 0.3;
  margin-top: 3px;
}

.btn-eject {
  background: none;
  border: 1px solid #330000;
  color: #ff0033;
  font-family: 'VT323', monospace;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 5px;
  flex-shrink: 0;
  min-height: 24px;
  min-width: 40px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 16px;
}

.empty-icon {
  font-size: 36px;
  opacity: 0.3;
  margin-bottom: 12px;
}

.empty-text {
  font-size: 20px;
  opacity: 0.4;
  margin-bottom: 8px;
}

.empty-hint {
  font-size: 14px;
  opacity: 0.3;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 6px;
  color: #1a3a1a;
  font-family: 'VT323', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.app-footer a {
  text-decoration: none;
}

/* ====== MOBILE RESPONSIVE ====== */
@media (max-width: 768px) {
  .app-outer {
    padding: 4px;
  }

  .crt-housing {
    border-radius: 10px;
    padding: 6px;
  }

  /* Hide channel name on very small screens */
  .vhs-hud-center {
    font-size: 13px;
    letter-spacing: 1px;
  }

  .vhs-hud-right {
    font-size: 12px;
  }

  /* Stack portrait above chat on mobile */
  .main-content {
    flex-direction: column;
  }

  /* Portrait panel: horizontal compact strip on mobile */
  .portrait-panel {
    width: 100%;
    flex-direction: row;
    padding: 8px;
    border-right: none;
    border-bottom: 1px solid #1a3a1a;
    gap: 10px;
    align-items: center;
    max-height: none;
    flex-shrink: 0;
  }

  .portrait-frame {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
  }

  .portrait-info-mobile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  .portrait-name {
    font-size: 14px;
    letter-spacing: 2px;
    text-align: left;
  }

  .portrait-status {
    font-size: 11px;
    text-align: left;
  }

  /* Tape library overlay on mobile */
  .tape-library {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 280px;
    z-index: 200;
    box-shadow: 4px 0 20px rgba(0,0,0,0.8);
  }

  /* Chat messages */
  .chat-msg-body {
    font-size: 15px;
  }

  /* Input area */
  .input-label {
    display: none;
  }

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

  .btn-transmit {
    font-size: 14px;
    padding: 8px 10px;
  }

  /* Bezel knobs smaller */
  .bezel-knob {
    width: 10px;
    height: 10px;
  }

  .bezel-bottom {
    gap: 14px;
    padding: 4px 0 0 0;
  }

  .app-footer {
    font-size: 11px;
    padding: 4px;
  }
}

@media (max-width: 380px) {
  .vhs-hud-center {
    display: none;
  }

  .portrait-frame {
    width: 64px;
    height: 64px;
  }

  .portrait-name {
    font-size: 12px;
    letter-spacing: 1px;
  }

  .btn-transmit {
    padding: 8px 8px;
    font-size: 13px;
    letter-spacing: 0;
  }
}