/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-ui:   'Syne', sans-serif;
  --font-code: 'JetBrains Mono', monospace;

  --bg-app:        #0f0f10;
  --bg-panel:      #161618;
  --bg-topbar:     #111113;
  --bg-statusbar:  #0a0a0b;
  --bg-input:      #1a1a1c;
  --bg-tab:        #1a1a1c;
  --bg-tab-active: #0f0f10;
  --bg-hover:      #222226;
  --bg-run:        #22c55e;
  --bg-run-hover:  #16a34a;

  --border:        #2a2a2e;
  --border-light:  #333338;

  --text-primary:   #e8e8ec;
  --text-secondary: #888890;
  --text-accent:    #22c55e;
  --text-error:     #f87171;
  --text-logo:      #ffffff;

  --run-text:      #fff;
  --resizer-bg:    #1e1e20;
  --resizer-dot:   #3a3a3f;

  --out-stdout:  #4ade80;
  --out-stderr:  #f87171;
  --out-system:  #6b7280;
  --out-warn:    #fbbf24;
  --out-time:    #555560;
}

[data-theme="light"] {
  --bg-app:        #f4f4f5;
  --bg-panel:      #ffffff;
  --bg-topbar:     #fafafa;
  --bg-statusbar:  #e8e8ec;
  --bg-input:      #f8f8fa;
  --bg-tab:        #ebebef;
  --bg-tab-active: #ffffff;
  --bg-hover:      #ececf0;
  --bg-run:        #16a34a;
  --bg-run-hover:  #15803d;

  --border:        #e2e2e8;
  --border-light:  #d4d4dc;

  --text-primary:   #18181b;
  --text-secondary: #71717a;
  --text-accent:    #16a34a;
  --text-error:     #dc2626;
  --text-logo:      #18181b;

  --resizer-bg:    #e8e8ec;
  --resizer-dot:   #c0c0c8;

  --out-stdout:  #15803d;
  --out-stderr:  #dc2626;
  --out-system:  #6b7280;
  --out-time:    #aaaaaa;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-ui);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.topbar-left  { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.logo {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  color: var(--text-logo);
  white-space: nowrap;
  letter-spacing: -0.3px;
}

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

.select-wrap { position: relative; display: flex; align-items: center; }

.select-wrap select {
  appearance: none;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 5px 28px 5px 11px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.select-wrap select:hover,
.select-wrap select:focus { border-color: var(--text-accent); }

.select-arrow {
  position: absolute;
  right: 9px;
  pointer-events: none;
  color: var(--text-secondary);
  font-size: 12px;
}

.run-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-run);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.run-btn:hover  { background: var(--bg-run-hover); }
.run-btn:active { transform: scale(0.97); }
.run-btn.running { background: #374151; cursor: not-allowed; }

.run-icon { font-size: 10px; }

.icon-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ── Pyodide Status ── */
.pyodide-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-code);
}

.py-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-accent);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Panel Label ── */
.panel-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-secondary);
  padding: 5px 14px 4px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}

/* ── Main Layout ── */
.main { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 120px;
  overflow: hidden;
  background: var(--bg-panel);
}

#monacoEditor { flex: 1; width: 100%; height: 100%; }

/* ── Resizer ── */
.resizer {
  height: 6px;
  background: var(--resizer-bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.resizer:hover { background: var(--bg-hover); }
.resizer-dots { width: 40px; height: 2px; border-radius: 1px; background: var(--resizer-dot); }

/* ── Bottom Panel ── */
.bottom-panel {
  display: flex;
  flex-direction: column;
  height: 220px;
  min-height: 80px;
  flex-shrink: 0;
  background: var(--bg-panel);
  overflow: hidden;
}

.tabs {
  display: flex;
  background: var(--bg-tab);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 16px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover  { color: var(--text-primary); }
.tab.active { color: var(--text-accent); border-bottom-color: var(--text-accent); background: var(--bg-tab-active); }

.tab-content { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── Output Area ── */
.output-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.8;
  background: var(--bg-panel);
}

.output-placeholder { color: var(--text-secondary); font-style: italic; font-family: var(--font-code); font-size: 12.5px; }

.out-line    { display: block; white-space: pre-wrap; word-break: break-all; }
.out-stdout  { color: var(--out-stdout); }
.out-stderr  { color: var(--out-stderr); }
.out-system  { color: var(--out-system); }
.out-warn    { color: var(--out-warn); }
.out-time    { color: var(--out-time); font-size: 11px; }

/* ── Plots Area ── */
.plots-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-content: flex-start;
  background: var(--bg-panel);
}

.plot-img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

/* ── Stdin ── */
.stdin-area {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.7;
  padding: 10px 14px;
}

.stdin-area::placeholder { color: var(--text-secondary); }

/* ── Status Bar ── */
.statusbar {
  display: flex;
  align-items: center;
  padding: 0 14px;
  height: 24px;
  background: var(--bg-statusbar);
  border-top: 1px solid var(--border);
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.statusbar .sep { margin: 0 8px; opacity: 0.4; }
.statusbar-right { margin-left: auto; display: flex; align-items: center; }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 5px;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

@media (max-width: 600px) {
  .topbar { padding: 0 10px; }
  .logo { font-size: 13px; }
}