@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,600;1,400&family=IBM+Plex+Sans:ital,wght@0,400;0,600;1,400&display=swap');

/* ─── Reset & Base ─────────────────────────────────────────────────────────── */

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

:root {
  --bg:          #0f1117;
  --surface:     #181c26;
  --border:      #2a2f3d;
  --text:        #cdd4e0;
  --muted:       #5a6580;
  --code-bg:     #12151f;

  --rec:         #1a3a2a;
  --rec-border:  #2e6e4e;
  --rec-label:   #5dba8a;

  --imp:         #3a1f1a;
  --imp-border:  #7a3a2e;
  --imp-label:   #e07060;

  --tri:         #1a2a3a;
  --tri-border:  #2e4e7a;
  --tri-label:   #5a9ade;

  --ref:         #26261a;
  --ref-border:  #5a5a2a;
  --ref-label:   #b0a850;

  --info:        #1e1e2e;
  --info-border: #3a3a5a;
  --info-label:  #8888cc;

  --play:        #111622;
  --play-border: #2a3560;
  --play-label:  #4a7aff;

  --run-bg:      #1e3a7a;
  --run-hover:   #2a50aa;
  --run-text:    #aaccff;

  --rec-label-bg:  #162e22;
  --imp-label-bg:  #2e1812;
  --tri-label-bg:  #14202e;
  --ref-label-bg:  #1e1e14;
  --info-label-bg: #18182a;
  --play-label-bg: #0e1428;
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  line-height: 1.7;
  padding: 2rem 1rem 6rem;
}

/* ─── Lesson Container ─────────────────────────────────────────────────────── */

.lesson {
  max-width: 740px;
  margin: 0 auto;
}

/* ─── Prose ────────────────────────────────────────────────────────────────── */

.lesson h1 {
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #eef2ff;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
  scroll-margin-top: 4rem;
}

.lesson h2 {
  font-size: 1.4rem;
  font-weight: 600;
  color: #eef2ff;
  margin: 3.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 4rem;
}

.lesson h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #c8d4f0;
  margin: 2.25rem 0 0.5rem;
  display: inline-block;
  border-bottom: 1px solid #4a5878;
  padding-bottom: 0.2rem;
  scroll-margin-top: 4rem;
}

/* ─── Foldable sections (## > / ## <) ──────────────────────────────────────── */

.section-fold { margin: 2.25rem 0; scroll-margin-top: 4rem; }

.section-fold-summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-weight: 600;
  color: #c8d4f0;
}

.section-fold-summary::-webkit-details-marker { display: none; }
.section-fold-summary:hover { color: #eef2ff; }

.section-fold-h2 > .section-fold-summary {
  font-size: 1.4rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: #eef2ff;
}

.section-fold-h3 > .section-fold-summary {
  font-size: 1.1rem;
  display: inline-block;
  border-bottom: 1px solid #4a5878;
  padding-bottom: 0.2rem;
}

.section-fold-h2 { margin: 3.5rem 0 0.75rem; }
.section-fold-h3 { margin: 2.25rem 0 0.5rem; }

.section-fold-body { margin-top: 1rem; }
.section-fold-body > *:first-child { margin-top: 0; }

.lesson p { margin-bottom: 1.1rem; }

.lesson a { color: var(--play-label); text-decoration: none; border-bottom: 1px solid #2a3560; }
.lesson a:hover { border-color: var(--play-label); }

.lesson code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  color: #a8c0e8;
}

.lesson pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}

.lesson pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  color: #b0c8e8;
}

.lesson ul, .lesson ol {
  padding-left: 1.5rem;
  margin-bottom: 1.1rem;
}

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

.lesson strong { color: #eef2ff; font-weight: 600; }
.lesson em { color: #b0b8d0; }

/* ─── Boxes (shared) ───────────────────────────────────────────────────────── */

.box {
  border-left: 3px solid;
  border-radius: 0 6px 6px 0;
  margin: 1.75rem 0;
  overflow: hidden;
}

.box-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.35rem 1rem;
}

.box-body {
  padding: 0.75rem 1rem 0.9rem;
  font-size: 0.95rem;
}

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

/* ─── Box Variants ─────────────────────────────────────────────────────────── */

.box-rec       { background: var(--rec);  border-color: var(--rec-border); }
.box-rec       > .box-label { color: var(--rec-label);  background: var(--rec-label-bg); }

.box-important { background: var(--imp);  border-color: var(--imp-border); }
.box-important > .box-label { color: var(--imp-label);  background: var(--imp-label-bg); }

.box-trivia    { background: var(--tri);  border-color: var(--tri-border); }
.box-trivia    > .box-label { color: var(--tri-label);  background: var(--tri-label-bg); }

.box-ref       { background: var(--ref);  border-color: var(--ref-border); }
.box-ref       > .box-label { color: var(--ref-label);  background: var(--ref-label-bg); }

.box-info      { background: var(--info); border-color: var(--info-border); }
.box-info      > .box-label { color: var(--info-label); background: var(--info-label-bg); }

.box-playground { background: var(--play); border-color: var(--play-border); }
.box-playground > .box-label { color: var(--play-label); background: var(--play-label-bg); }

.box-gadget    { background: var(--play); border-color: var(--play-border); }
.box-gadget    > .box-label { color: var(--play-label); background: var(--play-label-bg); }

/* ─── Foldable boxes ───────────────────────────────────────────────────────── */
/* Applied to any box type when a fold marker (> or <) is used in the fence.   */

.box-foldable > summary.box-label {
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.box-foldable > summary.box-label::-webkit-details-marker { display: none; }
.box-foldable > summary.box-label:hover { filter: brightness(1.15); }
.box-foldable > .box-body { border-top: 1px solid var(--border); }

/* Each variant's own border colour for the body divider line */
.box-rec.box-foldable       > .box-body { border-top-color: var(--rec-border); }
.box-important.box-foldable > .box-body { border-top-color: var(--imp-border); }
.box-trivia.box-foldable    > .box-body { border-top-color: var(--tri-border); }
.box-ref.box-foldable       > .box-body { border-top-color: var(--ref-border); }
.box-info.box-foldable      > .box-body { border-top-color: var(--info-border); }
.box-playground.box-foldable > .box-body { border-top-color: var(--play-border); }
.box-gadget.box-foldable    > .box-body { border-top-color: var(--play-border); }

/* ─── Playground internals ─────────────────────────────────────────────────── */

.playground-editor {
  display: block;
  width: 100%;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  color: #b8d0f0;
  background: #0a0e1a;
  border: none;
  border-top: 1px solid var(--play-border);
  border-bottom: 1px solid var(--play-border);
  padding: 0.9rem 1rem;
  resize: vertical;
  min-height: 7rem;
  outline: none;
  tab-size: 2;
}

.playground-editor:focus {
  background: #0c1020;
  box-shadow: inset 0 0 0 1px #2a3a6a;
}

.playground-controls {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: #0e1428;
  border-bottom: 1px solid var(--play-border);
}

.playground-run {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--run-text);
  background: var(--run-bg);
  border: 1px solid #2a4a9a;
  border-radius: 4px;
  padding: 0.3rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.playground-run:hover:not(:disabled) { background: var(--run-hover); }
.playground-run:disabled { opacity: 0.5; cursor: not-allowed; }

.playground-clear {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.playground-clear:hover { color: var(--text); border-color: var(--muted); }

.playground-output {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  color: #90aad0;
  background: #070a12;
  padding: 0.75rem 1rem;
  min-height: 2.5rem;
  white-space: pre-wrap;
  border-top: 1px solid #12182a;
}

.playground-output.error { color: #e07060; }

/* ─── SVG Frame Scrubber ───────────────────────────────────────────────────── */

.playground-svg {
  background: #070a12;
  border-top: 1px solid #12182a;
  padding: 1rem;
}

.svg-display {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.svg-display svg { max-width: 100%; height: auto; }

.svg-scrubber {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.25rem;
}

.svg-scrubber input[type="range"] { flex: 1; accent-color: var(--play-label); }

.svg-frame-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ─── Error ────────────────────────────────────────────────────────────────── */

.load-error {
  color: var(--imp-label);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  padding: 2rem;
  text-align: center;
}

/* ─── Site Header ──────────────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.lesson-nav {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  gap: 1rem;
}

.lesson-nav a { color: var(--muted); text-decoration: none; border: none; }
.lesson-nav a:hover { color: var(--text); }

.theme-toggle {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.theme-toggle:hover { color: var(--text); border-color: var(--muted); }

/* ─── Light Theme ──────────────────────────────────────────────────────────── */

[data-theme="light"] {
  --bg:          #f5f4f0;
  --surface:     #eeedea;
  --border:      #d0cdc8;
  --text:        #1e1c1a;
  --muted:       #888480;
  --code-bg:     #eae9e4;

  --rec:         #e8f5ee;
  --rec-border:  #5dba8a;
  --rec-label:   #1a6e42;

  --imp:         #fdf0ee;
  --imp-border:  #e07060;
  --imp-label:   #9a2a1a;

  --tri:         #eef3fb;
  --tri-border:  #5a9ade;
  --tri-label:   #1a4a8a;

  --ref:         #f8f6e8;
  --ref-border:  #b0a850;
  --ref-label:   #5a5010;

  --info:        #f0f0f8;
  --info-border: #8888cc;
  --info-label:  #3a3a8a;

  --play:        #eef1fa;
  --play-border: #4a7aff;
  --play-label:  #1a3aaa;

  --run-bg:      #dce8ff;
  --run-hover:   #c0d4ff;
  --run-text:    #1a3aaa;

  --rec-label-bg:  #d8eee0;
  --imp-label-bg:  #fbe2dd;
  --tri-label-bg:  #dde9f8;
  --ref-label-bg:  #f0ecd8;
  --info-label-bg: #e4e4f4;
  --play-label-bg: #d4dcf8;
}

[data-theme="light"] .lesson h1    { color: #111; border-color: var(--border); }
[data-theme="light"] .lesson h2    { color: #1a1a2e; border-color: var(--border); }
[data-theme="light"] .lesson h3    { color: #2a3a6a; border-color: #9aa8c8; }
[data-theme="light"] .section-fold-summary               { color: #2a3a6a; }
[data-theme="light"] .section-fold-summary:hover          { color: #1a1a2e; }
[data-theme="light"] .section-fold-h2 > .section-fold-summary { color: #1a1a2e; border-color: var(--border); }
[data-theme="light"] .section-fold-h3 > .section-fold-summary { border-color: #9aa8c8; }
[data-theme="light"] .lesson code  { color: #2a4a8a; background: var(--code-bg); }
[data-theme="light"] .lesson pre   { background: var(--code-bg); }
[data-theme="light"] .lesson pre code  { color: #2a4060; }
[data-theme="light"] .lesson strong    { color: #111; }
[data-theme="light"] .lesson em        { color: #555; }

[data-theme="light"] .box-foldable > summary.box-label:hover { filter: brightness(0.97); }

[data-theme="light"] .playground-editor         { background: #e8ecf8; color: #1a2a4a; }
[data-theme="light"] .playground-editor:focus   { background: #e0e6f8; }
[data-theme="light"] .playground-controls       { background: #dce4f8; }
[data-theme="light"] .playground-output         { background: #e4e8f8; color: #1a3060; }
[data-theme="light"] .playground-output.error   { color: #9a2a1a; }
[data-theme="light"] .playground-svg            { background: #e4e8f8; }

[data-theme="light"] .site-header   { background: #eeedea; border-color: #d0cdc8; }
[data-theme="light"] .theme-toggle  { color: #555; border-color: #ccc; }
[data-theme="light"] .theme-toggle:hover { color: #111; border-color: #888; }

/* ─── Mobile ───────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  body { padding: 0 0 4rem; }

  .site-header { padding: 0.5rem 1rem; margin-bottom: 1.5rem; }

  .lesson { padding: 0 1rem; }

  .lesson h1 { font-size: 1.4rem; }
  .lesson h2 { font-size: 1.1rem; }

  .box-label { font-size: 0.65rem; padding: 0.3rem 0.75rem; }
  .box-body  { padding: 0.65rem 0.75rem; font-size: 0.9rem; }

  .playground-editor    { font-size: 0.8rem; min-height: 8rem; padding: 0.75rem; }
  .playground-controls  { padding: 0.5rem 0.75rem; flex-wrap: wrap; }
  .playground-output    { font-size: 0.78rem; padding: 0.65rem 0.75rem; }
  .playground-run, .playground-clear { font-size: 0.75rem; }

  .svg-scrubber input[type="range"] { min-width: 0; }
}

/* ─── Page navigation (prev/next, bottom of page) ──────────────────────────── */

.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  max-width: 1000px;
  margin-left:auto;
  margin-right:auto;
}

.page-nav-link {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--play-label);
  border: 1px solid var(--play-border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  transition: background 0.15s, border-color 0.15s;
}

.page-nav-link:hover { background: var(--play); border-color: var(--play-label); }

.page-nav-disabled {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  opacity: 0.5;
  cursor: default;
}

@media (max-width: 640px) {
  .page-nav { padding: 1.5rem 1rem 0; margin-top: 3rem; }
  .page-nav-link, .page-nav-disabled { font-size: 0.78rem; padding: 0.4rem 0.75rem; }
}
