:root {
  --bg-color: #0c0d12;
  --bezel-color: #1a1b24;
  --screen-bg: #14161c;
  --accent-green: #39ff14;
  --accent-blue: #00e5ff;
  --accent-red: #ff2a74;
  --text-light: #e5e9f0;
  --text-muted: #707584;
  --card-bg: rgba(22, 24, 33, 0.85);
  --border: 2px solid #20222e;
}

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

body {
  font-family: 'Noto Sans SC', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-light);
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Starry space background */
.stars-overlay {
  position: fixed;
  inset: 0;
  background-image: 
    radial-gradient(1.5px 1.5px at 20px 30px, #ffffff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.7), rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 90px 10px, #ffffff, rgba(0,0,0,0));
  background-size: 150px 150px;
  opacity: 0.15;
  pointer-events: none;
  z-index: 1;
}

.container {
  width: 100%;
  max-width: 1200px;
  position: relative;
  z-index: 10;
}

/* ===== Typography & Headers ===== */
.pixel-font {
  font-family: 'Press Start 2P', 'VT323', monospace;
  text-transform: uppercase;
}

header {
  text-align: center;
  margin-bottom: 30px;
}
header h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent-red), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 10px rgba(255, 42, 116, 0.4));
  letter-spacing: 2px;
  margin-bottom: 8px;
}
.subtitle {
  font-size: 0.75rem;
  letter-spacing: 3px;
  color: var(--accent-blue);
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.3);
}

/* ===== Layout Structure ===== */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  align-items: start;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

/* ===== Left Column: CRT TV Bezel ===== */
.cabinet-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.crt-television {
  background-color: var(--bezel-color);
  border: 6px solid #282a36;
  border-radius: 40px;
  width: 100%;
  max-width: 540px;
  padding: 24px;
  box-shadow: 
    0 20px 40px rgba(0,0,0,0.6),
    inset 0 4px 10px rgba(255,255,255,0.05),
    inset 0 -10px 20px rgba(0,0,0,0.6);
  position: relative;
}

.tv-bezel {
  background-color: #0f1015;
  border-radius: 30px;
  border: 4px solid #14151b;
  padding: 16px;
  box-shadow: inset 0 8px 16px rgba(0,0,0,0.8);
}

.screen-frame {
  border-radius: 20px;
  overflow: hidden;
  border: 3px solid #08090c;
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
}

/* TV Screen Glass */
.screen-glass {
  width: 100%;
  height: 100%;
  background-color: var(--screen-bg);
  position: relative;
  overflow: hidden;
  transition: background-color 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-glass.off {
  background-color: #020203;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.95);
}

/* Phosphor screen curvature scanline shadow */
.screen-glass::after {
  content: " ";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, transparent 55%, rgba(0,0,0,0.3) 100%);
  z-index: 12;
  pointer-events: none;
}

/* CRT Scanlines effect */
.crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.crt-overlay.scanlines-active {
  opacity: 0.12;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.4) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.1), rgba(0, 255, 0, 0.05), rgba(0, 0, 255, 0.1));
  background-size: 100% 4px, 6px 100%;
}

/* Power On Flicker screen transition */
.screen-glass.power-on-anim {
  animation: crt-power-on 0.5s ease-out forwards;
}

@keyframes crt-power-on {
  0% {
    transform: scaleY(0.01) scaleX(0);
    background-color: #ffffff;
    filter: brightness(3);
  }
  50% {
    transform: scaleY(0.01) scaleX(1);
    background-color: #00e5ff;
    filter: brightness(2);
  }
  100% {
    transform: scaleY(1) scaleX(1);
    background-color: var(--screen-bg);
    filter: brightness(1);
  }
}

.crt-flicker {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.02);
  z-index: 11;
  pointer-events: none;
  opacity: 0;
}
.screen-glass:not(.off) .crt-flicker {
  animation: screen-flicker 0.15s infinite;
  opacity: 1;
}

@keyframes screen-flicker {
  0% { opacity: 0.18; }
  50% { opacity: 0.12; }
  100% { opacity: 0.22; }
}

/* Screen Contents container */
.screen-content {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-glass.off .screen-content {
  display: none !important;
}

/* Canvas styling */
#canvas-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: none;
  z-index: 3;
}

/* File Upload dragbox on screen */
.screen-placeholder {
  text-align: center;
  cursor: pointer;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 5;
}

.screen-placeholder input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  font-size: 3.5rem;
  margin-bottom: 15px;
  animation: bounce 2s infinite ease-in-out;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* TV Bezel Grill and Knobs */
.tv-bottom-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  border-top: 3px dashed #282a36;
  padding-top: 15px;
}

.speaker-grill {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100px;
}
.speaker-grill div {
  height: 4px;
  background-color: #0f1015;
  border-radius: 2px;
}

.physical-knobs {
  display: flex;
  gap: 20px;
}

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

.knob-label {
  font-size: 0.6rem;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.knob-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: #12131a;
  border: 3px solid #282a36;
  box-shadow: 
    0 4px 6px rgba(0,0,0,0.5),
    inset 0 2px 4px rgba(255,255,255,0.05);
  cursor: pointer;
  position: relative;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.knob-btn::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 14px;
  background-color: var(--accent-red);
  top: 4px;
  left: calc(50% - 2px);
  border-radius: 2px;
  transition: transform 0.2s;
}

.knob-btn.power-on {
  transform: rotate(45deg);
  border-color: var(--accent-green);
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.3);
}

.knob-btn.power-on::after {
  background-color: var(--accent-green);
}

.knob-btn.sound-on {
  transform: rotate(45deg);
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.knob-btn.sound-on::after {
  background-color: var(--accent-blue);
}

.privacy-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 15px;
  max-width: 450px;
}

/* ===== Right Column: Config Dashboard ===== */
.config-card, .output-card {
  background: var(--card-bg);
  border: var(--border);
  border-radius: 24px;
  padding: 24px;
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  margin-bottom: 24px;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 900;
  border-bottom: 2px dashed #20222e;
  padding-bottom: 12px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.emoji {
  filter: drop-shadow(0 0 5px rgba(255,255,255,0.2));
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

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

.control-group label {
  font-size: 0.82rem;
  font-weight: bold;
  color: var(--text-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.val-badge {
  background-color: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--accent-blue);
}

/* Sleek Select fields */
select {
  background-color: #101117;
  border: 2px solid #20222e;
  color: var(--text-light);
  padding: 10px;
  border-radius: 12px;
  outline: none;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

select:focus {
  border-color: var(--accent-blue);
}

/* Arcade slider bar styling */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: #101117;
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: 2px solid #fff;
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.25);
}

/* Toggle switches bar */
.toggle-bar {
  display: flex;
  gap: 15px;
  margin-top: 24px;
  border-top: 2px dashed #20222e;
  padding-top: 20px;
}

.toggle-switch {
  flex: 1;
  background-color: #101117;
  border: 2px solid #20222e;
  color: var(--text-muted);
  padding: 12px;
  border-radius: 14px;
  font-weight: bold;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-switch.active {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background-color: rgba(0, 229, 255, 0.05);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.15);
}

#btn-demo {
  color: var(--accent-red);
  border-color: #20222e;
}
#btn-demo:hover {
  border-color: var(--accent-red);
  background-color: rgba(255, 42, 116, 0.05);
}

/* ===== Right Column: Output Card ===== */
.action-buttons {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
}

@media (max-width: 480px) {
  .action-buttons {
    flex-direction: column;
  }
}

.action-btn {
  flex: 1;
  border: none;
  padding: 16px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 900;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.action-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  box-shadow: none !important;
  transform: none !important;
}

.btn-green {
  background-color: var(--accent-green);
  color: #000;
}
.btn-green:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(57, 255, 20, 0.4);
}
.btn-green:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-blue {
  background-color: var(--accent-blue);
  color: #000;
}
.btn-blue:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 229, 255, 0.4);
}
.btn-blue:active:not(:disabled) {
  transform: translateY(1px);
}

/* Code box rendering */
.code-box-wrapper {
  background-color: #0b0c11;
  border-radius: 16px;
  border: var(--border);
  overflow: hidden;
}

.code-header {
  background-color: #12131a;
  padding: 10px 16px;
  font-size: 0.65rem;
  font-family: monospace;
  font-weight: bold;
  color: var(--text-muted);
  border-bottom: 1px solid #20222e;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.copy-alert {
  color: var(--accent-green);
  opacity: 0;
  transition: opacity 0.2s;
}

.copy-alert.show {
  opacity: 1;
}

textarea {
  width: 100%;
  height: 120px;
  background-color: transparent;
  border: none;
  outline: none;
  color: #a6accd;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  padding: 16px;
  resize: none;
  line-height: 1.5;
}

footer {
  text-align: center;
  margin-top: 40px;
  color: var(--text-muted);
}
