/*
 * The page's layout over tokens.css. Every colour, radius and size is a token variable
 * (INV-205); the few numbers here that are not are the renderer's own constants, each named
 * after its home in shared's Compose code (MathMetrics.kt, DockStrip.kt).
 */

/* D-FONT-2: Inter for the math, the system's face for the words. The page's copy is cut to its
   glyphs and weights (tools/web/font-subset.py); `swap` draws the text at once in the system face
   and turns it into Inter when the file lands, never a blank page while it loads. The cut is four
   files by script (DEF-WEB-11): a piece is fetched only when the page holds a character of its
   unicode-range, so a Latin page never downloads the Cyrillic or the Greek glyphs, nor the letters
   of Latin Extended-A it does not write. */
@font-face {
  font-family: "Inter";
  src: url("inter.woff2?v=7d78a608") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0180-036F, U+0530-FFFF;
}

@font-face {
  font-family: "Inter";
  src: url("inter-latin-ext.woff2?v=27a57d6d") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0100-017F;
}

@font-face {
  font-family: "Inter";
  src: url("inter-cyrillic.woff2?v=b0ec58a7") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0400-052F;
}

@font-face {
  font-family: "Inter";
  src: url("inter-greek.woff2?v=17e884c8") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0370-03FF;
}

:root {
  --mathFace: "Inter", system-ui, sans-serif;
  --wordFace: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* MathMetrics.kt: CHIP_FONT_RATIO, CHIP_AIR_H / CHIP_AIR_V, CHIP_OUTER_AIR. */
  --chipFontRatio: 0.82;
  --chipAirH: 8px;
  --chipAirV: 2px;
  --chipOuterAir: 2px;
  --canvasMin: 120px;
  /* ResultLine.kt: RESULT_AIR 4 above/below, RESULT_BREATH 3 round the value; the room is the value's
     line plus the rung's, each at `LINE` x its font (the JVM dump's text metrics, tools/web/parity.py) */
  --resultAir: 4px;
  --resultBreath: 3px;
  --resultLine: 1.4545;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--wordFace);
  font-size: var(--type-bodyMd-size);
  line-height: var(--type-bodyMd-line);
}

/* ---- the header: the landing's own (site/web/site/src/styles/landing.css), the same class names — one site */
.wrap { max-width: calc(1100px + 2 * var(--screenMargin)); margin: 0 auto; padding-inline: var(--screenMargin); }
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; column-gap: var(--space24); padding-block: var(--space12); }
.brand { display: inline-flex; align-items: center; gap: var(--space10); min-height: 44px; font-weight: var(--weight-emphasis); font-size: 19px; letter-spacing: -0.01em; text-decoration: none; }
.brand img { border-radius: var(--chipRadius); }
.langs { display: flex; flex-wrap: wrap; margin-inline-end: calc(-1 * var(--space10)); }
.langs a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: var(--space10); font-size: 15px; text-decoration: none; border-radius: var(--pillRadius); }
.langs a:hover { text-decoration: underline; text-underline-offset: 4px; }
a { color: inherit; }
a:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: var(--chipRadius); }
@media (max-width: 639px) {
  .langs { width: 100%; margin-inline: calc(-1 * var(--space8)); }
  .langs a { padding-inline: var(--space8); font-size: 14px; }
}

/* ---- the page: two columns, the calculator right (SITE2-2) */
.nn-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  grid-template-rows: auto auto auto 1fr;
  column-gap: var(--sectionGap);
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--sectionGap) var(--screenMargin);
}
.nn-page > .nn-calc { grid-column: 2; grid-row: 1 / span 4; }
.nn-page > :not(.nn-calc) { grid-column: 1; }

.nn-title {
  margin: 0 0 var(--space16);
  font-size: var(--type-headLg-size);
  line-height: var(--type-headLg-line);
  font-weight: var(--type-headLg-weight);
  letter-spacing: var(--type-headLg-tracking);
}

/* ---- the fields: a parameter's name, its number, its unit as a chip */
.nn-fields { max-width: 340px; }
.nn-field { display: flex; flex-direction: column; gap: var(--space4); margin-bottom: var(--space14); }
.nn-label {
  color: var(--paramChipContent);
  font-size: var(--type-labelSm-size);
  font-weight: var(--weight-title);
}
.nn-field-box {
  display: flex;
  align-items: center;
  height: var(--minTouchTarget);
  padding: 0 var(--space6) 0 var(--space14);
  border: var(--border-card) solid var(--outline);
  border-radius: var(--pillRadius);
  background: var(--surfaceHigh);
}
.nn-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0; /* ring: .nn-field-box:focus-within - the pill draws the focus, not the bare text (G-10) */
  background: transparent;
  color: var(--ink);
  font-family: var(--mathFace);
  font-size: var(--editorMathFont);
}
/* G-10: a visible focus on the field (the pill that holds it) and on the unit picker; the ink is the page's own */
.nn-field-box:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.nn-pick:focus-visible, .nn-unit-item:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.nn-unit-item:focus-visible { outline-offset: -2px; }
.nn-field-unit {
  display: inline-flex;
  align-items: center;
  gap: var(--space4);
  cursor: default;
  padding: var(--space2) var(--space10);
  border: var(--chipBorderWidth) solid var(--unitOutline);
  border-radius: var(--chipRadius);
  background: var(--unitContainer);
  color: var(--unitContent);
  font-family: var(--mathFace);
  font-size: var(--type-bodyMd-size);
}

.nn-pick { position: relative; justify-content: center; min-width: var(--minTouchTarget); cursor: pointer; font: inherit; font-family: var(--mathFace); font-size: var(--type-bodyMd-size); }
/* G-10: the chip keeps its look; the tap target around it is the 44 px the pill is tall (the hit area, not the paint) */
.nn-pick::after { content: ""; position: absolute; inset-inline: 0; top: 50%; height: var(--minTouchTarget); transform: translateY(-50%); }
.nn-pick .nn-icon { width: var(--inlineIcon); height: var(--inlineIcon); }
.nn-field-box { position: relative; }
/* SITE3-7: the units of the field's category, under its chip */
.nn-unit-list {
  position: absolute;
  top: calc(100% + var(--space4));
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  padding: var(--space4);
  border: var(--border-card) solid var(--outline);
  border-radius: var(--chipRadius);
  background: var(--surfaceHigh);
}
.nn-unit-list[hidden] { display: none; }
.nn-unit-item {
  padding: var(--space6) var(--space12);
  border: 0;
  border-radius: var(--chipRadius);
  background: transparent;
  color: var(--ink);
  font-family: var(--mathFace);
  font-size: var(--type-bodyMd-size);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  min-height: var(--minTouchTarget);
}
.nn-unit-item:hover, .nn-unit-item.nn-on { background: var(--unitContainer); color: var(--unitContent); }

/* ---- the result line (formatResult + withUnit, INV-197) */
.nn-result {
  font-family: var(--mathFace);
  white-space: nowrap;
}
.nn-result > span + span { margin-left: 0.25em; }
.nn-rel { color: var(--ghostContent); }
.nn-error { color: var(--error); white-space: normal; font-family: var(--wordFace); font-size: var(--type-bodyMd-size); }
.nn-figure { color: var(--ink); font-weight: var(--weight-emphasis); }
.nn-result-unit { color: var(--unitContent); }
.nn-result-fields { font-size: var(--resultFont); min-height: var(--resultLineMinHeight); margin: var(--space4) 0 var(--space16); }
.nn-result-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: calc(2 * var(--resultAir) + 2 * var(--resultBreath) + (var(--resultFont) + var(--resultNextFont)) * var(--resultLine));
  padding: 0 var(--space16);
  font-size: var(--resultFont);
}

/* ---- the answer's step (D-SITE-18 SITE18-3/4): the next rung small under the answer, a tap rolls it in.
   The duration and the easing are tokens (motion.tokens.json: --resultMove, --resultMoveEase); one line of
   travel is the line factor x 1em (the app's pitch), the next line's ink is the app's alpha. */
/* scoped to the result: unscoped, the column reached the canvas and stacked its top row atom under atom */
.nn-result .nn-lines { display: flex; flex-direction: column; }
.nn-result-line .nn-lines { align-items: flex-end; }
.nn-answer > span + span, .nn-next > span + span { margin-left: 0.25em; }
/* DEF-SITE-17: a region that writes its signs before - «$60», «25%» - keeps the gap after «=» only */
.nn-answer.nn-tight > span + span + span { margin-left: 0; }
.nn-next {
  display: block;
  font-size: var(--resultNextFont);
  color: color-mix(in srgb, var(--ink) calc(var(--alpha-resultNext) * 100%), transparent);
}
.nn-walkable { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.nn-walkable:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@keyframes nnRollIn { from { transform: translateY(calc(var(--resultLine) * 1em)); opacity: 0; } }
@keyframes nnRollOut { to { transform: translateY(calc(var(--resultLine) * -1em)); opacity: 0; } }
.nn-walking .nn-enter { display: inline-block; animation: nnRollIn var(--resultMove) var(--resultMoveEase) both; }
.nn-walking .nn-next.nn-enter { display: block; }
/* The leaving copy is the line's own box laid over it, border and fill dropped, the `=` hidden (it stays). */
.nn-walkable.nn-walking > .nn-leave {
  position: absolute; inset: 0; margin: 0; min-height: 0; border: 0; background: none; box-shadow: none;
  pointer-events: none; cursor: default;
}
.nn-leave .nn-rel { visibility: hidden; }
.nn-leave .nn-figure, .nn-leave .nn-result-unit { display: inline-block; animation: nnRollOut var(--resultMove) var(--resultMoveEase) both; }
.nn-leave .nn-next { animation: nnRollOut var(--resultMove) var(--resultMoveEase) both; }
html[data-still] .nn-walking *, html[data-still] .nn-leave * { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  /* the step is the new answer at once; the leaving copy is not drawn at all */
  .nn-walking .nn-enter { animation: none; }
  .nn-walkable.nn-walking > .nn-leave { display: none; }
}

/* SITE21-5 (variant В): a visitor typed before the calculator came - the answer's figure is «…» and breathes until
   web.js draws their own answer; the example's figure never stands for a number it was not computed from. */
@keyframes nnPending { 50% { opacity: 0.35; } }
html.nn-pending .nn-result .nn-figure { animation: nnPending 1s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  html.nn-pending .nn-result .nn-figure { animation: none; }
}

/* ---- the words line: «площа = довжина × ширина → м²» */
.nn-words { font-family: var(--mathFace); font-size: var(--rowMathFont); color: var(--ink); margin: 0 0 var(--space16); }
.nn-words > span + span { margin-left: 0.3em; }
.nn-w-name { color: var(--paramChipContent); }
.nn-w-unit { color: var(--unitContent); }
.nn-w-op { color: var(--ghostContent); }

/* ---- the calculator card */
.nn-calc {
  background: var(--ground);
  border: var(--border-card) solid var(--ghostOutline);
  border-radius: var(--panelRadius);
  overflow: hidden;
}

/* a desktop card hugs its content (layout A) instead of stretching to the column's height */
@media (min-width: 900px) { .nn-calc { align-self: start; } }

/* ---- the canvas (D-SITE-3 SITE3-2, layout A): static, read-only, anchored top-left (D-CANVAS-2);
   the top row flows and wraps (INV-45: only the top-level row wraps), the card grows with it. */
.nn-canvas {
  padding: var(--space16);
  min-height: var(--canvasMin);
  font-family: var(--mathFace);
  font-size: var(--canvasFontMedium);
  --mathSize: var(--canvasFontMedium);
  overflow-x: auto;   /* a fraction wider than the card (a 320 px phone, the 440 px desktop card) scrolls inside it, never cut, never sliding the page */
}
.nn-lines { display: flex; flex-wrap: wrap; align-items: center; row-gap: var(--space8); }

/* the atoms */
.nn-digit, .nn-op, .nn-op-paren { color: var(--ink); }
.nn-op { padding: 0 0.12em; }
.nn-row, .nn-group, .nn-fn { display: inline-flex; align-items: center; }
.nn-lines > * { white-space: nowrap; }
.nn-chip {
  display: inline-flex;
  align-items: center;
  margin: 0 var(--chipOuterAir);
  padding: var(--chipAirV) var(--chipAirH);
  border: var(--chipBorderWidth) solid transparent;
  border-radius: var(--chipRadius);
  font-size: calc(var(--mathSize) * var(--chipFontRatio));
  line-height: 1.2;
}
/* D-SITE-17: a parameter's unit («%» for a percent one) stands AFTER its chip, as the app's canvas keeps it
   (PUNIT-4, D-PUNIT-2), in the unit ink at the chip's own size; the run never breaks between the two. */
.nn-param { background: var(--paramChipContainer); border-color: var(--paramChipOutline); color: var(--paramChipContent); }
.nn-param-run { display: inline-flex; align-items: center; }
.nn-param-run > .nn-unit-tag { color: var(--unitContent); font-size: calc(var(--mathSize) * var(--chipFontRatio)); margin-left: var(--space2); }
.nn-number { background: var(--numberContainer); color: var(--numberContent); }
.nn-formula { background: var(--formulaContainer); color: var(--formulaContent); }
.nn-calculation { background: var(--calculationContainer); color: var(--calculationContent); }
.nn-unit-tag { color: var(--unitContent); margin-left: 0.15em; }
.nn-slot { display: inline-flex; margin-left: var(--space4); }
.nn-empty {
  display: inline-block;
  width: 0.6em; height: 0.8em;
  border: 1px dashed var(--slotBorder);
  border-radius: 2px;
}
/* both rows stretch so the bar spans the WIDER one; it keeps air from each row and overhangs them
   by MathMetrics: FRACTION_GAP_EM 0.12 above and below, FRACTION_PADDING_EM 0.12 less its 0.25 inset aside;
   each row a flex row of its own, so a power inside it rises as on the top row */
.nn-frac { display: inline-flex; flex-direction: column; align-items: stretch; text-align: center; font-size: 0.8em; }
.nn-num, .nn-den { display: flex; justify-content: center; align-items: center; }
.nn-num { border-bottom: 1px solid var(--ink); padding: 0 0.09em 0.12em; }
.nn-sup { font-size: 0.66em; align-self: flex-start; }
.nn-sub { font-size: 0.66em; align-self: flex-end; }
.nn-den { padding: 0.12em 0.09em 0; }
.nn-name { white-space: nowrap; }
.nn-root { display: inline-flex; align-items: flex-end; }
.nn-root-degree { font-size: 0.5em; align-self: flex-start; }
.nn-radicand { display: inline-flex; align-items: center; border-top: 1px solid var(--ink); }   /* a flex row, so a power under the root rises */
.nn-fn { gap: 0.1em; }
.nn-fn-name { color: var(--ink); }
.nn-ceil { display: inline-flex; align-items: center; }
.nn-ceil > .nn-br { font-size: 1.6em; font-weight: 300; color: var(--ink); line-height: 1; }
.nn-pct { color: var(--unitContent); margin-left: 0.1em; }

/* ---- under 900 px: one column, fields → result → card → the words (D-SITE-3 SITE3-3, DEF-WEB-03:
   the 440 px card column needs ~900 px); the calculator is the window's width (W is cut from it) */
@media (max-width: 899px) {
  .nn-page > :not(.nn-calc) { margin-left: var(--screenMargin); margin-right: var(--screenMargin); }
  .nn-title { font-size: var(--type-headMd-size); line-height: var(--type-headMd-line); }
  .nn-fields { max-width: none; }
  .nn-calc { border: 0; border-radius: 0; border-top: var(--border-card) solid var(--ghostOutline); }
  .nn-page { display: flex; flex-direction: column; padding: var(--space16) 0 0; }
  .nn-page > .nn-words { order: 2; margin-top: var(--space16); }
  .nn-page > .nn-calc { order: 1; }
  :root { --canvasMin: 96px; }
  .nn-canvas { font-size: 24px; --mathSize: 24px; }
}

/* a wide window that still stacks (600-899 px): the card keeps the desktop's 440 px, centred, with its frame */
@media (min-width: 600px) and (max-width: 899px) {
  .nn-page > .nn-calc { width: 100%; max-width: 440px; margin: 0 auto var(--space16); border: var(--border-card) solid var(--ghostOutline); border-radius: var(--panelRadius); }
}
