:root {
  --beige: #d8c9a3;
  --beige-dark: #b6a37a;
  --shell: #cabf9c;
  --brown: #5b4a2f;
  --vic-blue: #4640a0;
  --vic-cyan: #70dee0;
  --ink: #1c150a;
  --panel: #1b1a24;
  --accent: #ffb02e;
  --ok: #7ee081;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Mono', monospace;
  background:
    radial-gradient(circle at 50% 0%, #2a2536 0%, #14121c 60%, #0a0810 100%);
  color: #e8e2d0;
  min-height: 100vh;
  padding: 16px;
}

#scanroot { max-width: 720px; margin: 0 auto; }

header { text-align: center; margin-bottom: 18px; }
h1 {
  font-family: 'VT323', monospace;
  font-size: clamp(32px, 7vw, 56px);
  margin: 0;
  letter-spacing: 2px;
  color: var(--vic-cyan);
  text-shadow: 0 0 14px rgba(112,222,224,0.5), 3px 3px 0 #23204a;
}
h1 .pal {
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255,176,46,0.5);
}
.subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: #a89f88;
  letter-spacing: 0.5px;
}

.hidden { display: none !important; }

/* ---------- LOADER ---------- */
.loader {
  background: var(--panel);
  border: 2px solid #2f2c3d;
  border-radius: 14px;
  padding: 22px;
  transition: border-color 0.2s, box-shadow 0.2s;
  animation: rise 0.5s ease both;
}
.loader.drag {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(255,176,46,0.15);
}
.loader-intro { font-size: 13px; color: #b7ae95; margin: 0 0 16px; }
.loader-intro code { color: var(--vic-cyan); }

.slots { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media(min-width: 560px){ .slots { grid-template-columns: repeat(3,1fr); } }

.slot {
  display: flex; flex-direction: column; gap: 4px;
  background: #12111a;
  border: 1px dashed #3a3650;
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
}
.slot:hover { border-color: var(--vic-cyan); transform: translateY(-2px); }
.slot.loaded { border-style: solid; border-color: var(--ok); background: #101a12; }
.slot-title { font-weight: 600; color: #f0ead6; font-size: 14px; }
.slot-file { font-size: 10.5px; color: #7d7460; }
.slot-status { font-size: 11px; color: #8a8170; margin-top: 4px; }
.slot-status.ok { color: var(--ok); }
.slot input { display: none; }

.loader-actions {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 18px;
}
.loader-msg { font-size: 12px; color: var(--vic-cyan); flex: 1; min-width: 120px; }

button {
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #201703;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s;
}
button:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.ghost { background: transparent; color: #9b9280; border: 1px solid #3a3650; }
button.active { background: var(--ok); }

#powerBtn { font-size: 15px; padding: 12px 22px; }

/* ---------- MACHINE ---------- */
.machine { animation: rise 0.5s ease both; }

.bezel {
  background: linear-gradient(160deg, var(--beige) 0%, var(--beige-dark) 100%);
  border-radius: 18px;
  padding: 22px;
  box-shadow:
    inset 0 2px 6px rgba(255,255,255,0.4),
    inset 0 -6px 12px rgba(0,0,0,0.25),
    0 14px 40px rgba(0,0,0,0.55);
  border: 1px solid #9c8b62;
}

.crt-wrap {
  position: relative;
  background: #05040a;
  border-radius: 10px;
  padding: 10px;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.9);
  overflow: hidden;
}

#canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 4px;
  aspect-ratio: 284 / 312;
}

.crtfx {
  position: absolute; inset: 10px;
  pointer-events: none;
  border-radius: 4px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0px, rgba(0,0,0,0.18) 1px, transparent 2px, transparent 3px);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.6),
    inset 0 0 20px rgba(112,222,224,0.06);
}
.crtfx::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.5) 100%);
}

/* ---------- CONTROLS ---------- */
.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 14px;
}
.controls button { background: #2a2740; color: #e8e2d0; font-size: 12px; padding: 9px 12px; }
.controls button:hover { background: #38344f; }
.controls button.active { background: var(--ok); color: #06210a; }
#vol { flex: 0 1 100px; accent-color: var(--accent); }
.perf {
  margin-left: auto;
  font-size: 11px;
  color: var(--vic-cyan);
  font-family: 'VT323', monospace;
  letter-spacing: 1px;
}

/* ---------- VIRTUAL KEYBOARD ---------- */
.vkbd {
  margin-top: 14px;
  background: #1c1a26;
  border: 1px solid #2f2c3d;
  border-radius: 12px;
  padding: 10px;
  user-select: none;
}
.vk-row { display: flex; gap: 4px; margin-bottom: 4px; justify-content: center; }
.vk {
  flex: 1;
  min-width: 0;
  background: #34314a;
  color: #e8e2d0;
  border-radius: 5px;
  padding: 10px 2px;
  font-size: 11px;
  border: 1px solid #444;
}
.vk.wide { flex: 5; }
.vk.down { background: var(--vic-cyan); color: #04222a; }

/* ---------- MONITOR ---------- */
.monitor {
  margin-top: 14px;
  background: #0a0910;
  border: 1px solid #2f2c3d;
  border-radius: 12px;
  padding: 14px;
  font-size: 11px;
  color: #8dff8d;
}
.reg-line {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.mon-controls { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.mon-controls input {
  background: #14121c; border: 1px solid #3a3650; color: var(--vic-cyan);
  border-radius: 6px; padding: 7px 10px; font-family: 'IBM Plex Mono', monospace;
  width: 100px;
}
.mon-controls button { background: #2a2740; color: #e8e2d0; font-size: 11px; }
.monitor pre {
  margin: 0 0 8px; white-space: pre; overflow-x: auto;
  font-size: 11px; line-height: 1.4; color: #6ad46a;
}
#chipDump { color: #b6a0ff; }

/* ---------- FOOTER ---------- */
footer {
  margin-top: 24px;
  text-align: center;
  font-size: 12px;
  color: #7d7460;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
footer a {
  color: var(--vic-cyan);
  text-decoration: none;
  border-bottom: 1px dotted var(--vic-cyan);
}
footer a:hover { color: var(--accent); border-color: var(--accent); }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}