:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #171717;
  color: #f4f0e7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 34rem),
    #171717;
}

button {
  font: inherit;
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #e38b31;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow a {
  color: inherit;
  text-decoration: none;
}

.eyebrow a:hover {
  text-decoration: underline;
}

.intro {
  max-width: 68ch;
  margin: 0 0 22px;
  color: #c9c4b8;
  line-height: 1.55;
}

.intro a {
  color: #f2b96d;
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.system-card {
  display: block;
  padding: 16px 18px;
  border: 1px solid #4c4943;
  border-radius: 4px;
  background: #202020;
  color: inherit;
  text-decoration: none;
  transition: border-color 120ms ease, background 120ms ease;
}

.system-card:hover {
  border-color: #e38b31;
  background: #262421;
}

.system-card h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  color: #f2b96d;
}

.system-card p {
  margin: 0;
  color: #b8b9ac;
  font-size: 0.85rem;
  line-height: 1.45;
}

.variant-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 16px;
  border: 1px solid #4c4943;
  border-radius: 4px;
  background: #202020;
}

.variant-picker label {
  color: #b8b9ac;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.variant-picker select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #5d584f;
  border-radius: 2px;
  background: #3d3b37;
  color: #ddd6c8;
  font: inherit;
}

.variant-picker button {
  padding: 8px 18px;
  border: 1px solid #757066;
  border-radius: 2px;
  background: #8a451e;
  color: white;
  font-weight: 750;
  cursor: pointer;
}

.variant-picker button:hover {
  background: #a4531f;
}

.variant-picker button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.variant-picker.started {
  display: none;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  letter-spacing: -0.04em;
}

.machine-state {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 210px;
  justify-content: flex-end;
  color: #c9c4b8;
  font: 0.82rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: right;
}

.state-lamp {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #666;
  box-shadow: 0 0 0 2px #0d0d0d;
}

.state-lamp.running {
  background: #ff9c36;
  box-shadow: 0 0 11px #ff7b00, 0 0 0 2px #0d0d0d;
}

.state-lamp.error {
  background: #e14b3d;
  box-shadow: 0 0 11px #e14b3d, 0 0 0 2px #0d0d0d;
}

.panel {
  overflow: hidden;
  border: 6px solid #d8d0bc;
  border-radius: 4px;
  background: #242424;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

.panel-brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 11px 18px;
  background: #cf5c27;
  color: #fff7e8;
  letter-spacing: 0.05em;
}

.panel-brand span {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: lowercase;
}

.panel-brand strong {
  font-size: 1.15rem;
  letter-spacing: 0.12em;
}

.lamp-section,
.switch-section {
  padding: 12px 16px 15px;
  border-top: 1px solid #4f4b43;
}

.lamp-section.compact {
  background: #20201f;
}

.section-label {
  margin-bottom: 7px;
  color: #aaa396;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.address-bits {
  grid-template-columns: repeat(22, minmax(18px, 1fr));
}

.data-bits {
  grid-template-columns: repeat(16, minmax(18px, 1fr));
}

.bit-labels,
.lamps,
.switches {
  display: grid;
  gap: clamp(3px, 0.55vw, 9px);
  align-items: center;
}

.bit-labels {
  margin-bottom: 5px;
  color: #858077;
  font: 0.58rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}

.lamp {
  width: clamp(8px, 1.05vw, 14px);
  aspect-ratio: 1;
  justify-self: center;
  border: 1px solid #5a4e3b;
  border-radius: 50%;
  background: #251f17;
  box-shadow: inset 0 0 4px #050505;
}

.lamp.on {
  border-color: #ffb04c;
  background: #ff9d2f;
  box-shadow: 0 0 6px #ff7a00, 0 0 13px rgba(255, 114, 0, 0.75);
}

.status-labels,
.status-lamps {
  display: grid;
  grid-template-columns: repeat(11, minmax(48px, 1fr));
  gap: 8px;
  text-align: center;
}

.status-labels {
  margin-bottom: 6px;
  color: #aaa396;
  font-size: clamp(0.48rem, 0.7vw, 0.65rem);
}

.controls {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 14px;
  padding: 14px 16px;
  border-top: 1px solid #4f4b43;
  background: #2d2c29;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 9px;
  border: 1px solid #5d584f;
}

legend {
  padding: 0 6px;
  color: #b7b0a2;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.selector-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.data-selector {
  grid-template-columns: repeat(2, 1fr);
}

.selector-grid button,
.action-buttons button {
  min-height: 34px;
  border: 1px solid #757066;
  border-radius: 2px;
  background: #3d3b37;
  color: #ddd6c8;
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 750;
}

.selector-grid button:hover,
.action-buttons button:hover {
  background: #4b4842;
}

.selector-grid button.selected {
  border-color: #f2a043;
  background: #8a451e;
  color: white;
  box-shadow: inset 0 0 0 1px #e3792f;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-content: end;
}

.action-buttons .danger {
  border-color: #a95a50;
  background: #662f2a;
}

.action-buttons button.active {
  background: #bd6c23;
  color: white;
}

.switch {
  position: relative;
  width: clamp(14px, 1.6vw, 23px);
  height: 42px;
  justify-self: center;
  border: 0;
  border-radius: 2px;
  background: #111;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px #4f4a42;
}

.switch::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 4px;
  height: 16px;
  border-radius: 1px;
  background: #b7ad98;
  box-shadow: 0 2px 3px #050505;
  transition: transform 80ms ease, background 80ms ease;
}

.switch.on::after {
  transform: translateY(-17px);
  background: #ec8b35;
}

.terminal-section {
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid #4c4943;
  border-radius: 4px;
  background: #090b09;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.32);
}

.terminal-title {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 9px 13px;
  background: #252722;
  color: #b8b9ac;
  font-size: 0.72rem;
}

.terminal-title > span:first-child {
  color: #e38b31;
  font-weight: 800;
  letter-spacing: 0.13em;
}

code {
  color: #f2b96d;
}

#terminal {
  height: min(42vh, 470px);
  margin: 0;
  overflow: auto;
  padding: 16px;
  outline: none;
  color: #9eee87;
  background: #090b09;
  font: clamp(0.78rem, 1.4vw, 1rem)/1.36 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  tab-size: 8;
  text-shadow: 0 0 5px rgba(118, 255, 97, 0.35);
}

#terminal::after {
  content: "";
  display: inline-block;
  width: 0.62em;
  height: 1.05em;
  margin-left: 0.08em;
  vertical-align: -0.16em;
  background: #6d8966;
}

#terminal:focus::after {
  background: #9eee87;
  box-shadow: 0 0 7px rgba(118, 255, 97, 0.7);
  animation: terminal-cursor 1s steps(1, end) infinite;
}

#terminal:focus {
  box-shadow: inset 0 0 0 2px #446c3d;
}

#terminal.bell {
  background: #26321f;
}

@keyframes terminal-cursor {
  0%,
  45% {
    opacity: 1;
  }

  46%,
  100% {
    opacity: 0;
  }
}

.error {
  padding: 12px 14px;
  border: 1px solid #a94e43;
  border-radius: 3px;
  background: #461f1b;
  color: #ffd4cf;
  font: 0.85rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 900px) {
  main {
    padding: 12px;
  }

  .masthead {
    align-items: start;
    flex-direction: column;
  }

  .machine-state {
    justify-content: flex-start;
    text-align: left;
  }

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

  .action-buttons {
    grid-template-columns: 1fr 1fr;
  }

  .panel {
    overflow-x: auto;
  }

  .lamp-section,
  .switch-section,
  .controls {
    min-width: 760px;
  }
}

.site-footer {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(244, 240, 231, 0.12);
  text-align: center;
  font-size: 0.85rem;
  color: #858077;
}

.site-footer a {
  color: inherit;
  text-decoration: underline;
}

.site-footer em {
  font-style: italic;
}

.category-heading {
  margin: 2rem 0 1rem;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #aaa396;
}

.category-heading:first-of-type {
  margin-top: 1.5rem;
}
