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

:root {
  --bg: #0000AA;
  --bg-dark: #000088;
  --text: #AAAAAA;
  --text-bright: #FFFFFF;
  --text-yellow: #FFFF55;
  --text-cyan: #55FFFF;
  --highlight: #5555FF;
  --btn-face: #AAAAAA;
  --btn-light: #FFFFFF;
  --btn-shadow: #555555;
  --btn-dark: #000000;
}

html, body {
  background: var(--bg);
  color: var(--text-bright);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

/* Header */
#header {
  text-align: center;
  padding: 20px 8px 12px;
  background: var(--bg-dark);
  border: 2px solid var(--text);
}

#header h1 {
  font-size: 28px;
  color: var(--text-yellow);
  text-shadow: 3px 3px 0 #AA5500;
  letter-spacing: 4px;
}

#header .subtitle {
  font-size: 8px;
  color: var(--text-cyan);
  margin-top: 8px;
}

.blink {
  animation: blink-anim 0.7s step-end infinite;
}

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

/* Upload Zone */
#upload-zone {
  cursor: pointer;
  text-align: center;
  padding: 16px;
  border: 2px dashed var(--text);
  transition: none;
  user-select: none;
}

#upload-zone:hover, #upload-zone:focus {
  border-color: var(--text-yellow);
  background: rgba(85, 85, 255, 0.15);
}

.dos-box {
  font-size: 10px;
}

.dos-box-title, .dos-box-bottom {
  color: var(--text-yellow);
  font-size: 9px;
  letter-spacing: 1px;
}

.dos-box-content {
  padding: 16px 0;
  font-size: 11px;
}

.dos-box-content p {
  margin: 4px 0;
}

.small-text {
  font-size: 8px;
  color: var(--text);
}

#file-prompt {
  font-size: 10px;
  color: var(--text-cyan);
  margin-top: 8px;
  text-align: left;
  padding: 4px 8px;
  background: #000;
}

.hidden { display: none !important; }
.hidden-input { position: absolute; opacity: 0; pointer-events: none; }

/* Section titles */
.section-title {
  font-size: 10px;
  color: var(--text-yellow);
  text-align: center;
  margin-bottom: 8px;
}

/* Palette */
#palette-mode-toggle {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#palette-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.swatch {
  width: 42px;
  height: 38px;
  border: 2px solid var(--btn-light);
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 2px;
  image-rendering: pixelated;
}

.swatch.disabled {
  opacity: 0.25;
  border-color: var(--btn-shadow);
}

.swatch .swatch-label {
  font-size: 4px;
  color: #000;
  text-shadow: 0 0 2px rgba(255,255,255,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  max-width: 100%;
  text-align: center;
  line-height: 1;
}

.swatch .swatch-num {
  font-size: 7px;
  font-weight: bold;
  color: #000;
  text-shadow: 0 0 3px rgba(255,255,255,0.8);
}

/* Canvas area */
#canvas-container {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.canvas-wrapper {
  flex: 1;
  min-width: 280px;
  max-width: 520px;
  text-align: center;
}

.canvas-label {
  font-size: 9px;
  color: var(--text-yellow);
  margin-bottom: 4px;
}

.canvas-wrapper canvas, #converted-container {
  width: 100%;
  background: #000;
  border: 2px solid var(--text);
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

#converted-container {
  position: relative;
  display: inline-block;
  width: 100%;
}

#converted-container canvas {
  border: none;
}

.overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
}

#converted-container.crt-on {
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(85, 85, 255, 0.3), inset 0 0 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

#pixel-tooltip {
  position: absolute;
  background: #000;
  border: 2px solid var(--text-yellow);
  color: var(--text-bright);
  font-size: 8px;
  padding: 6px 8px;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  line-height: 1.8;
}

/* Controls */
#controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 8px;
  color: var(--text-cyan);
}

.control-group.toggles {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* DOS-styled buttons */
.dos-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 6px 12px;
  background: var(--btn-face);
  color: #000;
  border: none;
  border-top: 2px solid var(--btn-light);
  border-left: 2px solid var(--btn-light);
  border-bottom: 2px solid var(--btn-dark);
  border-right: 2px solid var(--btn-dark);
  cursor: pointer;
  white-space: nowrap;
}

.dos-btn:active {
  border-top: 2px solid var(--btn-dark);
  border-left: 2px solid var(--btn-dark);
  border-bottom: 2px solid var(--btn-light);
  border-right: 2px solid var(--btn-light);
}

.dos-btn.active {
  background: var(--highlight);
  color: var(--text-bright);
}

.dos-btn.small {
  font-size: 7px;
  padding: 4px 8px;
}

.dos-btn.run-btn {
  background: #008800;
  color: var(--text-bright);
  font-size: 10px;
  padding: 8px 16px;
  border-top: 2px solid #00FF00;
  border-left: 2px solid #00FF00;
  border-bottom: 2px solid #003300;
  border-right: 2px solid #003300;
}

.dos-btn.run-btn:active {
  border-top: 2px solid #003300;
  border-left: 2px solid #003300;
  border-bottom: 2px solid #00FF00;
  border-right: 2px solid #00FF00;
}

/* DOS-styled select */
.dos-select {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 4px 6px;
  background: #000;
  color: var(--text-bright);
  border: 2px inset var(--text);
  cursor: pointer;
}

.dos-select option {
  background: #000;
  color: var(--text-bright);
}

/* DOS-styled range */
.dos-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  background: #000;
  border: 2px inset var(--text);
  outline: none;
}

.dos-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 18px;
  background: var(--btn-face);
  border-top: 2px solid var(--btn-light);
  border-left: 2px solid var(--btn-light);
  border-bottom: 2px solid var(--btn-dark);
  border-right: 2px solid var(--btn-dark);
  cursor: pointer;
}

.dos-range::-moz-range-thumb {
  width: 14px;
  height: 18px;
  background: var(--btn-face);
  border-top: 2px solid var(--btn-light);
  border-left: 2px solid var(--btn-light);
  border-bottom: 2px solid var(--btn-dark);
  border-right: 2px solid var(--btn-dark);
  cursor: pointer;
  border-radius: 0;
}

/* Histogram */
#histogram {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  align-items: flex-end;
  min-height: 80px;
  padding: 8px;
  background: #000;
  border: 2px inset var(--text);
}

.hist-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 36px;
}

.hist-bar {
  width: 20px;
  min-height: 1px;
  transition: none;
}

.hist-label {
  font-size: 5px;
  color: var(--text);
  margin-top: 2px;
  text-align: center;
  white-space: nowrap;
}

.hist-pct {
  font-size: 6px;
  color: var(--text-yellow);
  margin-bottom: 1px;
}

/* Export */
#export-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Footer */
#footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--text);
  color: #000;
  font-size: 8px;
  flex-wrap: wrap;
  gap: 6px;
}

#footer .footer-link {
  color: #000;
  text-decoration: none;
  font-size: 8px;
}

#footer .footer-link:hover {
  color: var(--bg);
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 640px) {
  #header h1 {
    font-size: 18px;
  }
  #header .subtitle {
    font-size: 6px;
  }
  #canvas-container {
    flex-direction: column;
  }
  .canvas-wrapper {
    max-width: 100%;
  }
  .swatch {
    width: 32px;
    height: 28px;
  }
  .swatch .swatch-label {
    display: none;
  }
  #controls-grid {
    grid-template-columns: 1fr;
  }
}