:root {
  color-scheme: dark;
  font-family: "Inter", "Avenir Next", system-ui, sans-serif;
  --bg: #141514;
  --panel: #101512;
  --panel-strong: #0b0f0e;
  --line: rgba(241, 241, 232, 0.16);
  --line-strong: rgba(241, 241, 232, 0.28);
  --text: #f1f1e8;
  --muted: #aeb5a7;
  --accent: #16c7bd;
  --yellow: #f3d447;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 0;
  overscroll-behavior: none;
  background:
    linear-gradient(90deg, rgba(31, 32, 30, 0.92), rgba(17, 22, 20, 0.94)),
    var(--bg);
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

button {
  border: 1px solid #6d6d62;
  border-radius: 6px;
  background: var(--text);
  color: #151515;
  cursor: pointer;
  font: inherit;
  min-height: 38px;
  padding: 0 14px;
}

button:focus-visible {
  outline: 3px solid #16c7bd;
  outline-offset: 2px;
}

.shell {
  width: min(1540px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 360px);
  gap: clamp(14px, 2vw, 24px);
  align-items: start;
}

.stage {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.screen-wrap {
  display: grid;
  place-items: center;
}

#screen {
  width: min(100%, 900px);
  max-height: min(68vh, 740px);
  image-rendering: pixelated;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #000;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
}

.panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 15, 13, 0.76);
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.32);
  padding: 14px;
}

.panel::before {
  content: "";
  display: block;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1d4ed8 0 25%, #c026d3 25% 50%, #dc2626 50% 75%, #f3d447 75%);
}

h1 {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 1.1;
}

output {
  color: #c9c9bd;
  font-size: 14px;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 4px;
}

.tool-tabs button {
  min-height: 34px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
}

.tool-tabs button[aria-selected="true"] {
  border-color: rgba(22, 199, 189, 0.42);
  background: rgba(22, 199, 189, 0.16);
  color: var(--text);
}

.tool-panel,
.paste-form {
  display: grid;
  gap: 10px;
}

.paste-form label,
.basic-file-panel label,
.tape-panel label,
.snapshot-panel label {
  color: #c9c9bd;
  font-size: 14px;
}

.paste-form textarea {
  width: 100%;
  min-height: 134px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: 13px/1.35 "SFMono-Regular", Consolas, monospace;
  padding: 10px;
}

.paste-form textarea:focus-visible {
  outline: 3px solid #16c7bd;
  outline-offset: 2px;
}

.tape-panel,
.basic-file-panel,
.snapshot-panel {
  display: grid;
  gap: 8px;
}

.tape-panel input,
.basic-file-panel input,
.snapshot-panel input {
  width: 100%;
  color: #c9c9bd;
  font: 12px/1.2 "SFMono-Regular", Consolas, monospace;
}

.tape-panel input::file-selector-button,
.basic-file-panel input::file-selector-button,
.snapshot-panel input::file-selector-button {
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #d9d8cc;
  color: #151515;
  font: 700 11px/1.2 "Inter", "Avenir Next", system-ui, sans-serif;
  margin-right: 8px;
  padding: 5px 8px;
}

.tap-list {
  display: grid;
  gap: 6px;
  max-height: min(34vh, 260px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 6px;
  color: var(--muted);
  font-size: 12px;
}

.tap-entry {
  display: grid;
  min-height: 0;
  justify-items: start;
  gap: 3px;
  border-color: rgba(241, 241, 232, 0.16);
  background: transparent;
  color: #f1f1e8;
  padding: 8px;
  text-align: left;
}

.tap-entry:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.tap-entry.selected {
  border-color: #16c7bd;
  background: rgba(22, 199, 189, 0.14);
}

.tap-entry span,
.tap-entry strong,
.tap-entry small {
  overflow-wrap: anywhere;
}

.tap-entry span {
  font-weight: 700;
}

.tap-entry small {
  color: #aeb5a7;
}

dl {
  display: grid;
  gap: 0;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-block: 8px;
}

dt {
  color: #c9c9bd;
}

dd {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  max-width: 130px;
  overflow-wrap: anywhere;
  text-align: right;
}

.debug-drawer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 13, 12, 0.52);
}

.debug-drawer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  padding: 12px 14px;
  list-style: none;
}

.debug-drawer summary::-webkit-details-marker {
  display: none;
}

.debug-drawer summary span {
  font-weight: 800;
}

.debug-drawer summary strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}

.debugger {
  display: grid;
  grid-template-areas:
    "registers disassembly"
    "basic memory";
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.4fr);
  gap: 12px;
  align-items: start;
  padding: 0 12px 12px;
}

.debug-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 13, 12, 0.76);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.26);
  padding: 12px;
}

.debug-card h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.register-grid,
.basic-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(54px, 1fr));
  gap: 6px;
}

.register-cell,
.basic-cell {
  min-width: 0;
  border: 1px solid rgba(241, 241, 232, 0.12);
  border-radius: 6px;
  background: var(--panel);
  padding: 7px 8px;
}

.register-cell span,
.basic-cell span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
}

.register-cell strong,
.basic-cell strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--text);
  font: 700 13px/1 "SFMono-Regular", Consolas, monospace;
}

.flag-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 10px;
}

.flag {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #777d72;
  font: 700 11px/24px "SFMono-Regular", Consolas, monospace;
  text-align: center;
}

.flag.on {
  border-color: var(--accent);
  background: var(--accent);
  color: #051615;
}

.basic-card {
  grid-area: basic;
}

.registers-card {
  grid-area: registers;
}

.basic-status {
  grid-template-columns: repeat(3, minmax(70px, 1fr));
}

.disassembly-card {
  grid-area: disassembly;
}

.disassembly {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
  font: 12px/1.35 "SFMono-Regular", Consolas, monospace;
}

.disassembly li {
  display: grid;
  grid-template-columns: 48px 78px minmax(0, 1fr);
  gap: 8px;
  border-radius: 5px;
  padding: 4px 6px;
  color: #d8d8cf;
}

.disassembly li.current {
  background: var(--yellow);
  color: #14130c;
}

.disassembly .addr,
.disassembly .bytes {
  color: inherit;
  opacity: 0.78;
}

.disassembly .asm {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.memory-card {
  grid-area: memory;
}

.memory-inspector {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.memory-inspector h3 {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.memory-inspector pre {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font: 11px/1.45 "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

@media (min-width: 1280px) {
  .debugger {
    grid-template-areas:
      "registers disassembly memory"
      "basic disassembly memory";
    grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.1fr) minmax(360px, 1.35fr);
  }
}

@media (max-width: 1180px) {
  body {
    place-items: start center;
    padding: 14px 0;
  }

  .shell {
    width: min(100vw - 24px, 1480px);
    grid-template-columns: minmax(0, 1fr) clamp(280px, 28vw, 340px);
  }

  #screen {
    width: min(100%, 760px);
    max-height: 58vh;
  }

  .debugger {
    grid-template-areas:
      "registers disassembly"
      "basic memory";
    grid-template-columns: minmax(240px, 0.85fr) minmax(300px, 1.3fr);
  }

  .register-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

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

  .panel {
    order: -1;
    position: static;
  }

  .tool-tabs {
    grid-template-columns: repeat(4, minmax(64px, 1fr));
  }

  .debugger {
    grid-template-areas:
      "registers"
      "basic"
      "disassembly"
      "memory";
    grid-template-columns: 1fr;
  }

  .memory-inspector {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 20px, 1480px);
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .register-grid,
  .basic-status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .disassembly li {
    grid-template-columns: 44px 68px minmax(0, 1fr);
    gap: 6px;
  }
}

.spectrum-page-body {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(14px, 2vw, 22px);
  align-items: center;
  justify-items: center;
  min-height: 100vh;
  padding: clamp(14px, 2.4vw, 28px);
  overflow-x: hidden;
}

.spectrum-page-body .shell {
  width: min(1540px, 100%);
}

.selector-body,
.cpm-page-body {
  display: block;
  min-height: 100vh;
  padding: clamp(14px, 2.4vw, 28px);
  background:
    linear-gradient(180deg, rgba(4, 7, 10, 0.72), rgba(17, 13, 11, 0.92)),
    #08090a;
  overflow-x: hidden;
}

.selector-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  gap: clamp(14px, 2vw, 22px);
}

.selector-hero {
  position: relative;
  min-height: clamp(360px, 62vh, 680px);
  overflow: hidden;
  border: 1px solid rgba(241, 241, 232, 0.18);
  border-radius: 8px;
  background: #07090b;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48);
}

.selector-hero-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selector-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(3, 5, 8, 0.68), rgba(3, 5, 8, 0.06) 42%, rgba(3, 5, 8, 0.56)),
    repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 4px);
  pointer-events: none;
}

.selector-overlay {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  align-content: start;
  min-height: inherit;
  padding: clamp(28px, 6vw, 72px) clamp(18px, 5vw, 60px);
  text-align: center;
}

.selector-kicker {
  margin: 0 0 8px;
  color: #f3d447;
  font: 700 14px/1.2 "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
}

.selector-overlay h1 {
  max-width: 12ch;
  margin: 0;
  color: #fffbe8;
  font-size: clamp(42px, 8vw, 92px);
  line-height: 0.94;
  text-shadow: 0 8px 32px rgba(0, 0, 0, 0.85);
}

.machine-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 18px);
}

.machine-link {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-height: 136px;
  border: 1px solid rgba(241, 241, 232, 0.18);
  border-radius: 8px;
  background: rgba(12, 16, 18, 0.92);
  color: var(--text);
  padding: 18px;
  text-decoration: none;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

.machine-link:hover,
.machine-link:focus-visible {
  border-color: rgba(243, 212, 71, 0.78);
  outline: none;
  transform: translateY(-1px);
}

.machine-link strong,
.machine-link small {
  grid-column: 2;
}

.machine-link strong {
  align-self: end;
  font-size: 24px;
  line-height: 1.05;
}

.machine-link small {
  align-self: start;
  color: #bbc4b7;
  font-size: 14px;
  line-height: 1.35;
}

.machine-screen {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 96px;
  aspect-ratio: 4 / 3;
  border: 8px solid #2a2925;
  border-radius: 6px;
  background: #060606;
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.85), 0 10px 24px rgba(0, 0, 0, 0.38);
}

.spectrum-screen span {
  width: 58px;
  height: 40px;
  background:
    linear-gradient(135deg, transparent 0 38%, #f3d447 38% 46%, #21c763 46% 54%, #16c7bd 54% 62%, #d946ef 62% 70%, transparent 70%),
    linear-gradient(180deg, #213fdd 0 34%, #d92d20 34% 66%, #111 66%);
  image-rendering: pixelated;
}

.cpm-screen {
  color: #5dff8b;
  font: 700 24px/1 "SFMono-Regular", Consolas, monospace;
  text-shadow: 0 0 12px rgba(93, 255, 139, 0.85);
}

.cpm-screen::after {
  content: "";
  width: 8px;
  height: 18px;
  margin-left: 4px;
  background: #5dff8b;
  box-shadow: 0 0 12px rgba(93, 255, 139, 0.85);
}

.site-contact-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(1180px, 100%);
  margin: 0 auto;
  min-height: 68px;
  border: 1px solid rgba(93, 255, 139, 0.18);
  border-radius: 8px;
  background:
    repeating-linear-gradient(180deg, rgba(93, 255, 139, 0.035) 0 1px, transparent 1px 4px),
    rgba(6, 13, 9, 0.78);
  color: #bbc4b7;
  font: 700 13px/1.2 "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
}

.cpm-page-body .site-contact-footer {
  width: min(980px, 100%);
  margin-top: clamp(14px, 2vw, 22px);
}

.site-contact-footer img {
  width: min(194px, 52vw);
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 10px rgba(93, 255, 139, 0.56));
}

.machine-nav {
  width: min(980px, 100%);
  margin: 0 auto 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.machine-nav a {
  border: 1px solid rgba(241, 241, 232, 0.2);
  border-radius: 6px;
  color: var(--text);
  background: rgba(12, 16, 18, 0.86);
  padding: 9px 12px;
  text-decoration: none;
}

.cpm-shell {
  width: min(980px, 100%);
  margin: 0 auto;
}

.cpm-terminal-frame {
  display: grid;
  gap: 16px;
  border: 1px solid rgba(93, 255, 139, 0.28);
  border-radius: 8px;
  background: rgba(7, 12, 9, 0.92);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48);
  padding: clamp(14px, 2vw, 22px);
}

.cpm-terminal-frame header {
  display: grid;
  gap: 2px;
}

.cpm-terminal-frame p {
  margin: 0;
  color: #5dff8b;
  font: 700 13px/1.2 "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
}

.cpm-terminal-frame h1 {
  margin: 0;
  font-size: 28px;
}

.cpm-terminal-frame output {
  color: #bbc4b7;
  font: 13px/1.3 "SFMono-Regular", Consolas, monospace;
}

.cpm-terminal {
  min-height: min(58vh, 520px);
  margin: 0;
  overflow: auto;
  border: 1px solid rgba(93, 255, 139, 0.25);
  border-radius: 6px;
  background:
    repeating-linear-gradient(180deg, rgba(93, 255, 139, 0.05) 0 1px, transparent 1px 4px),
    #031006;
  color: #72ff98;
  font: 18px/1.45 "SFMono-Regular", Consolas, monospace;
  padding: 18px;
  white-space: pre-wrap;
  text-shadow: 0 0 14px rgba(93, 255, 139, 0.42);
}

.cpm-terminal:focus-visible {
  outline: 3px solid #f3d447;
  outline-offset: 3px;
}

.cpm-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.cpm-profile-control {
  display: grid;
  gap: 4px;
  color: #bbc4b7;
  font: 12px/1.2 "SFMono-Regular", Consolas, monospace;
}

.cpm-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.cpm-file-panel {
  display: grid;
  gap: 10px;
  border-top: 1px solid rgba(93, 255, 139, 0.22);
  padding-top: 14px;
}

.cpm-file-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cpm-file-panel header p {
  margin: 0;
}

.cpm-file-panel header button {
  min-height: 32px;
}

.cpm-controls select,
.cpm-file-panel select {
  width: 100%;
  border: 1px solid rgba(93, 255, 139, 0.25);
  border-radius: 6px;
  background: #031006;
  color: #72ff98;
  font: 14px/1.4 "SFMono-Regular", Consolas, monospace;
  padding: 8px;
}

.cpm-file-panel header select {
  max-width: 180px;
}

.cpm-file-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 780px) {
  .selector-hero {
    min-height: 520px;
  }

  .selector-hero-image {
    object-position: center bottom;
  }

  .machine-grid {
    grid-template-columns: 1fr;
  }

  .machine-link {
    grid-template-columns: 82px minmax(0, 1fr);
    min-height: 124px;
    padding: 14px;
  }

  .machine-screen {
    width: 82px;
  }

  .machine-link strong {
    font-size: 20px;
  }

  .site-contact-footer {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .cpm-controls {
    grid-template-columns: 1fr;
  }

  .cpm-file-controls {
    grid-template-columns: 1fr;
  }
}
