/* =============================================================================
   02-layout.css — "First Steps in OpenUSD"
   The layout system: nine section patterns that turn vertical length into
   horizontal breadth without letting a paragraph get wider than it should be.

   Owns:      the content shell, the section grid, the nine patterns below.
   Does NOT own: masthead (.mast), menu (.menu), rail (.rail/.seg/.dot),
                 home view (.hero/.chapwall), scroll logic, animation.
   Depends on: --rail, --top, and the palette tokens, all restated here so the
               file works standalone; identical values to the spine.
   ============================================================================= */

:root{
  /* palette — restated, identical to the spine */
  --paper:#F6F3EC; --card:#FDFBF6; --chrome:#F0ECE2; --sunk:#EFEAE0;
  --ink:#1E1B16; --ink2:#5E574B; --ink3:#756F61;
  --rule:#E0D8C8; --rule2:#C7BCA6;
  --acc:#8A6E2A; --acctxt:#634E18; --wash:#F2EBDA;
  --flag:#7A4128; --flagrule:#9A5A3C; --flagwash:#F6E9E2;
  --sans:'Libre Franklin',system-ui,-apple-system,'Segoe UI',sans-serif;
  --serif:'Source Serif 4',Georgia,'Times New Roman',serif;
  --mono:'Courier Prime',ui-monospace,Consolas,monospace;

  /* chrome geometry — set by the rail/masthead owners, consumed here */
  --rail:252px;
  --top:52px;

  /* ---- layout tokens (new) ---- */
  --shell:1560px;                          /* content shell; see notes for why */
  --gut:clamp(1rem,2.2vw,2.25rem);         /* section side padding */
  --measure:66ch;                          /* HARD cap on any running text */
  --gap:clamp(1.1rem,1.8vw,2.4rem);        /* column gap inside patterns */
  --gap-y:clamp(.7rem,1vw,1.1rem);         /* row gap when a pattern wraps */
  --stop:calc(var(--top) + 1rem);          /* sticky offset under the masthead */
  --r:5px;                                 /* panel corner radius */
}

/* ---------- shell + section ------------------------------------------------
   .wrap keeps every pattern clear of the fixed right rail. Nothing inside
   may use position:fixed or a negative margin larger than --gut. */
.wrap{margin-right:var(--rail);padding:var(--top) 0 6rem}

/* .sect — one numbered section. Full shell width; patterns fill it sideways. */
.sect{max-width:var(--shell);margin:0 auto;padding:2.3rem var(--gut) 1.4rem;
      scroll-margin-top:calc(var(--top) + 8px)}
.sect + .sect{border-top:1px solid var(--rule)}
.sect > * + *{margin-top:0}

/* ---------- the measure guard ---------------------------------------------
   Widening the SHELL must never widen a PARAGRAPH. Any running text — loose
   in a section or inside a pattern cell — is clamped here, once. */
p,li,blockquote,.brief,.flagbox,.endcap,.dbody{max-width:var(--measure)}
.pane p,.tile p,.card p,.def p,.figc,figcaption{max-width:none}

/* ---------- overflow safety net -------------------------------------------
   Long unbreakable tokens (/World/Characters/CharacterA) must wrap, not push
   a grid track wide. Every pattern child also gets min-width:0 below. */
code{font-family:var(--mono);font-size:.86em;background:var(--wash);color:var(--acctxt);
     padding:.03rem .24rem;border-radius:2px;overflow-wrap:anywhere}
pre{margin:0;font-family:var(--mono);font-size:.79rem;line-height:1.6;
    overflow-x:auto;max-width:100%}
pre .k{color:var(--acctxt);font-weight:700}
pre .c{color:var(--ink3)}
img,svg,video,canvas{max-width:100%;height:auto}
table{border-collapse:collapse;width:100%}

/* ---------- shared furniture ----------------------------------------------
   .pane is the generic figure/code container the patterns place; .figc is its
   caption. Both are layout-level, not decoration owned elsewhere. */
.pane{background:var(--card);border:1px solid var(--rule);border-radius:var(--r);
      padding:.8rem .95rem;min-width:0}
.pane > h4{margin:0 0 .45rem;font-family:var(--sans);font-size:.67rem;letter-spacing:.09em;
           text-transform:uppercase;color:var(--ink3);font-weight:600}
.pane.sunk{background:var(--sunk)}
figure{margin:0;min-width:0}
.figc,figcaption{margin:.45rem 0 0;font-family:var(--sans);font-size:.72rem;line-height:1.5;
                 color:var(--ink3)}
.ptitle{margin:0 0 .5rem;font-family:var(--sans);font-size:.66rem;letter-spacing:.09em;
        text-transform:uppercase;color:var(--ink3);font-weight:600}


/* =============================================================================
   PATTERN 1 — .duo : figure beside the paragraph that explains it.
   Use for: the workhorse. One idea, one visual, read together. Text column is
   pinned at the measure; the figure absorbs ALL remaining shell width.
   ============================================================================= */
.duo{display:grid;align-items:start;gap:var(--gap-y) var(--gap);margin:0 0 1.5rem;
     grid-template-columns:minmax(0,var(--measure)) minmax(0,1fr)}
.duo--flip{grid-template-columns:minmax(0,1fr) minmax(0,var(--measure))} /* figure first in source */
.duo--even{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}            /* two figures, no prose */
.duo > *{min-width:0}
.duo > :last-child > p:last-child{margin-bottom:0}

/* PATTERN 2 — .aside : prose scrolls, the visual stays put beside it.
   Use for: one diagram that 3–6 paragraphs all refer back to. */
.aside{display:grid;align-items:start;gap:var(--gap-y) var(--gap);margin:0 0 1.5rem;
       grid-template-columns:minmax(0,var(--measure)) minmax(0,1fr)}
.aside--flip{grid-template-columns:minmax(0,1fr) minmax(0,var(--measure))}
.aside > *{min-width:0}
.stick{position:sticky;top:var(--stop)}
/* align-items:start above is load-bearing: it leaves .stick content-sized inside a
   full-height grid area, which is the only way sticky can travel in a grid.
   Sticky also needs no overflow-clipping ancestor — .wrap and .sect have none. */

/* PATTERN 3 — .wide : a table, timeline or diagram that needs the whole shell.
   .wide--bleed additionally eats the section's own side padding. */
.wide{margin:0 0 1.5rem;max-width:none;min-width:0}
.wide--bleed{margin-inline:calc(var(--gut) * -1)}
.wide.scrollx{overflow-x:auto;overscroll-behavior-x:contain}
.wide table{font-size:.86rem}
.wide th,.wide td{text-align:left;padding:.42rem .7rem;border-bottom:1px solid var(--rule);
                  vertical-align:top}
.wide thead th{font-family:var(--sans);font-size:.66rem;letter-spacing:.06em;
               text-transform:uppercase;color:var(--ink3);border-bottom-color:var(--rule2)}
.wide tbody tr:nth-child(even){background:var(--card)}

/* PATTERN 4 — .facts : 3–6 short facts as tiles instead of 6 stacked paragraphs.
   Each tile is one value + one clause. Never a paragraph. */
.facts{display:grid;gap:var(--gap-y);margin:0 0 1.5rem;
       grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr))}
.facts--roomy{grid-template-columns:repeat(auto-fit,minmax(min(100%,19rem),1fr))}
.facts > *{min-width:0}
.tile{background:var(--card);border:1px solid var(--rule);border-radius:var(--r);
      padding:.6rem .75rem}
.tile b{display:block;font-family:var(--mono);font-size:.95rem;color:var(--acctxt);
        line-height:1.3;overflow-wrap:anywhere}
.tile span{display:block;font-family:var(--sans);font-size:.74rem;line-height:1.45;color:var(--ink2)}

/* PATTERN 5 — .versus : two things judged against each other, side by side.
   before/after, right/wrong, Python/USDA. Columns are equal by contract. */
.versus{display:grid;gap:var(--gap-y) var(--gap);margin:0 0 1.5rem;
        grid-template-columns:repeat(2,minmax(0,1fr))}
.versus--3{grid-template-columns:repeat(3,minmax(0,1fr))}
.versus > *{min-width:0}
.versus .pane{height:100%}
.versus .pane.good{border-left:3px solid var(--acc)}
.versus .pane.bad{border-left:3px solid var(--flagrule);background:var(--flagwash)}
.versus .pane.bad > h4{color:var(--flag)}

/* PATTERN 6 — .reel : an enumerable set (the 6 arcs, the 5 nouns) as one row.
   Cards GROW to fill the shell when they fit, and scroll-snap when they don't. */
.reel{display:flex;gap:var(--gap-y);margin:0 0 1.5rem;padding-bottom:.55rem;
      overflow-x:auto;overscroll-behavior-x:contain;
      scroll-snap-type:x proximity;scroll-padding-left:0}
.reel > *{flex:1 1 15rem;min-width:15rem;scroll-snap-align:start}
.card{background:var(--card);border:1px solid var(--rule);border-radius:var(--r);
      padding:.7rem .8rem}
.card b{display:block;font-family:var(--sans);font-size:.83rem;margin-bottom:.1rem}
.card s{text-decoration:none;display:block;font-family:var(--mono);font-size:.68rem;
        color:var(--acctxt);margin-bottom:.3rem;overflow-wrap:anywhere}
.card p{margin:0;font-size:.83rem;line-height:1.5;color:var(--ink2)}
.reelhint{font-family:var(--sans);font-size:.66rem;color:var(--ink3);margin:-.15rem 0 .5rem}

/* PATTERN 7 — .asks : the questions a reader actually has, two or three up.
   Answers are collapsed, so height stays flat no matter how many questions. */
.asks{display:grid;gap:var(--gap-y);margin:0 0 1.5rem;align-items:start;
      grid-template-columns:repeat(auto-fit,minmax(min(100%,26rem),1fr))}
.asks > *{min-width:0;margin:0;max-width:none}
.asks details{background:var(--card);border:1px solid var(--rule);border-radius:var(--r)}
.asks summary{cursor:pointer;padding:.55rem .8rem;font-family:var(--sans);font-size:.84rem;
              font-weight:600;color:var(--acctxt);list-style:none;display:flex;gap:.5rem;
              align-items:baseline}
.asks summary::-webkit-details-marker{display:none}
html:not(.motion-js) .asks summary::before{content:"+";font-family:var(--mono);font-weight:700;color:var(--acc)}
html:not(.motion-js) .asks details[open] summary::before{content:"\2013"}
.asks summary:focus-visible{outline:2px solid var(--acc);outline-offset:-3px;border-radius:var(--r)}
.asks .dbody{padding:0 .8rem .7rem;font-size:.92rem;color:var(--ink2);max-width:none}

/* PATTERN 8 — .ledger : term → definition rows, two pairs per row at width.
   My addition. Kills the most height of anything here: twelve "X is Y"
   paragraphs become six rows. Definitions must be one short clause. */
.ledger{display:grid;column-gap:calc(var(--gap) * 1.4);margin:0 0 1.5rem;
        grid-template-columns:repeat(auto-fit,minmax(min(100%,25rem),1fr))}
.lrow{display:grid;grid-template-columns:minmax(0,10rem) minmax(0,1fr);gap:.9rem;
      padding:.5rem 0;border-top:1px solid var(--rule);min-width:0}
.lrow > *{min-width:0}
.term{font-family:var(--mono);font-size:.83rem;color:var(--acctxt);overflow-wrap:anywhere}
.def{font-size:.9rem;color:var(--ink2);line-height:1.5;max-width:none}

/* PATTERN 9 — .plates : 2–4 screenshots or diagrams as one captioned row.
   Media only. Text belongs in .facts or .reel, not here. */
.plates{display:grid;gap:var(--gap-y) var(--gap);margin:0 0 1.5rem;align-items:start;
        grid-template-columns:repeat(auto-fit,minmax(min(100%,17rem),1fr))}
.plates > *{min-width:0}
.plates figure > .frame{background:var(--sunk);border:1px solid var(--rule);border-radius:var(--r);
                        aspect-ratio:4/3;display:flex;align-items:center;justify-content:center;
                        overflow:hidden}
.plates figure > .frame > img{width:100%;height:100%;object-fit:cover;display:block}


/* =============================================================================
   RESPONSIVE — four steps. Every pattern is single-column by 900px.
   ============================================================================= */

/* 1400px — the shell no longer has room for a full 66ch of prose AND a figure
   worth looking at. Narrow the text track (a shorter measure is always safe;
   only a longer one is not) and hand the difference to the figure. */
@media (max-width:1400px){
  .duo,.aside{grid-template-columns:minmax(0,52ch) minmax(0,1fr)}
  .duo--flip,.aside--flip{grid-template-columns:minmax(0,1fr) minmax(0,52ch)}
  .duo--even{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
}

/* 1240px — three-up sets drop to two; the widest cells stop competing. */
@media (max-width:1240px){
  .versus--3{grid-template-columns:repeat(2,minmax(0,1fr))}
  .plates{grid-template-columns:repeat(auto-fit,minmax(min(100%,15rem),1fr))}
}

/* 1100px — a figure column would now be under ~400px, which is worse than no
   column at all. Everything two-column collapses; the visual un-sticks and
   leads the prose. Below here the page is single-column all the way down. */
@media (max-width:1100px){
  .duo,.duo--flip,.duo--even,
  .aside,.aside--flip,
  .versus,.versus--3{grid-template-columns:minmax(0,1fr)}
  .duo--flip > :first-child,
  .aside--flip > :first-child{order:-1}
  .stick{position:static}
  .ledger{grid-template-columns:minmax(0,1fr)}
}

/* 700px — bleed off (the gutter is now doing real work), tiles get denser,
   ledger rows stack term over definition. */
@media (max-width:700px){
  .wide--bleed{margin-inline:0}
  .facts,.facts--roomy{grid-template-columns:repeat(auto-fit,minmax(min(100%,10.5rem),1fr))}
  .lrow{grid-template-columns:minmax(0,1fr);gap:.15rem}
  .term{font-size:.78rem}
}

/* 420px — one column everywhere, reel cards sized to the viewport, tighter gutter. */
@media (max-width:420px){
  :root{--gut:1rem}
  .sect{padding:1.7rem var(--gut) 1.1rem}
  .facts,.facts--roomy,.plates{grid-template-columns:minmax(0,1fr)}
  .reel > *{flex:0 0 78%;min-width:0}
  .wide table{font-size:.8rem}
  .wide th,.wide td{padding:.35rem .45rem}
}

/* Reduced motion — the reel must not smooth-scroll or snap-animate. */
@media (prefers-reduced-motion:reduce){
  .reel{scroll-behavior:auto;scroll-snap-type:none}
}

/* Print — trivial: one column, nothing sticky, nothing clipped. */
@media print{
  .wrap{margin-right:0}
  .duo,.duo--flip,.duo--even,.aside,.aside--flip,.versus,.versus--3,
  .facts,.asks,.plates,.ledger{display:block}
  .reel{display:block;overflow:visible}
  .reel > *{min-width:0;margin-bottom:.5rem}
  .stick{position:static}
  .asks details{break-inside:avoid}
}
