:root {
  --bg: #0d0d1a;
  --bg2: #1a1a2e;
  --bg3: #16213e;
  --amber: #f0a500;
  --amber-dim: #8a6000;
  --green: #2ecc71;
  --red: #e74c3c;
  --blue: #3498db;
  --lcd-bg: #2d5016;
  --lcd-on: #8bac0f;
  --lcd-off: #305018;
  --text: #c8c8d0;
  --text-dim: #6a6a80;
  --border: #2a2a4a;
  --panel-bg: #12122a;
  --font-mono: 'JetBrains Mono', monospace;
  --font-pixel: 'Press Start 2P', monospace;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 20px rgba(240,165,0,0.05);
}

header h1 {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--amber);
  letter-spacing: 1px;
}

.subtitle {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status.stopped .status-dot { background: var(--red); }
.status.running .status-dot { background: var(--green); animation: pulse 1s infinite; }
.status.paused .status-dot { background: var(--amber); }
.status.stopped #status-text { color: var(--red); }
.status.running #status-text { color: var(--green); }
.status.paused #status-text { color: var(--amber); }

@keyframes pulse {
  0%,100% { opacity:1; box-shadow: 0 0 4px var(--green); }
  50% { opacity:0.5; box-shadow: 0 0 10px var(--green); }
}

.cycle-count {
  font-size: 10px;
  color: var(--text-dim);
}

#main-layout {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  flex: 1;
  gap: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}

#right-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-title {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--amber);
  margin: 14px 0 8px;
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.panel-title:first-child { margin-top: 0; }

/* Upload zones */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.3s, background 0.3s;
  margin-bottom: 8px;
  font-size: 11px;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--amber);
  background: rgba(240,165,0,0.05);
}

.upload-icon { font-size: 20px; margin-bottom: 4px; }

.file-input { display: none; }

.file-info {
  font-size: 10px;
  background: var(--bg3);
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 8px;
  color: var(--text-dim);
  word-break: break-all;
}

.file-info .warn { color: var(--amber); }

#charrom-preview {
  width: 100%;
  background: #000;
  border-radius: 4px;
  margin-bottom: 8px;
  image-rendering: pixelated;
}

/* Buttons */
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 700;
}

.btn:hover { background: var(--bg3); }
.btn:active { transform: scale(0.95); }

.btn-small { padding: 4px 10px; font-size: 10px; }
.btn-tiny { padding: 2px 6px; font-size: 9px; }

.btn-start { color: var(--green); border-color: var(--green); }
.btn-start:hover { background: rgba(46,204,113,0.15); }
.btn-stop { color: var(--red); border-color: var(--red); }
.btn-stop:hover { background: rgba(231,76,60,0.15); }
.btn-reset { color: var(--amber); border-color: var(--amber); }
.btn-reset:hover { background: rgba(240,165,0,0.15); }
.btn-step { color: var(--blue); border-color: var(--blue); }
.btn-step:hover { background: rgba(52,152,219,0.15); }

.control-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

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

.control-group label {
  display: block;
  font-size: 10px;
  margin-bottom: 4px;
  color: var(--text-dim);
}

.control-group input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
}

.control-group select {
  width: 100%;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  border-radius: 4px;
}

.alarm-indicator {
  font-size: 10px;
  margin: 8px 0;
}

.alarm-on { color: var(--green); font-weight: 700; }
.alarm-off { color: var(--red); font-weight: 700; }

#beeper-scope {
  width: 100%;
  background: #0a0a15;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Center: Device */
#center-panel {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}

#device-body {
  background: linear-gradient(145deg, #2a2a30 0%, #1e1e24 100%);
  border-radius: 16px;
  padding: 20px 24px 24px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  max-width: 540px;
  width: 100%;
  position: relative;
}

.device-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: rgba(255,255,255,0.12);
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: 4px;
}

#lcd-bezel {
  background: #111;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
}

#lcd-glass {
  background: var(--lcd-bg);
  border-radius: 4px;
  padding: 8px;
  position: relative;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.4);
}

#lcd-glass::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 40%,transparent 60%,rgba(0,0,0,0.05) 100%);
  pointer-events: none;
  border-radius: 4px;
}

#lcd-canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
}

/* Keyboard */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.key {
  min-width: 42px;
  height: 34px;
  border: none;
  border-radius: 4px;
  background: linear-gradient(180deg, #4a4a55 0%, #35353f 100%);
  color: #ddd;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #222, 0 4px 6px rgba(0,0,0,0.3);
  transition: all 0.08s;
  user-select: none;
}

.key:active, .key.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #222, 0 1px 2px rgba(0,0,0,0.3);
  background: linear-gradient(180deg, #3a3a45 0%, #2a2a34 100%);
}

.key-fn {
  background: linear-gradient(180deg, #5a4a20 0%, #3a3018 100%);
  color: var(--amber);
}

.key-exec {
  min-width: 64px;
  background: linear-gradient(180deg, #205a3a 0%, #18402a 100%);
  color: var(--green);
}

/* Debug panel */
.reg-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.reg-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 6px;
  background: var(--bg);
  border-radius: 2px;
  font-size: 11px;
}

.reg-name { color: var(--amber-dim); font-weight: 700; }
.reg-val { color: var(--text); font-weight: 500; }
.reg-val.changed { color: var(--amber); }

.flags-row {
  grid-column: 1 / -1;
}

.flag {
  display: inline-block;
  width: 18px;
  text-align: center;
  font-size: 10px;
  padding: 1px;
  border-radius: 2px;
  background: var(--bg2);
  color: var(--text-dim);
  margin: 0 1px;
}

.flag.set {
  background: var(--amber);
  color: #000;
  font-weight: 700;
}

.scroll-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 10px;
  line-height: 1.5;
}

.scroll-panel::-webkit-scrollbar { width: 6px; }
.scroll-panel::-webkit-scrollbar-track { background: var(--bg); }
.scroll-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.mem-controls {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.mem-controls input {
  width: 60px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  border-radius: 3px;
}

.mem-panel { font-size: 9px; max-height: 160px; }

.disasm-line {
  padding: 1px 4px;
  white-space: nowrap;
}

.disasm-current {
  background: rgba(240,165,0,0.2);
  color: var(--amber);
  font-weight: 700;
}

.mem-row { white-space: nowrap; padding: 0 2px; }
.mem-region-internal { color: #7799dd; }
.mem-region-io { color: #ccaa44; }
.mem-region-ram { color: #55bb77; }
.mem-region-rom { color: #cc7766; }

.io-panel { max-height: 150px; }
.io-entry { padding: 1px 4px; }
.io-lcd { color: #8bac0f; }
.io-beep { color: #f0a500; }
.io-other { color: #666; }

footer {
  text-align: center;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}

footer a {
  color: var(--amber-dim);
  text-decoration: none;
  font-size: 11px;
}

footer a:hover { color: var(--amber); }

/* Responsive */
@media (max-width: 1100px) {
  #main-layout {
    grid-template-columns: 1fr;
  }
  .panel {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #right-panel { border-left: none; }
  #center-panel { max-height: none; }
}