/* =========================================================
   SKETCH KIT — shared "handwritten notebook" components
   Hand-drawn SVG figures, sticky notes, dry-run traces,
   margin doodles & practice checklists.
   Used by: dsa-notes, system-design-notes
   ========================================================= */

:root {
  --sk-ink: var(--ink-dark, #1e293b);
  --sk-blue: var(--ink-blue, #2563eb);
  --sk-red: var(--ink-red, #dc2626);
  --sk-green: var(--ink-green, #059669);
  --sk-yellow: var(--ink-yellow, #d97706);
  --sk-purple: var(--ink-purple, #7c3aed);
  --sk-muted: #64748b;

  --sk-fill-yellow: #fef9c3;
  --sk-fill-blue: #dbeafe;
  --sk-fill-green: #dcfce7;
  --sk-fill-pink: #fce7f3;
  --sk-fill-purple: #ede9fe;
  --sk-fill-paper: #fffdf8;

  --sk-hand: 'Caveat', 'Patrick Hand', cursive;
  --sk-print: 'Patrick Hand', 'Kalam', cursive;
}

html[data-theme="dark"], html[data-theme="blueprint"] {
  --sk-muted: #94a3b8;
  --sk-fill-yellow: rgba(253, 224, 71, 0.16);
  --sk-fill-blue: rgba(56, 189, 248, 0.16);
  --sk-fill-green: rgba(52, 211, 153, 0.16);
  --sk-fill-pink: rgba(244, 114, 182, 0.16);
  --sk-fill-purple: rgba(192, 132, 252, 0.16);
  --sk-fill-paper: rgba(30, 41, 59, 0.6);
}

/* ---------- Inline math & code (rendered by sketch-kit.js) ---------- */
.sk-math {
  font-family: 'Kalam', var(--sk-print);
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.sk-math sup, .sk-math sub { font-size: 0.72em; line-height: 0; }

.sk-code {
  font-family: 'Fira Code', monospace;
  font-size: 0.86em;
  background: rgba(100, 116, 139, 0.12);
  border: 1px dashed rgba(100, 116, 139, 0.45);
  border-radius: 5px;
  padding: 0 5px;
  overflow-wrap: anywhere;
}

/* ---------- Figure wrapper: taped-in sketch ---------- */
.sk-figure {
  position: relative;
  contain: inline-size;
  margin: 22px 0 26px;
  padding: 18px 16px 10px;
  background: var(--sk-fill-paper);
  border: 2px solid rgba(100, 116, 139, 0.35);
  border-radius: 255px 18px 225px 18px / 18px 225px 18px 255px;
  box-shadow: 3px 4px 0 rgba(15, 23, 42, 0.06);
}
.sk-figure::before {
  content: '';
  position: absolute;
  top: -11px;
  left: 50%;
  width: 110px;
  height: 22px;
  transform: translateX(-50%) rotate(-2deg);
  background: rgba(251, 191, 36, 0.45);
  border-left: 2px dotted rgba(255, 255, 255, 0.6);
  border-right: 2px dotted rgba(255, 255, 255, 0.6);
}
.sk-figure.tape-pink::before { background: rgba(244, 114, 182, 0.4); }
.sk-figure.tape-blue::before { background: rgba(96, 165, 250, 0.4); }
.sk-figure.tape-green::before { background: rgba(52, 211, 153, 0.4); }

.sk-figure svg { display: block; width: 100%; height: auto; overflow: visible; }

.sk-caption {
  font-family: var(--sk-hand);
  font-size: 19px;
  color: var(--sk-muted);
  text-align: center;
  margin-top: 6px;
}
.sk-caption b { color: var(--sk-ink); }

/* ---------- SVG ink classes ---------- */
.sk-svg { color: var(--sk-ink); }
.sk-svg text {
  font-family: var(--sk-hand);
  font-size: 21px;
  fill: currentColor;
}
.sk-svg text.sm { font-size: 16px; }
.sk-svg text.xs { font-size: 14px; }
.sk-svg text.lg { font-size: 26px; font-weight: 700; }
.sk-svg text.mono { font-family: 'Fira Code', monospace; font-size: 13px; }
.sk-svg text.b, .sk-svg .tb { fill: var(--sk-blue); }
.sk-svg text.r, .sk-svg .tr { fill: var(--sk-red); }
.sk-svg text.g, .sk-svg .tg { fill: var(--sk-green); }
.sk-svg text.y, .sk-svg .ty { fill: var(--sk-yellow); }
.sk-svg text.p, .sk-svg .tp { fill: var(--sk-purple); }
.sk-svg text.m, .sk-svg .tm { fill: var(--sk-muted); }

/* stroke shapes get the pen-wobble filter */
.sk-svg .s {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: url(#sk-rough);
}
.sk-svg .s.thin { stroke-width: 1.5; }
.sk-svg .s.thick { stroke-width: 3.2; }
.sk-svg .s.dash { stroke-dasharray: 7 6; }
.sk-svg .s.b { stroke: var(--sk-blue); }
.sk-svg .s.r { stroke: var(--sk-red); }
.sk-svg .s.g { stroke: var(--sk-green); }
.sk-svg .s.y { stroke: var(--sk-yellow); }
.sk-svg .s.p { stroke: var(--sk-purple); }
.sk-svg .s.m { stroke: var(--sk-muted); }

.sk-svg .fy { fill: var(--sk-fill-yellow); }
.sk-svg .fb { fill: var(--sk-fill-blue); }
.sk-svg .fg { fill: var(--sk-fill-green); }
.sk-svg .fp { fill: var(--sk-fill-pink); }
.sk-svg .fv { fill: var(--sk-fill-purple); }
.sk-svg .fw { fill: var(--sk-fill-paper); }

/* highlighter swipe behind svg text */
.sk-svg .hl { fill: rgba(253, 224, 71, 0.55); stroke: none; }

/* arrows: marker-end set via class */
.sk-svg .a  { marker-end: url(#sk-arr); }
.sk-svg .a.b { marker-end: url(#sk-arr-b); }
.sk-svg .a.r { marker-end: url(#sk-arr-r); }
.sk-svg .a.g { marker-end: url(#sk-arr-g); }
.sk-svg .a.p { marker-end: url(#sk-arr-p); }
.sk-svg .a.m { marker-end: url(#sk-arr-m); }

/* draw-on animation (enabled by sketch-kit.js) */
@keyframes sk-draw { to { stroke-dashoffset: 0; } }
@keyframes sk-fade { from { opacity: 0; } to { opacity: 1; } }
/* --len is the measured stroke length, set per element by sketch-kit.js */
html.sk-anim .sk-svg .s.sk-drawing {
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
  animation: sk-draw 1.1s ease-out forwards;
}
html.sk-anim .notebook-page.active .sk-svg text {
  opacity: 0;
  animation: sk-fade 0.5s ease-out 0.5s forwards;
}
@media (prefers-reduced-motion: reduce) {
  html.sk-anim .sk-svg .s.sk-drawing,
  html.sk-anim .notebook-page.active .sk-svg text {
    animation: none; stroke-dasharray: none; opacity: 1;
  }
}

/* ---------- Sticky notes ---------- */
.sk-stickies {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  margin: 18px 0 24px;
}
.sk-sticky {
  position: relative;
  padding: 16px 16px 14px;
  background: #fef08a;
  color: #1e293b;
  font-family: var(--sk-print);
  font-size: 15.5px;
  line-height: 1.45;
  box-shadow: 2px 6px 12px rgba(15, 23, 42, 0.18);
  transform: rotate(-1.2deg);
  border-bottom-right-radius: 40px 6px;
}
.sk-sticky:nth-child(2n) { transform: rotate(1.1deg); }
.sk-sticky:nth-child(3n) { transform: rotate(-0.4deg); }
.sk-sticky.pink { background: #fbcfe8; }
.sk-sticky.blue { background: #bfdbfe; }
.sk-sticky.green { background: #bbf7d0; }
.sk-sticky.purple { background: #ddd6fe; }
.sk-sticky::before {
  content: '';
  position: absolute;
  top: -9px;
  left: 50%;
  width: 70px;
  height: 18px;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.sk-sticky h4 {
  font-family: var(--sk-hand);
  font-size: 23px;
  line-height: 1.1;
  margin-bottom: 6px;
  color: #0f172a;
}
.sk-sticky ul { list-style: none; padding: 0; }
.sk-sticky li { padding-left: 18px; position: relative; margin: 3px 0; color: #1e293b !important; }
.sk-sticky li::before { content: '✎'; position: absolute; left: 0; color: #64748b; }
.sk-sticky .sk-code { background: rgba(255, 255, 255, 0.55); }

/* ---------- Margin scribble / callout ---------- */
.sk-scribble {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 14px 0 18px;
  font-family: var(--sk-hand);
  font-size: 22px;
  line-height: 1.25;
  color: var(--sk-red);
}
.sk-scribble .sk-scribble-icon {
  flex: 0 0 auto;
  font-size: 26px;
  transform: rotate(-12deg);
}
.sk-scribble.blue { color: var(--sk-blue); }
.sk-scribble.green { color: var(--sk-green); }
.sk-scribble.purple { color: var(--sk-purple); }

/* hand-circled word */
.sk-circle {
  padding: 0 6px;
  border: 2px solid var(--sk-red);
  border-radius: 60% 40% 55% 45% / 55% 45% 60% 40%;
}
/* wavy underline */
.sk-wavy {
  text-decoration: underline wavy var(--sk-red);
  text-underline-offset: 4px;
  text-decoration-thickness: 1.5px;
}

/* ---------- Dry-run trace table ---------- */
/* inline-size containment: scroll boxes must not push the page wider */
.sk-trace-wrap { overflow-x: auto; margin: 12px 0 20px; contain: inline-size; }
.sk-trace {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--sk-print);
  font-size: 15px;
  background: var(--sk-fill-paper);
  border: 2px solid rgba(100, 116, 139, 0.45);
  border-radius: 12px 4px 14px 6px;
  overflow: hidden;
}
.sk-trace th {
  font-family: var(--sk-hand);
  font-size: 19px;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 2px solid rgba(100, 116, 139, 0.45);
  background: var(--sk-fill-yellow);
  color: var(--sk-ink);
}
.sk-trace td {
  padding: 5px 10px;
  border-bottom: 1px dashed rgba(100, 116, 139, 0.3);
  color: var(--sk-ink);
  vertical-align: top;
}
.sk-trace tr:last-child td { border-bottom: none; }
.sk-trace td.hit { color: var(--sk-green); font-weight: 700; }
.sk-trace td.miss { color: var(--sk-red); font-weight: 700; }
.sk-trace td.mono { font-family: 'Fira Code', monospace; font-size: 13px; }

/* ---------- Practice checklist ---------- */
.sk-practice {
  margin: 16px 0 22px;
  padding: 14px 18px 12px;
  border: 2px dashed rgba(100, 116, 139, 0.5);
  border-radius: 14px 6px 16px 8px;
  background: var(--sk-fill-paper);
}
.sk-practice-title {
  font-family: var(--sk-hand);
  font-size: 24px;
  font-weight: 700;
  color: var(--sk-ink);
  margin-bottom: 6px;
}
.sk-practice ul {
  list-style: none;
  padding: 0;
  columns: 2 260px;
  column-gap: 26px;
}
.sk-practice li {
  break-inside: avoid;
  font-family: var(--sk-print);
  font-size: 15px;
  padding: 3px 0 3px 26px;
  position: relative;
  color: var(--sk-ink);
}
.sk-practice li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  width: 15px;
  height: 15px;
  border: 2px solid var(--sk-muted);
  border-radius: 3px 5px 3px 6px;
}
.sk-diff {
  display: inline-block;
  font-family: var(--sk-hand);
  font-size: 15px;
  font-weight: 700;
  padding: 0 7px;
  margin-left: 4px;
  border-radius: 9px;
  line-height: 1.35;
}
.sk-diff.e { background: #dcfce7; color: #15803d; }
.sk-diff.m { background: #fef3c7; color: #b45309; }
.sk-diff.h { background: #fee2e2; color: #b91c1c; }

/* ---------- Common bugs / pitfalls ---------- */
.sk-bugs {
  margin: 16px 0 22px;
  padding: 12px 16px;
  border-left: 5px solid var(--sk-red);
  background: var(--sk-fill-pink);
  border-radius: 4px 14px 14px 4px;
}
.sk-bugs-title {
  font-family: var(--sk-hand);
  font-size: 23px;
  font-weight: 700;
  color: var(--sk-red);
  margin-bottom: 4px;
}
.sk-bugs ul { list-style: none; padding: 0; }
.sk-bugs li {
  font-family: var(--sk-print);
  font-size: 15px;
  padding: 3px 0 3px 24px;
  position: relative;
  color: var(--sk-ink);
}
.sk-bugs li::before { content: '✗'; position: absolute; left: 2px; color: var(--sk-red); font-weight: 700; }

/* ---------- Mnemonic / memory hook ---------- */
.sk-mnemonic {
  margin: 16px 0 22px;
  padding: 12px 18px;
  border: 2.5px solid var(--sk-purple);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: var(--sk-fill-purple);
  font-family: var(--sk-hand);
  font-size: 22px;
  line-height: 1.3;
  color: var(--sk-ink);
}
.sk-mnemonic strong { color: var(--sk-purple); }

/* ---------- Two-up figure layout ---------- */
.sk-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.sk-grid-2 > .sk-figure { margin: 14px 0 18px; }

/* ---------- Case-study step rail ---------- */
.sk-steps { counter-reset: skstep; margin: 10px 0 18px; }
.sk-step {
  position: relative;
  padding: 4px 0 12px 46px;
  border-left: 2px dashed rgba(100, 116, 139, 0.45);
  margin-left: 16px;
  font-family: var(--sk-print);
  font-size: 15.5px;
  color: var(--sk-ink);
}
.sk-step:last-child { border-left-color: transparent; }
.sk-step::before {
  counter-increment: skstep;
  content: counter(skstep);
  position: absolute;
  left: -17px;
  top: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-family: var(--sk-hand);
  font-size: 20px;
  font-weight: 700;
  color: var(--sk-blue);
  background: var(--paper-bg, #fdfbf7);
  border: 2.5px solid var(--sk-blue);
  border-radius: 50% 45% 55% 50%;
}
.sk-step h5 {
  font-family: var(--sk-hand);
  font-size: 22px;
  margin-bottom: 2px;
  color: var(--sk-ink);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sk-grid-2 { grid-template-columns: 1fr; }
  .sk-figure { padding: 16px 8px 8px; overflow-x: auto; }
  /* wide sketches keep a legible size and scroll sideways instead of shrinking */
  .sk-figure > svg[viewBox^="0 0 800"] { min-width: 620px; }
  .sk-figure::before { top: 0; }  /* overflow clips anything above the box */
  .sk-practice ul { columns: 1; }
  .sk-scribble { font-size: 19px; }
  .sk-math { white-space: normal; }
}

/* ---------- Print ---------- */
@media print {
  .sk-figure, .sk-sticky, .sk-trace-wrap, .sk-practice, .sk-bugs { break-inside: avoid; }
  .sk-sticky { box-shadow: none; transform: none !important; }
  html.sk-anim .sk-svg .s, html.sk-anim .sk-svg text { animation: none !important; stroke-dasharray: none !important; opacity: 1 !important; }
}
