: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;
}

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;
  }
}
