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

:root {
  --wood-dark: #3d2b1f;
  --wood-mid: #5c3d2e;
  --wood-light: #7a5740;
  --wood-highlight: #a07858;
  --panel-bg: #2a1f17;
  --knob-silver: #8a8a8a;
  --knob-dark: #3a3a3a;
  --led-green: #00ff44;
  --led-red: #ff2222;
  --screen-off: #0a0c0a;
  --text-glow: #33ff77;
  --accent: #d4a043;
}

body {
  background: #0d0a07;
  font-family: 'IBM Plex Mono', monospace;
  color: #b8a088;
  overflow-x: hidden;
  min-height: 100vh;
}

#tv-room {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  min-height: 100vh;
  background: 
    radial-gradient(ellipse at 50% 30%, rgba(60,40,20,0.3) 0%, transparent 70%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(40,30,20,0.03) 2px, rgba(40,30,20,0.03) 4px),
    #0d0a07;
}

#tv-set {
  max-width: 900px;
  width: 100%;
}

#tv-bezel {
  background: linear-gradient(145deg, var(--wood-light), var(--wood-dark) 30%, var(--wood-mid) 50%, var(--wood-dark) 70%, var(--wood-light));
  border-radius: 18px;
  padding: 24px 24px 12px;
  box-shadow: 
    0 8px 40px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -1px 0 rgba(0,0,0,0.5);
  position: relative;
}

#tv-bezel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 8px,
    rgba(0,0,0,0.04) 8px,
    rgba(0,0,0,0.04) 10px
  );
  pointer-events: none;
}

body.plastic-style #tv-bezel {
  background: linear-gradient(145deg, #3a3a3a, #1a1a1a 30%, #2a2a2a 50%, #1a1a1a 70%, #3a3a3a);
}

#screen-container {
  position: relative;
  width: 100%;
  padding-top: 75%;
  background: var(--screen-off);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.9), inset 0 0 4px rgba(0,0,0,1);
}

#canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: 12px;
  image-rendering: auto;
}

#screen-glare {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 40%, transparent 60%, rgba(255,255,255,0.02) 100%);
  pointer-events: none;
  z-index: 5;
}

#drop-zone {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  cursor: pointer;
  border-radius: 12px;
}

#drop-zone.hidden { display: none; }

#drop-content {
  text-align: center;
  z-index: 11;
}

.static-icon { font-size: 48px; margin-bottom: 10px; filter: drop-shadow(0 0 10px rgba(255,255,255,0.3)); }
.drop-title { font-family: 'VT323', monospace; font-size: 28px; color: #ddd; text-shadow: 0 0 10px rgba(255,255,255,0.5); letter-spacing: 2px; }
.drop-sub { font-family: 'VT323', monospace; font-size: 18px; color: #888; margin-top: 6px; }

#file-input {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

#brand-area {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 4px;
}

#power-led {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--led-green);
  box-shadow: 0 0 6px var(--led-green);
  transition: all 0.3s;
}

#power-led.off {
  background: var(--led-red);
  box-shadow: 0 0 4px var(--led-red);
}

#brand-name {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 4px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.5);
}

#brand-model {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: #7a6a58;
  letter-spacing: 3px;
  margin-left: auto;
}

/* Control Panel */
#control-panel {
  background: linear-gradient(180deg, var(--panel-bg) 0%, #1a1310 100%);
  border-radius: 0 0 14px 14px;
  margin-top: 4px;
  padding: 16px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}

body.plastic-style #control-panel {
  background: linear-gradient(180deg, #1a1a1a 0%, #111 100%);
}

/* Signal Mode Buttons */
#signal-modes {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.signal-btn {
  flex: 1;
  background: #1a1512;
  border: 1px solid #3a3028;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  color: #8a7a68;
}

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

.signal-btn.active {
  background: #2a2018;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(212,160,67,0.2);
}

.mode-label { font-family: 'Orbitron', sans-serif; font-size: 13px; font-weight: 700; display: block; }
.mode-joke { font-size: 8px; display: block; margin-top: 2px; opacity: 0.6; }

/* Knobs */
#knobs-area {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 14px;
}

.knob-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.knob {
  width: 48px;
  height: 48px;
  cursor: grab;
}

.knob-body {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #999, #555 40%, #333 80%, #222);
  box-shadow: 0 2px 6px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.15);
  position: relative;
  transition: transform 0.05s;
}

.knob-indicator {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 3px;
  height: 14px;
  margin-left: -1.5px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 3px rgba(255,255,255,0.5);
}

.knob-label {
  font-size: 9px;
  letter-spacing: 1px;
  color: #7a6a58;
  text-transform: uppercase;
  font-weight: 700;
}

body.plastic-style .knob-label { color: #777; }

/* Toggle Switches */
#switches-area {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 14px;
}

.switch-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.toggle-switch {
  width: 36px;
  height: 20px;
  background: #222;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  border: 1px solid #444;
  transition: background 0.2s;
}

.toggle-switch.on { background: #1a3a1a; border-color: #2a5a2a; }

.switch-handle {
  width: 16px;
  height: 16px;
  background: linear-gradient(180deg, #aaa, #666);
  border-radius: 50%;
  position: absolute;
  top: 1px;
  left: 1px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.toggle-switch.on .switch-handle { transform: translateX(16px); }

.switch-label {
  font-size: 8px;
  letter-spacing: 1px;
  color: #7a6a58;
  font-weight: 700;
}

/* Transport */
#transport-area {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#channel-selector { display: flex; align-items: center; gap: 6px; }

.channel-knob {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #777, #444 50%, #222);
  box-shadow: 0 2px 6px rgba(0,0,0,0.6);
  cursor: grab;
  position: relative;
}

.channel-indicator {
  position: absolute;
  top: 3px; left: 50%;
  width: 2px; height: 12px;
  margin-left: -1px;
  background: #fff;
  border-radius: 1px;
}

.channel-display {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--accent);
  min-width: 42px;
}

.transport-btn {
  background: #2a2218;
  border: 1px solid #4a3a28;
  color: #b8a088;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  transition: all 0.15s;
}

.transport-btn:hover { background: #3a3228; border-color: var(--accent); }
.transport-btn:active { transform: scale(0.95); }

#time-display {
  font-family: 'VT323', monospace;
  font-size: 22px;
  color: var(--led-green);
  text-shadow: 0 0 8px rgba(0,255,68,0.4);
  min-width: 60px;
  text-align: center;
}

#style-toggle { display: flex; gap: 4px; }

.style-btn {
  background: none;
  border: 1px solid #3a3028;
  color: #7a6a58;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
}

.style-btn.active { border-color: var(--accent); color: var(--accent); }

/* Signal Panel */
#signal-panel {
  max-width: 900px;
  width: 100%;
  margin-top: 12px;
  background: #111;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid #2a2a2a;
}

#signal-panel.hidden { display: none; }

#waveform-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.wf-toggle-btn {
  background: #1a2a1a;
  border: 1px solid #2a5a2a;
  color: #33ff55;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  transition: all 0.2s;
  text-shadow: 0 0 6px rgba(51,255,85,0.3);
}

.wf-toggle-btn:hover {
  background: #2a3a2a;
  border-color: #33ff55;
  box-shadow: 0 0 8px rgba(51,255,85,0.2);
}

.wf-toggle-btn.vsync-active {
  background: #1a1a3a;
  border-color: #4488ff;
  color: #4488ff;
  text-shadow: 0 0 6px rgba(68,136,255,0.3);
}

.wf-toggle-btn.vsync-active:hover {
  border-color: #66aaff;
  box-shadow: 0 0 8px rgba(68,136,255,0.2);
}

#wf-mode-desc {
  font-size: 9px;
  color: #556655;
  letter-spacing: 0.5px;
}

#waveform-canvas {
  background: #0a0a0a;
  border-radius: 4px;
  border: 1px solid #222;
  flex: 1;
  min-width: 250px;
  max-width: 100%;
  height: 180px;
}

#vectorscope-canvas {
  background: #0a0a0a;
  border-radius: 4px;
  border: 1px solid #222;
  width: 200px;
  height: 200px;
}

#line-timing {
  width: 100%;
  position: relative;
}

.timing-bar {
  display: flex;
  height: 24px;
  border-radius: 3px;
  overflow: hidden;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1px;
}

.timing-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.timing-title {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #779977;
  margin-bottom: 3px;
  text-transform: uppercase;
}

/* H-Sync timing segments */
.timing-segment.fp { background: #555; flex: 0.024; font-size: 7px; }
.timing-segment.sync { background: #2244aa; flex: 0.075; }
.timing-segment.bp { background: #aa7722; flex: 0.06; font-size: 7px; }
.timing-segment.active { background: #335522; flex: 0.841; }

/* V-Sync timing segments */
.timing-bar.vsync-bar {
  margin-top: 2px;
}
.timing-segment.pre-eq { background: #553388; flex: 0.22; font-size: 7px; }
.timing-segment.long-sync { background: #2244cc; flex: 0.20; font-size: 7px; font-weight: 700; }
.timing-segment.post-eq { background: #336688; flex: 0.18; font-size: 7px; }
.timing-segment.normal-lines { background: #335522; flex: 0.40; font-size: 7px; }

#hsync-timing, #vsync-timing {
  margin-bottom: 6px;
}

.timing-indicator {
  position: absolute;
  top: 0;
  width: 2px;
  height: 24px;
  background: #ff0;
  transition: left 0.016s linear;
}

.timing-labels {
  display: flex;
  gap: 8px;
  margin-top: 3px;
}

.tl-volt {
  font-size: 7px;
  color: #556655;
  letter-spacing: 0.5px;
}

#signal-info {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #1a1a1a;
}

.sig-detail {
  font-size: 9px;
  color: #556655;
  letter-spacing: 0.3px;
}

.sig-detail b {
  color: #779977;
}

/* Footer */
#footer {
  margin-top: 20px;
  font-size: 11px;
  color: #5a4a38;
  text-align: center;
  padding: 10px;
}

#footer a {
  color: var(--accent);
  text-decoration: none;
}

#footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 600px) {
  #tv-room { padding: 8px; }
  #tv-bezel { padding: 12px 12px 8px; border-radius: 12px; }
  #knobs-area { gap: 6px; }
  .knob { width: 38px; height: 38px; }
  .knob-label { font-size: 7px; }
  .signal-btn { padding: 4px; }
  .mode-label { font-size: 11px; }
  .mode-joke { display: none; }
  #transport-area { gap: 6px; }
  .transport-btn { padding: 4px 8px; font-size: 10px; }
  #brand-name { font-size: 12px; letter-spacing: 2px; }
  #signal-panel { flex-direction: column; }
  #vectorscope-canvas { width: 150px; height: 150px; }
}

/* Smack animation */
@keyframes tvShake {
  0%, 100% { transform: translate(0); }
  10% { transform: translate(-6px, 3px); }
  20% { transform: translate(5px, -4px); }
  30% { transform: translate(-3px, 2px); }
  40% { transform: translate(4px, -1px); }
  50% { transform: translate(-2px, 3px); }
  60% { transform: translate(3px, -2px); }
  70% { transform: translate(-1px, 1px); }
}

.shaking { animation: tvShake 0.5s ease; }

/* Power off CRT effect */
@keyframes crtOff {
  0% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
  50% { transform: scaleY(0.005) scaleX(1.1); filter: brightness(2); }
  100% { transform: scaleY(0) scaleX(0); filter: brightness(0); }
}

@keyframes crtOn {
  0% { transform: scaleY(0) scaleX(0); filter: brightness(3); }
  30% { transform: scaleY(0.005) scaleX(0.8); filter: brightness(2); }
  100% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
}