/* ─── CSS variables ──────────────────────────────────────────────────────── */
:root {
  --bg-1: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2128;
  --bg-4: #21262d;
  --bg-5: #2d333b;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #58a6ff;
  --accent-dim: #1f3a5f;
  --green: #3fb950;
  --green-dim: #1a3325;
  --orange: #f0883e;
  --orange-dim: #3d2200;
  --red: #f85149;
  --red-dim: #3d1a1a;
  --purple: #bc8cff;
  --fn-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  --fn-sans: "Inter", system-ui, sans-serif;
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,.4);
  --header-h: 50px;
}

body.light {
  --bg-1: #f6f8fa;
  --bg-2: #ffffff;
  --bg-3: #f0f2f5;
  --bg-4: #e6e9ec;
  --bg-5: #d0d5dc;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #636c76;
  --accent: #0969da;
  --accent-dim: #ddf4ff;
  --green-dim: #dcffe4;
  --orange-dim: #fff8e1;
  --red-dim: #ffebe9;
}

/* ─── reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: var(--fn-sans); background: var(--bg-1); color: var(--text); font-size: 13px; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ─── header ─────────────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { flex: 0 0 auto; }
.header-center { flex: 1 1 auto; display: flex; align-items: center; gap: 6px; justify-content: center; }
.header-right { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-svg { color: var(--accent); }
.hex-stroke { stroke: var(--accent); }
.logo-text-group { display: flex; flex-direction: column; }
.logo-text { font-size: 14px; font-weight: 700; color: var(--text); line-height: 1.2; }
.logo-accent { color: var(--accent); }
.logo-sub { font-size: 10px; color: var(--muted); line-height: 1.2; }

.header-link { font-size: 12px; color: var(--muted); transition: color .15s; }
.header-link:hover { color: var(--text); }
.header-brand { font-weight: 600; color: var(--accent); }

/* ─── buttons ─────────────────────────────────────────────────────────────── */
.btn {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-bench {
  background: var(--bg-4);
  color: var(--orange);
  border-color: var(--border);
}
.btn-bench:hover { background: var(--bg-5); border-color: var(--orange); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-4); color: var(--text); }
.btn-icon { font-size: 13px; font-weight: 700; }
.separator { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

.btn-theme {
  height: 28px; width: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-4);
  color: var(--muted);
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.btn-theme:hover { background: var(--bg-5); color: var(--text); }
.btn-login {
  background: var(--bg-4);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
}
.btn-login:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.user-chip:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* ─── layout ─────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ─── sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-width: 200px;
  max-width: 320px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: width .2s;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-toggle { left: 0; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -10px;
  transform: translateY(-50%);
  width: 10px;
  height: 32px;
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--muted);
  cursor: pointer;
  z-index: 10;
  transition: background .15s;
}
.sidebar-toggle:hover { background: var(--bg-5); color: var(--text); }

.sidebar-header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-size: 12px; font-weight: 600; color: var(--text); }

.cat-filter {
  padding: 8px 10px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}
.cat-btn {
  height: 22px;
  padding: 0 8px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  transition: all .15s;
}
.cat-btn:hover { background: var(--bg-4); color: var(--text); }
.cat-btn.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.example-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.example-list::-webkit-scrollbar { width: 4px; }
.example-list::-webkit-scrollbar-track { background: transparent; }
.example-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.example-item {
  padding: 8px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .12s;
}
.example-item:hover { background: var(--bg-3); }
.example-item.active { background: var(--bg-3); border-left-color: var(--accent); }
.example-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.example-desc { font-size: 11px; color: var(--muted); line-height: 1.4; }
.example-cat {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-5);
  color: var(--muted);
  margin-top: 3px;
}

.sidebar-about {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
}
.about-title { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.about-body { font-size: 11px; color: var(--muted); line-height: 1.6; }

.loading-msg { padding: 12px 14px; color: var(--muted); font-size: 12px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 18px;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-input {
  width: 100%;
  padding: 10px 12px;
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-1);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.modal-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,.18); }
.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.auth-tabs { display: flex; gap: 8px; padding: 14px 18px 6px; }
.auth-tab {
  flex: 1;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.auth-tab.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.auth-panel { padding-bottom: 14px; }
.auth-error {
  min-height: 18px;
  margin-top: 4px;
  color: var(--red);
  font-size: 12px;
}
.auth-switch-row {
  padding: 0 18px;
  color: var(--muted);
  font-size: 12px;
}
.auth-switch-link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 12px;
  font-weight: 600;
}
.auth-switch-link:hover { text-decoration: underline; }
.auth-hint {
  font-size: 13px;
  color: var(--muted);
  padding: 12px 18px 0;
  line-height: 1.6;
}
.profile-field { padding: 10px 18px; }
.profile-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}
.profile-value {
  font-size: 14px;
  color: var(--text);
  font-family: var(--fn-mono);
}
.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  padding: 6px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.btn-danger:hover { background: var(--red); color: #fff; }

/* ─── editor section ─────────────────────────────────────────────────────── */
.editor-section {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#editor-main-panel { flex: 3 1 0; }
#editor-ctx-panel  { flex: 1 1 0; border-top: 1px solid var(--border); }

.editor-toolbar {
  height: 32px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
  flex-shrink: 0;
}
.file-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-family: var(--fn-mono);
  color: var(--muted);
  padding: 0 8px;
  height: 24px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
}
.file-tab.active { color: var(--text); background: var(--bg-4); }
.editor-status { font-size: 11px; color: var(--muted); margin-left: auto; }
.ctx-hint { font-size: 11px; color: var(--muted); margin-left: auto; font-style: italic; }

.monaco-container { flex: 1; min-height: 0; }

.editor-divider {
  height: 4px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: row-resize;
  flex-shrink: 0;
}
.editor-divider:hover { background: var(--accent-dim); }

/* ─── panel resize handle ────────────────────────────────────────────────── */
.panel-resize-handle {
  width: 5px;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background .15s;
}
.panel-resize-handle:hover, .panel-resize-handle.dragging { background: var(--accent-dim); }

/* ─── results panel ──────────────────────────────────────────────────────── */
.results-panel {
  width: 420px;
  min-width: 300px;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-2);
}

.result-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.result-tab {
  flex: 1;
  height: 36px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all .15s;
  cursor: pointer;
}
.result-tab:hover { color: var(--text); background: var(--bg-3); }
.result-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-label { white-space: nowrap; }
.tab-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 0 5px;
  font-size: 10px;
  min-width: 16px;
  text-align: center;
}
.tab-badge-perf { background: var(--orange); }

.tab-content {
  flex: 1;
  overflow-y: auto;
  display: none;
  flex-direction: column;
}
.tab-content.active { display: flex; }
.tab-content::-webkit-scrollbar { width: 5px; }
.tab-content::-webkit-scrollbar-track { background: transparent; }
.tab-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── type intro ─────────────────────────────────────────────────────────── */
.type-intro {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.intro-hero { text-align: center; max-width: 340px; }
.intro-icon { font-size: 36px; margin-bottom: 10px; opacity: .7; }
.intro-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.intro-desc { font-size: 12px; color: var(--muted); line-height: 1.7; margin-bottom: 18px; }
.intro-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.intro-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px;
  display: flex;
  gap: 8px;
}
.intro-card-icon { font-size: 18px; flex-shrink: 0; }
.intro-card-text { font-size: 11px; color: var(--muted); line-height: 1.5; }
.intro-card-text strong { color: var(--text); display: block; margin-bottom: 2px; }
.intro-cards .intro-card:last-child { grid-column: 1/-1; }

/* ─── type result ────────────────────────────────────────────────────────── */
.type-result { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding-bottom: 12px; }

.stats-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
}
.stat { display: flex; flex-direction: column; align-items: center; padding: 0 12px; }
.stat:first-child { padding-left: 0; }
.stat-val { font-size: 16px; font-weight: 700; color: var(--accent); font-family: var(--fn-mono); }
.stat-key { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-sep { width: 1px; height: 24px; background: var(--border); }

.sym-section { padding: 10px 14px 6px; }
.sym-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.sym-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  font-size: 10px;
  font-weight: 600;
}
.sym-return { background: var(--green-dim); color: var(--green); }
.sym-param  { background: var(--accent-dim); color: var(--accent); }

.sym-list { display: flex; flex-direction: column; gap: 4px; }
.sym-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  font-family: var(--fn-mono);
  font-size: 12px;
}
.sym-name { color: var(--text); flex: 0 0 auto; }
.sym-colon { color: var(--muted); flex: 0 0 auto; }
.sym-type { color: var(--accent); flex: 1 1 0; word-break: break-word; }
.sym-func { color: var(--muted); font-size: 10px; flex: 0 0 auto; padding: 1px 5px; background: var(--bg-4); border-radius: 3px; }

/* ─── annotated tab ──────────────────────────────────────────────────────── */
.annotated-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.empty-icon { font-size: 28px; opacity: .5; }
#tab-annotated .monaco-container { flex: 1; }

/* ─── performance tab ────────────────────────────────────────────────────── */
.perf-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.perf-desc { font-size: 11px; }
.perf-note { font-size: 10px; color: var(--muted); opacity: .7; }

.perf-result { flex: 1; overflow-y: auto; padding: 12px; }
.perf-log-toggle { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.perf-headline { font-size: 13px; font-weight: 600; color: var(--text); }
.btn-log-toggle { font-size: 11px; color: var(--muted); background: none; border: none; cursor: pointer; }
.btn-log-toggle:hover { color: var(--accent); }
.perf-log {
  font-family: var(--fn-mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

.bench-table-wrap { overflow-x: auto; margin-bottom: 14px; }
.bench-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.bench-table th {
  background: var(--bg-3);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 11px;
}
.bench-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--fn-mono);
}
.bench-table tr:last-child td { border-bottom: none; }
.bench-table tr:hover td { background: var(--bg-3); }
.col-func { color: var(--text); max-width: 140px; word-break: break-all; }
.col-ns { color: var(--muted); }
.col-gcp { color: var(--green); }
.col-speedup { font-weight: 700; }
.speedup-high { color: var(--green); }
.speedup-mid  { color: var(--orange); }
.speedup-low  { color: var(--muted); }

/* Bar chart */
.bench-bars { display: flex; flex-direction: column; gap: 14px; }
.bar-group { }
.bar-func { font-size: 11px; font-family: var(--fn-mono); color: var(--text); margin-bottom: 5px; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.bar-label { width: 76px; font-size: 10px; color: var(--muted); text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; height: 14px; background: var(--bg-4); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width .4s ease; }
.bar-cpython { background: var(--muted); opacity: .6; }
.bar-bare    { background: var(--orange); }
.bar-gcp     { background: var(--green); }
.bar-val { font-size: 10px; font-family: var(--fn-mono); color: var(--muted); width: 56px; }

.perf-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
}
.error-icon { font-size: 28px; opacity: .6; }
.error-msg {
  font-size: 12px;
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--r-md);
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
}

/* ─── loading overlay ────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card .loading-msg { font-size: 13px; color: var(--muted); }

/* ─── toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--bg-4);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 8px 16px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ─── inlay hints (Monaco decorations) ──────────────────────────────────── */
.inlay-hint-type {
  color: var(--accent) !important;
  opacity: .75;
  font-style: italic;
  font-size: 11px;
}
