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

:root {
  --bg-primary: #0d0d1a;
  --bg-secondary: #1a1a2e;
  --bg-panel: #12122a;
  --cyan: #00fff5;
  --magenta: #ff00ff;
  --green: #00ff41;
  --amber: #ffb000;
  --red: #ff0000;
  --white: #e0e0e0;
  --win-blue-start: #000080;
  --win-blue-end: #1084d0;
  --bevel-light: #dfdfdf;
  --bevel-mid: #808080;
  --bevel-dark: #404040;
  --font-pixel: 'Press Start 2P', monospace;
  --font-terminal: 'VT323', monospace;
}

body {
  background: var(--bg-primary);
  color: var(--green);
  font-family: var(--font-terminal);
  min-height: 100vh;
  overflow-x: hidden;
}

#scanlines {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.97; }
}

@keyframes rainbow {
  0% { color: #ff0000; }
  16% { color: #ff8800; }
  33% { color: #ffff00; }
  50% { color: #00ff00; }
  66% { color: #0088ff; }
  83% { color: #8800ff; }
  100% { color: #ff0000; }
}

@keyframes rainbowBg {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes pixelFadeIn {
  0% { filter: blur(12px) brightness(1.5); transform: scale(1.05); }
  50% { filter: blur(4px) brightness(1.1); transform: scale(1.02); }
  100% { filter: blur(0) brightness(1); transform: scale(1); }
}

@keyframes fadeFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.crt-flicker {
  animation: flicker 0.15s infinite;
}

.rainbow-text {
  animation: rainbow 3s linear infinite;
}

.title-rainbow {
  background: linear-gradient(90deg, #ff0000, #ff8800, #ffff00, #00ff00, #0088ff, #8800ff, #ff0000);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: rainbowBg 3s linear infinite;
}

.shake {
  animation: shake 0.4s ease-in-out;
}

.slide-up {
  animation: slideUp 0.3s ease-out;
}

.pixel-fade-in {
  animation: pixelFadeIn 0.6s ease-out;
  image-rendering: auto;
}

.flicker-text {
  animation: fadeFlicker 1.5s ease-in-out infinite;
}

/* Retro Button */
.retro-btn {
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 8px 16px;
  background: #c0c0c0;
  color: #000;
  border: none;
  border-top: 2px solid var(--bevel-light);
  border-left: 2px solid var(--bevel-light);
  border-bottom: 2px solid var(--bevel-dark);
  border-right: 2px solid var(--bevel-dark);
  cursor: pointer;
  text-transform: uppercase;
  outline: none;
  user-select: none;
  white-space: nowrap;
}

.retro-btn:active {
  border-top: 2px solid var(--bevel-dark);
  border-left: 2px solid var(--bevel-dark);
  border-bottom: 2px solid var(--bevel-light);
  border-right: 2px solid var(--bevel-light);
  padding: 9px 15px 7px 17px;
}

.retro-btn.active {
  background: #000080;
  color: white;
  border-top: 2px solid var(--bevel-dark);
  border-left: 2px solid var(--bevel-dark);
  border-bottom: 2px solid var(--bevel-light);
  border-right: 2px solid var(--bevel-light);
}

.retro-btn:hover:not(:active):not(.active) {
  background: #d4d4d4;
}

.retro-btn.small {
  font-size: 8px;
  padding: 5px 10px;
}

.retro-btn.small:active {
  padding: 6px 9px 4px 11px;
}

/* Win3.1 Window Chrome */
.win-window {
  background: #c0c0c0;
  border-top: 2px solid var(--bevel-light);
  border-left: 2px solid var(--bevel-light);
  border-bottom: 2px solid var(--bevel-dark);
  border-right: 2px solid var(--bevel-dark);
  box-shadow: 1px 1px 0 #000;
}

.win-titlebar {
  background: linear-gradient(90deg, var(--win-blue-start), var(--win-blue-end));
  padding: 3px 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.win-titlebar span {
  color: white;
  font-family: var(--font-pixel);
  font-size: 9px;
  font-weight: bold;
}

.win-close {
  font-family: var(--font-pixel);
  font-size: 8px;
  width: 18px;
  height: 18px;
  background: #c0c0c0;
  border-top: 1px solid var(--bevel-light);
  border-left: 1px solid var(--bevel-light);
  border-bottom: 1px solid var(--bevel-dark);
  border-right: 1px solid var(--bevel-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  padding: 0;
  line-height: 1;
}

.win-close:active {
  border-top: 1px solid var(--bevel-dark);
  border-left: 1px solid var(--bevel-dark);
  border-bottom: 1px solid var(--bevel-light);
  border-right: 1px solid var(--bevel-light);
}

.win-content {
  background: var(--bg-secondary);
  margin: 3px;
  padding: 16px;
  border-top: 1px solid var(--bevel-dark);
  border-left: 1px solid var(--bevel-dark);
  border-bottom: 1px solid var(--bevel-light);
  border-right: 1px solid var(--bevel-light);
}

/* Image Frame */
.img-frame {
  border-top: 2px solid var(--bevel-dark);
  border-left: 2px solid var(--bevel-dark);
  border-bottom: 2px solid var(--bevel-light);
  border-right: 2px solid var(--bevel-light);
  padding: 2px;
  background: #000;
  display: inline-block;
}

/* DOS Input */
.dos-input-container {
  display: flex;
  align-items: center;
  background: #000;
  border: 2px solid #333;
  padding: 8px 12px;
  font-family: var(--font-terminal);
  font-size: 28px;
  color: var(--green);
}

.dos-input-container .prefix {
  color: var(--green);
  white-space: nowrap;
  user-select: none;
}

.dos-input-container input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--green);
  font-family: var(--font-terminal);
  font-size: 28px;
  flex: 1;
  width: 100%;
  caret-color: transparent;
}

.cursor-blink {
  display: inline-block;
  width: 14px;
  height: 24px;
  background: var(--green);
  animation: blink 1s step-end infinite;
  vertical-align: middle;
  margin-left: 2px;
}

/* Stat Box */
.stat-box {
  border: 1px solid #333;
  padding: 8px 14px;
  text-align: center;
  background: rgba(0,0,0,0.3);
  min-width: 90px;
}

.stat-box .label {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--bevel-mid);
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.stat-box .value {
  font-family: var(--font-terminal);
  font-size: 32px;
  line-height: 1;
}

/* Difficulty Bar */
.diff-block {
  display: inline-block;
  width: 14px;
  height: 18px;
  margin-right: 2px;
  font-family: var(--font-terminal);
  font-size: 18px;
  line-height: 18px;
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 14px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb {
  background: #555;
  border: 2px solid var(--bg-primary);
}

/* Progress Bar */
.progress-bar {
  height: 20px;
  background: #000;
  border: 1px solid #555;
  position: relative;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}

/* Game container glow */
.game-container {
  box-shadow: 0 0 40px rgba(0,255,245,0.05), 0 0 80px rgba(0,255,65,0.03);
}

/* Thumbnail mini window */
.thumb-window {
  cursor: pointer;
  transition: transform 0.15s;
}

.thumb-window:hover {
  transform: scale(1.05);
}

/* Error dialog */
.error-input {
  background: #fff;
  color: #000;
  border: 1px solid #888;
  font-family: var(--font-terminal);
  font-size: 16px;
  padding: 4px;
  width: 100%;
}

/* Responsive */
@media (max-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat-box {
    min-width: 70px;
    padding: 6px 8px;
  }
  .stat-box .value {
    font-size: 24px;
  }
  .dos-input-container {
    font-size: 22px;
  }
  .dos-input-container input {
    font-size: 22px;
  }
}

@media (max-width: 400px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }
}