/* Web build layout — hand-written, never overwritten by scripts/build-site.mjs.
   theme.css holds the tokens. sidepanel.css and preview.css are the extension's own
   stylesheets with their viewport-owning html/body rules stripped by the build; this file
   arranges those components on a page and holds the web-only decisions:
     - the whole page scrolls, including the settings column (no inner scroll containers)
     - the preview never takes the wheel
     - grid types run full width above everything; pages and the output buttons sit under
       the preview; zoom is a vertical control on the preview itself */

* { box-sizing: border-box; }
/* the header is sticky, so anchor targets must clear it or they land underneath */
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  font: 400 16px/1.55 var(--font);
  color: var(--text);
  background: var(--bg) radial-gradient(circle, var(--line) 1px, transparent 1.2px) 0 0 / 22px 22px;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---------- header ---------- */
.site-bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 10px clamp(14px, 3vw, 28px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-bar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; letter-spacing: -.02em;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.site-bar .brand img { border-radius: 7px; flex: none; }
/* preview.css hides .brand span below 1080px (and the whole brand below 560px) because in the
   extension's preview tab the toolbar needs the room. This is a site header with room to
   spare, and losing the site name on every screen under 1080px left a bare 28px icon. Keep
   the name; preview.css's own overflow/ellipsis on .brand span is the backstop. */
.site-bar .brand span { display: block; min-width: 0; }
.site-bar .brand em { font-style: normal; color: var(--highlight); }

.site-nav { display: flex; align-items: center; gap: clamp(10px, 2vw, 26px); }
.site-nav a {
  color: var(--muted); text-decoration: none; font-size: 14.5px; font-weight: 500;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text); }
/* Deliberately quiet: a pill in the bar, not a pitch. */
.store-pill {
  padding: 8px 16px; border-radius: 999px;
  background: var(--surface); color: var(--text) !important; font-weight: 600;
}
.store-pill:hover { background: var(--accent-soft); }

/* ---------- the tool ---------- */
/* Four areas. The settings column spans both lower rows on desktop; on narrow screens the
   order becomes types -> preview -> settings -> actions, so a phone user meets the settings
   before Download rather than after it. The 1-5 step badges are gone: once the sections are
   spread across two columns the numbers promise an order the layout does not follow. */
.app {
  display: grid;
  /* The tool fills the page. It briefly sized this column to the sheet instead, which read
     well for a portrait page but made the whole layout change width whenever the paper's
     orientation changed — a landscape sheet is half again as wide. The width of the furniture
     should not depend on what is being previewed. */
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-areas:
    "types types"
    "panel work"
    "panel out";
  align-items: start;
  gap: 10px 16px;
  margin: 16px auto 0;
  padding: 0 clamp(12px, 3vw, 28px);
  max-width: 1500px;
}

/* shared card shell */
.panel {
  font-size: 14px; line-height: 1.4;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: visible;
}

/* grid type: full width, as many tiles as fill the available width (see preview-controller.js) */
.gridbar { grid-area: types; padding: 0 var(--gutter); }
.gridbar .section { border-bottom: 0; padding: 12px 0 13px; }
.gridbar .type-grid { gap: 6px; }
.gridbar .more-types { width: auto; min-width: 190px; margin: 9px auto 0; padding: 0 18px; }

/* left column: how the grid looks */
.settings { grid-area: panel; }
.settings .controls { overflow: visible; padding: 0 var(--gutter); }

/* preview column */
.workspace {
  grid-area: work;
  display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px;
  justify-items: center; min-width: 0;
}
.stage-head { display: flex; justify-content: center; width: 100%; min-width: 0; }
/* The column is already the right width, so everything in it simply fills: the preview, the
   info pill above it and the Download/Print row below share one left and one right edge.
   sidepanel.css gives .workspace 24px of side padding, which is right in a side panel but
   here inset the preview 24px from the action row underneath it — two edges where there
   should be one. The vertical padding stays; it is what keeps the pill off the grid tiles. */
.workspace { width: 100%; padding-inline: 0; }
.pill { flex: 0 1 auto; min-width: 0; }

.desk { position: relative; width: 100%; height: min(70vh, 760px); min-height: 420px; }
/* The stage never scrolls and never takes the wheel: the page keeps scrolling under the
   pointer. A page zoomed past the frame is moved by dragging it (see preview-controller.js).
   overscroll-behavior MUST be auto here. preview.css sets `contain` on .stage, which is
   right for a side panel but on a page it stops scroll chaining, so the wheel dies over the
   biggest element on the screen and the page looks frozen. Removing the wheel handler alone
   does not fix that. */
.app .stage, .app .stage.fitting { overflow: hidden; overscroll-behavior: auto; }

/* zoom: a vertical cluster centred on the right edge of the preview */
.desk .zoom {
  /* Sizes to its content: "Fit" is 38px in English but 54px as "Einpassen", 47px as
     "Вписать", 44px as "Passend". A fixed width clipped those. */
  /* inset-inline-end, not `right`: /ar/ is dir=rtl, and with a physical `right` the cluster
     stayed on the preview's right edge — which after mirroring is the edge butted against the
     settings column, not the free outer edge it hugs in LTR. */
  position: absolute; top: 50%; inset-inline-end: 14px; transform: translateY(-50%); z-index: 2;
  flex-direction: column; height: auto; width: auto; min-width: 52px; max-width: 108px;
  padding: 6px; gap: 6px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.desk .zoom .zbtn { width: 100%; height: 32px; border: 1px solid transparent; }
.desk .zoom .zlabel {
  min-width: 0; width: 100%; padding: 3px 0; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.desk .zoom .ztext {
  width: 100%; padding: 0 6px; height: 28px; font-size: 11px; border: 1px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.desk .zoom .ztext .long { display: none; } /* "Fit", not "Fit to window", in a narrow column */
/* selected state: the extension's faint card-on-card does not read against the preview */
.desk .zoom .ztext[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  box-shadow: none; font-weight: 700;
}
.desk .zoom .zbtn:hover:not(:disabled), .desk .zoom .ztext:hover:not([aria-pressed="true"]) {
  background: var(--accent-soft); border-color: var(--accent-soft);
}

/* Pages and the output buttons share ONE card. They used to be a card (Pages) sitting beside
   two bare buttons and a line of help text laid straight on the dotted page background, which
   read as two unrelated pieces of furniture: every other block on this page is a card, so the
   buttons looked unmoored and the row had no bottom edge to sit on. One card gives the row a
   shape, lets the help text live somewhere, and lines Pages up with the buttons.
   The `panel` class stays on the markup for the extension's own styling; it is neutralised
   here rather than removed, so this file keeps all the web-only layout decisions. */
.actionrow {
  /* One column, always. The column is as wide as the sheet needs (~674px for A4 portrait),
     not as wide as the window, so Pages beside two buttons never had the room: the buttons
     wrapped under each other and the help text broke across two right-aligned lines. Stacked,
     the two rows each use the full width and the layout no longer depends on paper size. */
  grid-area: out; width: 100%;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: center;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 12px var(--gutter);
}
.actionrow .panel { background: none; border: 0; box-shadow: none; border-radius: 0; }
.pages-block { padding: 0; min-width: 0; }
/* "Pages" sits beside the stepper rather than above it: as a heading it cost a whole line and
   left the card taller than the buttons it is meant to sit level with. */
.pages-block .section { border-bottom: 0; padding: 0; display: flex; align-items: center; justify-content: center; gap: 14px; }
.pages-block h2 { margin: 0; white-space: nowrap; }

.output { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.output .btn { flex: 1 1 200px; max-width: 320px; height: 46px; font-size: 15.5px; }
.output .tip { flex-basis: 100%; margin: 0; text-align: center; font-size: 12.5px; color: var(--muted); }
.output #status { flex-basis: 100%; margin: 0; text-align: center; font-size: 13px; color: var(--accent); }
.output #status:empty { display: none; }

/* ---------- copy below the tool ---------- */
.copy { max-width: 860px; margin: 0 auto; padding: 56px clamp(18px, 4vw, 24px) 24px; }
.copy section + section { margin-top: 48px; }
.copy h2 {
  margin: 0 0 12px; font-size: clamp(21px, 2.6vw, 27px); font-weight: 700; letter-spacing: -.02em;
  scroll-margin-top: 72px;
}
.copy h3 { margin: 28px 0 6px; font-size: 17.5px; font-weight: 600; }
.copy p { margin: 0 0 12px; color: var(--muted); }
.copy b { color: var(--text); font-weight: 600; }

.grid-list { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 12px; }
.grid-list li {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-size: 14.5px; color: var(--muted);
}
.grid-list b { display: block; margin-bottom: 3px; font-size: 15.5px; color: var(--text); }
/* The homepage links every grid type that has a landing page. Browser-default blue and a
   full underline against this palette looked like a 1996 link farm, and the list reads as a
   sentence of names — so the links stay in the body colour and are marked with a thin rule
   that firms up on hover. The nine types with no page stay plain, which is the distinction a
   reader should see. */
.grid-list a {
  color: var(--text); text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.grid-list a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* padding-inline-start, not padding-left: in /ar/ a physical padding-left left the UA's own
   40px start indent on the right untouched and added 22px of dead space on the left, so the
   numbered steps sat further in than the 22px intended. */
.steps { margin: 0; padding-inline-start: 22px; display: grid; gap: 10px; color: var(--muted); }
.steps li::marker { color: var(--accent); font-weight: 700; }

.copy dl { margin: 0; }
.copy dt { margin-top: 20px; font-weight: 600; }
.copy dd { margin: 5px 0 0; color: var(--muted); }

/* ---------- footer ---------- */
.site-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 860px; margin: 0 auto; padding: 28px clamp(18px, 4vw, 24px) 40px;
  border-top: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
.site-foot p { margin: 0; }
.site-foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.site-foot a:hover { color: var(--text); }

/* ---------- narrow screens ---------- */
/* No room for Pages beside the buttons: stack them. */
@media (max-width: 1150px) {
  .actionrow { gap: 12px; }
}
@media (max-width: 900px) {
  /* One column. Settings come BEFORE the action row, so a phone user meets grid spacing,
     colour and paper size before Download rather than several screens after it. */
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "types" "work" "panel" "out";
    gap: 12px;
  }
  .desk { height: 56vh; min-height: 340px; }
  .site-nav a:not(.store-pill) { display: none; }
}
@media (max-width: 560px) {
  /* ...but not on a phone: the row also carries the "Add to Chrome" pill, and the longest
     names ("Millimeterpapier zum Ausdrucken" wants 237px of the ~119px left) only fit by
     ellipsis. Below 560px the icon stands alone rather than showing a cut-off name. */
  .site-bar .brand span { display: none; }
  .output .btn { flex: 1 1 100%; max-width: none; }
  /* The stepper and the preset chips need two lines of their own at this width, and "Pages"
     beside a two-line block floats against its middle. Put the label back on top. */
  .pages-block .section { display: block; text-align: center; }
  .pages-block h2 { margin-bottom: 8px; }
  .pages-block .pages-row { justify-content: center; }
  .desk .zoom { inset-inline-end: 8px; min-width: 46px; max-width: 92px; padding: 4px; gap: 4px; }
  .copy { padding-top: 40px; }
}

/* The margins row is the only five-option segmented control. `.seg label { flex: 1 }` gives
   every option an equal slice — about 57px inside the 340px settings column — and the labels
   at the two ends are long words nearly everywhere: Italian "Personalizzato" needs 82px and
   was cut mid-word to "rsonalizza", and "None" clipped in six more languages. Let this one
   control wrap and size each option to its own text, the way the grid-spacing and line-weight
   chip rows directly above it already do. The two-option orientation and unit segs still fit,
   so they keep the equal-slice behaviour. */
.settings [data-testid="margin"] { height: auto; flex-wrap: wrap; row-gap: 3px; }
/* Grow, never shrink: 1 0 auto. The basis is the label's own text, so nothing can be cut, and
   the grow fills the track so there is no dead space after the last option — `flex: 0 0 auto`
   fixed the clipping but left a visible gap on the right wherever the labels were short.
   It wraps only when the labels genuinely need a second row — five options fit one row in
   inches ("1/4''") but not in millimetres ("10 mm"), and in Russian they fit either way. A
   wrapped row fills too, so there is never dead space whichever way it lands. */
.settings [data-testid="margin"] label { flex: 1 0 auto; }
.settings [data-testid="margin"] span { height: calc(var(--control-h) - 6px); padding: 0 10px; white-space: nowrap; }

/* preview.css hides "Fit to window" below 560px and "100%" below 640px, because in the
   extension they compete with the toolbar. Here the zoom control has a column to itself, and
   those two are the only way back from a zoomed-in view — the ones a small screen needs most.
   Keep them at every width. */
.desk .zoom .ztext,
.desk .zoom #zoom-100 { display: block; }

/* related templates: internal cross-links at the foot of each landing page */
.related { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.related a {
  display: block; padding: 11px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none; font-size: 14.5px; line-height: 1.35;
}
.related a:hover { border-color: var(--accent); color: var(--accent); }
