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

body {
  background: #0a0a0a;
  color: #c8a96e;
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

/* Wood grain bg texture */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(80,50,20,0.03) 2px,
      rgba(80,50,20,0.03) 4px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 8px,
      rgba(60,35,15,0.02) 8px,
      rgba(60,35,15,0.02) 10px
    );
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 960px;
  width: 100%;
}

/* CRT Bezel */
#bezel {
  background: linear-gradient(145deg, #2a2018, #1a1410, #0d0a08);
  border: 3px solid #3a2a1a;
  border-radius: 20px;
  padding: 20px 24px 24px;
  box-shadow: 
    inset 0 1px 0 rgba(255,255,255,0.05),
    0 8px 32px rgba(0,0,0,0.8),
    0 0 60px rgba(0,0,0,0.5);
  position: relative;
}

#bezel-label {
  text-align: center;
  font-size: 11px;
  letter-spacing: 4px;
  color: #8a7a5a;
  margin-bottom: 12px;
  font-weight: 700;
}

#crt-container {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 2px solid #1a1a1a;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8), 0 0 2px rgba(0,255,0,0.1);
}

#crt {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* slight curvature */
  border-radius: 8px;
}

#scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  pointer-events: none;
  border-radius: 8px;
}

#crt-glow {
  position: absolute;
  top: -4px; left: -4px; right: -4px; bottom: -4px;
  border-radius: 14px;
  box-shadow: inset 0 0 60px rgba(51,255,51,0.03);
  pointer-events: none;
}

/* Controls Panel */
#controls-panel {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

#left-controls, #right-controls {
  flex: 1;
  min-width: 280px;
  background: linear-gradient(160deg, #2a2520, #1e1a16);
  border: 2px solid #3a2a1a;
  border-radius: 10px;
  padding: 16px;
}

.panel-title {
  font-size: 10px;
  letter-spacing: 3px;
  color: #6a5a3a;
  margin-bottom: 12px;
  text-align: center;
  border-bottom: 1px solid #2a2018;
  padding-bottom: 8px;
}

.control-group {
  margin-bottom: 10px;
}

.control-group.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ctrl-label {
  display: block;
  font-size: 10px;
  letter-spacing: 2px;
  color: #8a7a5a;
  margin-bottom: 4px;
}

.inline .ctrl-label {
  margin-bottom: 0;
}

/* Hardware Buttons */
.hw-button {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.1s;
  box-shadow: 0 3px 0 rgba(0,0,0,0.4), 0 4px 8px rgba(0,0,0,0.3);
}

.hw-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.4);
}

.hw-button.red {
  background: linear-gradient(180deg, #cc3333, #991111);
  color: #fff;
}
.hw-button.red:hover { background: linear-gradient(180deg, #dd4444, #aa2222); }

.hw-button.amber {
  background: linear-gradient(180deg, #b8860b, #8b6508);
  color: #fff;
}
.hw-button.amber:hover { background: linear-gradient(180deg, #c8960b, #9b7518); }

.hw-button.green {
  background: linear-gradient(180deg, #228b22, #166016);
  color: #fff;
}
.hw-button.green:hover { background: linear-gradient(180deg, #2a9b2a, #1e7a1e); }

.hw-button.small {
  padding: 4px 10px;
  font-size: 10px;
}

.hw-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  background: #0a0a0a;
  border: 2px solid #3a2a1a;
  color: #33ff33;
  padding: 6px 10px;
  border-radius: 4px;
  width: 80px;
  text-transform: uppercase;
}

.hw-input.small { width: 50px; font-size: 12px; padding: 4px 6px; }

.hw-input:focus {
  outline: none;
  border-color: #5a4a2a;
  box-shadow: 0 0 8px rgba(51,255,51,0.1);
}

.hw-select {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  background: #0a0a0a;
  border: 2px solid #3a2a1a;
  color: #c8a96e;
  padding: 6px 8px;
  border-radius: 4px;
}

.hw-file {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: #c8a96e;
  width: 100%;
}

.hw-file::file-selector-button {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  background: linear-gradient(180deg, #3a3020, #2a2018);
  color: #c8a96e;
  border: 1px solid #5a4a2a;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  margin-right: 8px;
}

#file-info {
  font-size: 10px;
  color: #6a5a3a;
  margin-bottom: 8px;
}

#hex-preview {
  font-size: 10px;
  color: #33aa33;
  background: #050505;
  padding: 6px 8px;
  border-radius: 4px;
  font-family: 'IBM Plex Mono', monospace;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 60px;
  overflow-y: auto;
  display: none;
}

#status-bar {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-top: 8px;
  padding: 6px 10px;
  background: #0a0a0a;
  border-radius: 4px;
  border: 1px solid #2a2018;
}

#status-text { color: #33ff33; }
#speed-text { color: #6a5a3a; }

/* CPU Inspector */
#cpu-inspector {
  margin-top: 12px;
  background: linear-gradient(160deg, #2a2520, #1e1a16);
  border: 2px solid #3a2a1a;
  border-radius: 10px;
  overflow: hidden;
}

#inspector-toggle {
  padding: 10px 16px;
  font-size: 10px;
  letter-spacing: 2px;
  color: #6a5a3a;
  cursor: pointer;
  user-select: none;
}

#inspector-toggle:hover { color: #8a7a5a; }

#inspector-content {
  display: none;
  padding: 0 16px 16px;
}

#cpu-inspector.expanded #inspector-content { display: block; }
#cpu-inspector.expanded #inspector-toggle::before { content: ''; }

#cpu-regs {
  font-size: 12px;
  color: #33ff33;
  background: #050505;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-family: 'IBM Plex Mono', monospace;
}

#mem-dump-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

#mem-dump {
  font-size: 10px;
  color: #33aa33;
  background: #050505;
  padding: 8px;
  border-radius: 4px;
  max-height: 160px;
  overflow-y: auto;
  font-family: 'IBM Plex Mono', monospace;
}

/* Footer */
footer {
  margin-top: 20px;
  text-align: center;
  font-size: 10px;
  color: #4a3a2a;
  letter-spacing: 1px;
}

footer a {
  color: #6a5a3a;
  text-decoration: none;
}

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

/* Focus the canvas properly */
#crt:focus { outline: none; }

/* Responsive */
@media (max-width: 640px) {
  body { padding: 8px; }
  #bezel { padding: 12px 14px 16px; border-radius: 14px; }
  #controls-panel { flex-direction: column; }
  .hw-button { padding: 6px 12px; font-size: 11px; }
}