:root {
  --bg: #111820;
  --panel: #1a2430;
  --panel-2: #202d3a;
  --line: #38495b;
  --text: #e4edf5;
  --muted: #93a6b8;
  --accent: #62c4d8;
  --accent-2: #d8bf62;
  --danger: #e06b6b;
  --ok: #79d88d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: #0d131a;
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
select,
input,
textarea {
  font: inherit;
}

.app-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px;
}

.top-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  background: #16202b;
}

h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
}

p {
  margin: 0;
}

.top-panel p,
.field-label,
.current-command span,
.register span,
.example-row label,
.memory-toolbar label,
.memory-toolbar span {
  color: var(--muted);
}

.status-lamps {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 145px;
  justify-content: flex-end;
}

.lamp {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 12px var(--danger);
}

.lamp.running {
  background: var(--ok);
  box-shadow: 0 0 12px var(--ok);
}

.layout {
  display: grid;
  grid-template-columns: 1.15fr 1.6fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.panel-title {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #223142;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 13px;
}

.registers-panel,
.command-panel,
.editor-panel,
.io-panel,
.log-panel {
  padding-bottom: 12px;
}

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

.register {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: #121b25;
}

.register strong {
  color: var(--accent-2);
  font-family: "Courier New", monospace;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.current-command {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.current-command > div {
  padding: 10px;
  border: 1px solid var(--line);
  background: #121b25;
}

.current-command strong {
  display: block;
  margin-top: 5px;
  font-family: "Courier New", monospace;
  color: var(--accent-2);
  overflow-wrap: anywhere;
}

.decode p {
  margin-top: 5px;
  color: var(--text);
  line-height: 1.4;
}

.editor-panel {
  grid-row: span 2;
}

.example-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 0;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--text);
  background: #101821;
}

select,
input {
  min-height: 38px;
  padding: 8px 10px;
}

#programInput {
  display: block;
  width: calc(100% - 24px);
  height: 340px;
  margin: 12px;
  padding: 12px;
  resize: vertical;
  font-family: "Courier New", monospace;
  line-height: 1.45;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 12px;
}

button {
  min-height: 40px;
  border: 1px solid #4c6075;
  color: var(--text);
  background: #26384a;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: #2e4459;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

.memory-panel {
  grid-column: span 2;
}

.memory-toolbar {
  display: grid;
  grid-template-columns: auto minmax(120px, 180px) auto auto auto auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #17212d;
}

.memory-toolbar label,
.memory-toolbar span,
.memory-note {
  font-size: 13px;
}

.memory-toolbar input {
  min-height: 38px;
}

.memory-toolbar button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.memory-toolbar span {
  justify-self: end;
  text-align: right;
}

.memory-format {
  display: inline-flex;
  border: 1px solid var(--line);
  background: #101821;
}

.memory-format button {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
}

.memory-format button:last-child {
  border-right: 0;
}

.memory-format button.active {
  color: #081018;
  background: var(--accent);
}

.memory-note {
  margin: 0;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.45;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
}

.command-table-wrap {
  max-height: 280px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Courier New", monospace;
  font-size: 14px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid #2c3b4a;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #172332;
  color: var(--muted);
  z-index: 1;
}

tr.current-row td {
  background: #3a3440;
  color: #fff2b0;
}

tr.data-row td {
  color: #bdd7c6;
}

.io-panel,
.log-panel {
  min-height: 260px;
}

.field-label {
  display: block;
  padding: 12px 12px 6px;
  font-size: 13px;
}

#inputBuffer,
#outputWindow {
  width: calc(100% - 24px);
  margin: 0 12px;
}

#outputWindow {
  height: 145px;
  padding: 10px;
  resize: vertical;
  font-family: "Courier New", monospace;
}

.log-window {
  height: 250px;
  margin: 12px;
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #101821;
  font-family: "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.error-line {
  color: var(--danger);
}

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

  .editor-panel,
  .memory-panel {
    grid-column: span 2;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .top-panel,
  .layout {
    display: block;
  }

  .panel {
    margin-top: 12px;
  }

  .control-row,
  .register-grid,
  .memory-toolbar {
    grid-template-columns: 1fr;
  }

  .memory-toolbar span {
    justify-self: start;
    text-align: left;
  }

  .top-panel {
    padding: 14px;
  }

  h1 {
    font-size: 20px;
  }
}
