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

html, body {
  width: 100%; height: 100%;
  background: #1a1a1a;
  font-family: 'IBM Plex Mono', monospace;
  color: #c8c8b0;
  overflow-x: hidden;
}

#scope-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  min-height: 100vh;
}

#crt-bezel {
  background: linear-gradient(145deg, #3a3a3a 0%, #2a2a2a 30%, #222 70%, #1a1a1a 100%);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08), 0 0 0 2px #111;
  border: 1px solid #444;
  position: relative;
}

#crt-bezel::before {
  content: '';
  position: absolute;
  top: 6px; left: 6px; right: 6px; bottom: 6px;
  border-radius: 14px;
  border: 1px solid #333;
  pointer-events: none;
}

#crt-screen-wrapper {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #050a05;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8), inset 0 0 4px rgba(0,80,0,0.15);
}

#canvas, #graticule {
  display: block;
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

#canvas { z-index: 1; }
#graticule { z-index: 2; pointer-events: none; }

#crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 3;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0,0,0,0.06) 2px,
      rgba(0,0,0,0.06) 4px
    ),
    radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.45) 100%);
  border-radius: 8px;
}

#drop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #80ff80;
  background: rgba(0, 40, 0, 0.6);
  border: 3px solid #40ff40;
  border-radius: 8px;
  pointer-events: none;
  text-shadow: 0 0 20px #00ff00, 0 0 40px #008800;
}

#crt-screen-wrapper.drag-active #drop-overlay {
  display: flex;
}

#controls {
  width: 100%;
  max-width: 760px;
  margin-top: 14px;
  background: linear-gradient(180deg, #333 0%, #282828 40%, #222 100%);
  border-radius: 12px;
  padding: 16px 16px 12px;
  border: 1px solid #444;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.06);
}

.ctrl-section {
  margin-bottom: 10px;
}

.ctrl-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #b0a880;
  margin-bottom: 6px;
  padding-bottom: 3px;
  border-bottom: 1px solid #3a3a3a;
}

.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  justify-content: center;
}

.knob-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}

.knob-label {
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #999;
  margin-bottom: 3px;
  text-align: center;
  white-space: nowrap;
}

.knob-container {
  position: relative;
  width: 48px;
  height: 48px;
}

.knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #555, #2a2a2a 70%, #1a1a1a);
  border: 2px solid #444;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
  cursor: grab;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.knob:active { cursor: grabbing; }

.knob-pointer {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  height: 12px;
  background: #e8e0c0;
  border-radius: 1px;
  pointer-events: none;
}

.knob-value {
  font-size: 8px;
  color: #70a070;
  margin-top: 2px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.waveform-selector {
  display: flex;
  gap: 2px;
  margin-top: 2px;
}

.wave-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  padding: 2px 5px;
  background: #2a2a2a;
  color: #777;
  border: 1px solid #444;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.wave-btn.active {
  background: #3a4a3a;
  color: #a0d0a0;
  border-color: #5a7a5a;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.preset-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 600;
  padding: 4px 8px;
  background: linear-gradient(180deg, #3a3a3a, #2a2a2a);
  color: #a0a080;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.preset-btn:active {
  background: #222;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
}

.preset-btn.active-preset {
  background: linear-gradient(180deg, #4a5a4a, #3a4a3a);
  color: #c0e0c0;
  border-color: #6a8a6a;
}

.ratio-display {
  font-size: 12px;
  font-weight: 700;
  color: #80c080;
  background: #111;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #333;
  text-align: center;
  min-width: 70px;
  font-variant-numeric: tabular-nums;
}

/* Source Mode Toggle */
.source-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
}

.source-toggle-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #888;
  cursor: pointer;
  transition: color 0.2s;
}

.source-toggle-label.active {
  color: #c0e0c0;
  text-shadow: 0 0 6px rgba(100, 200, 100, 0.3);
}

.toggle-switch {
  width: 52px;
  height: 24px;
  background: #1a1a1a;
  border: 2px solid #555;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.5);
  transition: border-color 0.3s;
}

.toggle-switch.ext {
  border-color: #6a8a6a;
}

.toggle-switch-handle {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #888, #555);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  transition: left 0.2s;
}

.toggle-switch.ext .toggle-switch-handle {
  left: 30px;
  background: radial-gradient(circle at 40% 40%, #a0d0a0, #6a9a6a);
}

/* External Input Section */
.ext-input-section {
  transition: opacity 0.3s;
}

.ext-input-section.dimmed {
  opacity: 0.35;
  pointer-events: none;
}

.internal-section {
  transition: opacity 0.3s;
}

.internal-section.dimmed {
  opacity: 0.35;
  pointer-events: none;
}

/* File readout LCD */
.file-readout {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  color: #80c060;
  background: #0a0a00;
  padding: 4px 10px;
  border-radius: 3px;
  border: 1px solid #333;
  min-width: 140px;
  max-width: 200px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 0 4px rgba(128, 192, 96, 0.4);
}

/* Transport controls */
.transport-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.transport-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  width: 34px;
  height: 28px;
  background: linear-gradient(180deg, #444, #2a2a2a);
  color: #c8c8b0;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.transport-btn:active {
  background: #222;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.transport-btn.playing {
  background: linear-gradient(180deg, #3a5a3a, #2a3a2a);
  color: #a0e0a0;
  border-color: #5a8a5a;
}

.time-readout {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  color: #c09030;
  background: #0a0800;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid #333;
  min-width: 90px;
  text-align: center;
  text-shadow: 0 0 4px rgba(192, 144, 48, 0.3);
}

.seek-bar {
  width: 120px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #1a1a1a;
  border: 1px solid #444;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: radial-gradient(circle at 40% 40%, #888, #555);
  border: 1px solid #666;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  cursor: grab;
}

.seek-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: radial-gradient(circle at 40% 40%, #888, #555);
  border: 1px solid #666;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  cursor: grab;
}

/* Routing selector */
.routing-selector {
  display: flex;
  gap: 2px;
}

.routing-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 7px;
  font-weight: 600;
  padding: 3px 5px;
  background: #2a2a2a;
  color: #777;
  border: 1px solid #444;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.routing-btn.active {
  background: #3a4a3a;
  color: #a0d0a0;
  border-color: #5a7a5a;
}

/* Loop toggle */
.loop-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.loop-toggle-label {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #777;
}

.loop-toggle-label.active {
  color: #a0d0a0;
}

.loop-switch {
  width: 28px;
  height: 14px;
  background: #1a1a1a;
  border: 1px solid #555;
  border-radius: 7px;
  position: relative;
  cursor: pointer;
}

.loop-switch-handle {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #666;
  transition: left 0.2s, background 0.2s;
}

.loop-switch.on .loop-switch-handle {
  left: 15px;
  background: #80c080;
}

.load-media-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 5px 12px;
  background: linear-gradient(180deg, #4a4a4a, #333);
  color: #c8c8b0;
  border: 1px solid #666;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.08);
  text-transform: uppercase;
}

.load-media-btn:active {
  background: #282828;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

footer {
  text-align: center;
  padding: 10px;
}

footer a {
  color: #444;
  text-decoration: none;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
}

footer a:hover { color: #666; }

@media (max-width: 500px) {
  #crt-bezel { padding: 10px; border-radius: 12px; }
  #controls { padding: 10px; }
  .knob { width: 40px; height: 40px; }
  .knob-container { width: 40px; height: 40px; }
  .knob-pointer { height: 10px; top: 3px; }
  .seek-bar { width: 80px; }
  .file-readout { min-width: 100px; max-width: 140px; font-size: 9px; }
}