:root {
  --stack-ink: #0b2545;
  --stack-muted: #5d677a;
  --stack-soft: #eef3f8;
  --stack-surface: #ffffff;
  --stack-line: #d9e2ec;
  --stack-accent: #dc2626;
  --stack-accent-dark: #b91c1c;
  --stack-shadow: 0 20px 50px rgba(11, 37, 69, 0.12);
  --mono: "JetBrains Mono", "IBM Plex Mono", monospace;
}

body.stack-page {
  background-image: radial-gradient(circle at top right, rgba(220, 38, 38, 0.08), transparent 32%), url('images/xameco_bg_light.svg');
  background-repeat: no-repeat, no-repeat;
  background-position: right top, left bottom;
  background-size: 42rem auto, contain;
}

.stack-hero {
  padding: 88px 0 40px;
}

.stack-hero__inner {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 28px;
  align-items: start;
}

.stack-hero h1 {
  max-width: 16ch;
  font-size: clamp(2.4rem, 5.8vw, 4.25rem);
}

.stack-hero p {
  color: var(--muted);
  max-width: 60ch;
  font-size: 1.08rem;
  margin: 22px 0 0;
}

.stack-hero__card {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--stack-shadow);
  padding: 24px;
}

.stack-hero__label,
.panel-kicker,
.editor-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
}

.stack-hero__card ul {
  margin: 16px 0 0;
  padding-left: 20px;
  color: var(--ink);
}

.stack-workbench {
  padding-top: 18px;
  padding-bottom: 72px;
}

.stack-app {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.92fr);
  gap: 24px;
  align-items: start;
}

.stack-panel,
.editor-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--stack-shadow);
  overflow: hidden;
}

.stack-panel {
  padding: 24px;
}

.editor-panel {
  padding: 24px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 20px;
}

.panel-head h2 {
  font-size: clamp(1.45rem, 3vw, 2.1rem);
  margin-top: 6px;
}

.status-pill,
.status-text,
.trace-panel__head span {
  font-family: var(--mono);
  font-size: 0.84rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.08);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.is-running {
  background: rgba(11, 37, 69, 0.08);
  color: var(--stack-ink);
}

.status-pill.is-error {
  background: rgba(185, 28, 28, 0.09);
  color: var(--accent-dark);
}

.register-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stack-ruler {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(11, 37, 69, 0.1);
  border-radius: 18px;
  background: linear-gradient(90deg, rgba(220, 38, 38, 0.08), rgba(11, 37, 69, 0.04));
  color: var(--stack-ink);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stack-ruler span:nth-child(2) {
  text-align: center;
  color: var(--accent);
  font-weight: 700;
}

.mode-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.mode-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--stack-ink);
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mode-button.active {
  background: var(--stack-ink);
  color: #fff;
  border-color: transparent;
}

.mode-button:hover {
  transform: translateY(-1px);
}

.register-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--stack-surface);
  padding: 14px;
}

.register-card__name {
  display: block;
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.register-card__value {
  font-family: var(--mono);
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--stack-ink);
  word-break: break-all;
}

.stack-column-head {
  display: flex;
  justify-content: space-between;
  color: var(--stack-muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.stack-column {
  display: grid;
  gap: 10px;
  max-height: 700px;
  overflow: auto;
  padding-right: 4px;
}

.stack-slot {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) minmax(126px, auto) minmax(88px, auto);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #fff 0%, #fbfcfe 100%);
  padding: 14px 16px;
}

.stack-slot.is-empty {
  background: rgba(238, 243, 248, 0.55);
  color: var(--stack-muted);
}

.stack-slot.is-reserved {
  background: linear-gradient(180deg, rgba(11, 37, 69, 0.04), rgba(11, 37, 69, 0.02));
  border-style: dashed;
}

.stack-slot.is-value.stack-slot--esp {
  border-color: rgba(220, 38, 38, 0.45);
  box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.12);
}

.stack-slot.is-value.stack-slot--ebp {
  border-color: rgba(11, 37, 69, 0.42);
  box-shadow: inset 0 0 0 1px rgba(11, 37, 69, 0.12);
}

.stack-slot--top {
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.08);
}

.stack-slot--recent {
  animation: stackPulse 0.7s ease;
}

.stack-slot__address,
.stack-slot__content,
.stack-slot__signal,
.stack-slot__offset {
  font-family: var(--mono);
}

.stack-slot__address {
  color: var(--stack-muted);
  font-size: 0.88rem;
}

.stack-slot__content {
  font-weight: 700;
  color: var(--stack-ink);
  min-width: 0;
  word-break: break-word;
}

.stack-slot__content-wrap {
  min-width: 0;
}

.stack-slot__note {
  margin-top: 5px;
  color: var(--stack-muted);
  font-size: 0.77rem;
  line-height: 1.3;
}

.stack-slot__signal {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.stack-slot__offset {
  justify-self: end;
  color: var(--stack-muted);
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}

.stack-slot__markers {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.marker--esp {
  background: rgba(220, 38, 38, 0.12);
  color: var(--accent);
}

.marker--ebp {
  background: rgba(11, 37, 69, 0.1);
  color: var(--stack-ink);
}

.marker--saved,
.marker--reserved {
  background: rgba(93, 103, 122, 0.14);
  color: var(--stack-muted);
}

.stack-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  align-items: center;
  margin-top: 18px;
  color: var(--stack-muted);
  font-size: 0.84rem;
}

.stack-legend span {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.legend {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.legend--esp { background: var(--accent); }
.legend--ebp { background: var(--stack-ink); }
.legend--saved { background: var(--stack-muted); }
.legend--reserved { background: rgba(11, 37, 69, 0.18); }

.preset-row,
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.preset-row {
  margin-bottom: 16px;
}

.stack-button {
  border: none;
  border-radius: 999px;
  background: var(--stack-ink);
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.stack-button:hover {
  transform: translateY(-1px);
  opacity: 0.96;
}

.stack-button--secondary {
  background: transparent;
  color: var(--stack-ink);
  border: 1px solid var(--line);
}

.stack-button--ghost {
  background: rgba(220, 38, 38, 0.08);
  color: var(--accent-dark);
}

.editor-label {
  display: inline-block;
  margin-bottom: 10px;
}

#assembly-input {
  width: 100%;
  min-height: 360px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: #e5eef8;
  padding: 18px;
  font-family: var(--mono);
  font-size: 0.96rem;
  line-height: 1.6;
  resize: vertical;
  tab-size: 2;
}

#assembly-input:focus {
  outline: 2px solid rgba(220, 38, 38, 0.28);
  border-color: transparent;
}

.editor-help {
  color: var(--stack-muted);
  margin: 12px 0 0;
  font-size: 0.95rem;
}

.control-row {
  margin-top: 18px;
}

.explanation-panel {
  margin-top: 22px;
  border: 1px solid rgba(11, 37, 69, 0.08);
  border-radius: 20px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(11, 37, 69, 0.03), rgba(255, 255, 255, 0.92));
}

.explanation-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}

.explanation-panel__head h3 {
  font-size: 1rem;
  margin: 0;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.08);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#explanation-body {
  margin: 0;
  color: var(--stack-muted);
}

.trace-panel {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--stack-surface);
  overflow: hidden;
}

.trace-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.trace-panel__head h3 {
  font-size: 1rem;
  margin: 0;
}

.trace-list {
  display: grid;
  gap: 10px;
  padding: 16px 18px 18px;
  max-height: 340px;
  overflow: auto;
}

.trace-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fbfcfe;
  font-family: var(--mono);
  font-size: 0.9rem;
}

.trace-item.is-current {
  border-color: rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.06);
}

.trace-item__line {
  color: var(--stack-muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.trace-item__text {
  color: var(--stack-ink);
  white-space: pre-wrap;
}

.trace-item__meta {
  margin-top: 6px;
  color: var(--stack-muted);
  font-size: 0.8rem;
}

.trace-empty {
  color: var(--stack-muted);
  padding: 18px;
}

@keyframes stackPulse {
  0% {
    transform: translateY(-2px);
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.18);
  }
  100% {
    transform: translateY(0);
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.08);
  }
}

.stack-slot.is-current {
  border-color: rgba(220, 38, 38, 0.55);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.08);
}

@media (max-width: 1100px) {
  .stack-app,
  .stack-hero__inner {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 760px) {
  .stack-panel,
  .editor-panel {
    padding: 18px;
  }

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

  .stack-slot {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stack-slot__signal,
  .stack-slot__markers {
    justify-content: flex-start;
    text-align: left;
  }

  .stack-slot__offset {
    justify-self: start;
    text-align: left;
  }

  .panel-head {
    flex-direction: column;
  }

  .mode-row {
    flex-direction: column;
  }

  .stack-ruler,
  .stack-column-head {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .stack-ruler span:nth-child(2),
  .stack-column-head span:last-child {
    text-align: left;
  }
}
