/* The coding cheat sheet, the side-by-side popup and the parts of a problem, shared by CODING.html and
   CHEATSHEET.html. Every size, colour and radius is a token from site/tokens.css, loaded first. Code sits on
   cream in light and dark alike. On a phone the sheet is one scrolling column and the popup is full screen
   with a Notes / Code switch. */

/* Code: Python colours on cream. The syntax colours are the one set of colours not in the tokens: they sit
   on --code-bg, which is cream in both schemes. */
pre { margin: var(--s3) 0; padding: var(--s3) var(--s4); background: var(--code-bg); color: var(--code-ink); border: var(--hair);
  border-radius: var(--radius); overflow-x: auto; font: var(--fs-code)/1.6 var(--mono); }
.tk { color: #A626A4; } .ts { color: #3F7A3E; } .tc { color: #7D7668; font-style: italic; } .tn { color: #A0580A; } .tf { color: #2F65D8; } .tb { color: #0E7486; }
code { font-family: var(--mono); font-size: var(--fs-code); background: var(--sunken); padding: 1px 4px; border-radius: var(--radius-sm); }
pre code { background: none; padding: 0; font-size: inherit; }
.cx { font-size: var(--fs-sm); color: var(--muted); margin: 0 0 var(--s3); }

/* A worked example on one line (the sheet's cards): input -> output */
.ex-in, .ex-out { font-family: var(--mono); }
.ex-out { font-weight: var(--w-strong); }
.ex-arrow { color: var(--muted); margin: 0 var(--s1); }

/* The parts of a problem on a label rail: a small label on the left, the part on the right, a hairline
   between parts. The examples sit on a sunken tint, their Input, Output and Why in aligned columns.
   Narrower than 480px the label goes above its part. --bleed lets the tint reach the card's edge. */
.st { container: st / inline-size; margin: 0 0 var(--s2); }
.r { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 0 var(--s4); align-items: baseline; padding: 10px 0; border-top: var(--hair); }
.r:first-child { border-top: 0; }
.rl { font-size: var(--fs-sm); font-weight: var(--w-strong); color: var(--soft); line-height: var(--lh-tight); }
.rv { min-width: 0; }
.rv p { margin: 0 0 var(--s2); max-width: var(--measure); }
.rv p:last-child { margin-bottom: 0; }
.rv ul { margin: 0; padding-left: 18px; font-size: var(--fs-sm); }
.rv li { margin: 0 0 2px; }
.r-ex { background: var(--sunken); margin: 0 calc(-1 * var(--bleed, var(--s3))); padding: 10px var(--bleed, var(--s3)); }
.r-ex + .r-ex { border-top-color: var(--rule); }
.io { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px var(--s4); align-items: baseline; font-size: var(--fs-sm); }
.io .k { color: var(--muted); }
.io code { background: none; padding: 0; color: var(--ink); overflow-wrap: anywhere; }
@container st (max-width: 480px) {
  .r { grid-template-columns: minmax(0, 1fr); gap: var(--s1); }
}

/* A shared figure, always on white */
.cfig { margin: var(--s3) 0 var(--s4); }
.cfig .fig-svg { background: #fff; border: var(--hair); border-radius: var(--radius-lg); padding: var(--s3); overflow-x: auto;
  --faint: #a2a09a; --dim: #6b6a65; --line: #c3c0b7; --ink: #1a1a19; --live: #fffdf5; }
.cfig svg { display: block; min-width: 520px; max-width: 100%; height: auto; margin: 0 auto; }
.cfig figcaption { color: var(--muted); font-size: var(--fs-sm); margin-top: var(--s2); max-width: var(--measure); }
.cfig figcaption b { color: var(--soft); }

/* The sheet: one screen of cards. fit() in sheet.js steps the card type down from 13px and picks six to eight columns. */
.cheat { position: fixed; inset: 0; z-index: 50; background: var(--bg); color: var(--ink); display: flex; flex-direction: column;
  font: var(--fs-sm)/1.3 var(--font); }
.cheat[hidden] { display: none; }
.cs-top { display: flex; gap: var(--s2) var(--s3); align-items: center; padding: 6px var(--s4); border-bottom: var(--hair); font-size: var(--fs-sm); line-height: var(--lh-tight); flex-wrap: wrap; }
.cs-top b { font-size: var(--fs-md); font-weight: var(--w-strong); }
.cs-top .hint { color: var(--muted); }
.cs-top .grow { flex: 1; }
.cs-top a { color: var(--accent); text-decoration: none; }
.cs-top button, .cs-tabs button { font: inherit; padding: 3px var(--s3); border: var(--hair); border-radius: var(--radius); background: var(--surface); color: var(--ink); cursor: pointer; }
.cs-tabs { display: flex; gap: var(--s1); }
.cs-tabs button { background: none; border-color: transparent; color: var(--muted); }
.cs-tabs button.on { background: var(--accent-soft); color: var(--ink); font-weight: var(--w-strong); }
.cs-grid { flex: 1; min-height: 0; padding: 10px var(--s4) var(--s3); column-count: 6; column-gap: 10px; column-fill: auto; overflow: auto; }
.cs-card { break-inside: avoid; border: var(--hair); border-radius: var(--radius); padding: 6px 9px 5px; margin: 0 0 var(--s2); background: var(--surface); }
.cs-card h3 { margin: 0 0 4px; font-size: 1.28em; line-height: 1.2; font-weight: 700; color: var(--ink); letter-spacing: -0.005em; }
.cs-card p { margin: 0 0 3px; }
.cs-card .cs-l { color: var(--muted); margin-right: .3em; }
.cs-card ul { margin: 3px 0 0; padding-left: 16px; color: var(--soft); }
.cs-card li { margin: 1px 0; }
.cs-card li.more { display: none; }
.cs-card code { font-size: .92em; padding: 0 3px; }
.cs-click { cursor: pointer; }
.cs-click:hover, .cs-click:focus-visible { border-color: var(--muted); outline: none; }
.cs-card .cs-ex { margin: 0 0 3px; }
.cs-card .cs-ex .ex-in, .cs-card .cs-ex .ex-out { font-size: .88em; }
.cs-card pre { margin: 3px 0; padding: 4px 7px; font-size: .9em; line-height: 1.3; border-radius: var(--radius-sm); white-space: pre-wrap; overflow: visible; }

/* Side by side: notes and the list on the left, the chosen item on the right. A floating layer: the one shadow. */
.pop { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .4); display: flex; align-items: center; justify-content: center; padding: 3vh 2vw; }
.pop[hidden] { display: none; }
.pop-in { position: relative; width: min(1480px, 96vw); height: min(900px, 92vh); background: var(--bg); color: var(--ink); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float); display: grid; grid-template-columns: minmax(320px, .8fr) minmax(0, 1.3fr); overflow: hidden; font: var(--fs-md)/var(--lh-body) var(--font); }
.pop-bar { display: none; }
.pop-l { overflow: auto; padding: var(--s5) var(--s5) var(--s5); background: var(--sunken); border-right: var(--hair); --bleed: var(--s3); }
.pop-l .r-ex { background: var(--surface); }
.pop-r { overflow: auto; padding: var(--s5) var(--s6) var(--s5); }
.pop-x { position: absolute; top: var(--s3); right: var(--s4); font: inherit; font-size: var(--fs-sm); padding: 3px var(--s3); border: var(--hair); border-radius: var(--radius); background: var(--surface); color: var(--ink); cursor: pointer; z-index: 2; }
.pop h2 { margin: 0 0 var(--s2); font-size: var(--fs-xl); line-height: var(--lh-tight); font-weight: var(--w-strong); padding-right: 70px; }
.pop .spot { color: var(--soft); margin: 0 0 var(--s3); }
.pop .spot b { color: var(--ink); }
.pop h4 { margin: var(--s5) 0 var(--s1); font-size: var(--fs-sm); font-weight: var(--w-strong); color: var(--muted); }
.pop ul.nu, .pop ol.nu { margin: 0; padding-left: 18px; }
.pop .nu li { margin: 0 0 var(--s1); }
.pop a { color: var(--accent); }
.pop details.ask { margin: var(--s1) 0; }
.pop details.ask summary { cursor: pointer; }
.pop details.ask p { margin: var(--s1) 0 var(--s2) var(--s4); color: var(--soft); }
.pi { display: block; width: 100%; text-align: left; font: inherit; background: none; border: 0; border-radius: var(--radius); padding: 5px 10px; margin: 1px 0; cursor: pointer; color: inherit; }
.pi:hover { background: var(--bg); }
.pi.on { background: var(--accent-soft); }
.pi b { display: block; font-size: var(--fs-sm); font-weight: var(--w-strong); }
.pi span { display: block; font-size: var(--fs-xs); color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-foot { margin: var(--s5) 0 0; font-size: var(--fs-sm); color: var(--muted); }
.pop-r h3 { margin: 0 90px var(--s3) 0; font-size: var(--fs-lg); line-height: var(--lh-tight); font-weight: var(--w-strong); }
.pr-kind { font-size: var(--fs-sm); font-weight: var(--w-regular); color: var(--muted); margin-left: var(--s2); }
.pop-r .pr-t { margin: 0 0 var(--s3); max-width: var(--measure); }
.pop-r .cx { margin-top: calc(-1 * var(--s1)); }

@media print { body > :not(.cheat) { display: none; } .cheat { position: static; } }

/* Scroll mode (sheet.js sets .scroll on a phone upright): readable cards in a grid of 300px columns, read row
   by row, every note shown, the whole sheet scrolls */
.cheat.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.cheat.scroll .cs-top { position: sticky; top: 0; z-index: 2; background: var(--bg); }
.cheat.scroll .cs-top .hint, .cheat.scroll .cs-top .wide { display: none; }
.cheat.scroll .cs-grid { flex: none; overflow: visible; columns: auto !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 var(--s3); align-items: start; padding: 10px var(--s3) var(--s7); }
.cheat.scroll .cs-card { padding: 10px var(--s3) var(--s2); margin-bottom: 10px; }
.cheat.scroll .cs-card li.more { display: list-item; }
.cheat.scroll .cs-card pre { font-size: var(--fs-xs); line-height: 1.45; }

/* Compact mode (sheet.js sets .compact on a phone on its side): every card a tile, all on one screen, no scrolling */
.cheat.compact .cs-top { padding: 3px 10px; gap: var(--s1) 10px; font-size: var(--fs-xs); }
.cheat.compact .cs-top b { font-size: var(--fs-sm); }
.cheat.compact .cs-top .hint, .cheat.compact .cs-top .wide { display: none; }
.cheat.compact .cs-tabs button { padding: 2px 10px; }
.cheat.compact .cs-grid { columns: auto !important; display: grid; grid-auto-rows: minmax(0, 1fr); gap: 6px; padding: 6px var(--s2) var(--s2); overflow: hidden; }
.cheat.compact .cs-card { margin: 0; padding: var(--s1) var(--s2); min-height: 0; overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
.cheat.compact .cs-card h3 { font-size: var(--fs-sm); line-height: 1.2; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cheat.compact .cs-card > :not(h3):not(.cs-ex) { display: none; }
.cheat.compact .cs-card .cs-ex { margin: 0; font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cheat.compact .cs-card .cs-ex .ex-in, .cheat.compact .cs-card .cs-ex .ex-out { font-size: inherit; }

/* A phone on its side: the popup fills the screen, notes left and code right, small type, code first */
@media (max-height: 560px) and (orientation: landscape) {
  .pop { padding: 0; }
  .pop-in { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; font-size: var(--fs-sm); line-height: 1.4; grid-template-columns: minmax(200px, .75fr) minmax(0, 1.5fr); }
  .pop-l, .pop-r { padding: var(--s2) var(--s3) 20px; }
  .pop h2 { font-size: var(--fs-md); padding-right: 0; }
  .pop h4 { margin: 10px 0 3px; font-size: var(--fs-xs); }
  .pop .spot { margin: 2px 0 6px; }
  .r { padding: 6px 0; }
  .r-ex { padding: 6px var(--bleed, var(--s3)); }
  .io, .rv ul { font-size: var(--fs-xs); }
  .pi { padding: 3px 7px; margin: 1px 0; }
  .pi b { font-size: var(--fs-xs); }
  .pl-foot { font-size: var(--fs-xs); margin-top: 10px; }
  .pop-r { display: flex; flex-direction: column; }
  .pop-r > * { order: 3; flex: none; }
  .pop-r > h3 { order: 1; }
  .pop-r > pre { order: 2; }
  .pop-r h3 { font-size: var(--fs-sm); margin: 0 70px var(--s1) 0; }
  .pop-r pre { font-size: var(--fs-xs); line-height: 1.4; padding: 6px var(--s2); margin: var(--s1) 0 var(--s2); white-space: pre-wrap; }
  .pop-r .cfig svg { min-width: 0; }
  .pop-x { top: 5px; right: var(--s2); font-size: var(--fs-xs); padding: 2px 10px; }
}

/* Phone upright: the sheet scrolls as one column with every note; the popup fills the screen with a Notes / Code switch */
@media (max-width: 760px) and (orientation: portrait) {
  .cs-top { padding: var(--s2) var(--s3); }
  .cs-top .hint, .cs-top .wide { display: none; }
  .cs-tabs { order: 5; width: 100%; }
  .cs-tabs button { flex: 1; padding: 6px var(--s2); }
  .pop { padding: 0; }
  .pop-in { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .pop-bar { display: flex; gap: 6px; padding: 10px 92px 10px var(--s3); border-bottom: var(--hair); background: var(--sunken); }
  .pop-bar button { flex: 1; font: inherit; font-size: var(--fs-sm); padding: 6px 10px; border: var(--hair); border-radius: var(--radius); background: none; color: var(--muted); }
  .pop-bar button.on { background: var(--surface); color: var(--ink); font-weight: var(--w-strong); }
  .pop-l, .pop-r { padding: var(--s4) var(--s4) var(--s6); border-right: 0; }
  .pop-in .pop-r { display: none; }
  .pop-in.show-r .pop-r { display: block; }
  .pop-in.show-r .pop-l { display: none; }
  .pop-x { top: 10px; right: var(--s3); padding: 6px var(--s3); }
  .pop h2 { padding-right: 0; }
  .pop-r h3 { margin-right: 0; }
  .pop-r pre { font-size: var(--fs-xs); white-space: pre-wrap; }
}
