:root {
  color-scheme: dark;
  --bg: #010501;
  --case: #050c05;
  --case-dark: #020602;
  --screen: #020802;
  --screen-soft: #061206;
  --panel: rgba(3, 12, 4, 0.95);
  --ink: #d9ffd9;
  --muted: #86c986;
  --dim: #3e6d3f;
  --line: #1e5c25;
  --line-strong: #51ff68;
  --accent: #39ff56;
  --accent-strong: #effff0;
  --glow: #9dffa8;
  --glow-soft: #0d1d0f;
  --danger: #a8ff9e;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.62), inset 0 0 0 1px rgba(57, 255, 86, 0.08);
  font-family: "Courier New", Courier, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(57, 255, 86, 0.13), transparent 36rem),
    radial-gradient(circle at 90% 100%, rgba(57, 255, 86, 0.055), transparent 28rem),
    linear-gradient(135deg, #020602, #000 58%, #041004);
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.025),
    rgba(255, 255, 255, 0.025) 1px,
    transparent 1px,
    transparent 4px
  );
  opacity: 0.42;
  mix-blend-mode: screen;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, transparent 46%, rgba(0, 0, 0, 0.46) 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1460px, calc(100% - 24px));
  height: calc(100vh - 24px);
  margin: 12px auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(57, 255, 86, 0.055), transparent 90px),
    var(--case);
  border: 1px solid #173d1c;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.app-shell::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(57, 255, 86, 0.16);
  border-radius: 5px;
  pointer-events: none;
}

.app-header {
  min-height: 0;
  padding: 8px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(57, 255, 86, 0.085), rgba(2, 8, 2, 0.97));
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 0;
  color: var(--accent-strong);
  font-size: clamp(1.45rem, 2.5vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 0 16px rgba(57, 255, 86, 0.38);
}

.app-header > p:not(.eyebrow) {
  max-width: 980px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.top-note {
  color: var(--glow) !important;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.left-column,
.right-column {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.left-column {
  grid-template-rows: minmax(0, 1.15fr) minmax(0, 0.85fr);
}

.right-column {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.panel,
.metric {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(57, 255, 86, 0.052), transparent 78px),
    var(--panel);
  box-shadow: inset 0 0 28px rgba(57, 255, 86, 0.05);
}

.panel {
  overflow: auto;
  padding: 12px;
}

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

.section-heading h2 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.96rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button,
.primary-button,
.example-strip button,
.segmented button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--case-dark);
  color: var(--ink);
}

.icon-button:hover,
.primary-button:hover,
.example-strip button:hover,
.segmented button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  box-shadow: 0 0 18px rgba(57, 255, 86, 0.2);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  flex: 0 0 34px;
  font-weight: 900;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  padding: 0 16px;
  background: #1d341d;
  color: var(--accent-strong);
  border-color: var(--line-strong);
  font-weight: 800;
  text-transform: uppercase;
}

.example-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.example-strip button {
  padding: 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}

.instruction-list {
  display: grid;
  gap: 7px;
}

.instruction-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: center;
}

.instruction-row label {
  color: var(--glow);
  font-weight: 900;
}

.instruction-combo {
  position: relative;
  min-width: 0;
}

.instruction-combo.open {
  z-index: 20;
}

.instruction-row input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 68px 0 12px;
  color: var(--ink);
  background: var(--screen);
  caret-color: var(--accent);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.instruction-row input:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 20px rgba(57, 255, 86, 0.08), 0 0 16px rgba(57, 255, 86, 0.16);
}

.instruction-row input::placeholder {
  color: var(--dim);
}

.combo-arrow {
  position: absolute;
  top: 1px;
  right: 1px;
  bottom: 1px;
  display: grid;
  place-items: center;
  width: 54px;
  border-left: 1px solid var(--line);
  border-radius: 0 3px 3px 0;
  background: #172617;
  color: var(--glow);
  font-size: 0.66rem;
  font-weight: 900;
  pointer-events: none;
}

.instruction-suggestions {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  display: none;
  max-height: min(252px, 48vh);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #081209;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.72), 0 0 24px rgba(57, 255, 86, 0.15);
}

.instruction-combo.open .instruction-suggestions {
  display: grid;
}

.instruction-suggestions button {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid rgba(57, 255, 86, 0.18);
  border-radius: 0;
  padding: 7px 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.instruction-suggestions button:hover,
.instruction-suggestions button:focus-visible {
  background: #173219;
  color: var(--accent-strong);
}

.instruction-suggestions span {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instruction-suggestions small {
  color: var(--glow);
  font-size: 0.64rem;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.hidden {
  display: none;
}

.error-box {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--accent-strong);
  background: #071607;
}

.controls-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.control-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.control-label {
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 190px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--screen);
}

.segmented button {
  min-height: 30px;
  border: 0;
  background: transparent;
  font-weight: 900;
  text-transform: uppercase;
}

.segmented button.active {
  background: #1d3a1d;
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
}

.switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.run-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.cycle-readout {
  min-width: 112px;
  color: var(--muted);
  text-align: right;
  text-transform: uppercase;
}

.cycle-readout strong {
  color: var(--accent-strong);
  font-size: 1.18rem;
  text-shadow: 0 0 12px rgba(57, 255, 86, 0.42);
}

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

.metric {
  min-height: 58px;
  padding: 9px 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 3px;
  color: var(--accent-strong);
  font-size: 1.45rem;
}

.stage-key {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.stage-key span {
  border-radius: 4px;
  padding: 4px 7px;
  background: #102111;
  color: var(--accent);
  border: 1px solid var(--line);
  font-size: 0.7rem;
  font-weight: 900;
}

.table-wrap {
  overflow-x: auto;
  max-height: calc(100vh - 322px);
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--screen);
  position: relative;
}

.trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.trace-legend span {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(13, 27, 16, 0.8);
  padding: 4px 6px;
}

.pipeline-table {
  width: auto;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.pipeline-table th,
.pipeline-table td {
  width: 84px;
  min-width: 84px;
  height: 38px;
  padding: 0 6px;
  border-right: 1px solid rgba(54, 85, 47, 0.85);
  border-bottom: 1px solid rgba(54, 85, 47, 0.85);
  text-align: center;
  vertical-align: middle;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}

.pipeline-table thead th {
  background: #0d1b10;
  color: var(--muted);
  font-size: 0.74rem;
}

.pipeline-table .instruction-col {
  width: 248px;
  min-width: 248px;
  padding: 0 9px;
  background: #0d1b10;
  color: var(--ink);
  text-align: left;
  font-size: 0.8rem;
  position: sticky;
  left: 0;
  z-index: 3;
  box-shadow: 1px 0 0 rgba(54, 85, 47, 0.95), 10px 0 18px rgba(0, 0, 0, 0.28);
}

.pipeline-table thead .instruction-col {
  z-index: 4;
}

.instruction-badge {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 22px;
  margin-right: 6px;
  border-radius: 4px;
  background: #172617;
  color: var(--glow);
  border: 1px solid var(--line);
  font-weight: 900;
}

.stage-cell {
  background: #102611;
  color: var(--accent-strong);
  font-weight: 900;
  font-size: 0.78rem;
  text-shadow: 0 0 10px rgba(112, 255, 99, 0.38);
}

.stage-cell::before {
  content: "[";
  color: var(--muted);
}

.stage-cell::after {
  content: "]";
  color: var(--muted);
}

.stall-cell {
  background:
    linear-gradient(180deg, rgba(57, 255, 86, 0.16), rgba(57, 255, 86, 0.055)),
    #071507;
  color: var(--accent-strong);
  font-weight: 900;
  font-size: 0.74rem;
  text-shadow: 0 0 12px rgba(57, 255, 86, 0.48);
}

.stall-cell::before {
  content: "!";
  color: var(--glow);
}

.stall-cell::after {
  content: "!";
  color: var(--glow);
}

.future-cycle {
  background: #07100a;
  color: transparent;
}

.future-cycle.stall-cell {
  background: #07100a;
  text-shadow: none;
}

.current-cycle {
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 16px rgba(57, 255, 86, 0.26);
}

.hazard-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.hazard-list li,
.hazard-empty {
  padding: 8px;
  border-radius: 4px;
  background: var(--screen-soft);
  border: 1px solid var(--line);
}

.hazard-list p,
.hazard-empty {
  margin: 3px 0;
  color: var(--muted);
}

.hazard-list span {
  color: var(--glow);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: calc(100vh - 24px);
  }

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

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

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 16px, 1460px);
    height: auto;
    margin: 8px auto;
    padding: 10px;
  }

  .controls-panel,
  .control-group,
  .run-controls {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

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

  .pipeline-table .instruction-col {
    width: 228px;
    min-width: 228px;
  }
}
