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

body {
  background: #0a0a14;
  background-image: radial-gradient(ellipse at 50% 30%, #12122a 0%, #0a0a14 70%);
  color: #6C5EB5;
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

#header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #c4b59a 0%, #a89478 100%);
  width: 100%;
  max-width: 800px;
  border-radius: 8px 8px 0 0;
  margin-top: 16px;
}

.commodore-logo {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.logo-stripes {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 20px;
}

.logo-stripes span { display: block; height: 4px; border-radius: 1px; }
.s1 { background: #e74c3c; }
.s2 { background: #f1c40f; }
.s3 { background: #27ae60; }

.logo-text {
  font-size: 9px;
  color: #4a3c28;
  letter-spacing: 2px;
}

.header-title {
  font-size: 6px;
  color: #4a3c28;
  letter-spacing: 1px;
  margin-left: auto;
  text-align: right;
}

#monitor-bezel {
  background: linear-gradient(160deg, #2a2a3a 0%, #1a1a2a 40%, #0f0f1f 100%);
  padding: 16px;
  border-radius: 0 0 12px 12px;
  box-shadow:
    0 0 0 3px #333,
    0 0 0 6px #1a1a1a,
    inset 0 0 40px rgba(0,0,0,0.5),
    0 8px 32px rgba(0,0,0,0.8);
  width: 100%;
  max-width: 800px;
}

#screen-container {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    inset 0 0 60px rgba(108, 108, 255, 0.05),
    0 0 20px rgba(108, 108, 255, 0.1);
}

#canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
}

#scanlines {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 1px, rgba(0,0,0,0.1) 1px, rgba(0,0,0,0.1) 2px);
  pointer-events: none;
  border-radius: 4px;
}

#screen-glow {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  border-radius: 4px;
}

#status-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #111122 0%, #0d0d1a 100%);
  border: 1px solid #222;
  border-top: none;
  max-width: 800px;
  width: 100%;
  font-size: 7px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.status-item .label { color: #588D43; font-size: 6px; }
.status-item .value { color: #9AD284; font-size: 7px; }

#sid-viz {
  vertical-align: middle;
  border: 1px solid #333;
  border-radius: 2px;
}

#debug-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #0d0d1a 0%, #111122 100%);
  border: 1px solid #222;
  border-top: none;
  max-width: 800px;
  width: 100%;
  align-items: center;
  justify-content: center;
}

.dbg-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 10px;
  border: 1px solid #444;
  border-radius: 4px;
  background: linear-gradient(180deg, #1a1a2e 0%, #0f0f1f 100%);
  color: #9AD284;
  cursor: pointer;
  transition: all 0.1s;
  touch-action: manipulation;
}
.dbg-btn:hover { background: linear-gradient(180deg, #222244 0%, #1a1a2e 100%); border-color: #9AD284; }
.dbg-btn:active { transform: translateY(1px); }
.dbg-btn:disabled { opacity: 0.4; cursor: default; }

.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
}
.speed-control .label { color: #588D43; font-size: 6px; }
.speed-control .value { color: #9AD284; font-size: 7px; min-width: 20px; }
#speed-slider { width: 60px; accent-color: #588D43; }

#datasette-panel {
  max-width: 800px;
  width: 100%;
  margin-top: 10px;
}

.datasette-body {
  background: linear-gradient(180deg, #d4c8a8 0%, #c4b490 50%, #b4a480 100%);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.3);
}

.datasette-label {
  font-size: 6px;
  color: #4a3c28;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 2px;
}

.tape-window {
  background: #2a2018;
  border-radius: 4px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 20px;
  margin-bottom: 6px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}

.tape-reel {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 3px solid #555;
  background: radial-gradient(circle, #444 30%, #333 70%);
}

.datasette-controls {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.tape-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 5px 10px;
  border: 2px solid #8a7a5a;
  border-radius: 4px;
  background: linear-gradient(180deg, #e8dcc0 0%, #c8bc9a 100%);
  color: #4a3c28;
  cursor: pointer;
  touch-action: manipulation;
}
.tape-btn:active { transform: translateY(1px); }

.tape-counter {
  font-size: 9px;
  color: #eee;
  background: #111;
  padding: 3px 6px;
  border-radius: 2px;
  letter-spacing: 2px;
}

#memory-panel {
  max-width: 800px;
  width: 100%;
  margin-top: 10px;
}

.mem-header {
  background: #1a1a2e;
  border: 1px solid #333;
  padding: 8px 12px;
  font-size: 7px;
  color: #6C5EB5;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  user-select: none;
}
.mem-header:hover { background: #222244; }

.mem-body {
  background: #0d0d1a;
  border: 1px solid #333;
  border-top: none;
  padding: 10px;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  border-radius: 0 0 4px 4px;
}
.mem-body.open { display: block; }

.mem-map {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  font-size: 5px;
  flex-wrap: wrap;
}

.map-region {
  padding: 3px 5px;
  border-radius: 2px;
  color: #fff;
  opacity: 0.6;
}
.map-region.active { opacity: 1; box-shadow: 0 0 8px rgba(111,61,134,0.5); }

.mem-nav {
  display: flex;
  gap: 3px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.mem-nav-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  padding: 4px 6px;
  border: 1px solid #444;
  border-radius: 3px;
  background: #1a1a2e;
  color: #6C5EB5;
  cursor: pointer;
  touch-action: manipulation;
}
.mem-nav-btn:hover, .mem-nav-btn.active { background: #352879; color: #fff; }

.hex-dump {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  color: #6C5EB5;
  line-height: 1.8;
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#virtual-keyboard {
  max-width: 800px;
  width: 100%;
  margin-top: 10px;
  padding: 0 4px;
  display: none;
}

.vk-row {
  display: flex;
  gap: 2px;
  margin-bottom: 2px;
  justify-content: center;
}

.vk-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 10px 4px;
  min-width: 30px;
  min-height: 36px;
  text-align: center;
  background: linear-gradient(180deg, #7a6a4a 0%, #5a4a2a 100%);
  color: #e8dcc0;
  border: 1px solid #4a3a1a;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 2px 0 #3a2a0a;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex: 1;
  max-width: 38px;
}
.vk-key:active { transform: translateY(2px); box-shadow: none; }
.vk-key.special {
  background: linear-gradient(180deg, #5a5a6a 0%, #3a3a4a 100%);
  color: #b0b0c0;
}
.vk-key.wide { max-width: 70px; flex: 2; }
.vk-key.space { max-width: 200px; flex: 5; }

footer {
  margin: 16px 0;
  font-size: 8px;
}
footer a { color: #588D43; text-decoration: none; }
footer a:hover { color: #9AD284; }

.mem-body::-webkit-scrollbar { width: 6px; }
.mem-body::-webkit-scrollbar-track { background: #0a0a14; }
.mem-body::-webkit-scrollbar-thumb { background: #352879; border-radius: 3px; }

@media (max-width: 768px) {
  #virtual-keyboard { display: block; }
}

@media (max-width: 600px) {
  #header { margin-top: 4px; padding: 6px 10px; gap: 8px; }
  .header-title { display: none; }
  #monitor-bezel { padding: 8px; border-radius: 0 0 8px 8px; }
  #status-bar { font-size: 5px; padding: 6px 8px; gap: 3px; }
  .status-item .label { font-size: 5px; }
  .status-item .value { font-size: 5px; }
  .status-row { gap: 4px 8px; }
  #debug-controls { gap: 4px; padding: 6px 8px; }
  .dbg-btn { font-size: 6px; padding: 5px 7px; }
  .hex-dump { font-size: 4px; }
  .mem-nav-btn { font-size: 4px; padding: 3px 5px; }
  .datasette-label { font-size: 5px; }
  .tape-btn { font-size: 5px; padding: 4px 7px; }
}