/* The Frappe Guy: comic components and template frames.
   Every value reads a token from tokens.css first; the fallbacks match tokens.json.
   Characters are never drawn here: .tfg-char only places a library export. */

/* ---------- ComicPanel ---------- */
.tfg-panel {
  position: relative;
  container-type: inline-size;
  aspect-ratio: var(--panel-ratio, 4 / 3);
  overflow: hidden;
  margin: 0;
  background: var(--comic-paper, #FAF8F2);
  border-radius: var(--radius-0, 0);
  box-shadow: none;
  isolation: isolate;
}
.tfg-panel[data-shape="wide"] { aspect-ratio: 1600 / 576; }
.tfg-panel[data-ground="flat"] { background: var(--tfg-ground, var(--highlight, #E8BE5F)); }
.tfg-panel > * { --bw: max(2px, 0.56cqw); }
.tfg-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  border: max(2px, 0.56cqw) solid var(--comic-ink, #000000);
  pointer-events: none;
}

/* Environment line art from the library, always at scenery-opacity */
.tfg-scenery {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center bottom;
  opacity: var(--scenery-opacity, 0.1);
  pointer-events: none;
}

/* ---------- TableStrip ---------- */
.tfg-table {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  height: var(--table-height, 8.5%);
  background: var(--comic-table, #E4CAB9);
  border-top: var(--bw, 3px) solid var(--comic-ink, #000000);
}

/* ---------- Character ----------
   --n is the pose's height normalised to Deepak's large poses (scale_to_match_large already applied).
   --fig is the layout factor: how tall a large pose stands in this frame. One --fig per frame. */
.tfg-char {
  position: absolute;
  z-index: 1;
  bottom: var(--y, 0);
  height: calc(var(--fig, 64%) * var(--n, 1));
  width: auto;
  max-width: none;
  pointer-events: none;
  user-select: none;
}
.tfg-char[data-side="right"] { right: var(--x, 5%); }
.tfg-char[data-side="left"] { left: var(--x, 5%); }
.tfg-char[data-baked-table] {
  z-index: 3;
  bottom: calc(var(--table-height, 8.5%) - var(--fig, 64%) * var(--n, 1) * var(--drop, 0.0873));
}

/* ---------- SpeechBubble ---------- */
.tfg-bubble {
  position: absolute;
  z-index: 4;
  box-sizing: border-box;
  margin: 0;
  max-width: var(--w, 46%);
  padding: 0.32em 0.62em 0.42em;
  background: var(--comic-bubble, #FFFFFF);
  border: var(--bw, 3px) solid var(--comic-ink, #000000);
  border-radius: var(--radius-0, 0);
  color: var(--comic-ink, #000000);
  font-family: var(--font-hand, "Caveat", cursive);
  font-weight: 500;
  font-size: var(--letter, 4.7cqw);
  line-height: 1.2;
  text-wrap: pretty;
}
/* Tail: the library speech box tail (same proportions as the logo), drawn as one open stroke */
.tfg-bubble::after {
  content: "";
  position: absolute;
  top: calc(100% - var(--bw, 3px));
  width: 1.12em;
  height: calc(var(--tail, 1.05em) + var(--bw, 3px));
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.tfg-bubble[data-tail="right"]::after {
  left: var(--tail-x, 68%);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 112 110' preserveAspectRatio='none'%3E%3Cpath d='M6 0 L104 104 L58 0' fill='%23fff' stroke='%23000' stroke-width='11' stroke-linejoin='miter' stroke-miterlimit='10'/%3E%3C/svg%3E");
}
.tfg-bubble[data-tail="left"]::after {
  right: var(--tail-x, 68%);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 112 110' preserveAspectRatio='none'%3E%3Cpath d='M106 0 L8 104 L54 0' fill='%23fff' stroke='%23000' stroke-width='11' stroke-linejoin='miter' stroke-miterlimit='10'/%3E%3C/svg%3E");
}

/* ---------- ThoughtBubble ---------- */
.tfg-thought {
  position: absolute;
  z-index: 4;
  box-sizing: border-box;
  margin: 0;
  width: var(--w, 46%);
  padding: 1.1em 1.25em 1.2em;
  color: var(--comic-ink, #000000);
  font-family: var(--font-hand, "Caveat", cursive);
  font-weight: 500;
  font-size: var(--letter, 4.7cqw);
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
  aspect-ratio: 5 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tfg-thought > svg { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; overflow: visible; }
.tfg-thought > svg path,
.tfg-thought > svg circle { fill: var(--comic-bubble, #FFFFFF); stroke: var(--comic-ink, #000000); stroke-width: var(--bw, 3px); vector-effect: non-scaling-stroke; }

/* ---------- CaptionBox (D-158) ----------
   Narration in the top-left corner, flush to the frame, no tail. One per panel; counts toward the 2-bubble limit. */
.tfg-caption {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  box-sizing: border-box;
  margin: 0;
  max-width: 100%;
  padding: 0.3em 0.7em 0.36em;
  background: var(--comic-bubble, #FFFFFF);
  border: var(--bw, 3px) solid var(--comic-ink, #000000);
  color: var(--comic-ink, #000000);
  font-family: var(--font-hand, "Caveat", cursive);
  font-weight: 600;
  font-size: 4.2cqw;
  line-height: 1.2;
}

/* ---------- Sticker ---------- */
.tfg-sticker {
  position: absolute;
  z-index: 4;
  width: var(--w, 30%);
  height: auto;
  pointer-events: none;
}

/* ---------- ComicGrid (layouts) ---------- */
.tfg-grid { display: grid; gap: var(--gutter, var(--space-4, 16px)); }
.tfg-grid[data-layout="single"] { grid-template-columns: 1fr; }
.tfg-grid[data-layout="2x2"] { grid-template-columns: 1fr 1fr; }
.tfg-grid[data-layout="3+1"] { grid-template-columns: 1fr 1fr 1fr; }
.tfg-grid[data-layout="3+1"] > :last-child { grid-column: 1 / -1; aspect-ratio: 1600 / 576; }

/* ---------- SceneGround ---------- */
.tfg-scene { position: relative; overflow: hidden; background: var(--scene-tangerine, #F0A25A); color: var(--on-scene, #000000); }
/* Ten scene colours, one per series. The first five are the library's app store colours (D-036); the other five sit in the same band (D-104). */
/* Topic scenes: a tint of each product's own logo colour, so the characters stay readable (D-114). */
.tfg-scene[data-scene="ink"] { background: var(--scene-ink, #171717); --on-scene: #FFFFFF; color: #FFFFFF; }
.tfg-scene[data-scene="blue"] { background: var(--scene-blue, #70BBF9); }
.tfg-scene[data-scene="cyan"] { background: var(--scene-cyan, #96DFF3); }
.tfg-scene[data-scene="yellow"] { background: var(--scene-yellow, #ECCC84); }
.tfg-scene[data-scene="mint"] { background: var(--scene-mint, #8CDAC4); }
.tfg-scene[data-scene="magenta"] { background: var(--scene-magenta, #F594F3); }
.tfg-scene[data-scene="violet"] { background: var(--scene-violet, #C2A4F8); }
.tfg-scene[data-scene="grey"] { background: var(--scene-grey, #BABCBE); }
.tfg-scene[data-scene="green"] { background: var(--scene-green, #84B4A5); }
.tfg-scene[data-scene="orange"] { background: var(--scene-orange, #F4BC8E); }

/* Topic text tones: the logo colour darkened to at least 5.5:1 on paper. */
[data-tone] { color: var(--tone, #000000); }
[data-tone="ink"] { --tone: #171717; --tint: #E9E7E1; --logo: #171717; }
[data-tone="blue"] { --tone: #0064BA; --tint: #DCEBF4; --logo: #0089FF; }
[data-tone="cyan"] { --tone: #006C8E; --tint: #DCF1F2; --logo: #00BAF4; }
[data-tone="yellow"] { --tone: #766130; --tint: #F8F1E0; --logo: #E8BE5F; }
[data-tone="mint"] { --tone: #047258; --tint: #DDF0E6; --logo: #06B58B; }
[data-tone="magenta"] { --tone: #B108B5; --tint: #F9DCF2; --logo: #EF0BF5; }
[data-tone="violet"] { --tone: #7439ED; --tint: #EBE2F4; --logo: #7D3DFF; }
[data-tone="grey"] { --tone: #60646C; --tint: #EBEAE6; --logo: #7B808A; }
[data-tone="green"] { --tone: #0E7159; --tint: #DEE8E0; --logo: #0E7159; }
[data-tone="orange"] { --tone: #925425; --tint: #F9EBDC; --logo: #F08A3C; }
.tfg-dot { position: absolute; z-index: 0; width: var(--d, 18px); height: var(--d, 18px); border-radius: 50%; background: var(--dot-pink, #F3AFAD); }
.tfg-dot[data-dot="blue"] { background: var(--dot-blue, #4B93EA); }

/* ---------- Tag (highlighter swipe) ---------- */
.tfg-tag {
  display: inline-block;
  padding: 0.04em 0.5em 0.1em;
  background: var(--highlight, #E8BE5F);
  color: var(--on-highlight, #000000);
  font-family: var(--font-hand, "Caveat", cursive);
  font-weight: 600;
  font-size: var(--tag-size, 25px);
  line-height: 1.15;
  transform: rotate(-2deg);
  clip-path: polygon(1.5% 12%, 9% 2%, 99% 0, 97.5% 48%, 100% 96%, 4% 100%, 0 70%, 2.5% 40%);
}

/* ---------- TakeawayLine ---------- */
.tfg-takeaway {
  margin: 0;
  padding-top: var(--space-4, 16px);
  border-top: var(--border-takeaway, 3px) solid var(--border-strong, #000000);
  color: inherit;
  font-family: var(--font-sans, "Inter", system-ui, sans-serif);
  font-weight: 700;
  font-size: var(--takeaway-size, 24px);
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.tfg-scene .tfg-takeaway { border-top-color: var(--on-scene, #000000); }

/* ---------- CreditLine ---------- */
.tfg-credit {
  margin: 0;
  color: var(--ink-3, #6B675F);
  font-family: var(--font-sans, "Inter", system-ui, sans-serif);
  font-weight: 400;
  font-size: var(--credit-size, 12px);
  line-height: 1.5;
}
.tfg-scene .tfg-credit, .tfg-credit[data-on="scene"] { color: var(--on-scene, #000000); }
.tfg-credit[data-on="ink"] { color: #A39F96; }

/* ---------- Template artboards ---------- */
.tfg-art {
  position: relative;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--paper, #FAF8F2);
  color: var(--ink, #000000);
  font-family: var(--font-sans, "Inter", system-ui, sans-serif);
}
/* Social and video frames are artwork: they keep the light values in dark mode, like comic panels. */
.tfg-art[data-fixed]:not(.tfg-scene) { background: #FAF8F2; }
.tfg-art[data-fixed] { color: #000000; --ink: #000000; --ink-2: #4E4B45; --ink-3: #6B675F; --border-strong: #000000; --paper: #FAF8F2; --surface: #FFFFFF; --rule: #E1DFDA; }
.tfg-art[data-fixed="ink"]:not(.tfg-scene) { background: #000000; color: #FAF8F2; }
.tfg-art img.tfg-logo { display: block; height: auto; }

/* ---------- Full comic (D-166, D-168, D-172) ----------
   Shots: medium (two at the table), close (one, bigger, scenery kept), flat (close-up on the library highlight),
   small (one of a row of three), wide (the library strip, silent). Text sits in one stack: the caption runs full
   width at the top, the left bubble in the left half, the reply in the right half one step lower. */
.tfg-panel[data-shot] { width: 100%; }
.tfg-panel[data-shot="wide"] { aspect-ratio: 1600 / 576; }
.tfg-panel[data-shot="flat"] { background: var(--highlight, #E8BE5F); }
.tfg-stack { position: absolute; z-index: 4; top: 0; left: 0; right: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 4cqw; row-gap: 2.4cqw; align-items: start; padding: 3cqw 3cqw 0; }
.tfg-stack.has-cap { padding-top: 0; }
.tfg-stack > * { grid-row: 1; }
.tfg-stack.has-cap > * { grid-row: 2; }
.tfg-stack > .tfg-caption { position: relative; grid-column: 1 / -1; grid-row: 1; justify-self: start; margin: 0 0 0 -3cqw; max-width: 78%; border-width: 0 var(--bw, 3px) var(--bw, 3px) 0; line-height: 1.18; }
.tfg-stack > .tfg-bubble { position: relative; grid-column: 1; justify-self: start; max-width: 100%; font-size: 4.7cqw; line-height: 1.16; --tail-x: 64%; }
.tfg-stack > .tfg-bubble[data-long] { font-size: 3.9cqw; }
.tfg-stack > .tfg-bubble[data-tail="right"] { grid-column: 2; justify-self: end; --tail-x: 58%; }
.tfg-stack > .tfg-bubble.is-reply { margin-top: 7cqw; }
.tfg-stack > .tfg-bubble.is-across { grid-column: 2; justify-self: start; --tail-x: 82%; }
.tfg-stack > .tfg-thought { position: relative; grid-column: 2; justify-self: end; margin: 2cqw 0 0; width: 100%; padding: 1em 1.2em 1.1em; font-size: 4.2cqw; line-height: 1.12; isolation: isolate; }
.tfg-panel[data-shot] .st-whoa { z-index: 5; right: 4%; top: 14%; width: 44%; }
.tfg-panel[data-shot="wide"] .st-whoa { right: 5%; top: 30%; width: 52%; }
.tfg-panel[data-shot] .st-ww { z-index: 0; left: 4%; width: 92%; top: 30%; }
.tfg-panel[data-shot="small"] .tfg-stack > .tfg-caption { font-size: 6.4cqw; max-width: 100%; }

/* ---------- Stage 6: teach every concept (D-180, D-184) ----------
   Narration: a caption alone in its panel runs the full width. One speaker with a listener: the bubble may use
   two thirds of the width. A long reply sits higher. Diagrams: ink lines on paper, labels in the hand font,
   layout only, never a character. */
.tfg-stack > .tfg-caption.is-narration { max-width: 100%; width: calc(100% + 6cqw); margin-right: -3cqw; font-size: 4.5cqw; padding: 0.45em 0.9em 0.5em; }
.tfg-stack > .tfg-bubble.is-wide { grid-column: 1 / -1; max-width: 66%; }
.tfg-stack > .tfg-bubble.is-wide[data-tail="left"] { --tail-x: 70%; }
.tfg-stack > .tfg-bubble.is-wide[data-tail="right"] { justify-self: end; --tail-x: 62%; }
.tfg-stack > .tfg-bubble.is-wide[data-long] { font-size: 4.3cqw; }
.tfg-stack > .tfg-bubble.is-reply.is-high { margin-top: 2.5cqw; }

.tfg-panel[data-shot="diagram"] { background: var(--comic-paper, #FAF8F2); }
.dg { position: absolute; z-index: 3; left: 6cqw; right: 6cqw; top: 15cqw; bottom: 4.5cqw; font-family: var(--font-hand, "Caveat", cursive); color: var(--comic-ink, #000000); --bw: max(2px, 0.56cqw); }
.dg-label { font-weight: 600; line-height: 1.1; }
.dg-box { position: absolute; display: flex; align-items: center; justify-content: center; text-align: center; text-wrap: balance; box-sizing: border-box; background: var(--comic-bubble, #FFFFFF); border: var(--bw) solid var(--comic-ink, #000000); padding: 0.4em 0.6em; font-size: 4.4cqw; }
.dg-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.dg-lines line { stroke: var(--comic-ink, #000000); stroke-width: var(--bw); vector-effect: non-scaling-stroke; }
.dg-one-record .dg-hub { left: 30%; right: 30%; top: 38%; height: 24%; background: var(--highlight, #E8BE5F); font-size: 5cqw; font-weight: 700; }
.dg-one-record .dg-c0, .dg-one-record .dg-c1, .dg-one-record .dg-c2, .dg-one-record .dg-c3 { width: 40%; height: 22%; }
.dg-one-record .dg-c0 { left: 0; top: 0; }
.dg-one-record .dg-c1 { right: 0; top: 0; }
.dg-one-record .dg-c2 { left: 0; bottom: 0; }
.dg-one-record .dg-c3 { right: 0; bottom: 0; }
.dg-timeline { display: grid; grid-template-columns: repeat(3, 1fr); align-items: center; }
.dg-rail { position: absolute; left: 4%; right: 4%; top: 50%; border-top: var(--bw) solid var(--comic-ink, #000000); }
.dg-step { position: relative; display: grid; grid-template-rows: 1fr auto 1fr; justify-items: center; height: 100%; text-align: center; }
.dg-year { align-self: end; margin-bottom: 2.4cqw; font-family: var(--font-sans, "Inter", sans-serif); font-weight: 800; font-size: 7cqw; letter-spacing: -0.02em; }
.dg-dot { width: 4.4cqw; height: 4.4cqw; border-radius: 50%; background: var(--highlight, #E8BE5F); border: var(--bw) solid var(--comic-ink, #000000); }
.dg-step .dg-label { align-self: start; margin-top: 2.4cqw; font-size: 4.5cqw; max-width: 24cqw; text-wrap: balance; }
.dg-two { display: grid; grid-template-columns: 1fr 1fr; gap: 5cqw; align-items: center; }
.dg-col { display: flex; flex-direction: column; gap: 1.6cqw; padding: 2.4cqw 2.8cqw; border: var(--bw) solid var(--comic-ink, #000000); background: var(--comic-bubble, #FFFFFF); }
.dg-col0 { border-style: dashed; }
.dg-col1 { background: #FFF6E0; }
.dg-title { font-family: var(--font-sans, "Inter", sans-serif); font-weight: 800; font-size: 4.4cqw; letter-spacing: -0.01em; padding-bottom: 1.4cqw; border-bottom: var(--bw) solid var(--comic-ink, #000000); }
.dg-item { font-size: 4.6cqw; }
.dg-family { display: flex; flex-direction: column; justify-content: center; gap: 2.6cqw; }
.dg-group { display: flex; flex-direction: column; gap: 1.6cqw; }
.dg-group .dg-title { border-bottom: 0; padding-bottom: 0; font-size: 4cqw; }
.dg-chips { display: flex; flex-wrap: wrap; gap: 1.6cqw; }
.dg-group[data-n="8"] .dg-chips { display: grid; grid-template-columns: 1fr 1fr; }
.dg-chip { display: inline-block; padding: 0.22em 0.55em 0.28em; background: var(--comic-bubble, #FFFFFF); border: var(--bw) solid var(--comic-ink, #000000); font-size: 4.1cqw; }
.dg-group:last-child .dg-chip:only-child { background: var(--highlight, #E8BE5F); }
.dg-one-site { display: flex; align-items: center; justify-content: center; }
.dg-site { width: 86%; border: var(--bw) solid var(--comic-ink, #000000); background: var(--comic-bubble, #FFFFFF); }
.dg-bar { display: block; padding: 1.4cqw 2.4cqw; border-bottom: var(--bw) solid var(--comic-ink, #000000); background: var(--highlight, #E8BE5F); font-family: var(--font-sans, "Inter", sans-serif); font-weight: 700; font-size: 3.6cqw; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.dg-site .dg-chips { padding: 3.4cqw 2.4cqw; justify-content: center; gap: 2.4cqw; }
.dg-site .dg-chip { font-size: 4.8cqw; }
.dg-site .dg-chip:last-child { border-style: dashed; }

/* ---------- Stage 8: real screens and ERPNext diagrams (D-216) ----------
   Screen: a real screen from The Coffee Company's ERPNext site, never redrawn. The caption sits above it in the
   same box as every caption; the screen sits on paper with a thin ink frame and opens full size on tap.
   Chain: documents in order, each made from the one before; the step the story is on is highlighted.
   Capability: the release's capability box, one row per flow, "Built in" solid and "A setting" dashed. */
.tfg-panel[data-shot="screen"] { aspect-ratio: auto; display: flex; flex-direction: column; align-items: stretch; gap: 3.4cqw; padding: 0 4.5cqw 4.5cqw; background: var(--comic-paper, #FAF8F2); }
.tfg-screen-cap { position: relative; z-index: 4; align-self: flex-start; box-sizing: border-box; margin: 0 0 0 -4.5cqw; max-width: calc(100% + 9cqw); padding: 0.45em 0.9em 0.5em; background: var(--comic-bubble, #FFFFFF); border: solid var(--comic-ink, #000000); border-width: 0 max(2px, 0.56cqw) max(2px, 0.56cqw) 0; color: var(--comic-ink, #000000); font-family: var(--font-hand, "Caveat", cursive); font-weight: 600; font-size: 4.5cqw; line-height: 1.2; }
.tfg-screen { display: block; align-self: center; width: 100%; max-width: 460px; border: max(1px, 0.3cqw) solid var(--comic-ink, #000000); border-radius: 1.6cqw; overflow: hidden; background: #FFFFFF; box-shadow: 0.9cqw 0.9cqw 0 var(--comic-ink, #000000); }
.tfg-screen img { display: block; width: 100%; height: auto; }
.tfg-screen:focus-visible { outline: 3px solid var(--highlight, #E8BE5F); outline-offset: 3px; }

.tfg-panel[data-dg="chain"] { aspect-ratio: 4 / 5; }
.tfg-panel[data-dg="capability"] { aspect-ratio: 3 / 4; }
.tfg-panel[data-dg="capability"] .dg { top: 21cqw; }
.dg-chain { display: flex; flex-direction: column; justify-content: space-between; gap: 4.6cqw; }
.dg-link { position: relative; flex: 1; display: grid; grid-template-columns: 44% 1fr; align-items: center; column-gap: 3cqw; padding: 0 3.2cqw; background: var(--comic-bubble, #FFFFFF); border: var(--bw) solid var(--comic-ink, #000000); }
.dg-link + .dg-link::before { content: ""; position: absolute; left: 22%; top: calc(-4.6cqw - var(--bw)); height: 4.6cqw; border-left: var(--bw) solid var(--comic-ink, #000000); }
.dg-link + .dg-link::after { content: ""; position: absolute; left: calc(22% - 1.5cqw + var(--bw) / 2); top: calc(-2.4cqw - var(--bw)); border: 1.5cqw solid transparent; border-top: 2cqw solid var(--comic-ink, #000000); border-bottom: 0; }
.dg-link.is-on { background: var(--highlight, #E8BE5F); }
.dg-doc { font-family: var(--font-sans, "Inter", sans-serif); font-weight: 800; font-size: 4.3cqw; letter-spacing: -0.01em; line-height: 1.1; }
.dg-link .dg-label { font-size: 4.9cqw; }
.dg-chain[data-n="6"] .dg-doc { font-size: 3.9cqw; }
.dg-capability { display: flex; flex-direction: column; justify-content: center; gap: 2.2cqw; }
.dg-cap { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 3cqw; padding-bottom: 2.2cqw; border-bottom: max(1px, 0.3cqw) solid var(--comic-ink, #000000); }
.dg-cap:last-child { border-bottom: 0; }
.dg-flow { font-size: 5cqw; }
.dg-level { font-family: var(--font-sans, "Inter", sans-serif); font-weight: 700; font-size: 3.6cqw; padding: 0.3em 0.7em; background: var(--highlight, #E8BE5F); border: var(--bw) solid var(--comic-ink, #000000); white-space: nowrap; }
.dg-level.is-setting { background: var(--comic-bubble, #FFFFFF); border-style: dashed; }
