:root {
  --bg-dark: #0d0d1a;
  --bg-medium: #1a1a2e;
  --bg-light: #252542;
  --accent-pink: #ff2a6d;
  --accent-magenta: #d300c5;
  --accent-cyan: #05d9e8;
  --accent-cyan-light: #00fff5;
  --accent-yellow: #ffd700;
  --accent-lime: #39ff14;
  --text-white: #ffffff;
  --text-gray: #a0a0a0;
  --pixel-size: 4px;
}

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

body {
  font-family: 'Press Start 2P', monospace;
  background: var(--bg-dark);
  color: var(--text-white);
  min-height: 100vh;
  overflow-x: hidden;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: 
    radial-gradient(ellipse at top, rgba(5, 217, 232, 0.1) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(255, 42, 109, 0.1) 0%, transparent 50%),
    var(--bg-dark);
}

.crt-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: 
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.1) 0px,
      rgba(0, 0, 0, 0.1) 1px,
      transparent 1px,
      transparent 3px
    );
  z-index: 1000;
  opacity: 0.3;
}

/* Header */
.header {
  padding: 24px 16px;
  text-align: center;
  background: linear-gradient(180deg, var(--bg-medium) 0%, transparent 100%);
  border-bottom: 4px solid var(--accent-pink);
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, 
    var(--accent-cyan) 0%, 
    var(--accent-pink) 50%, 
    var(--accent-yellow) 100%
  );
}

.header-content {
  max-width: 800px;
  margin: 0 auto;
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

.anvil-icon {
  font-size: 32px;
  animation: hammer-swing 1s infinite;
}

@keyframes hammer-swing {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-15deg); }
}

.title {
  font-size: clamp(24px, 6vw, 48px);
  background: linear-gradient(180deg, var(--accent-yellow) 0%, var(--accent-pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 
    4px 4px 0 rgba(211, 0, 197, 0.5),
    -2px -2px 0 rgba(5, 217, 232, 0.3);
  letter-spacing: 4px;
}

.subtitle {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--accent-cyan);
  letter-spacing: 8px;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Generation Panel */
.generation-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-container {
  width: 100%;
}

.terminal-frame {
  background: var(--bg-medium);
  border: 4px solid var(--accent-cyan);
  box-shadow: 
    inset 0 0 20px rgba(5, 217, 232, 0.2),
    0 0 20px rgba(5, 217, 232, 0.3),
    8px 8px 0 rgba(0, 0, 0, 0.5);
}

.terminal-header {
  background: var(--bg-light);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid var(--accent-cyan);
}

.terminal-dot {
  width: 12px;
  height: 12px;
  border-radius: 0;
}

.terminal-dot.red { background: #ff5f56; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #27ca40; }

.terminal-title {
  font-size: 10px;
  color: var(--text-gray);
  margin-left: auto;
}

.prompt-input {
  width: 100%;
  padding: 16px;
  font-family: 'VT323', monospace;
  font-size: 24px;
  background: transparent;
  border: none;
  color: var(--accent-lime);
  outline: none;
  caret-color: var(--accent-lime);
}

.prompt-input::placeholder {
  color: rgba(57, 255, 20, 0.4);
}

.prompt-input:focus {
  animation: cursor-blink 1s infinite;
}

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

/* Chips */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 8px 12px;
  background: var(--bg-light);
  border: 2px solid var(--accent-pink);
  color: var(--text-white);
  cursor: pointer;
  transition: all 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 4px 4px 0 rgba(255, 42, 109, 0.3);
}

.chip:hover {
  background: var(--accent-pink);
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 rgba(255, 42, 109, 0.5);
}

.chip:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 rgba(255, 42, 109, 0.3);
}

.chip-emoji {
  font-size: 16px;
}

.chip-text {
  text-transform: uppercase;
}

/* Action Row */
.action-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.generate-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  padding: 16px 32px;
  background: linear-gradient(180deg, var(--accent-pink) 0%, var(--accent-magenta) 100%);
  border: none;
  color: white;
  cursor: pointer;
  position: relative;
  box-shadow: 
    0 6px 0 #8b0040,
    0 8px 10px rgba(0, 0, 0, 0.5);
  transition: all 0.1s;
  animation: button-pulse 2s infinite;
}

@keyframes button-pulse {
  0%, 100% { box-shadow: 0 6px 0 #8b0040, 0 8px 10px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 42, 109, 0.3); }
  50% { box-shadow: 0 6px 0 #8b0040, 0 8px 10px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 42, 109, 0.5); }
}

.generate-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 
    0 8px 0 #8b0040,
    0 10px 15px rgba(0, 0, 0, 0.5);
}

.generate-button.pressed,
.generate-button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 
    0 2px 0 #8b0040,
    0 4px 5px rgba(0, 0, 0, 0.5);
}

.generate-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  animation: none;
}

.generate-button.loading {
  animation: none;
}

.loading-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.spinner {
  animation: spin 0.5s linear infinite;
  font-size: 20px;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.random-button {
  font-size: 24px;
  padding: 12px 16px;
  background: var(--bg-light);
  border: 3px solid var(--accent-yellow);
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(255, 215, 0, 0.4);
  transition: all 0.1s;
}

.random-button:hover {
  background: var(--accent-yellow);
  transform: translate(-2px, -2px);
}

.random-button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 rgba(255, 215, 0, 0.4);
}

/* Display Area */
.display-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.arcade-bezel {
  background: linear-gradient(135deg, #2a2a4e 0%, #1a1a2e 50%, #0d0d1a 100%);
  padding: 20px;
  border: 8px solid;
  border-image: linear-gradient(180deg, #4a4a6e, #1a1a2e) 1;
  box-shadow: 
    inset 0 0 30px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(5, 217, 232, 0.2),
    12px 12px 0 rgba(0, 0, 0, 0.5);
  position: relative;
}

.arcade-bezel.scanlines .screen-frame::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.2) 0px,
    rgba(0, 0, 0, 0.2) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
}

.screen-frame {
  background: #0a0a12;
  min-width: 280px;
  min-height: 280px;
  max-width: 400px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border: 4px solid var(--accent-cyan);
  box-shadow: inset 0 0 40px rgba(5, 217, 232, 0.1);
}

.generated-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  animation: fade-in 0.5s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.placeholder-screen {
  text-align: center;
  padding: 20px;
}

.insert-coin {
  font-size: 18px;
  color: var(--accent-yellow);
  margin-bottom: 16px;
  animation: blink-slow 1.5s infinite;
}

.blink-text {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--text-gray);
  animation: blink-fast 0.8s infinite;
}

@keyframes blink-slow {
  0%, 70% { opacity: 1; }
  71%, 100% { opacity: 0.3; }
}

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

.error-screen {
  text-align: center;
  padding: 20px;
}

.error-title {
  font-size: 24px;
  color: var(--accent-pink);
  margin-bottom: 16px;
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

.error-message {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--text-gray);
  margin-bottom: 16px;
}

.retry-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 12px 24px;
  background: var(--bg-light);
  border: 2px solid var(--accent-cyan);
  color: var(--accent-cyan);
  cursor: pointer;
}

.retry-button:hover {
  background: var(--accent-cyan);
  color: var(--bg-dark);
}

.scanline-toggle {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--text-gray);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.scanline-toggle input {
  accent-color: var(--accent-cyan);
  width: 18px;
  height: 18px;
}

/* Image Actions */
.image-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.action-button {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 10px 16px;
  background: var(--bg-light);
  border: 2px solid var(--accent-cyan);
  color: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(5, 217, 232, 0.3);
  transition: all 0.1s;
}

.action-button:hover {
  background: var(--accent-cyan);
  color: var(--bg-dark);
  transform: translate(-2px, -2px);
}

.action-button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 rgba(5, 217, 232, 0.3);
}

/* History Section */
.history-section {
  margin-top: 24px;
}

.history-toggle {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  width: 100%;
  padding: 12px;
  background: var(--bg-medium);
  border: 2px solid var(--accent-yellow);
  color: var(--accent-yellow);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 4px 4px 0 rgba(255, 215, 0, 0.3);
}

.history-toggle:hover {
  background: var(--bg-light);
}

.arrow {
  transition: transform 0.2s;
}

.arrow.open {
  transform: rotate(180deg);
}

.history-panel {
  background: var(--bg-medium);
  border: 2px solid var(--accent-yellow);
  border-top: none;
  padding: 16px;
  animation: slide-down 0.3s ease-out;
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-history {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--text-gray);
  text-align: center;
  padding: 24px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.history-item {
  aspect-ratio: 1;
  cursor: pointer;
  position: relative;
  border: 2px solid var(--bg-light);
  transition: all 0.1s;
  overflow: hidden;
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.history-item:hover {
  border-color: var(--accent-cyan);
  transform: scale(1.05);
  z-index: 10;
}

.history-tooltip {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.9);
  font-family: 'VT323', monospace;
  font-size: 12px;
  padding: 4px;
  color: var(--accent-cyan);
  opacity: 0;
  transition: opacity 0.2s;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.history-item:hover .history-tooltip {
  opacity: 1;
}

.clear-history {
  font-family: 'VT323', monospace;
  font-size: 14px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 2px solid var(--accent-pink);
  color: var(--accent-pink);
  cursor: pointer;
}

.clear-history:hover {
  background: var(--accent-pink);
  color: white;
}

/* Footer */
.footer {
  padding: 24px 16px;
  margin-top: auto;
}

.pixel-divider {
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    var(--accent-cyan) 0px,
    var(--accent-cyan) 8px,
    transparent 8px,
    transparent 16px,
    var(--accent-pink) 16px,
    var(--accent-pink) 24px,
    transparent 24px,
    transparent 32px
  );
  margin-bottom: 16px;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-sprite {
  font-size: 24px;
  animation: walk 0.5s steps(2) infinite;
}

@keyframes walk {
  0% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  100% { transform: translateX(-4px); }
}

.powered-by {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--text-gray);
}

.remix-link {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 8px 12px;
  background: var(--bg-light);
  border: 2px solid var(--accent-lime);
  color: var(--accent-lime);
  text-decoration: none;
  box-shadow: 3px 3px 0 rgba(57, 255, 20, 0.3);
  transition: all 0.1s;
}

.remix-link:hover {
  background: var(--accent-lime);
  color: var(--bg-dark);
  transform: translate(-2px, -2px);
}

/* Responsive */
@media (max-width: 600px) {
  .title {
    letter-spacing: 2px;
  }
  
  .subtitle {
    font-size: 12px;
    letter-spacing: 4px;
  }
  
  .prompt-input {
    font-size: 18px;
    padding: 12px;
  }
  
  .chip {
    font-size: 12px;
    padding: 6px 10px;
  }
  
  .generate-button {
    font-size: 14px;
    padding: 14px 24px;
  }
  
  .screen-frame {
    min-width: 240px;
    min-height: 240px;
  }
  
  .arcade-bezel {
    padding: 12px;
  }
  
  .history-grid {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 8px;
  }
  
  .footer-content {
    flex-direction: column;
    gap: 12px;
  }
}