/* Frugalab: one stylesheet for the whole site.
   Clean, modern UI chrome (Figtree, soft cards, pill buttons) around hand-drawn objects in the video house style
   (navy ballpoint ink, crayon colour, Mochiy pop words, Zen Kurenaido handwriting). */

:root {
  --paper: #f2eee2;      /* the sheet: warm cream */
  --card: #fbf8f0;       /* prop paper */
  --ink: #263255;        /* blue-black ballpoint */
  --ink-2: #4b5476;
  --ink-3: #7c839c;
  --line: rgba(38, 50, 85, 0.14);
  --grid: rgba(95, 134, 184, 0.16);
  --red: #e0533a;        /* dealer / interest */
  --red-text: #b5371f;
  --blue: #7fa7d9;       /* bank / what you still owe */
  --blue-dk: #3d6bb3;
  --yellow: #f2bb3b;     /* money */
  --coin: #f0b429;
  --green: #79b45a;      /* fits / cheaper */
  --green-dk: #3f7d2c;
  --grey: #a3a8b6;
  --skin: #f8f5ee; --beret: #e3dfd6; --shoe: #a3a8b6; /* the beret guy */

  --ui: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --pop: "Mochiy Pop One", "Figtree", sans-serif;
  --hand: "Zen Kurenaido", "Figtree", cursive;

  --hw: 0.055em;         /* the handwriting outline (user pick, Topic 2) */
  --m: clamp(20px, 6.7vw, 96px); /* outer margin: text and cards sit on it, drawings run past it to the edges */
  --col: 680px;
  --wide: 1040px;
  --r: 18px;
  --shadow: 0 1px 0 rgba(38, 50, 85, 0.06), 0 10px 30px -12px rgba(38, 50, 85, 0.22);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font: 400 18px/1.65 var(--ui);
  color: var(--ink);
  background-color: var(--paper);
  /* faint printed dots, like the reference sheet */
  background-image: radial-gradient(rgba(38, 50, 85, 0.11) 1px, transparent 1.3px);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, video, svg { max-width: 100%; display: block; }
a { color: inherit; text-decoration-color: rgba(38, 50, 85, 0.35); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { text-decoration-color: var(--ink); }
:focus-visible { outline: 3px solid var(--blue-dk); outline-offset: 3px; border-radius: 6px; }
/* titles are Mochiy Pop One in plain ink (one weight: never faux-bold it); the four-layer crayon treatment is kept for accent words (.pop) */
h1, h2, h3 { font-family: var(--pop); font-weight: 400; line-height: 1.28; letter-spacing: 0; margin: 0 0 0.55em; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 4.6vw, 3.1rem); }
h2 { font-size: clamp(1.45rem, 3vw, 1.95rem); }
h3 { font-size: 1.08rem; line-height: 1.35; }
p { margin: 0 0 1.1em; text-wrap: pretty; }
strong { font-weight: 700; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: min(100% - 32px, var(--wide)); margin-inline: auto; }
.col { width: min(100% - 32px, var(--col)); margin-inline: auto; }
/* small handwritten labels: Zen Kurenaido thickened by a same-colour 0.055em outline drawn behind the letters */
.kicker { font: 400 1.45rem/1.2 var(--hand); -webkit-text-stroke: var(--hw) currentColor; paint-order: stroke fill; color: var(--ink); margin-bottom: 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 0.88rem; }

/* ---------------------------------------------------------------- header + footer */
.site-head {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.site-head.scrolled { border-bottom-color: var(--line); }
.site-head .wrap, .site-foot .wrap { width: auto; margin-inline: var(--m); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; height: 72px; gap: 16px; }
.logo { display: inline-block; width: 64px; height: 56px; background: var(--ink); -webkit-mask: url("../assets/frugalab.svg") left center / contain no-repeat; mask: url("../assets/frugalab.svg") left center / contain no-repeat; }
.site-head nav { display: flex; gap: 6px; }
.site-head nav a { text-decoration: none; font-weight: 600; font-size: 0.95rem; padding: 8px 12px; border-radius: 999px; }
.site-head nav a:hover { background: rgba(38, 50, 85, 0.07); }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 100%; background: var(--ink); transform-origin: 0 50%; transform: scaleX(0); }
@supports (animation-timeline: scroll()) {
  .progress { animation: grow linear both; animation-timeline: scroll(root); }
  @keyframes grow { to { transform: scaleX(1); } }
}
.site-foot { margin-top: 120px; padding: 48px 0 64px; border-top: 1px solid var(--line); font-size: 0.92rem; color: var(--ink-2); }
.site-foot .wrap { display: flex; flex-wrap: wrap; gap: 24px; justify-content: space-between; align-items: center; }
.site-foot .logo { width: 56px; height: 50px; }
.site-foot nav { display: flex; gap: 20px; font-weight: 600; }
.site-foot nav a { text-decoration: none; }

/* ---------------------------------------------------------------- buttons, chips */
.btn {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 12px 22px;
  border-radius: 999px; border: 1.5px solid var(--ink); background: var(--ink); color: var(--card);
  font: 650 1rem/1 var(--ui); text-decoration: none; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px -8px rgba(38, 50, 85, 0.6); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: rgba(38, 50, 85, 0.06); }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: 0.9rem; }
.btn .play { width: 0; height: 0; border-left: 10px solid currentColor; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.chip { font: 600 0.78rem/1 var(--ui); padding: 7px 11px; border-radius: 999px; background: rgba(38, 50, 85, 0.07); color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--card); }

/* ---------------------------------------------------------------- the drawn layer */
.ink { fill: none; stroke: var(--ink); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.pen { fill: var(--ink); stroke: none; }
.hand-t { font-family: var(--hand); fill: var(--ink); stroke: var(--ink); stroke-width: 0.055em; paint-order: stroke; stroke-linejoin: round; }
.hand { font-family: var(--hand); -webkit-text-stroke: var(--hw) currentColor; paint-order: stroke fill; letter-spacing: 0.01em; } /* Zen Kurenaido has one weight: a same-colour outline thickens it */
.mo-t { font-family: var(--pop); }
svg.stage { --ink: #263255; overflow: visible; }
/* the guy is drawn in two passes: crayon fills underneath, pen lines on top */
.gF * { stroke: none !important; }
.gF [style*="fill:var(--ink"] { display: none; }
.gI [style*="fill:var(--s"] { fill: none !important; }

/* pop words: ink shadow, paper base, crayon colour, pen outline (built by doodle.js) */
.pop { font-family: var(--pop); font-weight: 400; display: inline-grid; line-height: 1.1; letter-spacing: 0.01em; vertical-align: baseline; --c: var(--yellow); white-space: nowrap; }
.pop > span { grid-area: 1 / 1; }
.pop .l-sh { color: var(--ink); -webkit-text-stroke: 0.16em var(--ink); transform: translate(0.05em, 0.07em); }
.pop .l-base { color: var(--card); -webkit-text-stroke: 0.16em var(--card); }
.pop .l-col { color: var(--c); filter: url(#crayonDense); }
.pop .l-ink { color: transparent; -webkit-text-stroke: 0.045em var(--ink); }
.pop i { font-style: normal; display: inline-block; transform-origin: 50% 85%; }
.pop.go i { animation: pop 0.42s step-end both; animation-delay: calc(var(--k) * 0.083s); }
@keyframes pop { /* on 2s (one step = 1/12 s): squash 0.35 -> 1.28 -> 0.88 -> 1 */
  0% { opacity: 0; }
  20% { transform: scale(0.35) rotate(-8deg); opacity: 1; }
  40% { transform: scale(1.28) rotate(4deg); }
  60% { transform: scale(0.88) rotate(-2deg); }
  80%, 100% { transform: none; }
}
.pop.wait i { opacity: 0; }

/* a paper object: the card the sums are written on */
.paper-card {
  position: relative; background: var(--card); border-radius: 4px; padding: 26px 28px 22px;
  box-shadow: 6px 8px 0 rgba(38, 50, 85, 0.08); border: 2px solid var(--ink);
  border-radius: 6px 3px 7px 4px / 4px 7px 3px 6px; /* never a perfect box */
}
.paper-card .clip { position: absolute; top: -18px; right: 34px; width: 18px; height: 44px; border: 2.5px solid var(--ink-2); border-radius: 9px; }
.paper-card.tilt { transform: rotate(-0.8deg); }

/* a sheet of graph paper the figures are drawn on (the videos' grid) */
.sheet {
  position: relative; background-color: var(--card);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px; background-position: -1px -1px;
  border-radius: var(--r); box-shadow: var(--shadow); border: 1px solid var(--line);
  overflow: hidden;
}

/* ---------------------------------------------------------------- video dialog */
dialog.player { border: 0; padding: 0; background: transparent; max-width: min(92vw, 420px, 48vh); width: 100%; overflow: visible; }
dialog.player::backdrop { background: rgba(23, 29, 52, 0.72); backdrop-filter: blur(4px); }
dialog.player video, dialog.player iframe { width: 100%; aspect-ratio: 9 / 16; max-height: 86vh; border: 0; border-radius: 16px; background: #000; object-fit: contain; }
dialog.player [hidden] { display: none; }
dialog.player .x { position: absolute; top: -14px; right: -14px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--card); color: var(--ink); font: 700 22px/1 var(--ui); cursor: pointer; box-shadow: var(--shadow); }
.phone { position: relative; aspect-ratio: 9 / 16; border-radius: 22px; overflow: hidden; background: var(--paper); box-shadow: var(--shadow); border: 6px solid var(--card); outline: 1px solid var(--line); cursor: pointer; padding: 0; }
.phone img { width: 100%; height: 100%; object-fit: cover; }
.phone .badge { position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: 64px; height: 64px; border-radius: 50%; background: rgba(251, 248, 240, 0.94); box-shadow: var(--shadow); display: grid; place-items: center; transition: scale 0.15s; }
.phone .badge::after { content: ""; margin-left: 5px; border-left: 18px solid var(--ink); border-top: 11px solid transparent; border-bottom: 11px solid transparent; }
.phone:hover .badge { scale: 1.08; }
.phone .len { position: absolute; right: 10px; bottom: 10px; font: 650 0.75rem/1 var(--ui); padding: 6px 9px; border-radius: 999px; background: rgba(38, 50, 85, 0.85); color: var(--card); }

/* ---------------------------------------------------------------- reveal on scroll */
/* only hidden when the script that reveals them is running */
.js [data-reveal] { opacity: 0; transform: translateY(14px); transition: opacity 0.6s, transform 0.6s; }
.js [data-reveal].in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js [data-reveal] { opacity: 1; transform: none; transition: none; }
  .pop.go i { animation: none; }
  .pop.wait i { opacity: 1; }
  .btn { transition: none; }
}
@media (max-width: 640px) {
  body { font-size: 17px; }
  .site-head nav a { padding: 8px 8px; font-size: 0.9rem; }
  .logo { width: 54px; height: 48px; }
}

/* ---------------------------------------------------------------- reading focus
   the passage you're reading is in full ink, the rest steps back; key phrases get a highlighter swipe
   in their meaning colour the first time you reach them, and keep it */
.rd { transition: opacity 0.45s, transform 0.6s; }
.focus-read .rd:not(.on) { opacity: 0.34; }
mark { color: inherit; background: linear-gradient(100deg, transparent 2%, var(--mk) 4%, var(--mk) 96%, transparent 98%) no-repeat 0 85% / 0% 62%; padding: 0 0.12em; margin: 0 -0.12em; border-radius: 0.2em 0.5em 0.3em 0.4em; transition: background-size 0.5s steps(5); --mk: rgba(242, 187, 59, 0.5); }
mark.hl-red { --mk: rgba(224, 83, 58, 0.3); }
mark.hl-blue { --mk: rgba(127, 167, 217, 0.45); }
mark.hl-green { --mk: rgba(121, 180, 90, 0.4); }
mark.lit { background-size: 100% 62%; }
@media (prefers-reduced-motion: reduce) { .rd, mark { transition: none; } }
