:root {
  --retro-orange: #E84420;
  --retro-orange-light: #FF6B35;
  --retro-cream: #FFF5E1;
  --retro-brown: #5C3D2E;
  --retro-dark: #2A2A2A;
  --retro-green: #6B8E23;
  --retro-beige: #D4C5A9;
  --retro-dark-brown: #3A2518;
}

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

body {
  font-family: 'Space Mono', monospace;
  background: linear-gradient(180deg, #E84420 0%, #FF6B35 30%, #FFF5E1 100%);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.03) 2px,
    rgba(0,0,0,0.03) 4px
  );
  pointer-events: none;
  z-index: 1000;
}

body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 999;
}

.font-righteous { font-family: 'Righteous', cursive; }
.font-bungee { font-family: 'Bungee', cursive; }
.font-space { font-family: 'Space Mono', monospace; }

/* RETRO TV STYLING */
.retro-tv {
  position: relative;
  background: linear-gradient(145deg, #F05A30 0%, #E84420 40%, #C23618 100%);
  border-radius: 30px;
  padding: 20px;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.4),
    0 0 0 3px #B82E15,
    inset 0 2px 4px rgba(255,255,255,0.2);
  max-width: 680px;
  margin: 0 auto;
}

.tv-inner {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

.tv-screen-wrapper {
  flex: 1;
  background: #1a1a1a;
  border-radius: 16px;
  padding: 12px;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.8),
    inset 0 0 4px rgba(0,0,0,0.9);
  position: relative;
  overflow: hidden;
}

.tv-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #111;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-screen::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  pointer-events: none;
  z-index: 5;
}

.tv-screen::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(0,0,0,0.4) 100%
  );
  pointer-events: none;
  z-index: 6;
}

.screen-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: relative;
  z-index: 2;
  filter: saturate(1.1) contrast(1.05) brightness(0.95);
}

/* STATIC NOISE ANIMATION */
@keyframes staticNoise {
  0% { background-position: 0 0; }
  10% { background-position: -5% -10%; }
  20% { background-position: -15% 5%; }
  30% { background-position: 7% -25%; }
  40% { background-position: -5% 25%; }
  50% { background-position: -15% 10%; }
  60% { background-position: 15% 0%; }
  70% { background-position: 0% 15%; }
  80% { background-position: 3% 35%; }
  90% { background-position: -10% 10%; }
  100% { background-position: 0 0; }
}

.static-noise {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='6' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  animation: staticNoise 0.2s steps(10) infinite;
  z-index: 3;
  opacity: 0.8;
}

/* TEST PATTERN */
.test-pattern {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  z-index: 2;
}

.test-bars {
  display: flex;
  flex: 1;
}

.test-bar {
  flex: 1;
}

/* TV TURN ON ANIMATION */
@keyframes tvTurnOn {
  0% {
    clip-path: inset(50% 0 50% 0);
    opacity: 0;
  }
  50% {
    clip-path: inset(48% 0 48% 0);
    opacity: 1;
  }
  100% {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}

.tv-turn-on {
  animation: tvTurnOn 0.5s ease-out forwards;
}

/* SCREEN FLICKER */
@keyframes screenFlicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.8; }
  94% { opacity: 1; }
}

.screen-flicker {
  animation: screenFlicker 4s infinite;
}

/* TV CONTROLS PANEL */
.tv-controls {
  width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0;
}

.tv-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(145deg, #888, #555);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.4),
    inset 0 1px 2px rgba(255,255,255,0.3);
  position: relative;
  cursor: pointer;
  transition: transform 0.2s;
}

.tv-knob:hover {
  transform: rotate(20deg);
}

.tv-knob::after {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  height: 14px;
  background: #ddd;
  border-radius: 2px;
}

.tv-knob-small {
  width: 28px;
  height: 28px;
}

.tv-knob-small::after {
  top: 5px;
  height: 8px;
  width: 2px;
}

.tv-brand {
  font-family: 'Righteous', cursive;
  font-size: 9px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.speaker-grille {
  width: 80%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 8px;
}

.speaker-line {
  height: 2px;
  background: rgba(0,0,0,0.3);
  border-radius: 1px;
}

/* CONTROL PANEL */
.control-panel {
  background: linear-gradient(135deg, #D4C5A9 0%, #C4B599 100%);
  border: 3px solid #8B7355;
  border-radius: 16px;
  padding: 24px;
  max-width: 680px;
  margin: 24px auto 0;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.2),
    inset 0 1px 2px rgba(255,255,255,0.5);
}

.prompt-input {
  width: 100%;
  padding: 14px 18px;
  border: 3px solid #5C3D2E;
  border-radius: 12px;
  background: #FFF5E1;
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  color: #2A2A2A;
  outline: none;
  transition: border-color 0.3s;
}

.prompt-input:focus {
  border-color: #E84420;
  box-shadow: 0 0 0 3px rgba(232,68,32,0.2);
}

.prompt-input::placeholder {
  color: #A89070;
  font-style: italic;
}

.generate-btn {
  background: linear-gradient(180deg, #FF6B35 0%, #E84420 100%);
  color: white;
  font-family: 'Bungee', cursive;
  font-size: 18px;
  padding: 14px 40px;
  border: 3px solid #B82E15;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow:
    0 6px 0 #8B1E0A,
    0 8px 16px rgba(0,0,0,0.3);
  text-transform: uppercase;
  letter-spacing: 2px;
  user-select: none;
}

.generate-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 0 #8B1E0A,
    0 10px 20px rgba(0,0,0,0.3);
}

.generate-btn:active {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #8B1E0A,
    0 4px 8px rgba(0,0,0,0.3);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.style-select {
  padding: 10px 14px;
  border: 2px solid #5C3D2E;
  border-radius: 10px;
  background: #FFF5E1;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  color: #2A2A2A;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%235C3D2E'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.style-select:focus {
  border-color: #E84420;
}

.aspect-btn {
  padding: 8px 16px;
  border: 2px solid #5C3D2E;
  border-radius: 8px;
  background: #FFF5E1;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: #5C3D2E;
  cursor: pointer;
  transition: all 0.2s;
}

.aspect-btn.active {
  background: #5C3D2E;
  color: #FFF5E1;
}

.aspect-btn:hover:not(.active) {
  background: #E8DCC8;
}

.channel-surf-btn {
  background: linear-gradient(180deg, #7BA328 0%, #6B8E23 100%);
  color: white;
  font-family: 'Righteous', cursive;
  font-size: 13px;
  padding: 10px 20px;
  border: 2px solid #4F6819;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 3px 0 #3D5013;
}

.channel-surf-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 #3D5013;
}

.channel-surf-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #3D5013;
}

/* DOWNLOAD BUTTON */
.download-btn {
  background: linear-gradient(180deg, #C23618, #8B1E0A);
  color: white;
  font-family: 'Bungee', cursive;
  font-size: 11px;
  padding: 8px 16px;
  border: 2px solid #6B1508;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.download-btn:hover {
  transform: scale(1.05);
}

/* GALLERY */
.gallery-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 12px 4px;
  scrollbar-width: thin;
  scrollbar-color: #E84420 #D4C5A9;
}

.gallery-strip::-webkit-scrollbar {
  height: 6px;
}

.gallery-strip::-webkit-scrollbar-track {
  background: #D4C5A9;
  border-radius: 3px;
}

.gallery-strip::-webkit-scrollbar-thumb {
  background: #E84420;
  border-radius: 3px;
}

.gallery-thumb {
  flex-shrink: 0;
  width: 80px;
  height: 64px;
  border-radius: 8px;
  background: linear-gradient(145deg, #F05A30, #E84420);
  padding: 4px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.gallery-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
  display: block;
}

.clear-history-btn {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  padding: 6px 12px;
  border: 1px solid #8B7355;
  border-radius: 6px;
  background: transparent;
  color: #8B7355;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.clear-history-btn:hover {
  background: #8B7355;
  color: #FFF5E1;
}

/* NO SIGNAL TEXT */
@keyframes noSignalBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.no-signal-text {
  color: #888;
  font-family: 'Bungee', cursive;
  font-size: 20px;
  text-align: center;
  animation: noSignalBlink 2s ease-in-out infinite;
  z-index: 4;
  text-shadow: 0 0 10px rgba(150,150,150,0.5);
}

.tuning-text {
  color: #ccc;
  font-family: 'Bungee', cursive;
  font-size: 16px;
  text-align: center;
  z-index: 10;
  position: absolute;
  text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.error-card {
  color: #fff;
  font-family: 'Bungee', cursive;
  font-size: 14px;
  text-align: center;
  z-index: 4;
  background: rgba(200,0,0,0.3);
  padding: 20px;
  border-radius: 8px;
}

/* PRICE TAG */
.price-tag {
  position: absolute;
  top: -12px;
  left: -8px;
  background: #fff;
  padding: 2px 10px;
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  font-weight: bold;
  color: #2A2A2A;
  transform: rotate(-8deg);
  box-shadow: 1px 2px 4px rgba(0,0,0,0.3);
  z-index: 20;
  border: 1px solid #ddd;
}

/* COUNTER */
.gen-counter {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: #8B7355;
  text-align: center;
}

/* RESPONSIVE */
@media (max-width: 640px) {
  .retro-tv {
    border-radius: 20px;
    padding: 12px;
    margin: 0 8px;
  }

  .tv-inner {
    flex-direction: column;
  }

  .tv-controls {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    gap: 12px;
    padding: 8px 0 0;
  }

  .tv-knob {
    width: 40px;
    height: 40px;
  }

  .speaker-grille {
    display: none;
  }

  .control-panel {
    margin: 16px 8px 0;
    padding: 16px;
  }

  .generate-btn {
    font-size: 14px;
    padding: 12px 28px;
  }

  .no-signal-text {
    font-size: 14px;
  }

  .tuning-text {
    font-size: 12px;
  }

  .price-tag {
    font-size: 11px;
  }
}

/* FOOTER */
.retro-footer {
  background: linear-gradient(180deg, transparent 0%, rgba(92,61,46,0.1) 100%);
  padding: 32px 16px;
  text-align: center;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: #8B7355;
}

.retro-footer a {
  color: #E84420;
  text-decoration: none;
  font-weight: bold;
}

.retro-footer a:hover {
  text-decoration: underline;
}