/* ==========================================================================
   Bookrot — Hand-Drawn School Notebook & Sketchbook Aesthetic for OLED
   ========================================================================== */

/* Bundled 100% offline open-source hand-drawn TTF fonts */
@font-face {
  font-family: "Patrick Hand";
  src: url("../fonts/PatrickHand-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Architects Daughter";
  src: url("../fonts/ArchitectsDaughter-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kalam";
  src: url("../fonts/Kalam-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kalam";
  src: url("../fonts/Kalam-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Indie Flower";
  src: url("../fonts/IndieFlower-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat-Variable.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root,
[data-theme="paper"] {
  --paper-bg: #faf6eb;
  --paper-surface: #fffdf7;
  --paper-inset: #f0e8d5;
  --paper-frame: #e3d9c3;
  --ink: #1e1c1a;
  --ink-soft: #37322c;
  --ink-muted: #655d52;
  --ink-faint: #afa492;
  --ink-shadow: rgba(30, 28, 26, 0.16);

  /* School notebook paper lines */
  --rule-line: rgba(94, 148, 212, 0.27);
  --rule-subgrid: rgba(94, 148, 212, 0.08);
  --margin-red: rgba(217, 83, 98, 0.42);
  --hole-fill: #e3d9c3;
  --hole-ring: rgba(110, 98, 82, 0.35);

  /* Stabilo-style highlighter marker palette */
  --hl-yellow: rgba(255, 232, 92, 0.62);
  --hl-mint: rgba(154, 236, 178, 0.54);
  --hl-pink: rgba(255, 178, 198, 0.54);
  --hl-sky: rgba(164, 216, 255, 0.56);
  --hl-peach: rgba(255, 204, 146, 0.58);
  --highlight: var(--hl-yellow);

  /* Colored pen ink & underline palette */
  --pen-red: #c23b32;
  --pen-blue: #235ea8;
  --pen-green: #247348;
  --pen-purple: #6e3fa3;
  --pen-orange: #c7621a;

  --good: #237044;
  --good-bg: rgba(154, 236, 178, 0.3);
  --bad: #c0392b;
  --bad-bg: rgba(255, 178, 198, 0.28);

  --accent-ochre: #b56318;
  --accent-sage: #2b7049;
  --accent-terracotta: #ba4130;
  --accent-slate: #2b5d8f;
  --accent-indigo: #5a4399;

  --grain-opacity: 0.055;
  --shadow-soft: 0 4px 20px rgba(30, 28, 26, 0.08);

  /* Default hand-drawn font roles (overridden per card via data-hand) */
  --font-title: "Kalam", cursive;
  --font-body: "Patrick Hand", cursive;
  --font-accent: "Caveat", cursive;
  --font-doodle: "Indie Flower", cursive;
  --font-tech: "Architects Daughter", cursive;
}

[data-theme="charcoal"] {
  --paper-bg: #111210;
  --paper-surface: #191a17;
  --paper-inset: #22231e;
  --paper-frame: #080807;
  --ink: #eee7d8;
  --ink-soft: #d5ccb9;
  --ink-muted: #9e9687;
  --ink-faint: #524c42;
  --ink-shadow: rgba(0, 0, 0, 0.55);

  /* Dark OLED ruled sketchbook */
  --rule-line: rgba(112, 166, 214, 0.13);
  --rule-subgrid: rgba(112, 166, 214, 0.045);
  --margin-red: rgba(230, 108, 120, 0.28);
  --hole-fill: #080807;
  --hole-ring: rgba(180, 170, 154, 0.2);

  /* Luminous pastel markers on charcoal paper */
  --hl-yellow: rgba(247, 209, 76, 0.27);
  --hl-mint: rgba(102, 214, 146, 0.24);
  --hl-pink: rgba(242, 122, 152, 0.25);
  --hl-sky: rgba(108, 188, 245, 0.25);
  --hl-peach: rgba(245, 162, 88, 0.26);
  --highlight: var(--hl-yellow);

  /* Bright gel-pen ink colors on dark paper */
  --pen-red: #f27c72;
  --pen-blue: #7ab8ff;
  --pen-green: #79d9a0;
  --pen-purple: #c59eff;
  --pen-orange: #f5ab67;

  --good: #79d9a0;
  --good-bg: rgba(102, 214, 146, 0.16);
  --bad: #f27c72;
  --bad-bg: rgba(242, 122, 152, 0.16);

  --accent-ochre: #eba85e;
  --accent-sage: #7ad19c;
  --accent-terracotta: #f08575;
  --accent-slate: #80b8eb;
  --accent-indigo: #b5a3f5;

  --grain-opacity: 0.036;
  --shadow-soft: 0 4px 22px rgba(0, 0, 0, 0.45);
}

/* ==========================================================================
   5 Rotating Handwriting Personas (switched on every card!)
   ========================================================================== */

[data-hand="0"] {
  --font-title: "Kalam", cursive;
  --font-body: "Patrick Hand", cursive;
  --font-accent: "Caveat", cursive;
  --font-doodle: "Indie Flower", cursive;
}

[data-hand="1"] {
  --font-title: "Architects Daughter", cursive;
  --font-body: "Kalam", cursive;
  --font-accent: "Indie Flower", cursive;
  --font-doodle: "Caveat", cursive;
}

[data-hand="2"] {
  --font-title: "Caveat", cursive;
  --font-body: "Patrick Hand", cursive;
  --font-accent: "Architects Daughter", cursive;
  --font-doodle: "Kalam", cursive;
}

[data-hand="3"] {
  --font-title: "Indie Flower", cursive;
  --font-body: "Architects Daughter", cursive;
  --font-accent: "Kalam", cursive;
  --font-doodle: "Patrick Hand", cursive;
}

[data-hand="4"] {
  --font-title: "Kalam", cursive;
  --font-body: "Indie Flower", cursive;
  --font-accent: "Caveat", cursive;
  --font-doodle: "Architects Daughter", cursive;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper-frame);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background-color 220ms ease, color 220ms ease;
}

/* Organic hand-sketched wobble box radii (safe at every aspect ratio) */
.wobble-box,
.choice-slip,
.flip-slip,
.rank-item,
.tradeoff-col,
.match-chip,
.stroop-stage,
.chart-stage,
.balance-stage,
.sheet-row,
.pack-info {
  border-radius: 14px 5px 12px 6px / 6px 13px 5px 14px;
}

/* Subtle fibrous paper grain overlay */
.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

[data-theme="charcoal"] .paper-grain {
  mix-blend-mode: screen;
}

/* Centered notebook column on desktop, edge-to-edge on Android */
.app-shell {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--paper-bg);
  overflow: hidden;
  transition: background-color 220ms ease;
}

@media (min-width: 540px) {
  .app-shell {
    border-left: 2px solid var(--ink-faint);
    border-right: 2px solid var(--ink-faint);
    box-shadow: var(--shadow-soft);
  }
}

/* ==========================================================================
   School Notebook Paper Overlay (Ruled Lines + Red Margin + Binder Holes)
   ========================================================================== */

.school-paper-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    /* Classic double-ish red/pink left margin rule */
    linear-gradient(
      90deg,
      transparent 0,
      transparent 34px,
      var(--margin-red) 34px,
      var(--margin-red) 35.5px,
      transparent 35.5px,
      transparent 38px,
      var(--margin-red) 38px,
      var(--margin-red) 38.8px,
      transparent 38.8px
    ),
    /* Horizontal school notebook ruled lines every 28px */
    repeating-linear-gradient(
      180deg,
      transparent 0,
      transparent 27px,
      var(--rule-line) 27px,
      var(--rule-line) 28.2px
    ),
    /* Faint vertical graph-paper / Seyes hint */
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 27px,
      var(--rule-subgrid) 27px,
      var(--rule-subgrid) 28px
    );
  background-position: 0 0, 0 54px, 38px 0;
}

.binder-holes {
  position: absolute;
  left: 9px;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
}

.binder-holes span {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--hole-fill);
  border: 1.4px solid var(--hole-ring);
  box-shadow: inset 1.5px 1.5px 2px rgba(0, 0, 0, 0.14);
}

/* ==========================================================================
   Highlighter Swipes & Colored Pen Underlines (Text + Tags)
   ========================================================================== */

.hl,
.marker-highlight {
  display: inline;
  padding: 0.04em 0.3em 0.08em;
  margin: 0 -0.08em;
  border-radius: 0.8em 0.25em 0.7em 0.3em / 0.25em 0.7em 0.3em 0.6em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  color: var(--ink);
}

.hl-yellow,
.marker-highlight {
  background: linear-gradient(
    102deg,
    transparent 0%,
    var(--hl-yellow) 4%,
    var(--hl-yellow) 95%,
    transparent 100%
  );
}

.hl-mint {
  background: linear-gradient(
    99deg,
    transparent 0%,
    var(--hl-mint) 4%,
    var(--hl-mint) 95%,
    transparent 100%
  );
}

.hl-pink {
  background: linear-gradient(
    104deg,
    transparent 0%,
    var(--hl-pink) 4%,
    var(--hl-pink) 95%,
    transparent 100%
  );
}

.hl-sky {
  background: linear-gradient(
    100deg,
    transparent 0%,
    var(--hl-sky) 4%,
    var(--hl-sky) 95%,
    transparent 100%
  );
}

.hl-peach {
  background: linear-gradient(
    103deg,
    transparent 0%,
    var(--hl-peach) 4%,
    var(--hl-peach) 95%,
    transparent 100%
  );
}

/* Colored pen underline + ink tint emphasis */
.ul {
  font-family: var(--font-accent);
  font-size: 1.08em;
  font-weight: 700;
  text-decoration-line: underline;
  text-decoration-thickness: 2.2px;
  text-underline-offset: 3px;
  text-decoration-skip-ink: none;
}

.ul-red {
  color: var(--pen-red);
  text-decoration-color: var(--pen-red);
  text-decoration-style: wavy;
}

.ul-blue {
  color: var(--pen-blue);
  text-decoration-color: var(--pen-blue);
  text-decoration-style: solid;
}

.ul-green {
  color: var(--pen-green);
  text-decoration-color: var(--pen-green);
  text-decoration-style: wavy;
}

.ul-purple {
  color: var(--pen-purple);
  text-decoration-color: var(--pen-purple);
  text-decoration-style: solid;
}

.ul-orange {
  color: var(--pen-orange);
  text-decoration-color: var(--pen-orange);
  text-decoration-style: wavy;
}

/* Typography helpers */
.mono-dim,
.mono-label {
  font-family: var(--font-doodle);
  font-size: 0.88rem;
  letter-spacing: 0.02em;
}

.mono-dim {
  color: var(--ink-muted);
}

.mono-label {
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-soft);
}

/* ==========================================================================
   Top Bar & Margin Ticks
   ========================================================================== */

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 8px 44px;
  background: linear-gradient(
    to bottom,
    var(--paper-bg) 72%,
    rgba(250, 246, 235, 0)
  );
  pointer-events: none;
}

[data-theme="charcoal"] .top-bar {
  background: linear-gradient(
    to bottom,
    var(--paper-bg) 72%,
    rgba(17, 18, 16, 0)
  );
}

.top-bar > * {
  pointer-events: auto;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-surface);
  color: var(--ink);
  border: 1.8px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 2.5px 2.5px 0 var(--ink-shadow);
  padding: 5px 13px;
  font-family: "Architects Daughter", cursive;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  max-width: 65%;
  transform: rotate(-0.5deg);
}

.pill-btn:active {
  transform: translate(1.5px, 1.5px) rotate(-0.5deg);
  box-shadow: 1px 1px 0 var(--ink-shadow);
}

.pill-btn span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pen-red);
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 42% 58% 49% 51% / 53% 45% 55% 47%;
  border: 1.4px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.icon-btn:hover,
.icon-btn:active {
  background: var(--hl-yellow);
  border-color: var(--ink-faint);
  color: var(--ink);
}

.icon-btn.active {
  color: var(--pen-red);
  background: var(--hl-pink);
  border-color: var(--pen-red);
}

.ico {
  width: 19px;
  height: 19px;
}

.badge-count {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 50%;
  background: var(--pen-red);
  color: #fffdf7;
  font-family: "Kalam", cursive;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* Right-margin notebook index ticks */
.margin-ticks {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
}

.margin-tick {
  width: 6px;
  height: 2.5px;
  border-radius: 3px;
  background: var(--ink-faint);
  opacity: 0.55;
  transition: width 180ms ease, background-color 180ms ease, opacity 180ms ease;
}

.margin-tick.active {
  width: 13px;
  background: var(--pen-red);
  opacity: 1;
}

.margin-tick.seen {
  background: var(--pen-blue);
  opacity: 0.75;
}

/* ==========================================================================
   Vertical Snap-Scroll Feed
   ========================================================================== */

.feed {
  position: relative;
  z-index: 5;
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  outline: none;
}

.feed::-webkit-scrollbar {
  display: none;
}

.card-slide {
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* Left padding respects the red notebook margin line! */
  padding: calc(env(safe-area-inset-top, 0px) + 56px) 20px
    calc(env(safe-area-inset-bottom, 0px) + 14px) 46px;
  position: relative;
  font-family: var(--font-body);
}

.loading-slide,
.empty-slide {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 14px;
}

.card-body-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 4px 4px 10px;
  opacity: 0.72;
  transform: translateY(5px);
  transition: opacity 280ms ease, transform 280ms ease;
}

/* Safe vertical centering: centers short cards, never clips the top of tall cards */
.card-inner {
  margin: auto 0;
  width: 100%;
}

.card-body-wrap::-webkit-scrollbar {
  display: none;
}

.card-slide.is-active .card-body-wrap {
  opacity: 1;
  transform: translateY(0);
}

/* Card meta header + Margin Doodle */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.margin-doodle {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--card-accent, var(--pen-orange));
  opacity: 0.88;
}

.type-stamp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Architects Daughter", cursive;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--card-accent, var(--pen-blue));
  padding: 2px 10px;
  border: 1.8px dashed var(--card-accent, var(--pen-blue));
  border-radius: 18px 6px 20px 8px / 8px 16px 6px 18px;
  background: var(--paper-surface);
  transform: rotate(-1.2deg);
}

.read-time {
  font-family: var(--font-doodle);
  font-size: 0.88rem;
  color: var(--ink-muted);
}

/* Highlighted & Underlined Sketchy Tags Row */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 9px;
  margin-bottom: 12px;
}

.tag-chip {
  display: inline-block;
  font-family: var(--font-doodle);
  font-size: 0.86rem;
  font-weight: 700;
  padding: 1px 8px 2px;
  border-radius: 0.8em 0.3em 0.7em 0.3em / 0.3em 0.7em 0.3em 0.6em;
  text-decoration-line: underline;
  text-decoration-thickness: 1.8px;
  text-underline-offset: 2px;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: transform 140ms ease;
}

.tag-chip:active {
  transform: scale(0.95);
}

.tag-chip.t0 {
  background: var(--hl-yellow);
  color: var(--pen-red);
  text-decoration-color: var(--pen-red);
  text-decoration-style: wavy;
  transform: rotate(-1.4deg);
}

.tag-chip.t1 {
  background: var(--hl-sky);
  color: var(--pen-blue);
  text-decoration-color: var(--pen-blue);
  text-decoration-style: solid;
  transform: rotate(1.1deg);
}

.tag-chip.t2 {
  background: var(--hl-mint);
  color: var(--pen-green);
  text-decoration-color: var(--pen-green);
  text-decoration-style: wavy;
  transform: rotate(-0.8deg);
}

.tag-chip.t3 {
  background: var(--hl-pink);
  color: var(--pen-purple);
  text-decoration-color: var(--pen-purple);
  text-decoration-style: solid;
  transform: rotate(1.4deg);
}

.tag-chip.t4 {
  background: var(--hl-peach);
  color: var(--pen-orange);
  text-decoration-color: var(--pen-orange);
  text-decoration-style: wavy;
  transform: rotate(-1deg);
}

/* Sketch frame container with paper masking tape accent */
.sketch-box {
  position: relative;
  background: var(--paper-surface);
  padding: 18px 17px;
  border-radius: 16px 6px 14px 8px / 7px 15px 6px 16px;
  box-shadow: 3.5px 3.5px 0 var(--ink-shadow);
}

.sketch-box::before {
  content: "";
  position: absolute;
  top: -8px;
  right: 22px;
  width: 48px;
  height: 15px;
  background: var(--hl-yellow);
  border: 1px dashed rgba(120, 108, 86, 0.35);
  transform: rotate(4deg);
  pointer-events: none;
  opacity: 0.78;
}

.sketch-border-svg {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  pointer-events: none;
  overflow: visible;
}

.sketch-divider {
  width: 100%;
  height: 15px;
  margin: 12px 0;
  display: block;
}

.sketch-underline {
  width: 100%;
  max-width: 260px;
  height: 11px;
  display: block;
  margin: 4px 0 11px;
}

/* ==========================================================================
   Card Type 1: Book Excerpt
   ========================================================================== */

.excerpt-mark {
  font-family: "Caveat", cursive;
  font-size: 3.6rem;
  line-height: 0.55;
  color: var(--pen-red);
  opacity: 0.7;
  margin-bottom: 4px;
  user-select: none;
}

.excerpt-quote {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(1.42rem, 5.6vw, 1.82rem);
  line-height: 1.38;
  color: var(--ink);
  font-weight: 700;
}

.context-toggle {
  margin-top: 14px;
  border-top: 1.5px dashed var(--ink-faint);
  padding-top: 9px;
}

.context-toggle summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-doodle);
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--pen-blue);
  text-decoration: underline dashed var(--pen-blue);
  text-underline-offset: 3px;
}

.context-toggle summary::-webkit-details-marker {
  display: none;
}

.context-toggle[open] summary {
  margin-bottom: 8px;
}

.context-text {
  margin: 0;
  font-size: 1.06rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* Sticky-note style margin note */
.margin-note {
  margin-top: 14px;
  padding: 11px 14px;
  background: var(--paper-surface);
  border: 1.6px solid var(--ink);
  border-left: 4.5px solid var(--card-accent, var(--pen-orange));
  border-radius: 12px 5px 14px 6px / 6px 12px 5px 14px;
  box-shadow: 2.5px 2.5px 0 var(--ink-shadow);
  font-family: var(--font-doodle);
  font-size: 1.04rem;
  line-height: 1.44;
  color: var(--ink-soft);
  transform: rotate(-0.45deg);
}

.margin-note strong {
  display: inline-block;
  font-family: "Architects Daughter", cursive;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pen-orange);
  background: var(--hl-peach);
  padding: 0 6px;
  border-radius: 6px;
  margin-bottom: 4px;
  margin-right: 6px;
}

/* ==========================================================================
   Card Type 2: Key Point
   ========================================================================== */

.model-chip {
  display: inline-block;
  font-family: "Architects Daughter", cursive;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--pen-purple);
  background: var(--hl-pink);
  text-decoration: underline wavy var(--pen-purple);
  text-underline-offset: 2px;
  padding: 2px 10px;
  border-radius: 12px 4px 14px 5px;
  margin-bottom: 8px;
  transform: rotate(-1deg);
}

.card-headline {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(1.42rem, 5.4vw, 1.76rem);
  line-height: 1.24;
  font-weight: 700;
  color: var(--ink);
}

.card-prose {
  margin: 0 0 12px;
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1.48;
  color: var(--ink-soft);
}

.sketch-bullets {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.sketch-bullets li {
  position: relative;
  padding-left: 22px;
  font-family: var(--font-body);
  font-size: 1.06rem;
  line-height: 1.44;
  color: var(--ink-soft);
}

.sketch-bullets li::before {
  content: "✎";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--card-accent, var(--pen-blue));
  font-size: 0.96rem;
}

/* ==========================================================================
   Card Type 3: Question (1-3 answers) & Choice Slips
   ========================================================================== */

.question-prompt {
  margin: 0 0 14px;
  font-family: var(--font-title);
  font-size: 1.28rem;
  line-height: 1.38;
  font-weight: 700;
  color: var(--ink);
}

.choice-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-slip {
  position: relative;
  width: 100%;
  text-align: left;
  background: var(--paper-surface);
  color: var(--ink);
  border: 1.8px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink-shadow);
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.38;
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease, background-color 150ms ease;
}

.choice-slip:nth-child(odd) {
  transform: rotate(-0.35deg);
}

.choice-slip:nth-child(even) {
  transform: rotate(0.35deg);
}

.choice-slip:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink-shadow);
}

.choice-slip:disabled {
  cursor: default;
}

.choice-slip .choice-sub {
  display: block;
  margin-top: 3px;
  font-family: var(--font-doodle);
  font-size: 0.94rem;
  color: var(--ink-muted);
}

.choice-slip.selected {
  border-color: var(--pen-blue);
  background: var(--hl-sky);
}

.choice-slip.is-correct {
  border-color: var(--good);
  background: var(--good-bg);
}

.choice-slip.is-wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}

.choice-feedback {
  display: block;
  margin-top: 5px;
  font-family: var(--font-doodle);
  font-size: 0.94rem;
  color: var(--ink-soft);
}

.reveal-panel {
  margin-top: 13px;
  padding: 12px 14px;
  background: var(--paper-surface);
  border: 1.9px dashed var(--card-accent, var(--pen-blue));
  border-radius: 14px 6px 12px 7px / 6px 14px 7px 12px;
  box-shadow: 3px 3px 0 var(--ink-shadow);
  animation: inkReveal 240ms ease;
}

.reveal-panel h4 {
  margin: 0 0 5px;
  font-family: "Kalam", cursive;
  font-size: 1.15rem;
  color: var(--ink);
}

.reveal-panel p {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.02rem;
  line-height: 1.46;
  color: var(--ink-soft);
}

@keyframes inkReveal {
  from {
    opacity: 0;
    transform: translateY(4px) rotate(-0.5deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
}

/* ==========================================================================
   Interactive Templates
   ========================================================================== */

.interactive-title {
  margin: 0 0 4px;
  font-family: var(--font-title);
  font-size: clamp(1.36rem, 5.2vw, 1.68rem);
  line-height: 1.24;
  font-weight: 700;
}

.interactive-prompt {
  margin: 0 0 12px;
  font-family: var(--font-body);
  font-size: 1.07rem;
  line-height: 1.44;
  color: var(--ink-soft);
}

/* Hand-drawn tactile button */
.sketch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--paper-bg);
  box-shadow: 3px 3px 0 var(--ink-shadow);
  font-family: "Architects Daughter", cursive;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.sketch-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink-shadow);
}

.sketch-btn.secondary {
  background: var(--paper-surface);
  color: var(--ink);
  border-color: var(--ink);
}

.sketch-btn:disabled {
  opacity: 0.48;
  cursor: default;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* 4. Prediction Slider */
.slider-readout {
  font-family: "Caveat", cursive;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--card-accent, var(--pen-red));
  margin: 2px 0 8px;
  font-variant-numeric: tabular-nums;
}

.paper-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  margin: 10px 0;
  background: transparent;
  touch-action: pan-x;
  cursor: pointer;
  height: 26px;
}

.paper-slider::-webkit-slider-runnable-track {
  height: 5px;
  background: var(--paper-inset);
  border: 1.5px solid var(--ink);
  border-radius: 12px 4px 10px 5px;
}

.paper-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -10px;
  border-radius: 48% 52% 55% 45% / 44% 56% 44% 56%;
  background: var(--card-accent, var(--pen-red));
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink-shadow);
}

.paper-slider::-moz-range-track {
  height: 5px;
  background: var(--paper-inset);
  border: 1.5px solid var(--ink);
  border-radius: 12px 4px 10px 5px;
}

.paper-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 48% 52% 55% 45% / 44% 56% 44% 56%;
  background: var(--card-accent, var(--pen-red));
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink-shadow);
}

.slider-bounds {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-doodle);
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.comparison-ruler {
  position: relative;
  height: 50px;
  margin: 12px 0 6px;
}

.ruler-track {
  position: absolute;
  top: 24px;
  left: 0;
  right: 0;
  height: 3.5px;
  background: var(--ink);
  border-radius: 4px;
}

.ruler-band {
  position: absolute;
  top: 17px;
  height: 17px;
  border-radius: 4px;
  background: repeating-linear-gradient(
    -45deg,
    var(--hl-mint),
    var(--hl-mint) 5px,
    transparent 5px,
    transparent 9px
  );
  border: 1.6px dashed var(--good);
  pointer-events: none;
}

.ruler-pin {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  text-align: center;
  font-family: "Architects Daughter", cursive;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.ruler-pin .pin-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin: 2px auto 0;
  border: 2px solid var(--ink);
}

.ruler-pin.actual {
  color: var(--good);
  top: -1px;
}

.ruler-pin.actual .pin-dot {
  background: var(--good);
}

.ruler-pin.yours {
  color: var(--pen-red);
  top: 23px;
}

.ruler-pin.yours .pin-dot {
  background: var(--pen-red);
  margin: 0 auto 2px;
}

.ruler-pin.typical {
  color: var(--ink-muted);
  top: 23px;
}

.ruler-pin.typical .pin-dot {
  background: var(--ink-muted);
  margin: 0 auto 2px;
}

/* 6. Rank / Order */
.rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-surface);
  border: 1.8px solid var(--ink);
  box-shadow: 2.5px 2.5px 0 var(--ink-shadow);
  padding: 9px 10px 9px 11px;
}

.rank-item.is-right {
  border-color: var(--good);
  background: var(--good-bg);
}

.rank-item.is-wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}

.rank-num {
  font-family: "Caveat", cursive;
  font-size: 1.15rem;
  font-weight: 700;
  width: 26px;
  height: 26px;
  border-radius: 54% 46% 49% 51% / 47% 53% 47% 53%;
  border: 1.7px solid var(--ink);
  background: var(--hl-yellow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink);
}

.rank-text {
  flex: 1;
  min-width: 0;
}

.rank-text strong {
  display: block;
  font-family: var(--font-title);
  font-size: 1.04rem;
}

.rank-text span {
  display: block;
  font-family: var(--font-doodle);
  font-size: 0.88rem;
  color: var(--ink-muted);
  line-height: 1.3;
}

.rank-arrows {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mini-arrow {
  width: 28px;
  height: 24px;
  border: 1.6px solid var(--ink);
  background: var(--paper-bg);
  color: var(--ink);
  border-radius: 8px 4px 7px 5px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mini-arrow:disabled {
  opacity: 0.28;
  cursor: default;
}

/* 7. Variable Tweak & Live Sketch Chart */
.chart-stage {
  background: var(--paper-surface);
  border: 1.8px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink-shadow);
  padding: 10px 10px 6px;
  margin-bottom: 10px;
}

.chart-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
  padding: 0 4px;
}

.chart-metric {
  font-family: "Caveat", cursive;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--pen-red);
  background: var(--hl-yellow);
  padding: 0 8px;
  border-radius: 10px 4px;
}

.sketch-chart-svg {
  width: 100%;
  height: 152px;
  display: block;
}

.tweak-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tweak-row label {
  display: flex;
  justify-content: space-between;
  font-family: "Architects Daughter", cursive;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-soft);
}

/* 8. Flip / Reveal Slips */
.flip-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flip-slip {
  width: 100%;
  text-align: left;
  background: var(--paper-surface);
  border: 1.8px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink-shadow);
  padding: 11px 14px;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--ink);
  transition: background-color 180ms ease, border-color 180ms ease, transform 140ms ease;
}

.flip-slip:nth-child(odd) {
  transform: rotate(-0.5deg);
}

.flip-slip:nth-child(even) {
  transform: rotate(0.45deg);
}

.flip-slip.flipped {
  border-color: var(--pen-green);
  background: var(--good-bg);
  transform: rotate(0deg);
}

.flip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.flip-tag {
  font-family: "Architects Daughter", cursive;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--hl-pink);
  color: var(--pen-red);
}

.flip-slip.flipped .flip-tag {
  background: var(--hl-mint);
  color: var(--pen-green);
}

.flip-body {
  margin: 0;
  font-size: 1.04rem;
  line-height: 1.4;
}

/* 9. Mini Experiment (Stroop / Recall / Anchor) */
.stroop-stage {
  text-align: center;
  padding: 16px 14px;
  background: var(--paper-surface);
  border: 1.8px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink-shadow);
}

.stroop-word {
  font-family: "Kalam", cursive;
  font-size: 2.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 10px 0 16px;
  user-select: none;
}

.stroop-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stroop-choices .choice-slip {
  text-align: center;
  padding: 9px 6px;
  font-size: 0.94rem;
}

.flash-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 14px 0;
}

.flash-chip {
  padding: 5px 12px;
  border: 1.8px solid var(--ink);
  border-radius: 18px 6px 20px 8px;
  background: var(--hl-yellow);
  font-family: "Kalam", cursive;
  font-size: 1.12rem;
  font-weight: 700;
}

/* 10. Spot the Flaw — Red-Pen Margin Review */
.flaw-sheet {
  padding: 13px 13px 11px;
}

.flaw-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 9px;
  padding-bottom: 5px;
  border-bottom: 1.6px dashed var(--ink-faint);
}

.flaw-lines {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.flaw-line {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: var(--paper-bg);
  color: var(--ink);
  border: 1.5px dashed var(--ink-faint);
  border-radius: 14px 6px 16px 5px;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 1.02rem;
  line-height: 1.38;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.flaw-line:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--hl-sky);
}

.flaw-line.is-checked-ok {
  opacity: 0.72;
  border-style: solid;
  border-color: var(--ink-faint);
  background: var(--paper-inset);
}

.flaw-line.is-flaw-found {
  border: 2px solid var(--pen-red);
  background: var(--hl-pink);
}

.flaw-line.is-flaw-found .flaw-text {
  color: var(--pen-red);
  text-decoration: underline wavy var(--pen-red);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.flaw-num {
  font-family: "Architects Daughter", cursive;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--pen-blue);
  margin-top: 2px;
  flex-shrink: 0;
}

.flaw-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.flaw-note {
  font-family: var(--font-doodle);
  font-size: 0.92rem;
  color: var(--ink-soft);
}

/* 11. Trade-off Dial — Hand-drawn Balance Scale */
.balance-stage {
  background: var(--paper-surface);
  border: 1.8px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink-shadow);
  padding: 8px 12px 10px;
  margin-bottom: 10px;
}

.balance-svg {
  width: 100%;
  height: 102px;
  display: block;
}

.tradeoff-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tradeoff-col {
  background: var(--paper-surface);
  border: 1.8px solid var(--ink);
  box-shadow: 2.5px 2.5px 0 var(--ink-shadow);
  padding: 9px 10px;
}

.tradeoff-col.gain {
  border-top: 4px solid var(--good);
}

.tradeoff-col.cost {
  border-top: 4px solid var(--bad);
}

.tradeoff-col p {
  margin: 4px 0 0;
  font-family: var(--font-body);
  font-size: 0.97rem;
  line-height: 1.36;
  color: var(--ink-soft);
}

/* 12. Concept Match — Ink Threads */
.match-board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.38fr);
  column-gap: 30px;
  align-items: stretch;
  width: 100%;
}

.match-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  z-index: 2;
}

.match-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.match-chip {
  width: 100%;
  min-width: 0;
  text-align: left;
  background: var(--paper-surface);
  color: var(--ink);
  border: 1.8px solid var(--ink);
  box-shadow: 2.5px 2.5px 0 var(--ink-shadow);
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 0.94rem;
  line-height: 1.3;
  overflow-wrap: break-word;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.match-chip.left {
  font-family: var(--font-title);
  font-weight: 700;
}

.match-chip.selected {
  border-color: var(--pen-blue);
  background: var(--hl-sky);
}

.match-chip.matched {
  border-color: var(--good);
  background: var(--good-bg);
  cursor: default;
}

.match-chip.wrong-flash {
  border-color: var(--bad);
  background: var(--bad-bg);
}

/* ==========================================================================
   Card Footer (Book attribution + Quiet Actions)
   ========================================================================== */

.card-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1.6px dashed var(--ink-faint);
}

.book-credit {
  min-width: 0;
  cursor: pointer;
}

.book-credit .book-title {
  display: block;
  font-family: "Kalam", cursive;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-credit .book-author {
  display: block;
  font-family: "Patrick Hand", cursive;
  font-size: 0.92rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-credit .book-locator {
  display: inline-block;
  font-family: "Architects Daughter", cursive;
  font-size: 0.74rem;
  color: var(--pen-blue);
  background: var(--hl-sky);
  padding: 0 5px;
  border-radius: 5px;
  margin-top: 2px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.scroll-hint {
  text-align: center;
  font-family: "Caveat", cursive;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--pen-red);
  margin-top: 8px;
  opacity: 0.85;
}

/* ==========================================================================
   Bottom Sheets & Toast
   ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(17, 16, 14, 0.48);
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet-panel {
  width: 100%;
  max-width: 480px;
  max-height: 78dvh;
  background: var(--paper-bg);
  color: var(--ink);
  border-top: 2.2px solid var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--ink-faint);
  margin: 0 auto 4px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-title {
  margin: 0;
  font-family: "Kalam", cursive;
  font-size: 1.32rem;
}

.text-btn {
  background: var(--hl-yellow);
  border: 1.5px solid var(--ink);
  border-radius: 14px 5px 12px 6px;
  color: var(--ink);
  font-family: "Architects Daughter", cursive;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  padding: 3px 10px;
}

.sheet-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1.5px dashed var(--ink-faint);
  padding-bottom: 8px;
}

.sheet-tab {
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 16px 6px 14px 8px;
  padding: 4px 12px;
  font-family: "Architects Daughter", cursive;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-muted);
  cursor: pointer;
}

.sheet-tab.active {
  background: var(--hl-sky);
  border-color: var(--ink);
  color: var(--ink);
}

.sheet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-row {
  width: 100%;
  text-align: left;
  background: var(--paper-surface);
  border: 1.6px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink-shadow);
  padding: 10px 13px;
  color: var(--ink);
  font-family: "Patrick Hand", cursive;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.sheet-row.active {
  border-color: var(--pen-blue);
  background: var(--hl-sky);
}

.sheet-row small {
  display: block;
  color: var(--ink-muted);
  font-family: "Indie Flower", cursive;
  font-size: 0.9rem;
  margin-top: 2px;
}

.pack-info {
  background: var(--paper-surface);
  border: 1.6px solid var(--ink);
  padding: 12px 14px;
  font-size: 1rem;
  line-height: 1.45;
}

.sync-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sync-input {
  flex: 1;
  min-width: 0;
  background: var(--paper-bg);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 10px 4px 8px 5px;
  padding: 7px 10px;
  font-family: "Patrick Hand", cursive;
  font-size: 0.96rem;
}

.import-box summary {
  cursor: pointer;
  margin-bottom: 8px;
}

.import-box textarea {
  width: 100%;
  background: var(--paper-surface);
  color: var(--ink);
  border: 1.6px solid var(--ink);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  resize: vertical;
}

.import-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 74px);
  left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  z-index: 80;
  background: var(--ink);
  color: var(--paper-bg);
  font-family: "Architects Daughter", cursive;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 7px 16px;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 3px 3px 0 var(--ink-shadow);
}
