:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --primary-soft: #e8f0fe;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #263248;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --success: #4ade80;
  --success-soft: rgba(34, 197, 94, 0.15);
  --warning: #fbbf24;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --code-bg: #020617;
  --code-text: #e2e8f0;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  display: grid;
  place-items: center;
  letter-spacing: 0.5px;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
}

.brand-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.progress-card {
  margin: 14px 16px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.progress-bar {
  height: 7px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #34a853);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.lesson-nav {
  flex: 1;
  padding: 4px 10px 16px;
}

.phase-group {
  margin-bottom: 12px;
}

.phase-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 8px 4px;
  letter-spacing: 0.02em;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
  transition: background 0.15s;
}

.nav-item:hover {
  background: var(--surface-alt);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav-status {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 11px;
  margin-top: 1px;
}

.nav-item.done .nav-status {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* Main area */
.main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left, .topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-crumb {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.mobile-menu-btn {
  display: none;
}

.content {
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

/* Lesson Header */
.lesson-header {
  margin-bottom: 20px;
}

.lesson-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}

.pill-done {
  background: var(--success-soft);
  color: var(--success);
}

.lesson-title {
  margin: 0 0 6px;
  font-size: 26px;
  line-height: 1.3;
}

.lesson-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

/* Step Tabs */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Cards & Content Blocks */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.card p {
  margin: 0 0 12px;
}

.card p:last-child {
  margin-bottom: 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 5px;
}

pre {
  margin: 12px 0 0;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.code-wrap {
  position: relative;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11.5px;
  cursor: pointer;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.diagram-box {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-x: auto;
  margin-top: 10px;
}

.callout {
  border-radius: 8px;
  padding: 14px 16px;
  border-left: 4px solid var(--primary);
  background: var(--primary-soft);
}

.callout.warning {
  border-left-color: var(--warning);
  background: var(--warning-soft);
}

.callout.tip {
  border-left-color: var(--success);
  background: var(--success-soft);
}

.callout-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

/* Quizzes */
.quiz-card {
  margin-bottom: 18px;
}

.quiz-q {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 12px;
  white-space: pre-line;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.quiz-opt {
  text-align: left;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.quiz-opt:hover {
  border-color: var(--primary);
}

.quiz-opt.correct {
  border-color: var(--success);
  background: var(--success-soft);
  font-weight: 600;
}

.quiz-opt.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.quiz-feedback {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
}

.quiz-feedback.correct {
  background: var(--success-soft);
  border: 1px solid var(--success);
}

.quiz-feedback.wrong {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
}

/* Drill */
.drill-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.sql-editor {
  width: 100%;
  min-height: 190px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  padding: 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--code-bg);
  color: var(--code-text);
  resize: vertical;
  tab-size: 2;
}

.sql-editor:focus {
  outline: none;
  border-color: var(--primary);
}

.hint-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--warning-soft);
  font-size: 13.5px;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
}

th {
  background: var(--surface-alt);
  font-weight: 700;
}

/* Buttons */
.btn-primary, .btn-outline, .btn-ghost, .btn-success {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-sm {
  font-size: 12.5px;
  padding: 6px 11px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border: 1px solid var(--success);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--surface-alt);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.icon-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 15px;
}

/* Footer navigation */
.lesson-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 780px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 200;
}

/* Responsive */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: -310px;
    z-index: 50;
    transition: left 0.22s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: grid;
  }
  .content {
    padding: 20px 16px 56px;
  }
}
