/* ================================================================
   content.css -- Styles for lesson content rendered inside the SPA
   ================================================================
   Adapted from the original lesson.css. Key differences:
   - Everything scoped under .lesson-content wrapper
   - Removed standalone page assumptions (body max-width, padding)
   - Removed reset rules (site.css handles those)
   - Kept all typography, code blocks, .example, callouts, tables
   - Added styles for example viewer (iframe + source toggle)
   ================================================================ */

/* ----------------------------------------------------------------
   Container -- constrains lesson text to a readable width
   ---------------------------------------------------------------- */
.lesson-content {
  max-width: 820px;
  margin: 0 auto;
  line-height: 1.7;
  color: #2d3436;
}

/* ----------------------------------------------------------------
   Typography
   ---------------------------------------------------------------- */
.lesson-content h1,
.lesson-content h2,
.lesson-content h3,
.lesson-content h4,
.lesson-content h5,
.lesson-content h6 {
  color: #1a7a6d;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.lesson-content h1 {
  font-size: 2rem;
  border-bottom: 3px solid #1a7a6d;
  padding-bottom: 0.5rem;
  margin-top: 0;
}

.lesson-content h2 { font-size: 1.5rem; }
.lesson-content h3 { font-size: 1.25rem; }
.lesson-content h4 { font-size: 1.1rem; }

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

.lesson-content a {
  color: #0984e3;
  text-decoration: none;
}

.lesson-content a:hover {
  text-decoration: underline;
  color: #065a9e;
}

/* ----------------------------------------------------------------
   Inline Code & Code Blocks
   ---------------------------------------------------------------- */
.lesson-content code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
  background: #e9ecef;
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.lesson-content pre {
  background: #2d3436;
  color: #dfe6e9;
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

/* Reset inline-code styles when inside a pre block */
.lesson-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: 0.875rem;
}

/* ----------------------------------------------------------------
   Example Wrapper
   .example > .example-label + pre > code + .example-result
   ---------------------------------------------------------------- */
.lesson-content .example {
  border: 1px solid #dee2e6;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.lesson-content .example-label {
  background: #1a7a6d;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35rem 1rem;
}

.lesson-content .example pre {
  border-radius: 0;
  margin-bottom: 0;
}

.lesson-content .example-result {
  padding: 1.25rem;
  background: #fff;
  border-top: 2px dashed #dee2e6;
}

.lesson-content .example-result-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #868e96;
  margin-bottom: 0.5rem;
}

/* ----------------------------------------------------------------
   Callout Boxes (.note, .tip, .warning)
   ---------------------------------------------------------------- */
.lesson-content .note,
.lesson-content .tip,
.lesson-content .warning {
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  border-radius: 6px;
  border-left: 4px solid;
}

.lesson-content .note    { background: #e7f5ff; border-left-color: #339af0; }
.lesson-content .tip     { background: #ebfbee; border-left-color: #40c057; }
.lesson-content .warning { background: #fff9db; border-left-color: #fab005; }

.lesson-content .note::before,
.lesson-content .tip::before,
.lesson-content .warning::before {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.lesson-content .note::before    { content: "Note";    color: #1971c2; }
.lesson-content .tip::before     { content: "Tip";     color: #2b8a3e; }
.lesson-content .warning::before { content: "Warning"; color: #e67700; }

/* ----------------------------------------------------------------
   Lists
   ---------------------------------------------------------------- */
.lesson-content ul,
.lesson-content ol {
  margin-bottom: 1rem;
  padding-left: 1.75rem;
}

.lesson-content li {
  margin-bottom: 0.35rem;
}

.lesson-content li > ul,
.lesson-content li > ol {
  margin-bottom: 0;
  margin-top: 0.25rem;
}

/* Definition lists */
.lesson-content dl {
  margin-bottom: 1rem;
}

.lesson-content dt {
  font-weight: 600;
  margin-top: 0.75rem;
}

.lesson-content dd {
  margin-left: 1.75rem;
  margin-bottom: 0.35rem;
}

/* ----------------------------------------------------------------
   Tables
   ---------------------------------------------------------------- */
.lesson-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
}

.lesson-content th,
.lesson-content td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border: 1px solid #dee2e6;
}

.lesson-content th {
  background: #1a7a6d;
  color: #fff;
  font-weight: 600;
}

.lesson-content tr:nth-child(even) {
  background: #f1f3f5;
}

/* ----------------------------------------------------------------
   Miscellaneous
   ---------------------------------------------------------------- */
.lesson-content hr {
  border: none;
  border-top: 1px solid #dee2e6;
  margin: 2rem 0;
}

.lesson-content img {
  max-width: 100%;
  height: auto;
}

.lesson-content blockquote {
  border-left: 4px solid #dee2e6;
  padding: 0.75rem 1.25rem;
  margin: 0 0 1.5rem 0;
  color: #495057;
  background: #f1f3f5;
  border-radius: 0 6px 6px 0;
}

/* ----------------------------------------------------------------
   Example Viewer (standalone examples shown in iframe + source)
   ---------------------------------------------------------------- */
.example-viewer {
  max-width: 960px;
  margin: 0 auto;
}

.example-viewer h1 {
  font-size: 1.5rem;
  color: #1a7a6d;
  margin: 0 0 1rem;
}

/* Toolbar above the iframe */
.example-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.example-toolbar button {
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: #e9ecef;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  cursor: pointer;
  color: #2d3436;
  transition: background 0.15s;
}

.example-toolbar button:hover {
  background: #dee2e6;
}

.example-toolbar button.active {
  background: #1a7a6d;
  color: #fff;
  border-color: #1a7a6d;
}

.example-toolbar a {
  font-size: 0.85rem;
  color: #0984e3;
  margin-left: auto;
}

/* The iframe that renders the example */
.example-frame {
  width: 100%;
  min-height: 400px;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  background: #fff;
}

/* Source code panel (shown when "View Source" is toggled) */
.example-source {
  display: none;
  margin-top: 0.75rem;
}

.example-source.visible {
  display: block;
}

.example-source pre {
  background: #2d3436;
  color: #dfe6e9;
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.875rem;
  max-height: 500px;
  overflow-y: auto;
}

.example-source pre code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

/* ----------------------------------------------------------------
   Content navigation (prev / next links at bottom of lesson)
   ---------------------------------------------------------------- */
.content-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  margin-top: 2rem;
  border-top: 1px solid #dee2e6;
  font-size: 0.9rem;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.content-nav a {
  color: #0984e3;
  font-weight: 500;
  text-decoration: none;
}

.content-nav a:hover {
  text-decoration: underline;
}

.content-nav .nav-prev::before { content: "\2190\00a0"; }
.content-nav .nav-next::after  { content: "\00a0\2192"; }

.content-nav .nav-disabled {
  color: #adb5bd;
}

/* ----------------------------------------------------------------
   Error message (when content fails to load)
   ---------------------------------------------------------------- */
.load-error {
  text-align: center;
  padding: 4rem 1rem;
  color: #e74c3c;
}

.load-error h2 {
  color: #e74c3c;
  margin-bottom: 0.5rem;
}

.load-error p {
  color: #6b7c8d;
}

/* ----------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------- */
@media (max-width: 600px) {
  .lesson-content h1 { font-size: 1.6rem; }
  .lesson-content h2 { font-size: 1.3rem; }

  .lesson-content pre {
    font-size: 0.8rem;
    padding: 1rem;
  }

  .example-frame {
    min-height: 300px;
  }
}

/* ================================================================
   EXERCISE EDITOR
   ================================================================
   Layout for the interactive exercise environment:
   - Collapsible instructions panel
   - Split pane: CodeMirror editor (left) + live preview (right)
   - Editor tab bar for multi-file exercises (HTML / CSS)
   - Action bar (Reset, Show Solution, Check Answer)
   - Solution display panel
   - Feedback panel
   ================================================================ */

/* ---- Container ----
   Uses min-height to ensure the split pane fills the content area.
   The content-area is position:fixed with top/bottom, so we can
   calculate available height minus padding. */
.exercise-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: calc(100vh - var(--header-height, 56px) - 4rem);
}

/* ---- Instructions panel (collapsible) ---- */
.instructions-panel {
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary, #f5f6f7);
}

.instructions-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1.25rem;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary, #1a1a2e);
  cursor: pointer;
  text-align: left;
}

.instructions-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
}

.toggle-chevron {
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.instructions-content {
  max-height: 40vh;
  overflow-y: auto;
  padding: 0 1.25rem 1rem;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

/* When collapsed, hide content */
.instructions-panel.collapsed .instructions-content {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}

/* ---- Split pane: editor + preview ---- */
.exercise-split {
  display: flex;
  flex: 1;
  min-height: 400px;
  border-bottom: 1px solid var(--border);
}

/* Editor pane (left half) */
.exercise-editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
}

/* Preview pane (right half) */
.exercise-preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---- Tab bar ---- */
.editor-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  background: #1e1e2e;
  border-bottom: 1px solid #333;
  padding: 0;
}

.editor-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: #888;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.editor-tab:hover {
  color: #ccc;
}

.editor-tab.active {
  color: #fff;
  border-bottom-color: var(--accent, #1a7a6d);
}

/* Only style button tabs as interactive */
button.editor-tab {
  cursor: pointer;
}

span.editor-tab {
  cursor: default;
}

/* ---- Editor wrapper (holds CodeMirror) ---- */
.editor-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Make CodeMirror fill the wrapper */
.editor-wrap .cm-editor {
  height: 100%;
}

.editor-wrap .cm-scroller {
  overflow: auto;
}

/* ---- Preview label ---- */
.preview-label {
  padding: 0.5rem 1rem;
  background: #f0f1f3;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
}

/* ---- Preview iframe ---- */
.exercise-preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

/* ---- Action bar ---- */
.exercise-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--bg-secondary, #f5f6f7);
  border-bottom: 1px solid var(--border);
}

.action-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.reset-btn {
  background: #fff;
  color: #555;
}

.reset-btn:hover {
  background: #eee;
}

.solution-btn {
  background: var(--accent, #1a7a6d);
  color: #fff;
  border-color: var(--accent, #1a7a6d);
}

.solution-btn:hover {
  opacity: 0.9;
}

.check-btn {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.check-btn:hover {
  opacity: 0.9;
}

/* ---- Solution panel ---- */
.solution-panel {
  background: #1e1e2e;
  color: #d4d4d4;
  padding: 1rem 1.25rem;
  overflow-y: auto;
  max-height: 50vh;
  border-bottom: 1px solid var(--border);
}

.solution-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--accent, #1a7a6d);
}

.solution-file-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #888;
  margin: 1rem 0 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.solution-panel pre {
  background: #282a36;
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0.25rem 0 0.5rem;
}

.solution-panel code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

.solution-error {
  color: #e74c3c;
  font-style: italic;
}

/* ---- Feedback panel ---- */
.feedback-panel {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.feedback-placeholder {
  padding: 0.75rem 1rem;
  background: #fef3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #856404;
}

/* ================================================================
   Exercise editor -- responsive
   ================================================================ */

@media (max-width: 768px) {
  /* Stack editor and preview vertically on narrow screens */
  .exercise-split {
    flex-direction: column;
  }

  .exercise-editor-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 250px;
    max-height: 50vh;
  }

  .exercise-preview-pane {
    min-height: 200px;
  }

  .instructions-content {
    max-height: 30vh;
  }
}
