:root {
  --bg: #0d1117;
  --bg-elevated: #131a24;
  --bg-panel: #161b22;
  --bg-panel-2: #0f141c;
  --border: #243041;
  --border-soft: #1c2636;
  --text: #e6edf3;
  --text-dim: #8b9bb4;
  --text-mute: #6b7a90;
  --accent: #e36b2c;
  --accent-2: #f0a060;
  --accent-glow: rgba(227, 107, 44, 0.28);
  --ok: #3fb950;
  --err: #f85149;
  --info: #7aa2f7;
  --pipeline: #3d4f6a;
  --pipeline-active: #e36b2c;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(227, 107, 44, 0.08), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(122, 162, 247, 0.06), transparent 50%),
    var(--bg);
  min-height: 100%;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* ——— Header ——— */
.header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 220px;
}

.logo {
  color: var(--accent);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(227, 107, 44, 0.15), rgba(227, 107, 44, 0.02));
  border: 1px solid rgba(227, 107, 44, 0.35);
  box-shadow: 0 0 24px var(--accent-glow);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.pipeline {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-mute);
  user-select: none;
}

.pipeline span {
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: all 0.25s ease;
}

.pipeline i {
  width: 14px;
  height: 1px;
  background: var(--pipeline);
  display: inline-block;
}

.pipeline.running span {
  color: var(--text-dim);
}

.pipeline.running span.active {
  color: #1a0f08;
  background: var(--accent);
  border-color: var(--accent-2);
  box-shadow: 0 0 16px var(--accent-glow);
  font-weight: 600;
}

.pipeline.success span[data-stage="asm"],
.pipeline.success span[data-stage="run"] {
  color: #06210f;
  background: var(--ok);
  border-color: #56d364;
  font-weight: 600;
}

.pipeline.failed span[data-stage="parser"],
.pipeline.failed span[data-stage="codegen"],
.pipeline.failed span.active-err {
  color: #2a0606;
  background: var(--err);
  border-color: #ff7b72;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: #3a4d68;
  background: #1a2330;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(180deg, #f07a3a 0%, var(--accent) 100%);
  border-color: #c45a1c;
  color: #1a0c04;
  box-shadow: 0 4px 18px var(--accent-glow);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #f58a4e 0%, #d96222 100%);
}

.btn.primary:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.btn.run {
  background: linear-gradient(180deg, #4ade80 0%, #22a85a 100%);
  border-color: #1a7f45;
  color: #04140a;
  box-shadow: 0 4px 18px rgba(34, 168, 90, 0.28);
}

.btn.run:hover {
  background: linear-gradient(180deg, #5ee89a 0%, #1f9a52 100%);
}

.btn.run:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.run kbd {
  color: rgba(4, 20, 10, 0.85);
  background: rgba(0, 0, 0, 0.15);
}

.btn.ghost {
  background: transparent;
  color: var(--text-dim);
}

.btn.icon {
  padding: 0.35rem 0.55rem;
  min-width: 2rem;
}

.btn kbd {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(0, 0, 0, 0.18);
  color: rgba(26, 12, 4, 0.85);
}

/* ——— Main split ——— */
.main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-height: 0;
  height: calc(100vh - 120px);
  min-height: 420px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-panel);
}

.editor-panel {
  border-right: 1px solid var(--border-soft);
}

.panel-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-panel-2);
  min-height: 42px;
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
}

.panel-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent-2);
}

.editor {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.editor .cm-editor {
  height: 100%;
  font-size: 13.5px;
}

.editor .cm-editor.cm-focused {
  outline: none;
}

.editor .cm-scroller {
  font-family: var(--mono) !important;
  line-height: 1.55;
}

/* ——— Tabs / output ——— */
.tabs {
  display: flex;
  gap: 0.2rem;
}

.tab {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text-mute);
  background: transparent;
  border: none;
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.tab.active {
  color: var(--text);
  background: rgba(227, 107, 44, 0.12);
  box-shadow: inset 0 0 0 1px rgba(227, 107, 44, 0.28);
}

.status {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-mute);
  white-space: nowrap;
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--err);
}

.status.busy {
  color: var(--accent-2);
}

.tab-panels {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #0b0f15;
}

.tab-panel {
  display: none;
  margin: 0;
  height: 100%;
  overflow: auto;
  padding: 1rem 1.1rem;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  color: #c8d1dc;
  white-space: pre-wrap;
  word-break: break-word;
}

.tab-panel.active {
  display: block;
}

.tab-panel.errors {
  color: #ffb4af;
}

.tab-panel.output {
  color: #b6f0c8;
}

.tab-panel.about {
  font-family: var(--font);
  font-size: 0.92rem;
  color: var(--text-dim);
  line-height: 1.6;
  white-space: normal;
}

.tab-panel.about h3 {
  margin: 1rem 0 0.4rem;
  color: var(--text);
  font-size: 0.95rem;
}

.tab-panel.about h3:first-child {
  margin-top: 0;
}

.tab-panel.about p {
  margin: 0.35rem 0 0.6rem;
}

.tab-panel.about .mono,
.inline-code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  color: #c8d1dc;
  overflow: auto;
}

.tab-panel.about code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--accent-2);
  background: rgba(227, 107, 44, 0.08);
  padding: 0.05em 0.35em;
  border-radius: 4px;
}

.placeholder {
  color: var(--text-mute);
  font-style: italic;
}

/* ——— Help drawer ——— */
.help-drawer {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 1rem;
}

.help-drawer[hidden] {
  display: none;
}

.help-card {
  width: min(440px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-soft);
}

.help-head h2 {
  margin: 0;
  font-size: 1rem;
}

.help-body {
  padding: 0.85rem 1.1rem 1.1rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.help-body ul {
  margin: 0;
  padding-left: 1.1rem;
}

.help-body li {
  margin: 0.35rem 0;
}

.help-body code {
  font-family: var(--mono);
  font-size: 0.84em;
  color: var(--accent-2);
}

.help-body .note {
  margin: 0.9rem 0 0;
  font-size: 0.82rem;
  color: var(--text-mute);
}

/* ——— Footer ——— */
.footer {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--border-soft);
  color: var(--text-mute);
  font-size: 0.75rem;
  background: rgba(13, 17, 23, 0.9);
}

.footer .dot {
  opacity: 0.5;
}

/* ——— Responsive ——— */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    height: auto;
    min-height: calc(100vh - 140px);
  }

  .editor-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
    min-height: 45vh;
  }

  .pipeline {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .header-actions {
    margin-left: auto;
  }

  .btn.primary kbd,
  .btn.run kbd {
    display: none;
  }
}
