/* ═══════════════════════════════════════════════
   DESIGN SYSTEM (CSS Variables — single source of truth)
   ════════════════════════════════════════════════ */
:root {
  /* Colors */
  --col-bg:       #070600;
  --col-surface:  #0f0e0a;
  --col-surface2: #161410;
  --col-border:   rgba(247, 247, 255, 0.07);
  --col-border2:  rgba(247, 247, 255, 0.12);
  --col-pink:     #EA526F;
  --col-cyan:     #23B5D3;
  --col-blue:     #279AF1;
  --col-text:     #F7F7FF;
  --col-muted:    #7a7a8a;
  --col-muted2:   #52525f;

  /* Spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* Radius */
  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;
  --r-xl:  20px;

  /* Multi-layer shadows */
  --shadow-sm:
    0 1px 2px rgba(0,0,0,0.3),
    0 2px 8px rgba(0,0,0,0.2);
  --shadow-md:
    0 2px 4px rgba(0,0,0,0.4),
    0 8px 24px rgba(0,0,0,0.3),
    0 1px 0 rgba(247,247,255,0.03) inset;
  --shadow-pink:
    0 0 0 1px rgba(234,82,111,0.2),
    0 4px 20px rgba(234,82,111,0.15),
    0 8px 40px rgba(234,82,111,0.08);
  --shadow-cyan:
    0 0 0 1px rgba(35,181,211,0.2),
    0 4px 20px rgba(35,181,211,0.12);

  /* Typography */
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Sidebar width */
  --sidebar-w: 220px;
}

/* ── Reset & Base ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font);
  background: var(--col-bg);
  color: var(--col-text);
  height: 100vh;
  overflow: hidden;
  line-height: 1.6;
}

/* ── Background layers ──────────────────────────── */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(247,247,255,0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(247,247,255,0.024) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 30%, transparent 100%);
}

.orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(140px); opacity: 0.12;
  animation: drift 24s ease-in-out infinite;
}
.orb-1 { width: 500px; height: 500px; background: #EA526F; top: -180px; right: -80px; }
.orb-2 { width: 400px; height: 400px; background: #279AF1; bottom: -100px; left: 20%; animation-delay: -12s; }

@keyframes drift {
  0%,100% { transform: translate(0,0); }
  50%      { transform: translate(-30px, 20px); }
}

/* ── Layout ─────────────────────────────────────── */
.page {
  position: relative; z-index: 1;
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--col-surface);
  border-right: 1px solid var(--col-border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-6);
  gap: var(--sp-6);
  box-shadow: 1px 0 0 rgba(247,247,255,0.03);
}

.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  padding-bottom: var(--sp-5);
  border-bottom: 1px solid var(--col-border);
}
.brand-icon { font-size: 1.4rem; line-height: 1; }
.brand-name {
  font-size: 1.05rem; font-weight: 700; letter-spacing: -0.3px;
  line-height: 1.2;
}
.brand-accent { color: var(--col-pink); }
.brand-sub { font-size: 0.67rem; color: var(--col-muted); font-weight: 400; margin-top: 1px; }

.nav-label {
  font-size: 0.6rem; font-weight: 600; letter-spacing: 1.2px;
  color: var(--col-muted2); text-transform: uppercase; margin-bottom: var(--sp-2);
}

.engine-nav { display: flex; flex-direction: column; gap: var(--sp-1); }

.engine-btn {
  width: 100%; display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  background: none; border: 1px solid transparent;
  border-radius: var(--r-md); cursor: pointer;
  color: var(--col-muted); font-family: var(--font);
  transition: all 0.18s ease; text-align: left;
}
.engine-btn:hover {
  color: var(--col-text);
  background: rgba(247,247,255,0.04);
  border-color: var(--col-border);
}
.engine-btn.active {
  color: var(--col-text);
  background: rgba(234,82,111,0.08);
  border-color: rgba(234,82,111,0.25);
  box-shadow: var(--shadow-pink);
}
.engine-icon { font-size: 1rem; line-height: 1; flex-shrink: 0; }
.engine-text { display: flex; flex-direction: column; gap: 1px; }
.engine-name { font-size: 0.72rem; font-weight: 600; }
.engine-meta { font-size: 0.6rem; color: var(--col-muted); font-weight: 400; }
.engine-btn.active .engine-meta { color: rgba(234,82,111,0.7); }

.sidebar-spacer { flex: 1; }

.layer-list { display: flex; flex-direction: column; gap: var(--sp-1); }
.layer-item {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: 0.65rem; color: var(--col-muted2);
  padding: 3px 0; transition: color 0.25s;
}
.layer-item.active { color: var(--col-cyan); }
.layer-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--col-muted2); flex-shrink: 0;
  transition: background 0.25s, box-shadow 0.25s;
}
.layer-item.active .layer-dot {
  background: var(--col-cyan);
  box-shadow: 0 0 6px var(--col-cyan);
}

/* ── Main ────────────────────────────────────────── */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  padding: var(--sp-6);
  gap: var(--sp-5);
  overflow: hidden;
}

/* ── Top Bar ─────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.topbar-left { display: flex; flex-direction: column; gap: 2px; }
.page-title { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.3px; line-height: 1; }
.page-sub { font-size: 0.72rem; color: var(--col-muted); }

.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }

.stat-pill {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--col-surface2);
  border: 1px solid var(--col-border);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--mono);
}
.stat-k { font-size: 0.58rem; font-weight: 600; color: var(--col-muted2); letter-spacing: 0.8px; text-transform: uppercase; }
.stat-v { font-size: 0.72rem; font-weight: 600; color: var(--col-cyan); margin-left: 5px; }
.stat-pill .divider { width: 1px; height: 14px; background: var(--col-border2); }

.run-btn {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  background: linear-gradient(135deg, var(--col-pink) 0%, #c03055 100%);
  border: none; border-radius: var(--r-md);
  color: #fff; font-family: var(--font);
  font-size: 0.78rem; font-weight: 600;
  cursor: pointer; letter-spacing: 0.2px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.1) inset,
    0 4px 14px rgba(234,82,111,0.35),
    0 2px 4px rgba(0,0,0,0.3);
  transition: all 0.18s ease;
}
.run-btn:hover {
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.1) inset,
    0 6px 20px rgba(234,82,111,0.45),
    0 3px 8px rgba(0,0,0,0.4);
}
.run-btn:active { transform: translateY(0); }
.run-btn.loading { opacity: 0.7; cursor: wait; animation: btn-pulse 1s ease-in-out infinite; }
@keyframes btn-pulse {
  0%,100% { box-shadow: 0 4px 14px rgba(234,82,111,0.35); }
  50%      { box-shadow: 0 4px 24px rgba(39,154,241,0.5); }
}

/* ── Editor Grid ─────────────────────────────────── */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  flex: 1; min-height: 0;
}

.editor-card {
  display: flex; flex-direction: column;
  background: var(--col-surface);
  border: 1px solid var(--col-border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s;
  min-height: 0;
}
.editor-card:focus-within {
  border-color: var(--col-border2);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(35,181,211,0.12);
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--col-border);
  background: rgba(247,247,255,0.015);
  flex-shrink: 0;
}
.tab {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: 0.72rem; font-weight: 500;
  color: var(--col-muted); font-family: var(--mono);
}
.tab.active { color: var(--col-text); }
.tab-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: #279AF1; box-shadow: 0 0 5px #279AF1; }
.dot-pink  { background: var(--col-pink); box-shadow: 0 0 5px var(--col-pink); }

.card-actions { display: flex; gap: var(--sp-2); }
.action-btn {
  background: none; border: 1px solid var(--col-border);
  color: var(--col-muted); border-radius: var(--r-sm);
  padding: 3px 10px; font-size: 0.68rem; font-family: var(--font);
  cursor: pointer; transition: all 0.15s;
}
.action-btn:hover {
  color: var(--col-text); border-color: var(--col-border2);
  background: rgba(247,247,255,0.05);
}

.code-editor {
  flex: 1; min-height: 0;
  background: transparent; border: none; outline: none;
  color: var(--col-text); font-family: var(--mono);
  font-size: 0.76rem; line-height: 1.7;
  padding: var(--sp-5);
  resize: none; width: 100%;
}
.code-editor::placeholder { color: var(--col-muted2); }
.output-code { color: var(--col-cyan); }

.card-footer {
  display: flex; justify-content: flex-end; gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--col-border);
  font-size: 0.62rem; color: var(--col-muted2);
  flex-shrink: 0;
}

/* ── Toast ───────────────────────────────────────── */
.toast {
  position: fixed; bottom: var(--sp-8); left: 50%; transform: translateX(-50%);
  background: var(--col-surface2);
  border: 1px solid var(--col-border2);
  border-radius: 100px;
  padding: var(--sp-2) var(--sp-6);
  font-size: 0.76rem; color: var(--col-text);
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  transform: translateX(-50%) translateY(6px);
  z-index: 999;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(39,154,241,0.4); color: var(--col-blue); }
.toast.error   { border-color: rgba(234,82,111,0.4); color: var(--col-pink); }

/* ── Scrollbar ───────────────────────────────────── */
textarea::-webkit-scrollbar { width: 5px; }
textarea::-webkit-scrollbar-track { background: transparent; }
textarea::-webkit-scrollbar-thumb { background: rgba(247,247,255,0.08); border-radius: 3px; }
textarea::-webkit-scrollbar-thumb:hover { background: rgba(247,247,255,0.14); }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 800px) {
  .sidebar { display: none; }
  .editor-grid { grid-template-columns: 1fr; }
  body { overflow: auto; }
  .page { height: auto; flex-direction: column; }
  .main { overflow: visible; }
}
