/* Learn By Inventing — shared chapter styles */

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

body {
  font-family: Georgia, serif;
  background: #fafaf8;
  color: #1a1a1a;
  max-width: 800px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  line-height: 1.7;
}

/* ── Navigation bar ────────────────────────────────────── */

.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  font-size: 0.85rem;
  color: #888;
}

.topnav a {
  color: #888;
  text-decoration: none;
}

.topnav a:hover {
  color: #c8a96e;
  text-decoration: underline;
}

.topnav-views {
  display: flex;
  gap: 10px;
  align-items: center;
}

.topnav-views strong {
  color: #333;
}

/* ── Chapter header ────────────────────────────────────── */

h1 {
  font-size: 2rem;
  font-weight: normal;
  letter-spacing: -0.5px;
  margin-bottom: 0.3rem;
}

.chapter-intro {
  color: #555;
  font-size: 1rem;
  margin-bottom: 2rem;
  font-style: italic;
}

/* ── Syntax overview (Python quick-reference) ─────────── */

.syntax-overview {
  background: #f5f3ef;
  border: 1px solid #e0ddd6;
  border-radius: 6px;
  padding: 1.2rem 1.5rem;
  margin-bottom: 2rem;
  font-size: 0.92rem;
  line-height: 1.6;
}

.syntax-overview h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #7a6b3a;
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 0.8rem;
  border-bottom: 1px solid #e0ddd6;
  padding-bottom: 0.4rem;
}

.syntax-overview p {
  margin-bottom: 0.5rem;
  color: #444;
}

.syntax-overview pre {
  font-size: 0.84rem;
  margin: 0.5rem 0;
  padding: 0.7rem 0.9rem;
}

.syntax-overview ul {
  margin: 0.4rem 0 0.6rem 1.2rem;
  color: #444;
}

.syntax-overview li {
  margin-bottom: 0.2rem;
}

/* ── Global controls ───────────────────────────────────── */

.global-controls {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 2rem;
}

.global-controls button {
  font-family: Georgia, serif;
  font-size: 0.82rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid #d5d0c8;
  border-radius: 4px;
  background: #f5f3ef;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.global-controls button:hover {
  background: #ebe8e2;
  border-color: #c8a96e;
}

/* ── Part / section dividers ───────────────────────────── */

.part {
  margin-top: 3rem;
  margin-bottom: 1.5rem;
}

.part h2 {
  font-size: 1.25rem;
  font-weight: normal;
  color: #1a1a1a;
  border-bottom: 2px solid #c8a96e;
  padding-bottom: 0.4rem;
  margin-bottom: 0.4rem;
}

.part-intro {
  color: #555;
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

/* ── Exercise cards ────────────────────────────────────── */

.exercise {
  background: #fff;
  border: 1px solid #e8e6e0;
  border-radius: 6px;
  padding: 1.5rem;
  margin-bottom: 1.8rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.exercise h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f0ede6;
}

/* ── Question block (always visible) ───────────────────── */

.question {
  margin-bottom: 1rem;
}

.question p {
  margin-bottom: 0.7rem;
}

.question ul,
.question ol {
  margin: 0.5rem 0 0.7rem 1.4rem;
}

.question li {
  margin-bottom: 0.3rem;
}

.question strong {
  color: #333;
}

.question em {
  color: #555;
}

.question blockquote {
  border-left: 3px solid #c8a96e;
  padding: 0.5rem 0.8rem;
  margin: 0.7rem 0;
  background: #faf8f4;
  color: #555;
  font-size: 0.95rem;
}

.question table {
  border-collapse: collapse;
  margin: 0.7rem 0;
  font-size: 0.92rem;
  width: 100%;
}

.question th,
.question td {
  border: 1px solid #ddd;
  padding: 0.4rem 0.7rem;
  text-align: left;
}

.question th {
  background: #f5f3ef;
  font-weight: 600;
}

/* ── Code blocks ───────────────────────────────────────── */

pre {
  background: #282c34;
  color: #abb2bf;
  padding: 1rem;
  border-radius: 5px;
  overflow-x: auto;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0.7rem 0;
}

code {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.88em;
}

p code,
li code,
td code {
  background: #f0ede6;
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  color: #c7254e;
  font-size: 0.85em;
}

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

/* ── Provided code blocks (non-collapsible helpers) ───── */

.provided-code {
  margin: 1rem 0;
  border: 1px solid #d5d0c8;
  border-radius: 5px;
  overflow: hidden;
}

.provided-code-label {
  background: #f5f3ef;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #d5d0c8;
}

.provided-code pre {
  margin: 0;
  border-radius: 0;
}

/* ── Hint blocks (details/summary) ─────────────────────── */

details.hint {
  margin: 0.6rem 0;
  border: 1px solid #e0ddd6;
  border-radius: 5px;
  overflow: hidden;
  transition: opacity 0.3s ease;
}

details.hint > summary {
  cursor: pointer;
  padding: 0.6rem 0.9rem;
  background: #fffcf5;
  font-weight: 600;
  font-size: 0.92rem;
  color: #7a6b3a;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: background 0.15s;
}

details.hint > summary::-webkit-details-marker { display: none; }

details.hint > summary::before {
  content: "\1F4A1";
  font-size: 1rem;
}

details.hint > summary::after {
  content: "\25B6";
  font-size: 0.65rem;
  margin-left: auto;
  transition: transform 0.2s;
  color: #aaa;
}

details.hint[open] > summary::after {
  transform: rotate(90deg);
}

details.hint > summary:hover {
  background: #faf5e8;
}

details.hint > .hint-body {
  padding: 0.8rem 0.9rem;
  background: #fffef9;
  border-top: 1px solid #e8e5dc;
  font-size: 0.95rem;
  color: #444;
}

details.hint > .hint-body p {
  margin-bottom: 0.5rem;
}

details.hint > .hint-body p:last-child {
  margin-bottom: 0;
}

details.hint.locked {
  display: none;
}

/* ── Solution blocks ───────────────────────────────────── */

details.solution {
  margin-top: 0.8rem;
  border: 1px solid #d5e8d5;
  border-radius: 5px;
  overflow: hidden;
}

details.solution > summary {
  cursor: pointer;
  padding: 0.6rem 0.9rem;
  background: #f2f9f2;
  font-weight: 600;
  font-size: 0.92rem;
  color: #3a7a3a;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: background 0.15s;
}

details.solution > summary::-webkit-details-marker { display: none; }

details.solution > summary::before {
  content: "\2705";
  font-size: 0.9rem;
}

details.solution > summary::after {
  content: "\25B6";
  font-size: 0.65rem;
  margin-left: auto;
  transition: transform 0.2s;
  color: #aaa;
}

details.solution[open] > summary::after {
  transform: rotate(90deg);
}

details.solution > summary:hover {
  background: #e8f5e8;
}

details.solution > .solution-body {
  padding: 0.8rem 0.9rem;
  background: #fafff9;
  border-top: 1px solid #d5e8d5;
}

details.solution > .solution-body p {
  margin-bottom: 0.5rem;
}

/* ── Your-answer prompt blocks ─────────────────────────── */

.answer-prompt {
  background: #f8f6f2;
  border: 1px dashed #d5d0c8;
  border-radius: 5px;
  padding: 0.8rem 1rem;
  margin: 0.8rem 0;
  font-size: 0.92rem;
  color: #666;
}

.answer-prompt strong {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #999;
}

/* ── MCQ exercises ────────────────────────────────────── */

.mcq-options {
  margin: 1rem 0;
}

.mcq-option {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  margin-bottom: 0.5rem;
  border: 1px solid #e0ddd6;
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.95rem;
  line-height: 1.5;
}

.mcq-option:hover {
  border-color: #c8a96e;
  background: #faf8f4;
}

.mcq-option input[type="radio"] {
  accent-color: #c8a96e;
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.mcq-option.correct {
  border-color: #3a7a3a;
  background: #f2f9f2;
}

.mcq-option.incorrect {
  border-color: #c0392b;
  background: #fdf2f2;
}

.mcq-options.checked .mcq-option {
  cursor: default;
}

.mcq-options.checked .mcq-option:hover {
  border-color: #e0ddd6;
  background: transparent;
}

.mcq-options.checked .mcq-option.correct:hover {
  border-color: #3a7a3a;
  background: #f2f9f2;
}

.mcq-options.checked .mcq-option.incorrect:hover {
  border-color: #c0392b;
  background: #fdf2f2;
}

.mcq-check {
  font-family: Georgia, serif;
  font-size: 0.88rem;
  padding: 0.45rem 1.2rem;
  border: 1px solid #c8a96e;
  border-radius: 4px;
  background: #fffcf5;
  color: #7a6b3a;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}

.mcq-check:hover {
  background: #faf5e8;
  border-color: #b8994e;
}

.mcq-check:disabled {
  opacity: 0.5;
  cursor: default;
}

.mcq-feedback {
  display: none;
  margin-top: 0.8rem;
  padding: 0.6rem 1rem;
  border-radius: 5px;
  font-size: 0.92rem;
  font-weight: 600;
}

.mcq-feedback.correct {
  background: #f2f9f2;
  color: #2d6a2d;
  border: 1px solid #d5e8d5;
}

.mcq-feedback.incorrect {
  background: #fdf2f2;
  color: #a93226;
  border: 1px solid #f0c8c8;
}

/* ── MathJax / LaTeX inline ────────────────────────────── */

.math {
  font-style: italic;
}

/* ── Footer ────────────────────────────────────────────── */

.chapter-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e8e6e0;
  font-size: 0.85rem;
  color: #aaa;
}

.chapter-footer a {
  color: #aaa;
}

.chapter-footer a:hover {
  color: #c8a96e;
}

/* ── Progress indicator ───────────────────────────────── */

.progress-indicator {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(200, 169, 110, 0.92);
  color: #fff;
  padding: 0.3rem 0.75rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  z-index: 1000;
  display: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  letter-spacing: 0.02em;
}

/* ── Time estimate badge ──────────────────────────────── */

.time-estimate {
  font-size: 0.72rem;
  color: #999;
  font-weight: normal;
  font-family: system-ui, sans-serif;
  background: #f0ede6;
  padding: 0.15rem 0.5rem;
  border-radius: 8px;
  margin-left: 0.6rem;
  vertical-align: middle;
}

/* ── Copy code button ─────────────────────────────────── */

pre {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(255, 255, 255, 0.12);
  color: #999;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.3;
  z-index: 10;
}

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

.copy-btn.copied {
  color: #7ec87e;
  border-color: rgba(126, 200, 126, 0.4);
}

/* ── Completion checkbox ──────────────────────────────── */

.completion-check-label {
  display: inline;
  margin-right: 0.35rem;
  vertical-align: middle;
  cursor: pointer;
}

.completion-check {
  accent-color: #c8a96e;
  transform: scale(1.15);
  vertical-align: middle;
  cursor: pointer;
}

/* ── Editable answer textarea ─────────────────────────── */

.prompt-text {
  margin-bottom: 0.4rem;
}

.answer-input {
  width: 100%;
  font-family: Georgia, serif;
  font-size: 0.92rem;
  padding: 0.6rem;
  border: 1px solid #d5d0c8;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  resize: vertical;
  min-height: 60px;
  margin-top: 0.3rem;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.answer-input:focus {
  outline: none;
  border-color: #c8a96e;
  box-shadow: 0 0 0 2px rgba(200, 169, 110, 0.15);
}

/* ── CartPole animation ───────────────────────────────── */

.cartpole-demo {
  max-width: 400px;
  margin: 1.2rem auto;
  text-align: center;
}

.cartpole-demo svg {
  width: 100%;
  height: auto;
}

.cartpole-caption {
  font-size: 0.85rem;
  color: #888;
  font-style: italic;
  margin-top: 0.5rem;
}

@keyframes cartpole-swing {
  0%, 100% { transform: rotate(0deg); }
  30% { transform: rotate(-12deg); }
  70% { transform: rotate(10deg); }
}

.cartpole-pole {
  animation: cartpole-swing 2.5s ease-in-out infinite;
  transform-origin: 200px 130px;
}

/* ── Glossary panel ───────────────────────────────────── */

.glossary-toggle {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: rgba(200, 169, 110, 0.92);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  transition: background 0.15s;
}

.glossary-toggle:hover {
  background: rgba(180, 149, 90, 0.95);
}

.glossary-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 320px;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 20px rgba(0,0,0,0.12);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.glossary-panel.open {
  transform: translateX(0);
}

.glossary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid #e8e6e0;
}

.glossary-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0;
}

.glossary-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #888;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}

.glossary-close:hover {
  color: #333;
}

.glossary-search {
  margin: 0.8rem 1.2rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid #d5d0c8;
  border-radius: 4px;
  font-size: 0.88rem;
  font-family: Georgia, serif;
}

.glossary-search:focus {
  outline: none;
  border-color: #c8a96e;
}

.glossary-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 1.2rem 1.2rem;
  margin: 0;
}

.glossary-entry {
  padding: 0.7rem 0;
  border-bottom: 1px solid #f0ede6;
}

.glossary-entry.hidden {
  display: none;
}

.glossary-entry dt {
  font-weight: 600;
  font-size: 0.92rem;
  color: #7a6b3a;
  margin-bottom: 0.2rem;
}

.glossary-entry dd {
  font-size: 0.88rem;
  color: #555;
  margin: 0;
  line-height: 1.5;
}

.glossary-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.15);
  z-index: 1999;
  display: none;
}

.glossary-overlay.open {
  display: block;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 600px) {
  body { padding: 1.5rem 1rem 3rem; }
  .exercise { padding: 1rem; }
  pre { font-size: 0.82rem; padding: 0.7rem; }
  .progress-indicator { top: auto; bottom: 16px; right: 16px; font-size: 0.7rem; }
  .glossary-panel { width: 100%; }
  .global-controls { flex-wrap: wrap; }
  .answer-input { font-size: 16px; }
}

/* Hide reveal.js fade-out placeholders (the "?" in table cells) in the interactive view */
td .fragment.fade-out { display: none; }
