:root {
  /* Playground editor/console/sidebar and static code-preview blocks —
     these now follow the site's light/dark toggle. Light values below;
     dark overrides (matching the CodeMirror Dracula theme, used when
     data-theme="dark") are in :root[data-theme="dark"]. See
     playground/static/playground/run.js and static/highlight.js for how
     the CodeMirror "theme" option / cm-s-dracula class switch alongside
     these tokens. */
  --code-bg: #ffffff;
  --code-panel-bg: #f4f5f7;
  --code-border: #dde1e7;
  --code-text: #1e1f29;
  --code-muted: #626a7a;
  --code-accent: #0050dc;
  --code-danger: #d1453b;

  /* Light theme (default) tokens for general site chrome. */
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --border: #dde1e7;
  --text: #1e1f29;
  --muted: #626a7a;
  --accent: #0050dc;
  --accent-dark: #1034a6;
  --danger: #d1453b;

  /* Home page hero code snippet — unlike --code-*, this DOES follow the
     site's light/dark toggle (it's a plain marketing illustration, not
     paired with a fixed-dark CodeMirror instance). Light values below;
     dark overrides in :root[data-theme="dark"]. */
  --hero-code-bg: #f4f5f7;
  --hero-code-border: transparent;
  --hero-code-text: #1e1f29;
  --hero-code-comment: #2e7d32;
  --hero-code-kw-action: #8250df;
  --hero-code-kw-block: #0057b7;
  --hero-code-type: #0b7285;
  --hero-code-string: #c2410c;
  --hero-code-var: #1e1f29;
  --hero-code-number: #1e1f29;

  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  /* Dark theme tokens for general site chrome — identical to the fixed
     --code-* values above, since the whole site was originally dark-only,
     but kept as separate variables so the two can be tuned independently. */
  --bg: #1e1f29;
  --panel-bg: #282a36;
  --border: #3a3d4d;
  --text: #f1f2f6;
  --muted: #9aa0b4;
  --accent: #5b8ff8;
  --accent-dark: #3d6fe0;
  --danger: #ff6b6b;

  --code-bg: #1e1f29;
  --code-panel-bg: #282a36;
  --code-border: #3a3d4d;
  --code-text: #f1f2f6;
  --code-muted: #9aa0b4;
  --code-accent: #5b8ff8;
  --code-danger: #ff6b6b;

  /* Dark values match the real CodeMirror Dracula theme used everywhere
     else on the site (see codefr-mode.js/highlight.js), for consistency. */
  --hero-code-bg: #282a36;
  --hero-code-border: #3a3d4d;
  --hero-code-text: #f1f2f6;
  --hero-code-comment: #6272a4;
  --hero-code-kw-action: #ff79c6;
  --hero-code-kw-block: #ff79c6;
  --hero-code-type: #ffb86c;
  --hero-code-string: #f1fa8c;
  --hero-code-var: #50fa7b;
  --hero-code-number: #bd93f9;
}

/* Reskin Bulma to the brand palette above (HSL). Hue/saturation stay
   constant across themes (brand identity) and live on :root; lightness is
   Bulma's own light-mode default on :root, overridden for dark under
   [data-theme="dark"] below. The toggle in base.html always sets one of
   the two explicitly (never removes the attribute), so this never races
   with Bulma's own prefers-color-scheme fallback. */
:root {
  --bulma-scheme-h: 235;
  --bulma-scheme-s: 15%;
  --bulma-primary-h: 220deg;
  --bulma-primary-s: 88%;
  --bulma-link-h: 220deg;
  --bulma-link-s: 88%;
  --bulma-danger-h: 0deg;
  --bulma-danger-s: 100%;
}

:root[data-theme="dark"] {
  --bulma-scheme-main-l: 14%;      /* page background ~ --bg */
  --bulma-scheme-main-bis-l: 18%;  /* boxes/cards ~ --panel-bg */
  --bulma-scheme-main-ter-l: 22%;
  --bulma-background-l: 18%;
  --bulma-border-weak-l: 22%;
  --bulma-border-l: 26%;           /* ~ --border */
  --bulma-text-l: 65%;             /* body text ~ --muted */
  --bulma-text-strong-l: 95%;      /* headings/emphasis ~ --text */
  --bulma-primary-l: 63%;
  --bulma-link-l: 63%;
  --bulma-danger-l: 71%;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Grows to push the footer down on short pages, but never shrinks below its
   own content — lets body grow past 100vh and the page scroll normally on
   tall pages (docs, home, lists...). */
.site-main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

/* The playground's two-pane editor (playground/style.css) fills remaining
   viewport height via a flex:1 chain rooted here, with its own panes
   scrolling internally instead of the page — the opposite of every other
   page, so it opts out of the natural-height behavior above. */
.site-main.playground-page {
  flex: 1 1 0%;
  min-height: 0;
}

.footer {
  --bulma-footer-padding: 2rem 1.5rem;
  flex-shrink: 0;
}

.inline-form {
  display: inline;
}

.empty-state {
  color: var(--muted);
  padding: 2rem 0;
  text-align: center;
}

.challenge-description {
  white-space: pre-wrap;
}

.code-preview {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 1rem 0;
}

.like-button.liked {
  border-color: var(--accent);
  color: var(--accent);
}

.button.is-primary,
.button.is-primary:hover,
.button.is-primary:focus {
  color: #ffffff;
}

.comments {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.comments h2 {
  font-size: 1.1rem;
  margin-top: 0;
}

.comment-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.comment {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.comment-body {
  margin: 0 0 0.5rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 500px;
}

.comment-form button {
  align-self: flex-start;
}

.icon-illustration {
  margin-bottom: 0.5rem;
}

.icon-illustration svg {
  width: 56px;
  height: 56px;
  color: var(--accent);
}

.icon-illustration-inline {
  display: inline-flex;
  vertical-align: middle;
}

.icon-illustration-inline svg {
  width: 1.3em;
  height: 1.3em;
  color: var(--accent);
}

/* Learning path: persistent chapter sidebar (learning/_sidebar.html) plus
   the matching locked/unlocked treatment reused on the chapter list boxes
   (learning/list.html). Locked chapters are visually muted and inert —
   never a clickable <a> — so "locked" reads clearly at a glance. */
.chapter-menu {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  position: sticky;
  top: 1rem;
}

.chapter-menu-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border-left: 3px solid transparent;
  color: var(--text);
  text-decoration: none;
}

a.chapter-item:hover {
  background: var(--bg);
}

.chapter-item.is-active {
  border-left-color: var(--accent);
  background: var(--bg);
  font-weight: 600;
}

.chapter-item.is-locked {
  color: var(--muted);
  cursor: not-allowed;
}

.chapter-index {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 600;
}

.chapter-item.is-locked .chapter-index {
  background: transparent;
  border: 1px solid var(--border);
}

.chapter-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chapter-title {
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-score {
  font-size: 0.75rem;
  color: var(--muted);
}

.chapter-item.is-done .chapter-icon svg {
  color: #2ea043;
}

.chapter-icon svg {
  width: 1.1em;
  height: 1.1em;
  color: var(--muted);
}

.box.is-locked {
  opacity: 0.65;
}

/* Home page hero: a fixed brand-blue banner (independent of the site's
   light/dark toggle) with a static, hand-colored code snippet that DOES
   follow the toggle — see --hero-code-* tokens above (dark values match
   the real CodeMirror Dracula theme used everywhere else on the site).
   Hand-colored rather than run through CodeMirror since this content never
   changes and shouldn't depend on loading CodeMirror just for the homepage. */
.hero-intro {
  background: #1034a6;
}

.hero-code-card {
  position: relative;
  background: var(--hero-code-bg);
  border: 1px solid var(--hero-code-border);
  border-radius: 10px;
  padding: 1.75rem 1.5rem 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
}

.hero-code-badge {
  position: absolute;
  top: -12px;
  right: 20px;
  background: #1034a6;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 4px;
}

.hero-code-snippet {
  margin: 0;
  background: transparent;
  color: var(--hero-code-text);
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre;
  overflow-x: auto;
}

.hero-code-snippet .tok-comment { color: var(--hero-code-comment); }
.hero-code-snippet .tok-kw-action { color: var(--hero-code-kw-action); }
.hero-code-snippet .tok-kw-block { color: var(--hero-code-kw-block); }
.hero-code-snippet .tok-type { color: var(--hero-code-type); }
.hero-code-snippet .tok-string { color: var(--hero-code-string); }
.hero-code-snippet .tok-var { color: var(--hero-code-var); }
.hero-code-snippet .tok-number { color: var(--hero-code-number); }

/* ---------------------------------------------------------------------
   Site-wide animation & micro-interactions. Kept subtle and consistent
   rather than page-specific, since every page shares this stylesheet via
   base.html. Respects prefers-reduced-motion (rule at the very end).
   --------------------------------------------------------------------- */

@keyframes codefr-fade-in-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes codefr-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes codefr-icon-flip {
  from { transform: rotate(0deg); }
  to { transform: rotate(180deg); }
}

html {
  scroll-behavior: smooth;
}

/* Every page's main content gently settles in on load. */
.site-main {
  animation: codefr-fade-in-up 0.45s ease-out both;
}

/* Flash messages arrive with their own, slightly quicker fade so they
   don't look like part of the initial page settle. */
.site-main > .container > .notification {
  animation: codefr-fade-in 0.3s ease-out both;
}

/* Cards/boxes lift slightly on hover across the whole site (lesson list,
   home page feature boxes, locked-lesson panel, etc). Locked chapter
   entries opt out — they're inert, so a hover affordance would mislead. */
.box {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.box:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.box.is-locked:hover {
  transform: none;
  box-shadow: none;
}

/* Buttons/links get a quick, tactile press instead of just Bulma's
   instant hover-color swap. */
.button,
.navbar-item,
a.chapter-item {
  transition: transform 0.1s ease, background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.button:active {
  transform: scale(0.96);
}

a.chapter-item:hover:not(.is-active) {
  transform: translateX(2px);
}

/* The sun/moon theme-toggle icon spins into place on toggle (nav.js adds
   this class right before it swaps the SVG, then removes it once the
   animation ends). */
#theme-toggle-icon.is-flipping {
  animation: codefr-icon-flip 0.3s ease;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.exercise-last-submission {
  margin-top: 0.75rem;
}

.exercise-last-submission summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

.exercise-last-submission[open] summary {
  margin-bottom: 0.5rem;
}

.rubric-report {
  list-style: none;
  margin: 0.5rem 0;
  padding: 0;
}

.rubric-report li {
  padding: 0.15rem 0;
}

.quiz-question p {
  font-weight: 600;
}

.difficulty-stars {
  color: var(--accent);
  letter-spacing: 1px;
}

/* select[data-chip-picker] is progressively enhanced into this by
   chip-multiselect.js — hidden via .is-chip-enhanced once the chips exist,
   so it stays the real (working) field for no-JS clients. */
select.is-chip-enhanced {
  display: none;
}

.chip-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-option {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip-option:hover {
  border-color: var(--accent);
}

.chip-option.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.leaderboard-rank {
  flex: none;
  width: 1.8rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.leaderboard-name {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
}

.leaderboard-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.leaderboard-points {
  flex: none;
  font-weight: 700;
  color: var(--accent);
}
