/* ============================================================
   Python Lab — Premium SaaS / EdTech Design System
   ============================================================ */
:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text: #0F172A;
  --text-2: #334155;
  --muted: #64748B;
  --faint: #94A3B8;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-soft: #EEF2FF;
  --accent: #0D9488;
  --accent-soft: #CCFBF1;
  --success: #10B981;
  --success-bg: #ECFDF5;
  --success-border: #A7F3D0;
  --warning: #F59E0B;
  --warning-bg: #FFFBEB;
  --danger: #EF4444;
  --danger-bg: #FEF2F2;
  --danger-border: #FECACA;
  --info-bg: #EFF6FF;
  --info-border: #BFDBFE;
  --code-bg: #0F172A;
  --code-surface: #1E293B;
  --code-text: #E2E8F0;
  --code-gutter: #334155;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px -8px rgba(15, 23, 42, 0.12);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --topbar-h: 60px;
}

[data-theme="dark"] {
  --bg: #0B0F19;
  --surface: #111827;
  --surface-2: #1F2937;
  --border: #1F2937;
  --border-strong: #374151;
  --text: #F8FAFC;
  --text-2: #E2E8F0;
  --muted: #94A3B8;
  --faint: #64748B;
  --primary-soft: #1E1B4B;
  --accent-soft: #134E4A;
  --success-bg: #064E3B;
  --success-border: #065F46;
  --danger-bg: #450A0A;
  --danger-border: #7F1D1D;
  --warning-bg: #451A03;
  --info-bg: #1E3A5F;
  --info-border: #1E40AF;
  --code-bg: #020617;
  --code-surface: #0F172A;
  --shadow: 0 4px 24px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px -8px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.brand-icon { font-size: 20px; }
.brand-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, #4F46E5, #0D9488);
  color: #fff;
}
.topbar-center {
  flex: 1;
  max-width: 320px;
  margin: 0 auto;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 500;
}
.progress-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4F46E5, #0D9488);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.xp-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
}
.xp-label { font-size: 11px; font-weight: 600; opacity: 0.7; }
.userbox {
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.userbox .btn { margin: 0; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon,
:root:not([data-theme="dark"]) .icon-moon { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 80px;
}
.nav-rail {
  display: flex;
  gap: 6px;
  padding: 12px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-rail::-webkit-scrollbar { display: none; }
.navbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  font-family: inherit;
}
.navbtn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.navbtn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.nav-ico { font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
h1, h2, h3 { margin: 0 0 10px; line-height: 1.3; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }
.muted { color: var(--muted); }
p { margin: 0 0 12px; }

.auth-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  max-width: 880px;
  margin: 48px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.auth-visual {
  background: linear-gradient(145deg, #4F46E5 0%, #0D9488 100%);
  color: #fff;
  padding: 48px 36px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-orb {
  position: absolute;
  width: 280px; height: 280px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  top: -80px; right: -60px;
}
.auth-visual h1 { font-size: 2rem; margin-bottom: 12px; position: relative; }
.auth-visual p { opacity: 0.9; position: relative; font-size: 15px; }
.auth-form { padding: 40px 32px; }
.auth-hint { font-size: 12px; color: var(--muted); margin-top: 16px; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; }
.tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  color: var(--muted);
  transition: all 0.15s;
}
.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.field {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-2);
}
.field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  line-height: 1.2;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, #4F46E5, #6366F1);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4338CA, #4F46E5);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.loading { pointer-events: none; opacity: 0.75; }
.btn .spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.workspace-split {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.3fr);
  gap: 16px;
  align-items: start;
}
.theory-panel { position: sticky; top: calc(var(--topbar-h) + 12px); }
.chapter-card { margin-bottom: 20px; }
.chapter-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.chapter-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-done { background: var(--success-bg); color: var(--success); }
.status-current { background: var(--primary-soft); color: var(--primary); }
.status-locked { background: var(--surface-2); color: var(--muted); }

.theory-text {
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.7;
  margin-bottom: 14px;
}
.example-box {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--r);
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  overflow-x: auto;
  margin: 12px 0 20px;
  white-space: pre-wrap;
  word-break: break-word;
}
.inline-code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 500;
}
[data-theme="dark"] .inline-code {
  background: #1E1B4B;
  color: #A5B4FC;
}
.tip-list {
  padding-left: 18px;
  color: var(--text-2);
  font-size: 14px;
}
.tip-list li { margin-bottom: 6px; }

.exercise {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 18px;
}
.exercise-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.exercise-title h3 { margin: 0; }
.badge-ok {
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
  background: var(--success-bg);
  padding: 3px 10px;
  border-radius: 999px;
}
.prompt {
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.65;
  margin-bottom: 14px;
}

.ide-window {
  background: var(--code-bg);
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--code-surface) 80%, #000);
  box-shadow: var(--shadow-lg);
}
.ide-titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--code-surface);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.traffic { display: flex; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 50%; }
.dot.red { background: #FF5F57; }
.dot.yellow { background: #FEBC2E; }
.dot.green { background: #28C840; }
.ide-filename {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  color: #94A3B8;
  font-weight: 500;
}
.ide-actions { display: flex; gap: 6px; }
.ide-actions .btn {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: #E2E8F0;
  font-size: 12px;
}
.ide-actions .btn:hover { background: rgba(255,255,255,0.12); }

.quickbar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: #0B1220;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.quickbar::-webkit-scrollbar { display: none; }
.qb-btn {
  flex-shrink: 0;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #E2E8F0;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}
.qb-btn:active { background: rgba(255,255,255,0.16); }

.CodeMirror {
  height: auto !important;
  min-height: 160px;
  max-height: 420px;
  font-family: var(--mono) !important;
  font-size: 15px !important;
  line-height: 1.55 !important;
  background: var(--code-bg) !important;
  color: var(--code-text) !important;
}
.CodeMirror-scroll { min-height: 160px; }
.CodeMirror-gutters {
  background: var(--code-surface) !important;
  border-right: 1px solid rgba(255,255,255,0.06) !important;
}
.CodeMirror-linenumber { color: #64748B !important; }
.CodeMirror-cursor { border-left: 2px solid #A5B4FC !important; }
.CodeMirror-focused .CodeMirror-selected { background: rgba(79, 70, 229, 0.35) !important; }
.CodeMirror-hints {
  font-family: var(--mono) !important;
  font-size: 13px !important;
  border-radius: 10px !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-lg) !important;
  z-index: 200 !important;
}
.CodeMirror-hint { padding: 6px 12px !important; }
.CodeMirror-hint-active {
  background: var(--primary) !important;
  color: #fff !important;
}

textarea.code-area {
  width: 100%;
  min-height: 160px;
  padding: 14px;
  border: none;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
  resize: vertical;
  outline: none;
}

.terminal {
  border-top: 1px solid rgba(255,255,255,0.06);
  background: #020617;
}
.terminal-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748B;
  padding: 8px 14px 0;
}
.terminal-body {
  margin: 0;
  padding: 8px 14px 14px;
  font-family: var(--mono);
  font-size: 13.5px;
  color: #A7F3D0;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 28px;
  max-height: 200px;
  overflow: auto;
}

.feedback {
  margin-top: 14px;
  border-radius: var(--r);
  padding: 14px 16px;
  animation: slideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.feedback-success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}
.feedback-success .fb-title {
  color: var(--success);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.feedback-error {
  background: var(--surface);
  border: 1px solid var(--border);
}
.diag-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.diag-cause {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
}
.diag-cause .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #B45309;
  margin-bottom: 4px;
}
[data-theme="dark"] .diag-cause .label { color: #FBBF24; }
.diag-hint {
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
}
.diag-hint .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2563EB;
  margin-bottom: 4px;
}
[data-theme="dark"] .diag-hint .label { color: #93C5FD; }
.fb-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 200;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 210;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-header h3 { margin: 0; }
.code-block {
  flex: 1;
  overflow: auto;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 13.5px;
  padding: 16px;
  border-radius: var(--r);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.msg { margin-top: 12px; font-size: 14px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--success); font-weight: 600; }
.countdown {
  font-weight: 800;
  color: var(--danger);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.scorebar-mini {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(10px);
  padding: 10px 0;
  margin: 0 -4px;
  display: flex;
  gap: 8px;
  z-index: 20;
  border-top: 1px solid var(--border);
}
.sticky-actions .btn { flex: 1; }

@media (max-width: 900px) {
  .workspace-split { grid-template-columns: 1fr; }
  .theory-panel { position: static; }
  .auth-card { grid-template-columns: 1fr; }
  .auth-visual { padding: 28px 24px; }
  .auth-visual h1 { font-size: 1.5rem; }
  .topbar-center { display: none; }
}
@media (max-width: 600px) {
  .app-shell { padding: 0 10px 100px; }
  .card, .panel { padding: 14px; border-radius: var(--r); }
  .CodeMirror { font-size: 16px !important; }
  textarea.code-area { font-size: 16px; }
  .brand-text { display: none; }
  .xp-badge .xp-label { display: none; }
  .userbox { font-size: 12px; }
}

/* ---------- Live Linter ---------- */
.lint-banner {
  display: none;
  margin: 10px 0 0;
  border-radius: var(--r);
  border: 1px solid #FCD34D;
  background: linear-gradient(180deg, #FFFBEB 0%, #FEF3C7 100%);
  padding: 10px 12px;
  animation: slideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
[data-theme="dark"] .lint-banner {
  background: linear-gradient(180deg, #451A03 0%, #78350F 100%);
  border-color: #B45309;
}
.lint-banner.open { display: block; }
.lint-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
}
.lint-item + .lint-item {
  border-top: 1px dashed rgba(180, 83, 9, 0.25);
  margin-top: 4px;
  padding-top: 10px;
}
.lint-msg {
  flex: 1;
  min-width: 180px;
  font-size: 13.5px;
  color: #92400E;
  line-height: 1.5;
}
[data-theme="dark"] .lint-msg { color: #FDE68A; }
.lint-fix-btn {
  flex-shrink: 0;
  background: #F59E0B !important;
  border-color: #D97706 !important;
  color: #1C1917 !important;
  font-weight: 700;
  font-size: 12.5px !important;
  padding: 6px 12px !important;
}
.lint-fix-btn:hover {
  background: #D97706 !important;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

/* CodeMirror lint markers */
.cm-lint-bg {
  background: rgba(245, 158, 11, 0.12) !important;
}
.cm-lint-line {
  border-left: 3px solid #F59E0B;
}
.cm-lint-wave {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: #F59E0B;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
[data-theme="dark"] .cm-lint-bg {
  background: rgba(245, 158, 11, 0.18) !important;
}
[data-theme="dark"] .cm-lint-wave {
  text-decoration-color: #FBBF24;
}
