/* ═══════════════════════════════════════════════════════════════
   Head First-style components — shared across all tutorial pages.
   Conventions:
     .hf-talk         → chatty section intro paragraph(s)
     .hf-speech       → coach speech bubble with SP avatar
     .hf-callout      → boxed callout with pill-shaped title
       .hf-callout--brain    purple   "Brain Power"     (predict + reveal)
       .hf-callout--qa       blue     "No Dumb Questions" Q&A list
       .hf-callout--pencil   yellow   "Sharpen Your Pencil" exercise
       .hf-callout--master   green    "Mastery Move"    (next-level insight)
       .hf-callout--trap     red      "Watch Out"       (common bug)
       .hf-callout--bullets  yellow   "Bullet Points"   end-of-section summary
     .hf-pin          → numbered marker placed inline inside <code>
     .hf-anno         → ordered list paired with hf-pins (data-n attribute)
     .hf-trace        → coloured step-by-step array trace ladder
     .hf-legend       → mini legend chips for trace colours

   Also adds:
     .tutorial-card__badge--yellow — missing yellow badge variant
   ═══════════════════════════════════════════════════════════════ */

/* Chatty intro paragraphs used at the top of a section */
.hf-talk { font-size: 1.05rem; line-height: 1.75; color: var(--text); }
.hf-talk p { margin-bottom: 14px; }
.hf-talk em { color: #ffb060; font-style: normal; font-weight: 600; }

/* Generic callout box with a pill-shaped title chip */
.hf-callout {
  position: relative;
  margin: 18px 0;
  padding: 20px 22px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card2);
}
.hf-callout__title {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.7rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.14em;
  padding: 6px 12px; border-radius: 999px;
  margin-bottom: 12px;
}
.hf-callout__title svg { width: 14px; height: 14px; }
.hf-callout__body { font-size: 0.96rem; line-height: 1.7; color: var(--text); }
.hf-callout__body > p { margin-bottom: 10px; }
.hf-callout__body > p:last-child { margin-bottom: 0; }

/* "Brain Power" — purple, asks the reader to predict */
.hf-callout--brain {
  background: linear-gradient(135deg, rgba(124,92,191,0.10), rgba(79,142,247,0.07));
  border-color: rgba(124,92,191,0.35);
}
.hf-callout--brain .hf-callout__title { background: rgba(124,92,191,0.22); color: #c9b5ff; }

/* "There Are No Dumb Questions" — Q & A list */
.hf-callout--qa { background: rgba(0,164,239,0.06); border-color: rgba(0,164,239,0.25); }
.hf-callout--qa .hf-callout__title { background: rgba(0,164,239,0.18); color: #7fc8ff; }
.hf-callout--qa dl { margin: 0; }
.hf-callout--qa dt { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.hf-callout--qa dt::before { content: "Q: "; color: #58b9ff; font-weight: 800; }
.hf-callout--qa dd {
  margin: 0 0 14px;
  color: var(--text-muted);
  padding-left: 14px;
  border-left: 2px solid rgba(0,164,239,0.25);
}
.hf-callout--qa dd::before { content: "A: "; color: #58b9ff; font-weight: 800; }
.hf-callout--qa dd:last-of-type { margin-bottom: 0; }

/* "Sharpen Your Pencil" — yellow exercise w/ hidden answer */
.hf-callout--pencil { background: rgba(255,200,80,0.08); border-color: rgba(255,200,80,0.30); }
.hf-callout--pencil .hf-callout__title { background: rgba(255,200,80,0.20); color: #ffd76e; }
.hf-callout--pencil details {
  margin-top: 12px; padding: 12px 14px;
  background: rgba(52,211,153,0.08);
  border: 1px dashed rgba(52,211,153,0.30);
  border-radius: 10px;
}
.hf-callout--pencil details summary {
  cursor: pointer; font-weight: 700; color: #6ee7b7; outline: none;
  list-style: none; user-select: none;
}
.hf-callout--pencil details summary::-webkit-details-marker { display: none; }
.hf-callout--pencil details summary::before { content: "👉  "; }
.hf-callout--pencil details[open] summary { margin-bottom: 10px; }
.hf-callout--pencil details[open] summary::before { content: "👇  "; }
.hf-callout--pencil details pre {
  margin: 0; padding: 10px 12px;
  background: var(--bg-dark); border-radius: 8px;
  font-size: 0.82rem; line-height: 1.55;
  overflow-x: auto;
}

/* "Mastery Move" — next-level insight (green-purple) */
.hf-callout--master {
  background: linear-gradient(135deg, rgba(52,211,153,0.10), rgba(124,92,191,0.08));
  border-color: rgba(52,211,153,0.40);
}
.hf-callout--master .hf-callout__title { background: rgba(52,211,153,0.18); color: #6ee7b7; }

/* "Trap" — common bug warning (red) */
.hf-callout--trap {
  background: rgba(239,68,68,0.07);
  border-color: rgba(239,68,68,0.35);
}
.hf-callout--trap .hf-callout__title { background: rgba(239,68,68,0.18); color: #fca5a5; }
.hf-callout--trap code { color: #ffb4b4; }

/* "Bullet Points" summary — yellow sticky note */
.hf-callout--bullets {
  background: rgba(255,200,80,0.06);
  border-color: rgba(255,200,80,0.25);
  border-style: dashed;
}
.hf-callout--bullets .hf-callout__title { background: rgba(255,200,80,0.18); color: #ffd76e; }
.hf-callout--bullets ul { list-style: none; padding: 0; margin: 0; }
.hf-callout--bullets li { position: relative; padding-left: 24px; margin-bottom: 10px; line-height: 1.6; }
.hf-callout--bullets li::before {
  content: "✓"; position: absolute; left: 0; top: 0;
  color: #6ee7b7; font-weight: 800;
}
.hf-callout--bullets li:last-child { margin-bottom: 0; }

/* Speech bubble — coach talking to the reader */
.hf-speech {
  position: relative;
  margin: 18px 0 18px 58px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  font-style: italic;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.65;
}
.hf-speech::before {
  content: "SP";
  position: absolute;
  left: -50px; top: 2px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-style: normal;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(79,142,247,0.30);
}
.hf-speech::after {
  content: "";
  position: absolute;
  left: -7px; top: 18px;
  width: 14px; height: 14px;
  background: var(--bg-card2);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}

/* Numbered pin used inside code to mark annotated spots */
.hf-pin {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #ffb060; color: #1a1108;
  font-weight: 800; font-size: 0.72rem;
  font-family: 'JetBrains Mono', monospace;
  vertical-align: 1px;
  margin: 0 4px;
  box-shadow: 0 0 0 2px rgba(255,176,96,0.25);
}

/* Annotation list under code — pairs with .hf-pin numbers */
.hf-anno {
  margin: 12px 0 0; padding: 0;
  list-style: none;
  display: grid; gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.hf-anno li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
}
.hf-anno li::before {
  content: attr(data-n);
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: #ffb060; color: #1a1108;
  font-weight: 800; font-size: 0.74rem;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 1px;
}
.hf-anno li strong { color: var(--text); }
.hf-anno li code {
  font-size: 0.82rem;
  background: rgba(255,255,255,0.06);
  padding: 1px 6px; border-radius: 4px;
}

/* Coloured trace ladder — one row per algorithm step */
.hf-trace { display: grid; gap: 8px; margin: 14px 0 4px; }
.hf-trace__step {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.hf-trace__label {
  color: var(--text-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.hf-trace__cells {
  display: flex; gap: 5px; flex-wrap: wrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
}
.hf-trace__cell {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; padding: 4px 8px;
  border-radius: 7px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text);
}
.hf-trace__cell--look {
  background: rgba(255,176,96,0.22);
  border-color: rgba(255,176,96,0.55);
  color: #ffd09b;
  font-weight: 700;
}
.hf-trace__cell--swap {
  background: rgba(239,68,68,0.22);
  border-color: rgba(239,68,68,0.55);
  color: #ffb4b4;
  font-weight: 700;
}
.hf-trace__cell--final {
  background: rgba(52,211,153,0.18);
  border-color: rgba(52,211,153,0.55);
  color: #b8f4d0;
  font-weight: 700;
}
.hf-trace__note {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.84rem;
  text-align: right;
  min-width: 90px;
}

/* Tiny legend chip used above the trace */
.hf-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.hf-legend span {
  display: inline-flex; align-items: center; gap: 6px;
}
.hf-legend i {
  width: 12px; height: 12px; border-radius: 4px;
  display: inline-block;
}
.hf-legend i.look  { background: rgba(255,176,96,0.55); }
.hf-legend i.swap  { background: rgba(239,68,68,0.55); }
.hf-legend i.final { background: rgba(52,211,153,0.55); }

/* Missing yellow badge variant — used by some tutorial pages */
.tutorial-card__badge--yellow {
  background: rgba(255,200,80,0.14);
  color: #ffd76e;
  border-color: rgba(255,200,80,0.30);
}

/* Light theme tweaks for legibility */
[data-theme="light"] .hf-callout--brain  { background: linear-gradient(135deg, rgba(124,92,191,0.06), rgba(79,142,247,0.04)); }
[data-theme="light"] .hf-callout--qa     { background: rgba(0,164,239,0.05); }
[data-theme="light"] .hf-callout--pencil { background: rgba(255,200,80,0.12); }
[data-theme="light"] .hf-callout--bullets{ background: rgba(255,200,80,0.12); }
[data-theme="light"] .hf-callout--master { background: linear-gradient(135deg, rgba(52,211,153,0.06), rgba(124,92,191,0.04)); }
[data-theme="light"] .hf-callout--trap   { background: rgba(239,68,68,0.05); }
[data-theme="light"] .hf-speech          { background: var(--bg-card); }
[data-theme="light"] .hf-speech::after   { background: var(--bg-card); }
[data-theme="light"] .hf-trace__step     { background: var(--bg-card); }

@media (max-width: 640px) {
  .hf-trace__step { grid-template-columns: 1fr; }
  .hf-trace__note { text-align: left; }
  .hf-speech { margin-left: 50px; }
  .hf-speech::before { width: 34px; height: 34px; left: -44px; font-size: 0.75rem; }
}

/* ── Sorting visualizer (sorting-for-dummies.html) ── */
.sort-viz {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 20px 0;
}
.sort-viz__bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 220px;
  padding: 12px 8px;
  background: rgba(0,0,0,0.15);
  border-radius: 8px;
  margin-bottom: 16px;
}
.sort-viz__bar {
  flex: 1;
  max-width: 48px;
  min-width: 12px;
  background: linear-gradient(180deg, var(--accent) 0%, rgba(79,142,247,0.5) 100%);
  border-radius: 4px 4px 0 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: height 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.sort-viz__bar span {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  padding-bottom: 3px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.sort-viz__bar--look {
  background: linear-gradient(180deg, #ffb060 0%, rgba(255,176,96,0.6) 100%);
  transform: scaleY(1.04);
}
.sort-viz__bar--swap {
  background: linear-gradient(180deg, #ef4444 0%, rgba(239,68,68,0.6) 100%);
  transform: scaleY(1.08);
}
.sort-viz__bar--done {
  background: linear-gradient(180deg, var(--green) 0%, rgba(52,211,153,0.5) 100%);
}
.sort-viz__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.sort-viz__controls select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.85rem;
}
.sort-viz__btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.sort-viz__btn:hover { border-color: var(--accent); }
.sort-viz__btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sort-viz__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.sort-viz__stats strong { color: var(--text); }

/* ── Sort comparison table ── */
.sort-table-wrap { overflow-x: auto; margin: 14px 0; }
.sort-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.sort-table th, .sort-table td {
  padding: 10px 12px;
  border: 1px solid var(--border);
  text-align: center;
}
.sort-table th {
  background: rgba(79,142,247,0.12);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.sort-table td:first-child { text-align: left; font-weight: 600; }
.sort-table tr:hover td { background: rgba(79,142,247,0.06); }
.sort-table .yes { color: var(--green); font-weight: 700; }
.sort-table .no  { color: var(--text-muted); }
.sort-table .star { color: #ffd76e; }

[data-theme="light"] .sort-viz__bars { background: rgba(0,0,0,0.04); }

/* ─────────────────────────────────────────────────
   Tutorial jump-bar — "Jump to another tutorial"
   Shared by the home page and every tutorial page.
   ───────────────────────────────────────────────── */
.tut-jumpbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 900px;
  margin: 0 auto 8px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tut-jumpbar__label {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-right: 4px;
}
.tut-jumpbar__chip {
  text-decoration: none;
  transition: transform .15s ease, filter .15s ease;
  cursor: pointer;
}
.tut-jumpbar__chip:hover {
  transform: translateY(-1px);
  filter: brightness(1.18);
}
.tut-jumpbar__chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tut-jumpbar__chip[aria-current="page"] {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  pointer-events: none;
}


/* =============================================
   FULL-WIDTH TUTORIAL CARDS
   One card per row on every tutorial page so
   code samples get the full content width.
   ============================================= */
.tut-page .tut-grid { grid-template-columns: 1fr; }
.tut-page .tutorial-card__code { font-size: 0.85rem; }


/* =============================================
   READING PROGRESS BAR (tutorial pages)
   ============================================= */
.read-progress {
  position: fixed; top: 0; left: 0;
  height: 3px; width: 0;
  background: linear-gradient(90deg, #58b9ff, #b794f4 50%, #6ee7b7);
  z-index: 1000;
  transition: width 0.12s linear;
  box-shadow: 0 0 10px rgba(124,92,191,0.55);
  will-change: width;
}
@media (prefers-reduced-motion: reduce) {
  .read-progress { transition: none; }
}


/* =============================================
   COPY-TO-CLIPBOARD BUTTON (code blocks)
   ============================================= */
.tutorial-card__code { position: relative; }
.copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s, color 0.18s, border-color 0.18s, background 0.18s, transform 0.18s;
}
.tutorial-card__code:hover .copy-btn,
.copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover {
  color: var(--accent);
  border-color: rgba(79,142,247,0.45);
  background: rgba(79,142,247,0.12);
}
.copy-btn.copied {
  color: #6ee7b7;
  border-color: rgba(52,211,153,0.45);
  background: rgba(52,211,153,0.12);
  opacity: 1;
}
.copy-btn svg { width: 12px; height: 12px; }
[data-theme="light"] .copy-btn { background: rgba(0,0,0,0.04); }

/* Language note on tutorial pages */
.tut-lang-note {
  max-width: 720px;
  margin: 0 auto 28px;
  padding: 12px 16px;
  background: rgba(79,142,247,0.08);
  border: 1px solid rgba(79,142,247,0.22);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

/* TOC — active item gets a glowing dot */
.tut-toc__link { position: relative; }
.tut-toc__link.active::after {
  content: "";
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse-dot 1.8s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1;   transform: translateY(-50%) scale(1); }
  50%      { opacity: 0.6; transform: translateY(-50%) scale(1.3); }
}
@media (prefers-reduced-motion: reduce) {
  .tut-toc__link.active::after { animation: none; }
}
