:root {
  --bg-color: #f0f2f5;
  --panel-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --danger: #ef4444;
  --accent: #8b5cf6;
  --mem-bg: #f8fafc;
  --mem-alt: #f1f5f9;
  --font-sans: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

body.dark-mode {
  --bg-color: #0f172a;
  --panel-bg: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --mem-bg: #0f172a;
  --mem-alt: #1e293b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

.hidden { display: none !important; }

/* Top Nav */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--panel-bg);
  border-bottom: 2px solid var(--border-color);
}
.logo { font-size: 1.5rem; font-weight: 700; }
.logo .dot { color: var(--primary); }

.nav-controls { display: flex; gap: 1rem; align-items: center; }

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}
.nav-link:hover {
  background: var(--mem-alt);
  color: var(--primary);
}
body.dark-mode .nav-link:hover {
  color: #60a5fa;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: transparent; border-color: var(--border-color); color: var(--text-main); }
.btn.secondary:hover:not(:disabled) { background: var(--mem-alt); }
.btn.text-btn { background: transparent; color: var(--text-muted); padding: 0; }
.btn.text-btn:hover { color: var(--primary); }

/* Main Layout */
.ide-container {
  flex: 1;
  display: flex;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem;
  gap: 1.5rem;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.panel-memory {
  flex: 0 0 35%;
  max-width: 450px;
  min-width: 300px;
}

.panel-editor {
  flex: 1;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--panel-bg);
}
.panel-header h2 { font-size: 1.25rem; font-weight: 600; }
.pc-indicator { font-weight: 600; font-family: var(--font-mono); color: var(--text-muted); }
.pc-indicator span { color: var(--danger); font-size: 1.1em; }

.toolbar-btns { display: flex; gap: 0.5rem; }

/* Memory Table */
.memory-wrapper { flex: 1; overflow-y: auto; background: var(--mem-bg); }
.memory-table { width: 100%; border-collapse: collapse; text-align: left; font-family: var(--font-mono); font-size: 0.95rem; }
.memory-table th { position: sticky; top: 0; background: var(--panel-bg); padding: 0.75rem 1.5rem; border-bottom: 2px solid var(--border-color); color: var(--text-muted); font-family: var(--font-sans); }
.memory-table td { padding: 0.75rem 1.5rem; border-bottom: 1px solid var(--border-color); }
.memory-table th:first-child,
.memory-table td:first-child { width: 60px; text-align: center; border-right: 1px solid var(--border-color); }
.memory-table tr:nth-child(even) { background: var(--mem-alt); }
.memory-table tr.active td { 
  background-color: #eff6ff; 
  border-left: 4px solid var(--primary);
  color: var(--primary); 
  font-weight: 700;
}
.memory-table tr.updated td { 
  color: var(--success); 
  font-weight: 700;
}

body.dark-mode .memory-table tr.active td { 
  background-color: rgba(59, 130, 246, 0.15); 
  color: #60a5fa; 
}

/* Editor Section */
#editor-wrapper { flex: 1; position: relative; }
#editor { position: absolute; inset: 0; font-family: var(--font-mono); font-size: 15px; }

/* Custom Ace Editor Syntax Colors */
.ace_editor .ace_label { color: #8b5cf6; font-weight: bold; }
.ace_editor .ace_arithmetic { color: #ef4444; font-weight: bold; }
.ace_editor .ace_logic { color: #10b981; font-weight: bold; }
.ace_editor .ace_branch { color: #f59e0b; font-weight: bold; }
.ace_editor .ace_move { color: #2563eb; font-weight: bold; }
.ace_editor .ace_number { color: #475569; }

body.dark-mode .ace_editor .ace_label { color: #a78bfa; }
body.dark-mode .ace_editor .ace_arithmetic { color: #f87171; }
body.dark-mode .ace_editor .ace_logic { color: #34d399; }
body.dark-mode .ace_editor .ace_branch { color: #fbbf24; }
body.dark-mode .ace_editor .ace_move { color: #60a5fa; }
body.dark-mode .ace_editor .ace_number { color: #cbd5e1; }

/* Force Ace Editor Dark Mode Colors Offline */
body.dark-mode .ace_editor {
  background-color: var(--mem-bg) !important;
  color: #f8fafc !important;
}
body.dark-mode .ace_gutter {
  background-color: var(--panel-bg) !important;
  color: #64748b !important;
  border-right: 1px solid var(--border-color) !important;
}
body.dark-mode .ace_active-line {
  background-color: rgba(255,255,255,0.05) !important;
}
body.dark-mode .ace_cursor {
  color: #f8fafc !important;
}

/* Status Bar */
.status-bar {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--mem-alt);
  color: var(--text-muted);
}
.status-bar .success { color: var(--success); }
.status-bar .error { color: var(--danger); }

/* Journey Banner */
.journey-banner {
  background: var(--primary);
  color: #fff;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}
.journey-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.journey-header h3 { font-size: 1.25rem; font-weight: 600; }
.lesson-progress { font-size: 0.9rem; opacity: 0.8; }
.lesson-desc { font-size: 1rem; line-height: 1.5; opacity: 0.95; margin-bottom: 1rem; }
.lesson-desc code { background: rgba(0,0,0,0.2); padding: 0.1em 0.3em; border-radius: 4px; font-family: var(--font-mono); }

/* Hint Box Injection */
.hint-box {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  padding: 12px 16px;
  border-radius: 8px;
  border-left: 4px solid #fff;
  margin-top: 15px;
  font-weight: 600;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

/* Banner specific buttons */
.journey-banner .btn.secondary {
  border-color: rgba(255,255,255,0.4);
  color: #fff;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(4px);
}
.journey-banner .btn.secondary:hover {
  background: rgba(255,255,255,0.25);
  border-color: #fff;
  transform: translateY(-1px);
}
.journey-banner .btn.text-btn {
  color: rgba(255,255,255,0.7);
  font-weight: 600;
}
.journey-banner .btn.text-btn:hover {
  color: #fff;
  text-decoration: underline;
}

/* Dark Mode Overrides for Journey Banner */
body.dark-mode .journey-banner {
  background: linear-gradient(135deg, rgba(37,99,235,0.15) 0%, rgba(15,23,42,1) 100%);
  border-bottom: 1px solid var(--border-color);
}
body.dark-mode .lesson-desc code {
  color: #60a5fa;
  background: rgba(255,255,255,0.1);
}
body.dark-mode .hint-box {
  background: rgba(0, 0, 0, 0.3);
  border-left-color: var(--primary);
  color: #e2e8f0;
}

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: var(--panel-bg); padding: 2rem; border-radius: 12px; text-align: center; max-width: 400px; width: 100%; border: 2px solid var(--success); box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); }
.modal-content h2 { color: var(--success); font-size: 2rem; margin-bottom: 0.5rem; }
.modal-content p { color: var(--text-muted); margin-bottom: 2rem; }
.btn.large { width: 100%; padding: 1rem; font-size: 1.1rem; }

@media(max-width: 1024px) {
  .ide-container { flex-direction: column; }
  .panel { min-height: 400px; }
}

/* ========================================================= */
/* PATHWAY UI (Duolingo-style)                                 */
/* ========================================================= */
#pathway-modal .pathway-content {
  background: var(--panel-bg);
  width: 100%; height: 100%; max-width: 900px;
  margin: 0 auto; display: flex; flex-direction: column;
}
.pathway-header {
  padding: 1.5rem 2rem; display: flex;
  justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border-color);
}
.pathway-scroll {
  flex: 1; overflow-y: auto; padding: 3rem 1rem; position: relative;
}
.pathway-nodes-container {
  display: flex; flex-direction: column;
  align-items: center; position: relative; gap: 2rem;
}
/* Central Line */
.pathway-nodes-container::before {
  content: ''; position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 6px; background: var(--border-color);
  transform: translateX(-50%); z-index: 1;
}

.module-section {
  width: 100%; display: flex; flex-direction: column;
  align-items: center; z-index: 2; margin-bottom: 2rem;
}
.module-badge {
  background: var(--primary); color: white;
  padding: 0.5rem 1.5rem; border-radius: 20px;
  font-weight: 700; margin-bottom: 2rem; z-index: 2;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.lesson-wrapper {
  position: relative; margin: 1.5rem 0;
  display: flex; justify-content: center; width: 100%;
}
.lesson-node {
  width: 75px; height: 75px; border-radius: 50%;
  background: var(--panel-bg); border: 6px solid var(--border-color);
  display: flex; justify-content: center; align-items: center;
  font-size: 1.5rem; cursor: pointer; z-index: 2;
  transition: all 0.2s; color: var(--text-muted);
}
.lesson-node:hover:not(.locked) { transform: scale(1.1); }
.lesson-node.completed {
  border-color: var(--success); color: var(--success);
  background: rgba(16, 185, 129, 0.1);
}
.lesson-node.current {
  border-color: var(--primary); color: var(--primary);
  box-shadow: 0 0 0 10px rgba(37, 99, 235, 0.2);
}
.lesson-node.locked {
  cursor: not-allowed; opacity: 0.5; background: var(--mem-alt);
}
.lesson-label {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-weight: bold; font-size: 1rem; color: var(--text-color);
  background: var(--panel-bg); padding: 0.5rem 1rem;
  border-radius: 12px; border: 1px solid var(--border-color);
  white-space: nowrap; z-index: 2;
}

/* Alternate sides for labels */
.lesson-wrapper:nth-child(even) .lesson-label { right: calc(50% + 60px); }
.lesson-wrapper:nth-child(odd) .lesson-label { left: calc(50% + 60px); }

/* Progress Bar in Banner */
.lesson-progress-bar {
  width: 100%; height: 6px; background: rgba(0,0,0,0.2);
  border-radius: 4px; overflow: hidden; margin-top: 1rem;
}
.progress-fill {
  height: 100%; background: #fbbf24; width: 0%;
  transition: width 0.3s;
}

.journey-banner-actions { display: flex; gap: 0.5rem; }
