/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-dark: #0a0a0c;
  --bg-panel: #111114;
  --bg-bezel: #1a1a1e;
  --bg-input: #0d0d10;
  --text-primary: #c8c8d0;
  --text-dim: #666670;
  --text-label: #888890;
  --accent: #00cc66;
  --accent-dim: #00994d;
  --accent-glow: rgba(0, 204, 102, 0.3);
  --danger: #ff3344;
  --screen-bg: #050508;
  --bezel-color: #222228;
  --bezel-highlight: #2a2a32;
  --slider-track: #1e1e24;
  --slider-thumb: #00cc66;
  --radius: 6px;
  --monitor-radius: 16px;
}

html, body {
  height: 100%;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===== Layout ===== */
.crt-shell {
  display: flex;
  height: 100vh;
  gap: 0;
}

/* ===== Monitor Frame ===== */
.monitor-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 24px 12px 24px;
  min-width: 0;
}

.monitor-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 10px 8px;
}

.monitor-badge {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.monitor-model {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  opacity: 0.5;
}

/* ===== Screen Bezel ===== */
.screen-bezel {
  flex: 1;
  background: var(--bezel-color);
  border-radius: var(--monitor-radius);
  padding: 12px;
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.03),
    inset 0 -2px 4px rgba(0,0,0,0.5),
    0 8px 32px rgba(0,0,0,0.6);
  min-height: 0;
}

.screen-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--screen-bg);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Power-on scanline animation ===== */
.power-scanline {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.power-scanline.active {
  display: block;
  animation: powerOn 0.6s ease-out forwards;
}

@keyframes powerOn {
  0% {
    background: white;
    clip-path: inset(49.5% 0 49.5% 0);
  }
  30% {
    background: white;
    clip-path: inset(45% 5% 45% 5%);
  }
  60% {
    background: rgba(255,255,255,0.3);
    clip-path: inset(10% 2% 10% 2%);
  }
  100% {
    background: transparent;
    clip-path: inset(0);
  }
}

/* ===== Upload Zone ===== */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  cursor: pointer;
  padding: 40px;
  transition: all 0.2s;
}

.upload-zone:hover {
  background: rgba(0, 204, 102, 0.02);
}

.upload-zone.drag-over {
  background: rgba(0, 204, 102, 0.05);
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}

.upload-icon {
  width: 64px;
  height: 64px;
  color: var(--text-dim);
  transition: color 0.2s;
}

.upload-zone:hover .upload-icon {
  color: var(--accent);
}

.upload-text {
  font-size: 14px;
  color: var(--text-dim);
}

.upload-hint {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.5;
}

/* ===== Canvas ===== */
#previewCanvas {
  display: none;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#previewCanvas.visible {
  display: block;
}

/* ===== Monitor Bottom Bar ===== */
.monitor-controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 0 8px;
}

.monitor-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  transition: all 0.3s;
}

.monitor-led.on {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent), 0 0 12px var(--accent-glow);
}

.monitor-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid #333;
  border-radius: 50%;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  transition: all 0.2s;
}

.monitor-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.monitor-knob {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #1a1a1e;
  border: 2px solid #2a2a30;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

/* ===== Controls Panel ===== */
.controls-panel {
  width: 300px;
  min-width: 300px;
  background: var(--bg-panel);
  border-left: 1px solid #1e1e24;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #1e1e24;
}

.panel-header h2 {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--text-dim);
  font-weight: 600;
}

.panel-actions {
  display: flex;
  gap: 6px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid #2a2a30;
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: all 0.15s;
}

.btn-icon:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0, 204, 102, 0.05);
}

.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== Controls Scroll Area ===== */
.controls-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  scrollbar-width: thin;
  scrollbar-color: #2a2a30 transparent;
}

.controls-scroll::-webkit-scrollbar {
  width: 4px;
}

.controls-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.controls-scroll::-webkit-scrollbar-thumb {
  background: #2a2a30;
  border-radius: 2px;
}

/* ===== Control Groups ===== */
.control-group {
  margin-bottom: 20px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.control-row label {
  font-size: 12px;
  color: var(--text-label);
  font-weight: 500;
}

.value-display {
  font-size: 11px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

/* ===== Range Sliders ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--slider-track);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--slider-thumb);
  border: none;
  box-shadow: 0 0 4px var(--accent-glow);
  cursor: pointer;
  transition: box-shadow 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 8px var(--accent-glow), 0 0 16px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--slider-thumb);
  border: none;
  box-shadow: 0 0 4px var(--accent-glow);
  cursor: pointer;
}

/* ===== Presets ===== */
.preset-group label {
  display: block;
  font-size: 12px;
  color: var(--text-label);
  font-weight: 500;
  margin-bottom: 10px;
}

.preset-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid #1e1e24;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.preset-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0, 204, 102, 0.06);
}

/* ===== CRT screen overlay (always-on subtle effect) ===== */
.screen-container::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  z-index: 5;
  border-radius: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .crt-shell {
    flex-direction: column;
    overflow-y: auto;
  }

  .monitor-frame {
    min-height: 50vh;
  }

  .controls-panel {
    width: 100%;
    min-width: unset;
    border-left: none;
    border-top: 1px solid #1e1e24;
    max-height: 50vh;
  }
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}
