/* ============================================================
   The Unofficial Zef Zine — shared stylesheet
   ============================================================ */

:root {
  --cream:   #fdf5e0;
  --cream2:  #fffaea;
  --paper:   #fbf5df;
  --ink:     #1a1a2e;
  --ink2:    #2b2b44;
  --red:     #e63946;
  --coral:   #ff6b6b;
  --yellow:  #ffd166;
  --high:    #fff176;
  --mint:    #a8dadc;
  --pink:    #ffc6d3;
  --blue:    #457b9d;
  --deep:    #1d3557;
  --sage:    #b7d5a2;
  --grey:    #8a8a9a;
  --leaf:    #6bbf59;
  --purple:  #b794f4;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  /* prevent horizontal jitter from decorative rotated elements */
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Patrick Hand", "Comic Sans MS", cursive;
  background:
    radial-gradient(circle at 20% 10%, #fff8dc 0, transparent 40%),
    radial-gradient(circle at 85% 70%, #fce4ec 0, transparent 45%),
    var(--cream);
  color: var(--ink);
  font-size: 19px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Notebook paper lines in bg */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 29px,
    rgba(0,0,50,0.03) 29px,
    rgba(0,0,50,0.03) 30px
  );
  pointer-events: none;
  z-index: 0;
}

/* Top progress bar */
.progress-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 5px;
  background: rgba(0,0,50,0.08);
  z-index: 100;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--leaf));
  width: 0;
  transition: width 0.3s ease;
}

/* Main page container */
.page {
  max-width: 820px;
  margin: 0 auto;
  padding: 80px 40px 140px;
  position: relative;
  z-index: 1;
}

/* Chapter number badge in corner */
.chapter-badge {
  position: fixed;
  top: 20px;
  left: 20px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 8px 16px;
  font-family: "Caveat";
  font-size: 22px;
  font-weight: 700;
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-3deg);
  z-index: 50;
}
.chapter-badge .num { font-size: 32px; display: block; line-height: 0.8; }
.chapter-badge .label { font-size: 14px; color: var(--grey); }

/* Home button */
.home-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--mint);
  border: 3px solid var(--ink);
  border-radius: 50%;
  width: 52px; height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 3px 3px 0 var(--ink);
  text-decoration: none;
  z-index: 50;
  transition: transform 0.2s;
}
.home-btn:hover { transform: rotate(-10deg) scale(1.05); }

/* Typography */
h1, h2, h3, h4 {
  font-family: "Caveat", "Kalam", cursive;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  margin: 2em 0 0.5em;
}
h1 {
  font-size: 78px;
  letter-spacing: -1px;
  transform: rotate(-1deg);
  margin-top: 0.4em;
}
h2 {
  font-size: 48px;
  border-bottom: 4px dashed var(--ink);
  padding-bottom: 8px;
}
h3 { font-size: 34px; color: var(--deep); }
h4 { font-size: 26px; color: var(--red); font-family: "Kalam"; }

p { margin: 0.8em 0; }
em { font-style: italic; background: linear-gradient(transparent 60%, var(--high) 60%); padding: 0 2px; }
strong { font-weight: 700; color: var(--red); }
a { color: var(--blue); }

/* Inline code */
code {
  font-family: "JetBrains Mono", "Menlo", monospace;
  font-size: 15px;
  background: #fff7d0;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid #e8d96c;
  color: #333;
}

/* Code blocks */
pre {
  font-family: "JetBrains Mono", "Menlo", monospace;
  font-size: 14.5px;
  line-height: 1.55;
  background: var(--ink);
  color: #f5f5f5;
  padding: 18px 22px;
  border-radius: 8px;
  overflow-x: auto;
  border: 2px solid var(--ink2);
  box-shadow: 4px 4px 0 var(--ink2);
  margin: 1.2em 0;
  position: relative;
}
pre code { background: transparent; color: inherit; padding: 0; border: 0; }
pre::before {
  content: "$ python";
  position: absolute;
  top: 2px; right: 12px;
  font-family: "Patrick Hand";
  font-size: 11px;
  color: #888;
}

/* Tokens */
.tok-kw  { color: #ff9fdc; }
.tok-str { color: #c3e88d; }
.tok-num { color: #f78c6c; }
.tok-com { color: #9aa0a6; font-style: italic; }
.tok-fn  { color: #82aaff; }
.tok-op  { color: #ffcb6b; }
.tok-type{ color: #c792ea; font-weight: 600; }

/* Boxes — the zine thing */
.box {
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 20px 24px;
  margin: 22px 0;
  background: var(--cream2);
  box-shadow: 5px 5px 0 var(--ink);
  position: relative;
}
.box h4 { margin-top: 0; }

.aha   { background: #fff6c7; border-color: #d1a728; box-shadow: 5px 5px 0 #d1a728; }
.gotcha{ background: #ffe0e0; border-color: var(--red);  box-shadow: 5px 5px 0 var(--red); }
.ask   { background: #e0f2ff; border-color: var(--blue); box-shadow: 5px 5px 0 var(--blue); }
.try   { background: #e6f9d6; border-color: var(--leaf); box-shadow: 5px 5px 0 var(--leaf); }
.think { background: #f0e8ff; border-color: var(--purple); box-shadow: 5px 5px 0 var(--purple); }
.mental{ background: #fff2e8; border-color: #ff8c42;  box-shadow: 5px 5px 0 #ff8c42; }

.aha::before    { content: "💡 aha!"; background: #ffd166; }
.gotcha::before { content: "⚠️ gotcha!"; background: var(--coral); color: white; }
.ask::before    { content: "🤔 wait, what?"; background: #9ec6ff; }
.try::before    { content: "✍️  try it!"; background: var(--sage); }
.think::before  { content: "🧠 think about it"; background: var(--purple); color: white; }
.mental::before { content: "🗺 mental model"; background: #ff8c42; color: white; }

.aha::before, .gotcha::before, .ask::before,
.try::before, .think::before, .mental::before {
  position: absolute;
  top: -18px; left: 18px;
  padding: 2px 14px;
  border: 2px solid var(--ink);
  border-radius: 20px;
  font-family: "Caveat";
  font-size: 22px;
  font-weight: 700;
  transform: rotate(-3deg);
}
.gotcha::before { transform: rotate(2deg); }
.ask::before    { transform: rotate(-2deg); }
.try::before    { transform: rotate(3deg); }
.mental::before { transform: rotate(-2deg); }

/* Zen style quote */
.zen {
  background: repeating-linear-gradient(-45deg, #fffae6, #fffae6 10px, #f9f2c6 10px, #f9f2c6 20px);
  border: 3px solid #b8860b;
  box-shadow: 5px 5px 0 #b8860b;
  border-radius: 10px;
  padding: 20px 24px;
  text-align: center;
  font-family: "Caveat";
  font-size: 28px;
  line-height: 1.3;
  margin: 24px 0;
}

/* ASCII diagrams */
.diagram {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  line-height: 1.3;
  white-space: pre;
  background: #fff9e0;
  border: 2px dashed var(--ink);
  padding: 14px 18px;
  margin: 14px 0;
  border-radius: 8px;
  overflow-x: auto;
  color: var(--ink);
}

/* Tables */
table {
  border-collapse: collapse;
  margin: 16px 0;
  width: 100%;
  background: var(--cream2);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: "Patrick Hand";
}
th, td {
  border: 1px solid var(--ink);
  padding: 8px 12px;
  text-align: left;
  font-size: 17px;
  vertical-align: top;
}
th { background: var(--high); font-family: "Caveat"; font-size: 22px; }

/* Two-column layouts */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.three-col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* Contrast blocks */
.contrast {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 18px 0;
}
.contrast > div {
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 14px 18px;
  background: var(--cream2);
}
.contrast .bad  { background: #ffe6e6; border-color: var(--red); }
.contrast .good { background: #e6f9d6; border-color: var(--leaf); }
.contrast h5 { margin: 0 0 6px; font-family: "Caveat"; font-size: 26px; }

/* Pipe demo */
.pipe-demo {
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 20px;
  background: var(--cream2);
  border: 3px solid var(--ink);
  padding: 20px 10px;
  border-radius: 10px;
  margin: 20px 0;
}
.pipe-demo .bit {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 6px;
  margin: 4px;
}
.pipe-demo .data  { background: var(--mint); border: 2px solid #2b7a78; }
.pipe-demo .op    { background: var(--pink); border: 2px solid #b14365; }
.pipe-demo .pipe  { color: var(--red); font-size: 26px; font-weight: bold; padding: 0 4px; }
.pipe-demo .run   { background: var(--yellow); border: 2px solid #8d6a00; }

/* Highlighter spans */
.highlighter { background: linear-gradient(transparent 50%, var(--high) 50%); padding: 0 3px; }
.pink-hi     { background: linear-gradient(transparent 50%, var(--pink) 50%); padding: 0 3px; }
.mint-hi     { background: linear-gradient(transparent 50%, var(--mint) 50%); padding: 0 3px; }

/* Leaf bullet list */
.leaf-bullet { list-style: none; padding-left: 0; }
.leaf-bullet li::before { content: "🌿 "; margin-right: 4px; }

/* Big emoji headline */
.big-emoji {
  font-size: 90px;
  display: block;
  text-align: center;
  margin: 10px 0;
}

/* Big arrow text */
.big-arrow {
  font-family: "Shadows Into Light";
  font-size: 48px;
  color: var(--red);
  text-align: center;
  margin: 10px 0;
}

/* Sidenotes */
.sidenote {
  float: right;
  width: 38%;
  margin: 8px 0 10px 20px;
  padding: 10px 14px;
  background: var(--pink);
  border: 2px solid var(--red);
  font-family: "Kalam";
  font-size: 16px;
  border-radius: 8px;
  transform: rotate(1deg);
}
.sidenote.left { float: left; margin: 8px 20px 10px 0; transform: rotate(-1deg); background: var(--mint); border-color: #2b7a78; }

/* Comic panels */
.comic-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}
.comic-panel .panel {
  background: var(--cream2);
  border: 3px solid var(--ink);
  border-radius: 8px;
  padding: 12px;
  min-height: 120px;
  box-shadow: 4px 4px 0 var(--ink);
  font-family: "Patrick Hand";
  font-size: 17px;
}
.comic-panel .panel .head {
  font-family: "Caveat";
  font-size: 24px;
  color: var(--red);
  border-bottom: 2px dashed var(--ink);
  margin-bottom: 8px;
  padding-bottom: 4px;
}

/* Hr wavy */
hr {
  border: 0;
  height: 30px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20'><path d='M0 10 Q 25 0 50 10 T 100 10' stroke='%231a1a2e' stroke-width='2' fill='none'/></svg>") center/contain repeat-x;
  margin: 40px 0;
}

/* Page navigation footer */
.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 30px;
  margin-top: 60px;
  gap: 20px;
  border-top: 3px dashed var(--ink);
}
.page-nav a {
  background: var(--cream2);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 12px 22px;
  text-decoration: none;
  color: var(--ink);
  font-family: "Caveat";
  font-size: 26px;
  box-shadow: 4px 4px 0 var(--ink);
  transition: all 0.15s;
  max-width: 45%;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.page-nav a:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ink);
  background: var(--high);
}
.page-nav a.prev .dir { font-size: 16px; color: var(--grey); }
.page-nav a.next { text-align: right; }
.page-nav a.next .dir { font-size: 16px; color: var(--grey); }
.page-nav a.disabled {
  opacity: 0.3;
  pointer-events: none;
}
.page-nav .page-count {
  font-family: "Caveat";
  font-size: 22px;
  color: var(--grey);
  text-align: center;
}

/* Keyboard hint */
.kbd-hint {
  position: fixed;
  bottom: 14px;
  right: 20px;
  background: rgba(255,255,255,0.85);
  border: 2px dashed var(--ink);
  border-radius: 8px;
  padding: 4px 10px;
  font-family: "Caveat";
  font-size: 16px;
  color: var(--grey);
  z-index: 40;
}
.kbd-hint kbd {
  background: var(--ink);
  color: white;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "JetBrains Mono";
  font-size: 13px;
  margin: 0 2px;
}

/* Stickers */
.sticker {
  display: inline-block;
  background: var(--high);
  padding: 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 30px;
  transform: rotate(-3deg);
  margin: 4px;
  font-family: "Caveat";
  font-size: 22px;
  box-shadow: 3px 3px 0 var(--ink);
}
.sticker.pink { background: var(--pink); transform: rotate(3deg); }
.sticker.mint { background: var(--mint); transform: rotate(-1deg); }
.sticker.yellow { background: var(--yellow); }

/* Mental-model floating diagram */
.mental-model {
  background: #fff2e8;
  border: 3px solid #ff8c42;
  border-radius: 12px;
  padding: 20px 24px;
  margin: 22px 0;
  box-shadow: 5px 5px 0 #ff8c42;
  position: relative;
}
.mental-model .label {
  position: absolute;
  top: -14px; right: 20px;
  background: #ff8c42;
  color: white;
  padding: 2px 12px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  font-family: "Caveat";
  font-size: 20px;
  transform: rotate(3deg);
}

/* Cover page special */
.cover {
  text-align: center;
  padding: 70px 0 40px;
  border-bottom: 6px double var(--ink);
  margin-bottom: 40px;
}
.cover h1 {
  font-size: 104px;
  margin: 0;
  background: linear-gradient(90deg, var(--red), var(--blue), var(--leaf));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transform: rotate(-2deg);
}
.cover .tagline {
  font-family: "Shadows Into Light";
  font-size: 32px;
  color: var(--ink);
  margin-top: 6px;
  transform: rotate(1deg);
  display: inline-block;
}

/* TOC */
.toc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 18px;
  margin: 20px 0;
}
.toc-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--cream2);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--ink);
  font-family: "Patrick Hand";
  font-size: 17px;
  box-shadow: 3px 3px 0 var(--ink);
  transition: all 0.15s;
}
.toc-entry:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
  background: var(--high);
}
.toc-entry .ch-num {
  display: inline-block;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--yellow);
  border: 2px solid var(--ink);
  text-align: center;
  line-height: 30px;
  font-family: "Caveat";
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}
.toc-entry .ch-title { flex: 1; line-height: 1.2; }
.toc-entry .ch-sub { font-size: 13px; color: var(--grey); font-family: "Kalam"; }

.part-divider {
  grid-column: 1 / -1;
  margin-top: 20px;
  font-family: "Caveat";
  font-size: 28px;
  color: var(--red);
  border-bottom: 3px dashed var(--red);
  padding-bottom: 4px;
}

/* ────────── tablets ────────── */
@media (max-width: 900px) {
  /* tables become horizontally scrollable inside a wrapper */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  table th, table td { white-space: normal; }
}

/* ────────── phones ────────── */
@media (max-width: 700px) {
  body { font-size: 17px; line-height: 1.55; }
  h1 { font-size: 48px; }
  h2 { font-size: 34px; }
  h3 { font-size: 24px; }
  h4 { font-size: 22px; }
  .cover { padding: 50px 0 30px; }
  .cover h1 { font-size: 56px; }
  .cover .tagline { font-size: 24px; }
  .big-emoji { font-size: 64px; }
  .page { padding: 68px 16px 130px; max-width: 100%; }
  .comic-panel, .two-col, .contrast, .three-col, .toc-grid {
    grid-template-columns: 1fr;
  }
  .sidenote, .sidenote.left {
    float: none; width: 100%; margin: 10px 0; transform: none;
  }

  /* fixed corner ornaments: smaller so they don't overlap content */
  .chapter-badge {
    top: 8px; left: 8px; padding: 4px 10px;
    border-width: 2px; box-shadow: 2px 2px 0 var(--ink);
  }
  .chapter-badge .num { font-size: 22px; }
  .chapter-badge .label { font-size: 11px; }
  .home-btn {
    top: 8px; right: 8px;
    width: 40px; height: 40px; font-size: 20px;
    border-width: 2px; box-shadow: 2px 2px 0 var(--ink);
  }
  .kbd-hint { display: none; }

  /* boxes: less padding + tighter shadow */
  .box, .zen, .mental-model {
    padding: 16px 16px; margin: 16px 0;
    box-shadow: 3px 3px 0 var(--ink);
  }
  .aha    { box-shadow: 3px 3px 0 #d1a728; }
  .gotcha { box-shadow: 3px 3px 0 var(--red); }
  .ask    { box-shadow: 3px 3px 0 var(--blue); }
  .try    { box-shadow: 3px 3px 0 var(--leaf); }
  .think  { box-shadow: 3px 3px 0 var(--purple); }
  .mental { box-shadow: 3px 3px 0 #ff8c42; }
  .zen    { box-shadow: 3px 3px 0 #b8860b; font-size: 22px; }

  /* de-rotate label pills to avoid edge overflow */
  .aha::before, .gotcha::before, .ask::before,
  .try::before, .think::before, .mental::before {
    font-size: 18px; padding: 1px 10px; top: -15px; transform: none;
  }

  /* code blocks: smaller, soft-wrap long lines so no sideways scroll */
  pre {
    font-size: 13px; padding: 12px 14px;
    box-shadow: 3px 3px 0 var(--ink2);
    white-space: pre-wrap; word-break: break-word;
    margin: 1em 0;
  }
  pre::before { display: none; }
  code { font-size: 13.5px; }

  /* ascii diagrams keep their scrollbar (readability > wrapping) */
  .diagram { font-size: 12px; padding: 10px 12px; }

  /* page nav: stack, full-width buttons, easy thumb tap */
  .page-nav {
    flex-direction: column; padding: 20px 0; gap: 12px;
    border-top-style: dashed;
  }
  .page-nav a {
    max-width: 100%; width: 100%;
    padding: 14px 18px; font-size: 22px;
    min-height: 60px; box-shadow: 3px 3px 0 var(--ink);
  }
  .page-nav a.next { text-align: left; }
  .page-nav .page-count { order: 3; }

  /* pipe-demo: let blocks wrap naturally */
  .pipe-demo { font-size: 16px; padding: 14px 8px; }
  .pipe-demo .bit { padding: 4px 8px; margin: 3px; display: inline-block; }
  .pipe-demo .pipe { font-size: 22px; }

  /* stickers */
  .sticker {
    font-size: 18px; padding: 4px 10px;
    box-shadow: 2px 2px 0 var(--ink);
  }

  /* TOC cards: bigger touch target */
  .toc-entry { padding: 12px 14px; font-size: 17px; min-height: 56px; }
  .toc-entry .ch-num { width: 40px; height: 40px; line-height: 36px; font-size: 20px; }
  .toc-entry .ch-sub { font-size: 13px; }
  .part-divider { font-size: 22px; margin-top: 14px; }

  /* comic panels */
  .comic-panel { gap: 10px; }
  .comic-panel .panel { padding: 10px; min-height: auto; box-shadow: 3px 3px 0 var(--ink); }

  hr { height: 20px; margin: 28px 0; }
}

/* ────────── small phones ────────── */
@media (max-width: 420px) {
  body { font-size: 16px; }
  h1 { font-size: 40px; }
  .cover h1 { font-size: 46px; }
  .cover .tagline { font-size: 20px; }
  h2 { font-size: 28px; }
  h3 { font-size: 22px; }
  .page { padding: 64px 12px 120px; }
  pre { font-size: 12px; padding: 10px 12px; }
  .diagram { font-size: 11px; }
  .chapter-badge { padding: 3px 8px; }
  .chapter-badge .num { font-size: 18px; }
  .home-btn { width: 36px; height: 36px; font-size: 18px; }
  .sticker { font-size: 16px; }
  .big-emoji { font-size: 54px; }
  .box, .zen, .mental-model { padding: 14px 14px; }
}

/* better tap feedback on all touch devices */
a.toc-entry, .page-nav a, .home-btn {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
}
