/*
 * The six sections' replicas (D-SITE-5 SITE5-1): each section's own rules under its `.s<n>` prefix,
 * folded from the B2 mockup's sections/s<n>.css; the kit is ui.css. No hex: the looks s6 shows come
 * from tokens.css (--look-*, tools/dtcg/css_gen.py).
 */

/* s1 — Вирази з одиницями (brief-b2-sections s1): the units keyboard in step with the hero's five measures.
   Composes the kit (ui.css § 3–8); only the keyboard's own arrangement lives here. */

/* the top row is a key row like the four under it (09_units_keyboard: five rows of one height, so the
   keyboard takes exactly the «123» grid's place) */
.nn-demo.s1 .nn-unitkb { grid-template-rows: none; }

/* the categories column: five rows on the 4th column, the first one in the top row */
.nn-demo.s1 .nn-cat { grid-column: 4; }
.nn-demo.s1 .nn-cat[data-on="0"] { grid-row: 1; }
.nn-demo.s1 .nn-cat[data-on="1"] { grid-row: 2; }
.nn-demo.s1 .nn-cat[data-on="2"] { grid-row: 3; }
.nn-demo.s1 .nn-cat[data-on="3"] { grid-row: 4; }
.nn-demo.s1 .nn-cat[data-on="4"] { grid-row: 5; }

/* the lit category = the kit's .nn-cat.is-on, walking with the phase */
.nn-demo.s1[data-phase="0"] .nn-cat[data-on="0"],
.nn-demo.s1[data-phase="1"] .nn-cat[data-on="1"],
.nn-demo.s1[data-phase="2"] .nn-cat[data-on="2"],
.nn-demo.s1[data-phase="3"] .nn-cat[data-on="3"],
.nn-demo.s1[data-phase="4"] .nn-cat[data-on="4"] {
  background: var(--unitContainer);
  color: var(--unitContent);
}

/* the lit category's units: three columns × four rows under the top row, one page per phase,
   cross-faded by the kit's .nn-stack */
.nn-demo.s1 .s1-tiles { grid-column: 1 / 4; grid-row: 2 / 6; min-width: 0; }
.nn-demo.s1 .s1-tiles > [data-k] {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: var(--keyFace);
  gap: var(--keyGap);
  align-content: start;
}

/* s2 — «Свої числа»: the x= panel list under a canvas that uses one of its variables (frames/numbers.png). The header is the kit's — menu · «Обчислення» · the green «+» — the same
   bar the app draws on every calculator (the owner, 11.10: «хідер Свої числа не такий як решта»). Only
   what the kit lacks: the row whose value was edited (lit while it differs from the bundled 52,00). */
.nn-demo.s2 { display: flex; justify-content: center; min-width: 0; width: 100%; }
.s2 .nn-prow { transition: background-color var(--roll) var(--rollEase), border-color var(--roll) var(--rollEase); }
.s2[data-phase="1"] .s2-edit { background: var(--numberContainer); border-color: var(--numberContent); }

/* s3 — Свої формули: the f panel -> «площа» inserted with dashed places -> filled -> one place changed.
   Composes the kit (nn-panel.is-f, nn-chip.nn-formula / nn-param, nn-result-line, nn-keys); adds only the
   rules below. */
.s3 .nn-canvas { position: relative; }
.s3 .nn-lines .nn-stack { max-width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr); }
.s3 .nn-lines .nn-stack > [data-k] { min-width: 0; display: flex; }
.s3[data-phase="2"] .nn-lines .nn-stack > [data-k], .s3[data-phase="3"] .nn-lines .nn-stack > [data-k] { justify-content: flex-end; }
.s3 .nn-lines .nn-chip.nn-formula { max-width: 100%; overflow: hidden; padding-inline: var(--space6); }
.s3 .nn-formula .nn-name { color: var(--formulaContent); }
/* the slot bubble (the editor's pointer to the place being filled, frames/formulas.png «ширина м»): under the
   ACTIVE place, on the ground face with the popup's shadow (D-ELEV-2: popups keep theirs), the name bold.
   Its x is the active place's start, MEASURED per language by the clock (index.astro place(), the tip's
   data-at = the place sitegen names): the first place in k1; k2/k3 the second, the line end-anchored at
   the caret, so the bubble may hang off the right edge by the closing bracket as in the app frames. */
.s3 .bubble { align-self: flex-start; margin-top: var(--space4); }
.s3 .bubble .nn-tip { justify-self: start; }
.s3 .nn-tip {
  justify-self: start;
  padding: var(--space4) var(--space10);
  background: var(--ground);
  border-radius: calc(var(--chipRadius) * 0.75);
  box-shadow: 0 calc(var(--elevation-popup) / 2) var(--elevation-popup) color-mix(in srgb, var(--ink) 22%, transparent);
  font-family: var(--wordFace);
  font-size: var(--captionFont);
  color: var(--ink);
  white-space: nowrap;
}
.s3 .nn-tip b { font-weight: var(--weight-emphasis); }
/* the f panel's rows: all on one face, nothing lit (the app marks no row) */
.s3 .nn-prow { transition: background-color var(--roll) var(--rollEase); }
/* the result block of two lines keeps the line's own height in every phase */
.s3 .nn-result-line { padding: 0; }
/* k1: the app's ask while a place is empty (PreviewLine.Ask, pixel.md item 10) - right-aligned, muted, body size */
.s3 .s3-ask {
  display: flex; align-items: center; justify-content: flex-end; text-align: end;
  padding: var(--resultAir) var(--space16);
  font-family: var(--wordFace); font-size: var(--bodyFont); color: var(--onSurfaceLow);
}
.s3 .s3-res { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; padding: var(--resultAir) var(--space16); }
/* a chip longer than the line is end-anchored at the caret, its start cut off under the ink-mask fade (D-CANVAS-5);
   the fade only where the start IS cut (is-cut-start, measured by the clock) - a chip that fits keeps its first letter */
.s3[data-phase="2"] .nn-lines .nn-chip.nn-formula, .s3[data-phase="3"] .nn-lines .nn-chip.nn-formula { justify-content: flex-end; }
.s3 .nn-lines .nn-chip.nn-formula.is-cut-start {
  -webkit-mask-image: linear-gradient(90deg, transparent, black 18px); mask-image: linear-gradient(90deg, transparent, black 18px);
}
/* «=» is off while a place is empty (k1): the neutral face, the glyph dimmed (DEF: the app's disabled key) */
.s3[data-phase="1"] .nn-key.is-eq {
  background: color-mix(in srgb, var(--surfaceLow) 50%, var(--ground));
  border-color: color-mix(in srgb, var(--surfaceLow) 50%, var(--ground));
  color: color-mix(in srgb, var(--ink) calc(var(--alpha-dimmed) * 100%), var(--ground));
}
/* the caret stands inside the first empty place (k1) */
.s3[data-phase="1"] .nn-op-paren + .nn-slot.is-empty { position: relative; margin-inline-start: 5px; }
.s3[data-phase="1"] .nn-op-paren + .nn-slot.is-empty::before {
  content: "";
  position: absolute;
  inset-inline-start: -5px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--ink);
}

/* s4 — Підрахунки: the calculations list, the record open as one-line rows, a new position typed on the
   calculator. Composes the kit (nn-wbar · nn-body · nn-split · nn-list · nn-shelf · nn-tag · nn-bar · nn-canvas ·
   nn-keys); the record screen's own rows are here, in tokens.css variables only. Three phases:
   k0 the list · k1 the record · k2 the calculator the record names, «3» typed. */
.s4 .nn-phone { --phoneH: 800px; }

/* the screens share one cell and cross-fade (kit FADE); the stack fills the phone under the frame */
.s4 .s4-screens { flex: 1 1 auto; min-height: 0; grid-template-rows: minmax(0, 1fr); }
.s4 .s4-screen { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.s4 .s4-screen > .nn-body { flex: 1 1 auto; }
.s4 .nn-row .nn-title { white-space: nowrap; }

/* k1: the record — the description, then a row = ⠿ · name · value (the app's one-line position) */
.s4 .s4-body { display: flex; flex-direction: column; }
.s4 .s4-desc { padding-block: var(--space4) var(--space12); font-size: var(--captionFont); color: var(--onSurfaceLow); }
.s4 .s4-pos {      /* a position row of record-open.png: 53.7 high, the hairline from x 8 to the frame's edge, the handle at x 21.7, the name at x 50 */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: 22.3px;
  align-items: center;
  min-height: 53.7px;
  margin-inline: calc(var(--space8) - var(--space16)) calc(-1 * var(--space16));
  padding-inline: calc(21.7px - var(--space8)) var(--space16);
  border-bottom: var(--border-row) solid color-mix(in srgb, var(--outline) calc(var(--border-rowAlpha) * 100%), transparent);
}
/* the frame's INK is 6 x 9.3, and grip.svg's ink fills 8.7 x 14.7 of its 24 box: the box is 16, the margins leave the row's column at the ink's 6 */
.s4 .s4-grip { width: 16px; height: 16px; margin-inline: -5px; color: var(--onSurfaceLow); }
.s4 .s4-name { font-size: var(--bodyFont); font-weight: var(--weight-emphasis); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* an aggregation row wears the app's Σ before its name (CalculationRows, AG2-12): the CALCULATION kind's ink, inlineIcon, space4 */
.s4 .s4-sum { width: var(--inlineIcon); height: var(--inlineIcon); vertical-align: -0.2em; margin-inline-end: var(--space4); color: var(--calculationContent); }
.s4 .s4-res { font-family: var(--mathFace); font-size: var(--rowMathFont); white-space: nowrap; }
/* the «Документ» deed at the bottom (calculation_preview): ink fill, ground label */
.s4 .s4-deed {
  display: grid;
  place-items: center;
  flex: none;
  min-height: 43.7px;
  margin: var(--space4) var(--space16) var(--space12);   /* + the foot = 33 above the frame bottom */
  background: var(--ink);
  color: var(--ground);
  border-radius: 10.8px;
  font-size: var(--rowTitleFont);
  font-weight: var(--weight-title);
}

/* k2: the calculator — the canvas keeps the room, the result line sits above the strip */
.s4 .s4-calc .nn-canvas { flex: 1 1 auto; }
.s4 .s4-calc .nn-result-line { flex: none; }

/* s5 — Поділитися: the share page of the app, its pill moving over Картка · PDF · Excel and the
   preview cross-fading (kit: nn-preview, nn-stack, nn-doc, nn-seg, nn-drawer, nn-deed). Tokens only. */

/* the pill: ONE selected segment that slides (the kit's seg swaps spans; here the thumb travels) */
.s5 .nn-seg { position: relative; }
.s5 .nn-seg > span { position: relative; z-index: 1; }
.s5 .s5-thumb {
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  inset-inline-start: 3px;
  width: calc((100% - 10px) / 3);
  background: var(--surfaceHigh);
  border: 1px solid var(--outline);
  border-radius: calc(var(--pillRadius) - 3px);
  transition: transform var(--roll) var(--rollEase);
}
.s5[data-phase="1"] .s5-thumb { transform: translateX(calc(100% + 2px)); }
.s5[data-phase="2"] .s5-thumb { transform: translateX(calc(200% + 4px)); }
.s5[data-phase="0"] .nn-seg > span:nth-of-type(1),
.s5[data-phase="1"] .nn-seg > span:nth-of-type(2),
.s5[data-phase="2"] .nn-seg > span:nth-of-type(3) { color: var(--ink); font-weight: var(--weight-title); }

/* the preview: one cell, three documents cross-fading, each pinned to the top */
.s5 .nn-stack > [data-k] { align-self: start; }

/* 0 — the card: the record as a picture */
.s5 .s5-card {
  padding: var(--space16);
  background: var(--surfaceHigh);
  border: var(--border-card) solid var(--outline);
  border-radius: var(--panelRadius);
}
.s5 .s5-card h4 { margin: 0; font-size: var(--headingFont); font-weight: var(--weight-emphasis); }
.s5 .s5-card p { margin: 2px 0 var(--space8); font-size: var(--captionFont); color: var(--onSurfaceLow); }
.s5 .s5-card dl { margin: 0; }
.s5 .s5-card dl > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space8);
  padding: var(--space8) 0;
  border-top: 1px solid var(--ghostOutline);
}
.s5 .s5-card dt, .s5 .s5-card dd { margin: 0; }
.s5 .s5-card dt { font-size: var(--rowTitleFont); font-weight: var(--weight-title); }
.s5 .s5-card dt small { display: block; font-family: var(--mathFace); font-size: var(--panelCaptionFont); font-weight: var(--weight-body); color: var(--onSurfaceLow); }
.s5 .s5-card dd { font-family: var(--mathFace); font-size: var(--rowTitleFont); font-weight: var(--weight-title); white-space: nowrap; }
.s5 .s5-card .nn-result-unit { color: var(--unitContent); margin-inline-start: 0.2em; }
.s5 .s5-sum {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: var(--space8);
  padding: var(--space8) var(--space12);
  background: var(--calculationContainer);
  color: var(--calculationContent);
  border-radius: var(--cardRadius);
  font-size: var(--rowTitleFont);
}
.s5 .s5-sum b { font-family: var(--mathFace); font-size: var(--headingFont); font-weight: var(--weight-emphasis); white-space: nowrap; }
.s5 .s5-sum .nn-result-unit { color: inherit; margin-inline-start: 0.2em; }

/* 1 — the PDF page: the kit's document, A4 proportions (the page runs past the preview's edge, as in the app) */
.s5 .s5-page { position: relative; min-height: 464px; }
.s5 .s5-pageno { position: absolute; inset-inline-end: var(--space16); bottom: var(--space8); font-size: 8px; color: var(--ghostContent); }

/* 2 — the Excel grid: row numbers, column letters, cells with hairlines */
.s5 .s5-grid {
  display: grid;
  grid-template-columns: 22px minmax(0, 1.2fr) minmax(0, 1.5fr) minmax(0, 1.3fr);
  counter-reset: s5row s5col;
  background: var(--surfaceHigh);
  border: 1px solid var(--ghostOutline);
  font-size: var(--panelCaptionFont);
}
.s5 .s5-grid > span {
  min-height: 28px;
  padding: 0 var(--space6);
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  border-inline-end: 1px solid var(--ghostOutline);
  border-bottom: 1px solid var(--ghostOutline);
}
.s5 .s5-grid > .s5-h { justify-content: center; padding: 0; background: var(--surfaceLow); color: var(--onSurfaceLow); }
/* the sheet's own heads are the sheet's counters, not typed (SITE5-5): letters on top, numbers down the side */
.s5 .s5-grid > .s5-col::before { counter-increment: s5col; content: counter(s5col, upper-alpha); }
.s5 .s5-grid > .s5-row::before { counter-increment: s5row; content: counter(s5row); }
.s5 .s5-grid > .is-num .nn-result-unit { color: var(--unitContent); margin-inline-start: 0.2em; }
.s5 .s5-page { counter-reset: s5page 1; }
.s5 .s5-pageno::before { content: counter(s5page); }
.s5 .s5-grid > .is-math { font-family: var(--mathFace); color: var(--onSurfaceLow); }
.s5 .s5-grid > .is-num { justify-content: flex-end; font-family: var(--mathFace); font-weight: var(--weight-title); }
.s5 .s5-grid > .is-unit { color: var(--unitContent); }
.s5 .s5-grid > .is-total { font-weight: var(--weight-emphasis); background: var(--calculationContainer); color: var(--calculationContent); }

/*
 * s6 «Свій вигляд» — a picker the visitor plays with (S6.astro): the settings card's
 * buttons (colour, accent, mode, anchor, the thousands' switch) and the phone that wears what they say.
 * The looks are tokens.css's `.nn-look` sets (css_gen.py picker_looks); the operator / «=» roles the kit
 * reads as accent* follow the accent's own fill and ink here, as the app's accent does.
 */
.s6 { display: flex; flex-direction: column; align-items: center; gap: var(--space16); width: 100%; max-width: 360px; }
.s6 > .s6-set { width: 100%; margin: 0; }
/* on a phone the phone comes first: its keys stand right above the buttons that repaint them */
@media (max-width: 899px) { .s6 > .nn-phone { order: -1; } }
@media (min-width: 900px) {
  .s6 { flex-direction: row; align-items: center; gap: var(--space24); max-width: none; width: auto; }
  .s6 > .s6-set { width: 272px; flex: none; }
}

.s6 .s6-row {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--space8);
  width: 100%; padding: var(--space10) var(--space12); margin: 0;
  font: inherit; color: inherit; text-align: start; background: none; border: 0;
}
.s6 .s6-row + .s6-row { border-top: var(--border-row) solid var(--ghostOutline); }
.s6 .s6-row .nn-title { font-size: var(--rowTitleFont); }
.s6 .s6-row .nn-sub { font-size: var(--captionFont); color: var(--onSurfaceLow); line-height: 1.35; }
.s6 .s6-static .nn-sub { margin-top: calc(-1 * var(--space4)); }

/* a segmented choice: the picked one is the app's lit chip */
.s6 .s6-seg { display: flex; flex-wrap: wrap; gap: var(--space4); }
.s6 .s6-seg button {
  display: inline-flex; align-items: center; gap: var(--space4); min-height: 36px; padding: var(--space4) var(--space12);
  font: inherit; font-size: var(--captionFont); color: var(--ink); cursor: pointer;
  background: var(--surfaceHigh); border: var(--border-pill) solid var(--outline); border-radius: var(--pillRadius);
  transition: background-color var(--roll) var(--rollEase), color var(--roll) var(--rollEase);
}
.s6 .s6-seg button:hover { background: var(--surfaceLow); }
.s6 .s6-seg button[aria-checked="true"] { background: var(--accentContainer); color: var(--onAccentContainer); border-color: transparent; font-weight: var(--weight-title); }
.s6 .s6-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--outline); flex: none; }
.s6 .s6-dot-white { background: var(--pick-white); }
.s6 .s6-dot-sand { background: var(--pick-sand); }

/* the accents: three round swatches, each its own «=» fill (light), the picked one ringed */
.s6 .s6-swatches { display: flex; gap: var(--space10); }
.s6 .s6-sw {
  width: 36px; height: 36px; padding: 0; cursor: pointer; border-radius: 50%;
  border: 2px solid var(--surfaceHigh); box-shadow: 0 0 0 1px var(--outline);
  transition: box-shadow var(--roll) var(--rollEase);
}
.s6 .s6-sw[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surfaceHigh), 0 0 0 4px var(--ink); }
.s6 .s6-sw-sage { background: var(--pick-sage); }
.s6 .s6-sw-cobalt { background: var(--pick-cobalt); }
.s6 .s6-sw-rose { background: var(--pick-rose); }

/* the thousands' switch: the whole row is the button */
.s6 .s6-toggle { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: var(--space12); row-gap: 0; cursor: pointer; }
.s6 .s6-toggle > .nn-title, .s6 .s6-toggle > .nn-sub { grid-column: 1; }
.s6 .s6-toggle > .nn-switch { grid-column: 2; grid-row: 1 / span 2; }
.s6 .s6-toggle .nn-sub { font-family: var(--mathFace); font-variant-numeric: tabular-nums; }
.s6 .s6-toggle:hover { background: var(--surfaceLow); }

.s6 button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* the phone: the accent's fill and ink also stand for the kit's accent roles, as in the app */
.s6 .nn-phone.nn-look[data-accent] {
  --accentContainer: var(--operatorFill);
  --onAccentContainer: var(--operatorInk);
  --accent2: var(--equalsFill);
  --onAccent2: var(--equalsInk);
  --accent2Container: var(--equalsFill);
  --onAccent2Container: var(--equalsInk);
  background: var(--ground);
  color: var(--ink);
}
.s6 .nn-phone.nn-look[data-mode="dark"] { color-scheme: dark; }
.s6 .s6-canvases { flex: 1 1 auto; min-height: 0; grid-template-rows: minmax(0, 1fr); }
.s6 .s6-canvases > .nn-canvas { min-height: 0; }
/* the theme sample's line is longer than the phone: its top row WRAPS between atoms as the app's does
   (INV-45, core/layout) - each phase of the rolling term is a wrapping row; a chip, a number with its unit stay whole */
.s6 .s6-canvases .nn-lines > .nn-term { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 100%; }
.s6 .s6-canvases .nn-term > [data-k] { display: flex; flex-wrap: wrap; align-items: center; row-gap: var(--space8); min-width: 0; white-space: normal; }
.s6 .s6-canvases .nn-term > [data-k] > * { white-space: nowrap; }
.s6 .s6-canvases .nn-canvas.is-end .nn-term > [data-k] { justify-content: flex-end; }

/* every face a look repaints glides with the keys (ui.css gives .nn-key its background transition) */
.s6 .nn-phone, .s6 .nn-round, .s6 .nn-pill, .s6 .nn-door, .s6 .nn-cell, .s6 .nn-key,
.s6 .nn-digit, .s6 .nn-op, .s6 .nn-unit-tag, .s6 .nn-result, .s6 .nn-result-unit, .s6 .nn-caret {
  transition: background-color var(--roll) var(--rollEase), color var(--roll) var(--rollEase), border-color var(--roll) var(--rollEase);
}
