:root {
  --control-width: 260px;
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #5c6875;
  --line: #d9e0e7;
  --accent: #f26a21;
  --accent-dark: #a94310;
  --green: #2d8a4b;
  --blue: #2468b2;
  --off: #d2d8df;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

select,
input {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input {
  padding: 0 10px;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
}

h2 {
  font-size: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.status,
output,
.hint,
#serialStatus {
  color: var(--muted);
  font-size: 13px;
}

.panel-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

textarea {
  width: 100%;
  min-height: 390px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  color: #101820;
  background: #fbfcfd;
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.hint {
  margin-top: 10px;
}

.assemble-row {
  display: flex;
  justify-content: center;
  margin: 8px 0;
}

.assemble-row button {
  min-width: 160px;
}

.program-preview {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 10px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.subhead {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.machine-code-input {
  display: block;
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  overflow: auto;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.program-preview .hint {
  margin-top: 8px;
}

.destination-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.destination-card {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.destination-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.destination-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.destination-emulator {
  border-top: 3px solid var(--blue);
}

.destination-hardware {
  border-top: 3px solid var(--accent);
}

.destination-card button {
  width: 100%;
}

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

.hardware-settings label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.cpu-io-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
  margin-bottom: 12px;
}

.cpu-debug-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
  margin-top: 4px;
}

.display-row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 16px;
  align-items: start;
}

.io-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}


.io-block {
  margin: 0;
}

.seven-seg {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid #2c3136;
  border-radius: 8px;
  background: #101418;
}

.seg {
  position: absolute;
  display: block;
  border-radius: 999px;
  background: #3b1514;
}

.seg.on {
  background: #ff3b30;
  box-shadow: 0 0 12px rgba(255, 59, 48, 0.55);
}

.seg-0,
.seg-3,
.seg-6 {
  left: 27%;
  width: 46%;
  height: 7%;
}

.seg-0 {
  top: 12%;
}

.seg-6 {
  top: 46.5%;
}

.seg-3 {
  bottom: 12%;
}

.seg-1,
.seg-2,
.seg-4,
.seg-5 {
  width: 7%;
  height: 33%;
}

.seg-1 {
  top: 16%;
  right: 19%;
}

.seg-2 {
  right: 19%;
  bottom: 16%;
}

.seg-4 {
  left: 19%;
  bottom: 16%;
}

.seg-5 {
  top: 16%;
  left: 19%;
}

.seg-7 {
  right: 9%;
  bottom: 11%;
  width: 8%;
  height: 8%;
}

.led-bank {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  width: var(--control-width);
}

.led {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--off);
  border: 1px solid #b8c0c8;
}

.led.on {
  background: var(--green);
  box-shadow: 0 0 12px rgba(45, 138, 75, 0.55);
}

.control-cluster {
  display: flex;
  gap: 8px;
  align-items: start;
  width: var(--control-width);
}

.keyboard-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.hw-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hw-btn {
  width: 44px;
  height: 38px;
  min-height: 38px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hw-btn.adr-active {
  border-color: var(--blue);
  background: #e8f0fb;
}

.control-cluster.write-mode .keyboard-grid button {
  border-color: var(--blue);
  background: #f0f4fd;
}

.control-cluster.write-mode .keyboard-grid button:hover {
  border-color: var(--blue);
  background: #dde8f8;
}

.hw-btn.running {
  border-color: var(--green);
  background: #e8f5ec;
}

.buzzer-title {
  margin-top: 14px;
}

.buzzer-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.buzzer {
  width: 42px;
  height: 24px;
  border-radius: 6px;
  background: #2c3136;
  border: 2px solid #444c55;
  flex-shrink: 0;
  transition: background 0.08s, box-shadow 0.08s;
}

.buzzer.on {
  background: #ff9500;
  border-color: #cc7700;
  box-shadow: 0 0 14px rgba(255, 149, 0, 0.65);
  animation: buzz-pulse 0.18s ease-in-out;
}

@keyframes buzz-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.buzzer-label {
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.keyboard-grid button {
  width: 100%;
  height: 38px;
  min-height: 38px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.keyboard-grid button.active {
  border-color: var(--accent);
  background: #fff1e8;
}

.machine-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: start;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
}

.machine-meta output {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.register-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(64px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.register,
.memory-cell {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfd;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.register span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(16, minmax(30px, 1fr));
  gap: 4px;
}

.memory-cell {
  min-height: 34px;
  padding: 7px 4px;
  text-align: center;
  font-size: 13px;
}

.memory-cell.active {
  border-color: var(--accent);
  background: #fff1e8;
}

.accordion {
  margin-top: 10px;
}

.accordion-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  cursor: pointer;
  user-select: none;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.accordion-summary::before {
  content: '▶';
  font-size: 9px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

details[open] > .accordion-summary::before {
  transform: rotate(90deg);
}

.cpu-debug-accordion {
  margin-top: 12px;
}

.source-samples {
  margin-top: 8px;
}

.examples-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.examples-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.example-card {
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  min-height: auto;
}

.example-card:hover {
  border-color: var(--accent);
  background: #fff8f4;
}

.example-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
}

.example-desc {
  font-size: 12px;
  color: var(--muted);
}

.keypad-guide-section {
  margin-top: 16px;
}

.guide-steps {
  margin: 6px 0 12px;
  padding-left: 18px;
  font-size: 13px;
  line-height: 2;
  color: var(--text);
}

.guide-examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-example {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
}

.guide-example-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.guide-key-seq {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
}

.guide-key-seq span {
  color: var(--muted);
  font-size: 11px;
  padding: 0 1px;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid #b8c0c8;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #f4f6f8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-style: normal;
  color: var(--text);
  white-space: nowrap;
}

.serial-panel {
  margin-top: 16px;
}

.serial-panel .panel-header {
  align-items: start;
}

.serial-panel h2 + p {
  margin: 6px 0 0;
}

.monitor-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(88px, 1fr)) minmax(92px, 0.7fr) minmax(108px, 0.8fr);
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.monitor-grid button {
  min-width: 0;
}

.manual-send {
  display: grid;
  grid-template-columns: 1fr 88px 96px;
  gap: 8px;
  margin-bottom: 10px;
}

.serial-log {
  min-height: 180px;
  max-height: 260px;
  margin: 0;
  overflow: auto;
  border: 1px solid #202832;
  border-radius: 6px;
  background: #111820;
  color: #d8f3dc;
  padding: 12px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
    display: grid;
  }

  .panel-header,
  .preview-header {
    align-items: stretch;
    flex-direction: column;
  }

  .source-actions,
  .machine-actions {
    justify-content: start;
  }

  .display-row {
    grid-template-columns: 132px 1fr;
  }

  .memory-grid {
    grid-template-columns: repeat(8, minmax(30px, 1fr));
  }

  .serial-panel .panel-header,
  .monitor-grid,
  .manual-send,
  .destination-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .serial-actions {
    justify-content: start;
  }
}
