@tailwind base;

:root {
  --c0: #e0f8cf;
  --c1: #86c06c;
  --c2: #306850;
  --c3: #071821;
  --bg-deep: #060612;
  --bg-mid: #0e0e24;
  --bg-surface: #161638;
  --accent: #86c06c;
  --accent-dim: #306850;
  --glow: rgba(134, 192, 108, 0.25);
}

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

html, body {
  background: var(--bg-deep);
  color: var(--c0);
  font-family: 'JetBrains Mono', monospace;
  overflow-x: hidden;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(48,104,80,0.15) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-deep) 0%, #0a0a20 50%, var(--bg-deep) 100%);
}

.pixel-font { font-family: 'Press Start 2P', cursive; }
.mono-font { font-family: 'JetBrains Mono', monospace; }

/* CRT Bezel */
.crt-bezel {
  background: linear-gradient(145deg, #1a1a3a 0%, #0a0a1e 50%, #151535 100%);
  border-radius: 16px;
  padding: 16px;
  box-shadow:
    0 0 40px rgba(134,192,108,0.08),
    0 0 80px rgba(7,24,33,0.5),
    inset 0 2px 4px rgba(255,255,255,0.03),
    inset 0 -2px 4px rgba(0,0,0,0.5);
  position: relative;
}

.crt-bezel::before {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 10px;
  border: 1px solid rgba(134,192,108,0.08);
  pointer-events: none;
}

/* Scanline overlay */
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  border-radius: 4px;
}

.scanlines-off { display: none; }

/* CRT glow */
.crt-glow {
  position: relative;
}
.crt-glow::after {
  content: '';
  position: absolute;
  inset: -20px;
  border-radius: 24px;
  background: radial-gradient(ellipse, rgba(134,192,108,0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
}

/* Canvas rendering */
#wasm4-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  border-radius: 2px;
}

/* Upload zone */
.upload-zone {
  border: 3px dashed var(--accent-dim);
  border-radius: 12px;
  background:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(48,104,80,0.03) 10px,
      rgba(48,104,80,0.03) 20px
    ),
    var(--bg-surface);
  transition: all 0.3s ease;
  cursor: pointer;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background-color: rgba(134,192,108,0.05);
  box-shadow: 0 0 30px rgba(134,192,108,0.1);
}

.upload-zone.inserting {
  animation: cartridge-insert 0.6s ease-out;
}

@keyframes cartridge-insert {
  0% { transform: translateY(-20px); opacity: 0.5; }
  50% { transform: translateY(5px); }
  100% { transform: translateY(0); opacity: 1; }
}

/* Retro buttons */
.retro-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
  color: var(--bg-deep);
  background: var(--accent);
  box-shadow:
    0 4px 0 var(--accent-dim),
    0 6px 10px rgba(0,0,0,0.3);
}

.retro-btn:hover {
  transform: translateY(-1px);
  box-shadow:
    0 5px 0 var(--accent-dim),
    0 8px 14px rgba(0,0,0,0.3);
}

.retro-btn:active {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 var(--accent-dim),
    0 2px 4px rgba(0,0,0,0.3);
}

.retro-btn.secondary {
  background: var(--bg-surface);
  color: var(--accent);
  border: 2px solid var(--accent-dim);
  box-shadow:
    0 4px 0 rgba(0,0,0,0.4),
    0 6px 10px rgba(0,0,0,0.2);
}

.retro-btn.secondary:hover {
  border-color: var(--accent);
  background: rgba(134,192,108,0.1);
}

.retro-btn.danger {
  background: #c0392b;
  box-shadow:
    0 4px 0 #8e2b20,
    0 6px 10px rgba(0,0,0,0.3);
}

.retro-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

/* Virtual gamepad */
.dpad-btn {
  width: 44px;
  height: 44px;
  background: var(--bg-surface);
  border: 2px solid var(--accent-dim);
  border-radius: 4px;
  color: var(--accent);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: all 0.1s;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: var(--accent);
  color: var(--bg-deep);
  box-shadow: 0 0 12px var(--glow);
}

.action-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--accent-dim);
  color: var(--accent);
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: all 0.1s;
}
.action-btn:active, .action-btn.pressed {
  background: var(--accent);
  color: var(--bg-deep);
  box-shadow: 0 0 16px var(--glow);
}

/* Console log */
.console-log {
  background: #010a02;
  border: 1px solid #0a3a0a;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #33ff33;
  max-height: 150px;
  overflow-y: auto;
  padding: 8px 12px;
  line-height: 1.6;
}

.console-log::-webkit-scrollbar { width: 6px; }
.console-log::-webkit-scrollbar-track { background: #010a02; }
.console-log::-webkit-scrollbar-thumb { background: #0a3a0a; border-radius: 3px; }

/* Settings panel */
.settings-panel {
  background: var(--bg-surface);
  border: 1px solid rgba(134,192,108,0.1);
  border-radius: 10px;
  padding: 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(134,192,108,0.06);
}
.setting-row:last-child { border-bottom: none; }

/* Toggle switch */
.toggle {
  width: 40px;
  height: 22px;
  background: var(--bg-deep);
  border: 2px solid var(--accent-dim);
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
}
.toggle.on {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.toggle::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--accent-dim);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}
.toggle.on::after {
  left: 20px;
  background: var(--accent);
}

/* FPS counter */
.fps-counter {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: var(--c1);
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  padding: 2px 6px;
  border-radius: 3px;
  z-index: 20;
}

/* Palette swatches */
.palette-swatch {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 2px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: transform 0.15s;
}
.palette-swatch:hover { transform: scale(1.2); }
.palette-swatch.active { border-color: white; box-shadow: 0 0 8px rgba(255,255,255,0.3); }

/* Title animation */
@keyframes title-glow {
  0%, 100% { text-shadow: 0 0 10px rgba(134,192,108,0.3); }
  50% { text-shadow: 0 0 20px rgba(134,192,108,0.6), 0 0 40px rgba(134,192,108,0.2); }
}

.title-glow {
  animation: title-glow 3s ease-in-out infinite;
}

/* Loading animation */
@keyframes spin-pixel {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-spin {
  animation: spin-pixel 1s steps(8) infinite;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .crt-bezel { padding: 8px; border-radius: 10px; }
  .retro-btn { font-size: 8px; padding: 8px 12px; }
}

/* Palette presets highlight */
.preset-btn {
  padding: 4px 8px;
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  background: transparent;
  color: var(--c1);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.preset-btn:hover, .preset-btn.active {
  background: var(--accent-dim);
  color: var(--c0);
  border-color: var(--accent);
}

/* Fullscreen canvas */
.fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}