@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

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

:root {
  --bg: #f8f9fb;
  --bg-white: #ffffff;
  --bg-code: #1e1e2e;
  --bg-code-gutter: #181825;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-code: #cdd6f4;
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --blue-mid: #dbeafe;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-light: #fef2f2;
  --red-bg: #fee2e2;
  --orange: #ea580c;
  --orange-light: #fff7ed;
  --cyan: #0891b2;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow: 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.08);
  --shadow-xl: 0 20px 60px rgba(0,0,0,.12);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: .2s ease;
}

html { scroll-behavior: smooth; overflow: hidden; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  line-height: 1.6;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ═══════════════ HEADER ═══════════════ */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 14px; }
.header-logo-img {
  width: 40px; height: 40px; border-radius: 8px;
  object-fit: contain;
}
.header h1 { font-size: 1.15rem; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.header p { font-size: .78rem; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: 8px; }
.header-names { font-size: .75rem; font-weight: 500; color: var(--text-secondary); }
.header-divider { font-size: .75rem; color: var(--text-muted); }


/* ═══════════════ MAIN LAYOUT ═══════════════ */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  overflow: hidden;
}

/* ═══════════════ LEFT: CODE EDITOR ═══════════════ */
.editor-panel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-code);
  overflow: hidden;
}
.editor-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: #11111b;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.btn-choose {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1);
  color: #cdd6f4; padding: 7px 12px; border-radius: var(--radius-xs);
  font-size: .78rem; font-family: 'Inter', sans-serif; cursor: pointer;
  transition: all var(--transition);
}
.btn-choose:hover { background: rgba(255,255,255,.12); border-color: var(--blue); }

.examples-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.example-btn {
  background: var(--bg); border: 1px solid var(--border);
  padding: 10px; border-radius: var(--radius-xs); text-align: left;
  cursor: pointer; font-family: 'JetBrains Mono', monospace;
  font-size: .75rem; color: var(--text); transition: all .2s ease;
}
.example-btn:hover {
  background: var(--blue-light); border-color: var(--blue-mid); color: var(--blue);
}

.btn-compile {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 18px; border: none; border-radius: var(--radius-xs);
  font-size: .78rem; font-weight: 600; cursor: pointer;
  background: var(--blue); color: #fff;
  font-family: 'Inter', sans-serif;
  transition: all var(--transition); margin-left: auto;
}
.btn-compile:hover { background: #1d4ed8; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(37,99,235,.3); }
.btn-compile:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-compile svg { width: 13px; height: 13px; }
.btn-compile.running { animation: btn-shimmer 1.2s infinite; }
@keyframes btn-shimmer { 0%,100% { opacity: 1; } 50% { opacity: .6; } }

.editor-area { flex: 1; display: flex; overflow: auto; }
.line-numbers {
  padding: 16px 0; min-width: 48px; text-align: right;
  background: var(--bg-code-gutter);
  color: #585b70; font-size: .78rem;
  font-family: 'JetBrains Mono', monospace;
  user-select: none; border-right: 1px solid rgba(255,255,255,.05);
  line-height: 1.7;
}
.line-numbers span { display: block; padding: 0 12px 0 0; line-height: 1.7; }
.editor-textarea {
  flex: 1; padding: 16px; resize: none; border: none; outline: none;
  background: transparent; color: var(--text-code);
  font-family: 'JetBrains Mono', monospace;
  font-size: .82rem; line-height: 1.7;
  tab-size: 4; white-space: pre; overflow: auto;
}
.editor-textarea::placeholder { color: #585b70; }
.editor-status {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
  background: #11111b; border-top: 1px solid rgba(255,255,255,.06);
  font-size: .7rem; color: #585b70;
}

/* ═══════════════ RIGHT: PIPELINE PANEL ═══════════════ */
.pipeline-panel {
  display: flex; flex-direction: column;
  background: var(--bg);
  overflow: auto;
}
.pipeline-header {
  padding: 20px 28px 0;
}
.pipeline-header h2 { font-size: .95rem; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.pipeline-header p { font-size: .78rem; color: var(--text-muted); }

/* ═══════════════ HORIZONTAL PIPELINE ═══════════════ */
.pipeline-container {
  padding: 32px 28px 24px;
  flex-shrink: 0;
}
.pipeline {
  display: flex; align-items: flex-start; gap: 0;
  position: relative;
}

/* Stage */
.stage {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; flex: 1; position: relative; cursor: pointer;
  transition: transform var(--transition);
}
.stage:hover { transform: translateY(-2px); }
.stage-circle {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-white); border: 2px solid var(--border);
  transition: all .3s ease; position: relative; z-index: 2;
  box-shadow: var(--shadow-sm);
}
.stage-circle svg { width: 22px; height: 22px; color: var(--text-muted); transition: color .3s; }
.stage-label { font-size: .72rem; font-weight: 600; color: var(--text-muted); text-align: center; transition: color .3s; white-space: nowrap; }
.stage-badge {
  font-size: .62rem; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); transition: all .3s;
}

/* Connector */
.connector {
  flex: 1; height: 2px; background: var(--border);
  margin-top: 28px; position: relative;
  min-width: 24px;
}
.connector::after {
  content: ''; position: absolute; left: 0; top: 0;
  width: 0%; height: 100%;
  background: var(--blue);
  transition: width .5s ease;
}
.connector.active::after { width: 100%; }

/* Divider */
.pipeline-divider-line {
  display: flex; flex-direction: column; align-items: center;
  margin-top: 10px; padding: 0 8px; flex-shrink: 0;
}
.pipeline-divider-line .dline { width: 1px; height: 56px; background: var(--border); border-style: dashed; }
.pipeline-divider-line .dtag {
  font-size: .55rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); padding: 4px 0;
  writing-mode: vertical-lr; transform: rotate(180deg);
}

/* Stage States */
.stage.processing .stage-circle { border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-light); animation: circle-pulse 1.5s infinite; }
.stage.processing .stage-circle svg { color: var(--blue); }
.stage.processing .stage-label { color: var(--blue); }
.stage.processing .stage-badge { background: var(--blue-light); color: var(--blue); border-color: var(--blue-mid); }
@keyframes circle-pulse { 0%,100% { box-shadow: 0 0 0 4px var(--blue-light); } 50% { box-shadow: 0 0 0 8px rgba(37,99,235,.1); } }

.stage.success .stage-circle { border-color: var(--green); background: var(--green-light); box-shadow: 0 0 0 4px rgba(22,163,74,.08); }
.stage.success .stage-circle svg { color: var(--green); }
.stage.success .stage-label { color: var(--green); }
.stage.success .stage-badge { background: var(--green-light); color: var(--green); border-color: var(--green-bg); }

.stage.error .stage-circle { border-color: var(--red); background: var(--red-light); box-shadow: 0 0 0 4px rgba(220,38,38,.08); }
.stage.error .stage-circle svg { color: var(--red); }
.stage.error .stage-label { color: var(--red); }
.stage.error .stage-badge { background: var(--red-light); color: var(--red); border-color: var(--red-bg); }

.stage.disabled { cursor: default; opacity: .4; }
.stage.disabled:hover { transform: none; }
.stage.disabled .coming-soon {
  font-size: .6rem; font-weight: 600; padding: 2px 8px;
  border-radius: 8px; background: var(--bg);
  border: 1px solid var(--border); color: var(--text-muted);
}

/* Active ring when a popup is open for this stage */
.stage.active-popup .stage-circle { border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-light); }

/* ═══════════════ STAGE RESULTS LIST ═══════════════ */
.stage-results-list {
  padding: 0 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-list-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  border-left: 4px solid var(--border-strong);
  animation: fadeIn .3s ease;
}
.result-list-item.success { border-left-color: var(--green); }
.result-list-item.error { border-left-color: var(--red); background: var(--red-light); border-color: var(--red-bg); }
.result-list-info { display: flex; align-items: center; gap: 8px; }
.result-list-title { font-size: .75rem; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .3px; }
.result-list-desc { font-size: .75rem; color: var(--text-muted); }
.result-list-item.error .result-list-title { color: var(--red); }
.result-list-item.error .result-list-desc { color: var(--red); opacity: 0.8; }
.btn-view {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-xs); padding: 4px 10px;
  font-size: .65rem; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition);
  font-family: 'Inter', sans-serif; letter-spacing: .5px;
}
.btn-view:hover { background: var(--blue-light); color: var(--blue); border-color: var(--blue-mid); }
.btn-view.error:hover { background: var(--red-bg); color: var(--red); border-color: var(--red); }

/* ═══════════════ POPUP OVERLAY ═══════════════ */
.popup-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.25); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
.popup-overlay.open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.popup {
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  width: 90vw; max-width: 780px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: popupSlide .25s ease;
  border: 1px solid var(--border);
}
@keyframes popupSlide { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.popup-header h3 {
  font-size: 1rem; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
.popup-header .popup-badge {
  font-size: .68rem; font-weight: 600; padding: 3px 10px;
  border-radius: 10px;
}
.popup-badge.pass { background: var(--green-light); color: var(--green); }
.popup-badge.fail { background: var(--red-light); color: var(--red); }

.popup-close {
  width: 32px; height: 32px; border: none; border-radius: 8px;
  background: var(--bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all var(--transition);
}
.popup-close:hover { background: var(--border); color: var(--text); }
.popup-close svg { width: 18px; height: 18px; }

.popup-body {
  flex: 1; overflow: auto; padding: 20px 24px;
}

/* ═══════════════ TOKEN TABLE ═══════════════ */
.token-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.token-table th {
  text-align: left; padding: 8px 12px; font-weight: 600;
  color: var(--text-muted); border-bottom: 2px solid var(--border);
  font-size: .7rem; text-transform: uppercase; letter-spacing: .5px;
  position: sticky; top: 0; background: var(--bg-white); z-index: 1;
}
.token-table td {
  padding: 5px 12px; border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace; font-size: .78rem;
}
.token-table tr:hover td { background: var(--bg); }
.token-type {
  display: inline-block; padding: 1px 8px; border-radius: 4px;
  font-size: .68rem; font-weight: 600; font-family: 'Inter', sans-serif;
}
.token-type.KEYWORD { background: #ede9fe; color: #7c3aed; }
.token-type.ID { background: var(--blue-light); color: var(--blue); }
.token-type.INT_CONST, .token-type.REAL_CONST { background: var(--orange-light); color: var(--orange); }
.token-type.STRING, .token-type.CHAR_CONST { background: #fefce8; color: #ca8a04; }
.token-type.OP, .token-type.OP_ASSIGN, .token-type.OP_NEQ, .token-type.OP_GEQ, .token-type.OP_LEQ {
  background: #ecfeff; color: var(--cyan);
}

/* ═══════════════ AST TREE ═══════════════ */
.ast-raw {
  background: var(--bg); padding: 14px 16px; border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', monospace; font-size: .76rem;
  color: var(--text-secondary); overflow-x: auto; white-space: pre-wrap;
  word-break: break-all; max-height: 120px; overflow-y: auto;
  line-height: 1.6; margin-bottom: 16px; border: 1px solid var(--border);
}
.ast-tree { font-family: 'JetBrains Mono', monospace; font-size: .8rem; line-height: 1.5; }
.t-node { margin: 1px 0; }
.t-row {
  display: inline-flex; align-items: center; padding: 3px 8px;
  border-radius: var(--radius-xs); cursor: pointer;
  transition: all .12s; border: 1px solid transparent; gap: 5px;
}
.t-row:hover { background: var(--bg); border-color: var(--border); }
.t-toggle { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-muted); transition: transform .15s; cursor: pointer; font-size: .7rem; }
.t-toggle.open { transform: rotate(90deg); }
.t-toggle.hide { visibility: hidden; }
.t-type { font-weight: 600; font-size: .8rem; }
.t-val { color: var(--text-secondary); font-weight: 400; font-size: .76rem; }
.t-kids { margin-left: 18px; padding-left: 14px; border-left: 1px dashed var(--border); overflow: hidden; }
.t-kids.shut { display: none; }

/* AST node colors */
.c-prog { color: #be185d; } .c-struct { color: #7c3aed; }
.c-stmt { color: var(--blue); } .c-decl { color: var(--cyan); }
.c-ctrl { color: var(--red); } .c-expr { color: var(--green); }
.c-lit { color: var(--orange); } .c-type { color: #7c3aed; }
.c-mem { color: var(--red); } .c-call { color: var(--green); }
.c-id { color: var(--blue); } .c-op { color: var(--cyan); }
.c-assign { color: #7c3aed; } .c-spec { color: var(--text-muted); }

/* ═══════════════ SEMANTIC RESULT ═══════════════ */
.semantic-result { text-align: center; padding: 24px; }
.semantic-icon {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.semantic-icon.pass { background: var(--green-light); color: var(--green); }
.semantic-icon.fail { background: var(--red-light); color: var(--red); }
.semantic-icon svg { width: 28px; height: 28px; }
.semantic-msg { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.semantic-detail { font-size: .85rem; color: var(--text-secondary); }
.error-box {
  margin-top: 16px; padding: 14px 18px; border-radius: var(--radius-sm);
  background: var(--red-light); border: 1px solid var(--red-bg);
  color: var(--red); font-family: 'JetBrains Mono', monospace;
  font-size: .8rem; text-align: left; white-space: pre-wrap;
}

/* ═══════════════ CODEGEN ═══════════════ */
.codegen-placeholder {
  text-align: center; padding: 40px; color: var(--text-muted);
}
.codegen-placeholder svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .3; }
.codegen-placeholder h4 { font-size: .95rem; margin-bottom: 4px; }
.codegen-placeholder p { font-size: .82rem; }

/* ═══════════════ SCROLLBAR ═══════════════ */
.pipeline-panel::-webkit-scrollbar, .popup-body::-webkit-scrollbar { width: 6px; }
.pipeline-panel::-webkit-scrollbar-track, .popup-body::-webkit-scrollbar-track { background: transparent; }
.pipeline-panel::-webkit-scrollbar-thumb, .popup-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Editor scrollbar — dark */
.editor-area::-webkit-scrollbar { width: 8px; height: 8px; }
.editor-area::-webkit-scrollbar-track { background: var(--bg-code); }
.editor-area::-webkit-scrollbar-thumb { background: #45475a; border-radius: 4px; }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 900px) {
  .main-layout { grid-template-columns: 1fr; height: auto; display: flex; flex-direction: column; overflow: visible; }
  .editor-panel { min-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .pipeline { flex-wrap: wrap; }
}
