:root {
  --primary: #1a365d;
  --accent: #2b6cb0;
  --bg: #f7fafc;
  --surface: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --success: #38a169;
  --error: #e53e3e;
  --warning: #d69e2e;
  --sidebar-w: 280px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: white;
  padding: 1.5rem;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar h1 {
  font-size: 1.1rem;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.sidebar .subtitle {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-bottom: 1.5rem;
}

.sidebar nav a {
  display: block;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-bottom: 2px;
  transition: all 0.2s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

.sidebar nav a.locked {
  opacity: 0.4;
  pointer-events: none;
}

.sidebar .progress-bar {
  margin-top: 1.5rem;
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
}

.sidebar .progress-bar .fill {
  background: var(--success);
  height: 100%;
  border-radius: 10px;
  transition: width 0.5s;
}

.sidebar .progress-label {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 0.3rem;
}

/* Main content */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  max-width: 900px;
  padding: 2rem 3rem;
}

/* Chapter content */
.chapter-content h2 {
  font-size: 1.6rem;
  color: var(--primary);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

.chapter-content h3 {
  font-size: 1.25rem;
  color: var(--accent);
  margin-top: 2rem;
  margin-bottom: 0.8rem;
}

.chapter-content h4 {
  font-size: 1.05rem;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.chapter-content p {
  margin-bottom: 1rem;
}

.chapter-content ul, .chapter-content ol {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
}

.chapter-content li {
  margin-bottom: 0.4rem;
}

.chapter-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

.chapter-content th {
  background: var(--primary);
  color: white;
  padding: 0.6rem 0.8rem;
  text-align: left;
  font-weight: 600;
}

.chapter-content td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.chapter-content tr:hover td {
  background: #edf2f7;
}

.chapter-content blockquote {
  border-left: 4px solid var(--accent);
  padding: 0.8rem 1.2rem;
  margin: 1.5rem 0;
  background: #ebf4ff;
  border-radius: 0 6px 6px 0;
}

/* Glossary tooltip */
.glossary-term {
  border-bottom: 2px dotted var(--accent);
  cursor: help;
  position: relative;
}

.glossary-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.5;
  width: 350px;
  max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 1000;
  pointer-events: none;
}

.glossary-tooltip .term-title {
  font-weight: 700;
  margin-bottom: 0.3rem;
  color: #90cdf4;
}

.glossary-term:hover .glossary-tooltip {
  display: block;
}

/* Quiz section */
.quiz-container {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 2rem 0;
}

.quiz-container h3 {
  color: var(--primary);
  margin-top: 0;
}

.quiz-question {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.quiz-question:last-of-type {
  border-bottom: none;
}

.quiz-question p {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.quiz-option {
  display: block;
  padding: 0.5rem 0.8rem;
  margin: 0.3rem 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.quiz-option:hover {
  border-color: var(--accent);
  background: #ebf8ff;
}

.quiz-option.correct {
  border-color: var(--success);
  background: #f0fff4;
}

.quiz-option.wrong {
  border-color: var(--error);
  background: #fff5f5;
}

.quiz-option.disabled {
  pointer-events: none;
  opacity: 0.7;
}

.quiz-feedback {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  padding: 0.5rem;
  border-radius: 4px;
  display: none;
}

.quiz-feedback.show { display: block; }
.quiz-feedback.correct { background: #f0fff4; color: #276749; }
.quiz-feedback.wrong { background: #fff5f5; color: #9b2c2c; }

.quiz-score {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  padding: 1rem;
  display: none;
}

.quiz-score.show { display: block; }

/* Calculator widget */
.calculator {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 2rem 0;
}

.calculator h3 {
  margin-top: 0;
  color: var(--primary);
}

.calc-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.calc-row label {
  flex: 0 0 220px;
  font-size: 0.9rem;
}

.calc-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.calc-row .value {
  flex: 0 0 80px;
  text-align: right;
  font-weight: 600;
  font-family: 'Consolas', monospace;
}

.calc-result {
  margin-top: 1rem;
  padding: 1rem;
  background: #ebf4ff;
  border-radius: 8px;
  text-align: center;
  font-size: 1.1rem;
}

.calc-result strong {
  font-size: 1.4rem;
  color: var(--primary);
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin: 2rem 0 1rem;
}

.tab-btn {
  padding: 0.6rem 1.2rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 1rem; }
  .glossary-tooltip { width: 250px; }
  .calc-row { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  .calc-row label { flex: none; }
}
