/* Keep the scrollbar's width reserved whether or not the page scrolls. Page
   scripts are deferred, so the first paint shows the form before its
   initialization collapses sections; a page that is a little taller than the
   window then loses its scrollbar and everything jumps sideways (CLS 0.14 on
   flight at 1358x1069 with classic scrollbars, 0.02 with this rule). */
html {
  scrollbar-gutter: stable;
}

.main-header {
  width: auto;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px;
  margin: 2px;
  background-color: var(--bs-secondary-bg);
}

/* Modal titles are h2/h3 in the markup so the heading outline stays flat below
   the visually-hidden h1, but Bootstrap's .modal-title sets no font-size, so
   pin the size the old h5 gave them. Accordion headers are already 1rem via
   .accordion-button, so those need no extra rule. */
h2.modal-title,
h3.modal-title {
  font-size: 1.25rem;
}

.subheader {
  text-align: center;
  font-weight: 600;
  margin: 0;
}

[data-bs-theme="dark"] body {
  background-color: color-mix(in srgb, var(--bs-body-bg) 80%, black);
  color: var(--bs-info-text-emphasis);
}

/* Button surface knobs, see the .btn block further down. Kept next to the theme
   definitions so both tones are tuned in one place. */
[data-bs-theme="dark"] {
  --pfg-btn-bg: #272d34;
  --pfg-btn-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --pfg-btn-shadow-active: inset 0 1px 2px rgba(0, 0, 0, 0.5);
  /* Profile mark for a field that matches the game, see .pf-bound below. */
  --pfg-mark-same: var(--bs-success-text-emphasis);
  /* Stale resource caption, see .pf-resources-stale below: Bootstrap's dark
     warning text (#ffda6a) outshines the page text, so fade it 65% toward the
     page background - a muted ochre, still above 4.5:1. */
  --pfg-stale-text: color-mix(in srgb, var(--bs-warning-text-emphasis) 65%, color-mix(in srgb, var(--bs-body-bg) 80%, black));
}

/* Soften the pure-white light theme evenly across the whole UI (tune the 94% knob).
   Overriding --bs-body-bg cascades to cards, form controls, etc. that inherit it.
   --bs-tertiary-bg is set a step darker so table headers (.lined th) and the
   input-group "%" addons (.input-group-text) read as slightly muted, not brighter. */
[data-bs-theme="light"] {
  --bs-body-bg: color-mix(in srgb, #fff 96%, black);
  --bs-tertiary-bg: color-mix(in srgb, #fff 82%, black);
  --bs-border-color: color-mix(in srgb, #fff 70%, black);
  --bs-body-color: color-mix(in srgb, #000 85%, white);
  --pfg-btn-bg: #e3e8ef;
  --pfg-btn-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  --pfg-btn-shadow-active: inset 0 1px 2px rgba(0, 0, 0, 0.18);
  /* Profile mark for a field that matches the game, see .pf-bound below. */
  --pfg-mark-same: color-mix(in srgb, var(--bs-info) 50%, var(--bs-body-bg));
}

/* Darken the page surround around the calculator (tune the 88% knob). The panels
   are transparent .border.rounded boxes, so give them an explicit --bs-body-bg to
   keep them at #f0f0f0 — otherwise they'd show the darker body through. Elements
   carrying a .bg-* utility (!important) keep their own colour. */
[data-bs-theme="light"] body {
  background-color: color-mix(in srgb, #fff 90%, black);
}
[data-bs-theme="light"] .border.rounded {
  background-color: var(--bs-body-bg);
}

/* Mirror the dark theme, where editable inputs sit at the base --bs-body-bg and
   thus read lighter than the darkened surround. Here the surround/panels are
   toned down, so lift editable fields one step above the panels instead.
   readonly/disabled fields keep the panel tone. `ui-state-disabled´ is excluded
   for the same reason: a computed readout rendered as a <div> cannot carry the
   readonly or disabled attribute, so the marker class is its only signal.
   The :not()s also raise specificity above the .border.rounded rule so a
   .form-control.border still lifts. */
[data-bs-theme="light"] .form-control:not([readonly]):not(:disabled):not(.ui-state-disabled),
[data-bs-theme="light"] .form-select:not([readonly]):not(:disabled):not(.ui-state-disabled) {
  background-color: color-mix(in srgb, #fff 100%, black);
}

/* Same interactive-light tone for unchecked radios/checkboxes, so they don't blend
   into the panel. Overriding --bs-form-check-bg touches only the unchecked fill;
   the checked state keeps its primary colour. */
[data-bs-theme="light"] .form-check-input {
  --bs-form-check-bg: color-mix(in srgb, #fff 100%, black);
}

/* Slightly darken the calculator title header (next to the reset button). The
   header takes its fill from the .main-header rule above rather than from a
   .bg-body-secondary utility, whose !important no theme rule could beat. */
[data-bs-theme="light"] .main-header {
  background-color: color-mix(in srgb, var(--bs-secondary-bg) 92%, black);
}

/* Dark theme: sink editable form controls below the readonly/disabled tone so they are visually
   distinct. Editable inputs appear darker (more recessed), while readonly/disabled fields
   keep the panel tone (--bs-secondary-bg) and appear lighter/raised. This makes readonly
   inputs in modals visually distinguishable from editable ones. The :not()s lift the
   selector to (0,5,0), above Bootstrap's .form-control/.form-select fill and its :focus
   state, so no !important is needed. A page that wants a different sunk tone sets
   --pf-sunk-input-bg rather than writing a competing background rule. */
[data-bs-theme="dark"] .form-control:not([readonly]):not(:disabled):not(.ui-state-disabled),
[data-bs-theme="dark"] .form-select:not([readonly]):not(:disabled):not(.ui-state-disabled) {
  background-color: var(--pf-sunk-input-bg, rgb(20, 23, 27));
}

/* Modals: Bootstrap paints .modal-content with --bs-modal-color (#dee2e6 in dark
   mode), which reads as white against the calculators' cyan default text. Inherit
   from the page instead — the same fix the accordions carry in flight.css and
   production.css. Set on .modal because that is where Bootstrap declares the
   variable, so this also feeds the `color´ on .modal-content.

   A .table nested in a modal needs its own line: Bootstrap re-colours every cell
   with --bs-table-color (var(--bs-emphasis-color) — plain white in dark mode), so
   the inherited modal colour would stop at the table element. The striped/active/
   hover state variables default to the same emphasis colour and are listed too,
   otherwise the changelog's .table-striped rows alternate cyan and white. */
.modal {
  --bs-modal-color: inherit;
}

.modal .table {
  --bs-table-color: inherit;
  --bs-table-striped-color: inherit;
  --bs-table-active-color: inherit;
  --bs-table-hover-color: inherit;
}

[data-bs-theme="dark"] .nav-tabs .nav-link.active {
  color: var(--bs-primary);
}

/* `:not(.btn)´ keeps these away from Bootstrap buttons, which carry their own
   --bs-btn-color per variant. Without it the dark rule below, at (0,1,1), beats
   `.btn´ at (0,1,0) and paints the label of a solid .btn-primary cyan. */
.subheader,
button:not(.btn) {
  color: #0a58ca;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .subheader,
[data-bs-theme="dark"] button:not(.btn) {
  color: var(--bs-info-text-emphasis);
}

/* Buttons read as raised keys. Bootstrap's outline variants leave --bs-btn-bg at
   the base `transparent´, so they render exactly the panel colour while editable
   inputs get a lifted fill — the button ends up looking like a hole in the panel.
   Give the outline variants their own surface; the variant's accent stays in the
   text and the border.

   Do not fold this into a bare `.btn´ selector: that has the same (0,1,0)
   specificity as Bootstrap's .btn-primary and, loading later, would strip the
   fill off the solid variants too. */
.btn-outline-secondary,
.btn-outline-primary,
.btn-outline-danger {
  --bs-btn-bg: var(--pfg-btn-bg);
}

/* Relief and press feedback are safe on every .btn — box-shadow and transform do
   not collide with the --bs-btn-* variables, and the class also covers the
   <div class="btn"> controls in the flight calculator. Bootstrap's own
   .btn:focus-visible ring is (0,2,0) and still wins. */
.btn {
  box-shadow: var(--pfg-btn-shadow);
}

.btn:active,
.btn.active {
  transform: translateY(1px);
  box-shadow: var(--pfg-btn-shadow-active);
}

/* A key that cannot be pressed must not look raised. */
.btn:disabled,
.btn.disabled,
.btn.ui-state-disabled {
  box-shadow: none;
  transform: none;
}

.ui-input-margin {
  margin: 0;
  margin-left: 6px;
}

.hint-label {
  font-size: 0.8em;
}

.ui-checkbox {
  margin-right: 10px;
}

.no-mp {
  margin: 0;
  padding: 0;
}

#reset {
  padding: 4px;
  cursor: pointer;
  float: right;
  margin: 4px;
}

#tabs {
  margin: 4px;
  z-index: 0;
}

#warning {
  padding: 2px;
  margin: 4px;
  text-align: center;
  display: none;
}

#hint {
  padding: 2px;
  margin: 4px;
  margin-top: 20px;
}

#hint-message {
  margin-right: .3em;
  font-weight: lighter;
}

#vtable {
  width: 100%;
}

#vtablesb,
#vtablec {
  vertical-align: top;
}

#vtablesb {
  white-space: nowrap;
}

#vtablec {
  width: 100%;
}

#vtablet {
  text-align: right;
}

#vtablel {
  text-align: right;
}

#topbar {
  width: 100%
}

/* A side wider than its half (a phone) grows and pushes the selector off centre
   rather than overlapping it. */
.topbar-side {
  flex: 1 1 0;
}

#topbar td {
  white-space: nowrap;
  vertical-align: center;
}

#startpage {
  font-size: 1.2em;
  padding: 10px;
}

/* The start page's card about the AI assistants, and the page it leads to:
   both read as text, so they keep to a line length that reads comfortably. */
#ai-card {
  max-width: 40rem;
}

#assistants-page {
  max-width: 50rem;
}

#mcp-address-group {
  max-width: 28rem;
}

.assistants-examples q {
  font-style: italic;
}

/* Exchange rate inputs (costs / lfcosts / production). They hold MSU weights,
   so fractional values like 1,5 or 1,33 are the norm rather than the exception.
   The text is centered, so the roomy form-control-sm side padding buys nothing
   but clipping — trading it for content width fits the values without making
   the fields any wider. */
#exchange-rates-m,
#exchange-rates-c,
#exchange-rates-d {
  width: 48px;
  padding-left: 2px;
  padding-right: 2px;
  text-align: center;
}

.input-1column {
  width: 20px;
  text-align: center;
}

.input-2columns {
  width: 25px;
  text-align: center;
}

.input-3columns {
  width: 30px;
  text-align: center;
}

.input-4columns {
  width: 40px;
  text-align: center;
}

.input-5columns {
  width: 50px;
  text-align: center;
}

.input-10columns {
  width: 90px;
  text-align: center;
}

.input-20columns {
  width: 180px;
  text-align: center;
}

.input-in-table {
  margin: 0px;
}

.centered {
  text-align: center
}

.left-aligned {
  text-align: left
}

.right-aligned {
  text-align: right
}

abbr {
  border-bottom: .1em dotted;
  cursor: help;
}

/* Read-only and disabled inputs should show the default arrow cursor, not a text caret.
   This applies to readonly attributes and :disabled pseudo-class on inputs and textareas. */
input[readonly],
textarea[readonly],
input:disabled,
textarea:disabled {
  cursor: default;
}
/* Keep value inputs compact when wrapped in a Bootstrap input-group with a unit
   addon: Bootstrap forces `.input-group > .form-control { flex: 1 1 auto; width: 1% }`,
   which would otherwise blow these fixed-width numeric fields up to the browser's
   default text-input width. */
.input-group > .form-control.level-input,
.input-group > .form-control.fleet-input,
.input-group > .form-control.rate-input {
  flex: 0 0 auto;
  width: 3.5rem;
}

/* Tooltip skin shared by every calculator: the Bootstrap default is an opaque
   black bubble that ignores the theme, so repaint it off the theme variables.
   Kept here rather than restated in each `*.css´ — the eight copies this
   replaces were byte-identical.

   The fill is set through --bs-tooltip-bg rather than on .tooltip-inner: that is
   the variable Bootstrap's own arrow rules read, so the arrow follows the bubble
   for free. The copies this replaces instead tried to colour the arrow with
   `.tooltip.bs-tooltip-top .tooltip-arrow::before` and friends, which never
   matched anything — BS5 marks placement with a `bs-tooltip-auto` class plus a
   `data-popper-placement` attribute, so every calculator was drawing the themed
   bubble with a black default arrow. */
.tooltip {
  --bs-tooltip-bg: var(--bs-secondary-bg);
  --bs-tooltip-color: var(--bs-body-color);
  /* A tooltip is informational and must never swallow a click. Without this, the
     bubble of one control can cover its neighbour in a tight button row — the
     flight departure shortcuts, `(now)´ and `(00:00:00)´, sit close enough that
     auto-placement puts one bubble straight over the other button. */
  pointer-events: none;
  --tooltip-arrow-outline: var(--bs-border-color);
  --tooltip-arrow-offset: calc(-1px - 2px);
}

.tooltip-inner {
  border: 1px solid var(--bs-border-color);
  max-width: 250px;
  text-align: left;
}

/* The arrow is a single ::before triangle with no border of its own — giving the
   box a themed outline (above) still left the beak a flat, borderless fill in
   both themes. Bootstrap's popover arrow solves this with a second, inset
   ::after triangle (see .popover-arrow in bootstrap.min.css): ::before is the
   full-size triangle in the outline colour, ::after is the same triangle in the
   fill colour nudged *towards the bubble*, so the part of ::before it no longer
   covers — the tip and a sliver along both diagonal sides — is left showing as
   the outline. Reproduced here per placement since tooltips don't ship that
   second layer.

   The nudge direction is the whole trick: shifting ::after away from the bubble
   instead slides the fill triangle past the outline one and draws two separate
   triangles, one above the other. Bootstrap already offsets ::before by 1px
   into the bubble, so --tooltip-arrow-offset is that 1px plus the 2px of ring
   we want to see, applied on whichever side faces the bubble. 2px rather than
   the popover's 1px because these sides run at 45°, where a 1px shift leaves
   only ~0.7px of ring perpendicular to the edge — thinner than the 1px border
   it has to line up with. Verified against 1x screenshots in both themes.

   Overlapping the bubble is safe even though .tooltip-inner is a later sibling:
   the arrow is absolutely positioned and so paints above it, letting the fill
   hide the bubble's own border where the two meet.

   Selectors repeat the real BS5 selector (`bs-tooltip-auto[data-popper-placement]`)
   and the legacy fixed-placement one (`bs-tooltip-top` and friends) so this
   keeps working if a caller ever pins a placement instead of leaving it auto. */
.tooltip .tooltip-arrow::after {
  position: absolute;
  content: "";
  border-color: transparent;
  border-style: solid;
}

.tooltip.bs-tooltip-auto[data-popper-placement^="top"] .tooltip-arrow::before,
.tooltip.bs-tooltip-top .tooltip-arrow::before {
  border-top-color: var(--tooltip-arrow-outline);
}
.tooltip.bs-tooltip-auto[data-popper-placement^="top"] .tooltip-arrow::after,
.tooltip.bs-tooltip-top .tooltip-arrow::after {
  top: var(--tooltip-arrow-offset);
  border-width: var(--bs-tooltip-arrow-height) calc(var(--bs-tooltip-arrow-width) * .5) 0;
  border-top-color: var(--bs-tooltip-bg);
}

.tooltip.bs-tooltip-auto[data-popper-placement^="right"] .tooltip-arrow::before,
.tooltip.bs-tooltip-end .tooltip-arrow::before {
  border-right-color: var(--tooltip-arrow-outline);
}
.tooltip.bs-tooltip-auto[data-popper-placement^="right"] .tooltip-arrow::after,
.tooltip.bs-tooltip-end .tooltip-arrow::after {
  right: var(--tooltip-arrow-offset);
  border-width: calc(var(--bs-tooltip-arrow-width) * .5) var(--bs-tooltip-arrow-height) calc(var(--bs-tooltip-arrow-width) * .5) 0;
  border-right-color: var(--bs-tooltip-bg);
}

.tooltip.bs-tooltip-auto[data-popper-placement^="bottom"] .tooltip-arrow::before,
.tooltip.bs-tooltip-bottom .tooltip-arrow::before {
  border-bottom-color: var(--tooltip-arrow-outline);
}
.tooltip.bs-tooltip-auto[data-popper-placement^="bottom"] .tooltip-arrow::after,
.tooltip.bs-tooltip-bottom .tooltip-arrow::after {
  bottom: var(--tooltip-arrow-offset);
  border-width: 0 calc(var(--bs-tooltip-arrow-width) * .5) var(--bs-tooltip-arrow-height);
  border-bottom-color: var(--bs-tooltip-bg);
}

.tooltip.bs-tooltip-auto[data-popper-placement^="left"] .tooltip-arrow::before,
.tooltip.bs-tooltip-start .tooltip-arrow::before {
  border-left-color: var(--tooltip-arrow-outline);
}
.tooltip.bs-tooltip-auto[data-popper-placement^="left"] .tooltip-arrow::after,
.tooltip.bs-tooltip-start .tooltip-arrow::after {
  left: var(--tooltip-arrow-offset);
  border-width: calc(var(--bs-tooltip-arrow-width) * .5) 0 calc(var(--bs-tooltip-arrow-width) * .5) var(--bs-tooltip-arrow-height);
  border-left-color: var(--bs-tooltip-bg);
}

/* Flattens <fieldset>/<legend> browser chrome (border, padding, block-level
   legend) so a semantic form-field group can sit inline in a flex row instead
   of rendering as a bordered box. Used where a group heading was a bare
   <label> with no associated control (SonarQube Web:S6853). */
.fieldset-reset {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}
/* The float is what puts the legend back in the row. A fieldset lays its
   children out inside an anonymous box that takes the fieldset's own display,
   and the *rendered legend* — the first <legend> child whose float computes to
   `none` — is pulled out of that box and placed above it. So on a `d-flex`
   fieldset a non-floated legend is never a flex item and always sits on its own
   line, however it is styled. Any float disqualifies it from being the rendered
   legend, and it joins the anonymous flex box as an ordinary item, where the
   float itself is then ignored. */
.fieldset-reset > legend {
  float: left;
  width: auto;
  padding: 0;
  margin: 0;
  font-size: inherit;
  line-height: inherit;
}

/* The profile's planet (and moon) selects next to a calculator's title: a
   few pixels off the panel's top edge, so the gap above them matches the one
   below, to the panel underneath - and to the title when they wrap under it. */
.pf-header-bodies {
  margin-top: 3px;
}

/* The profile select in the top bar: never wider than the bar can spare. */
#pf-select {
  max-width: 40vw;
}

/* Player profiles (profiles-ui.js): a field the active profile owns gets a
   stripe on its left edge; one whose value differs from the game gets it in the
   warning colour, followed by a button that restores the game value.
   The "matches the game" colour, --pfg-mark-same, is per theme and lives in the
   theme blocks at the top: the dark theme already sets its body text in the
   info colour, so the mark there is green; in the light theme the info colour
   is kept but faded towards the background. */
.pf-bound {
  box-shadow: inset 3px 0 0 var(--pfg-mark-same);
}

.pf-bound.pf-differs {
  box-shadow: inset 3px 0 0 var(--bs-warning);
}

input[type="checkbox"].pf-bound,
input[type="radio"].pf-bound {
  box-shadow: none;
  outline: 2px solid var(--pfg-mark-same);
  outline-offset: 1px;
}

input[type="checkbox"].pf-bound.pf-differs,
input[type="radio"].pf-bound.pf-differs,
fieldset.pf-bound.pf-differs {
  outline-color: var(--bs-warning);
}

fieldset.pf-bound {
  box-shadow: none;
  border-left: 3px solid var(--pfg-mark-same);
  padding-left: 0.25rem;
}

/* "Game data as of ..." under the available resources of the cost tables
   (PfBodyResources): it takes the width the columns already have and wraps
   in it, rather than widening the energy and time columns of a max-content
   table. d-none still hides it - it is !important. */
.pf-resources-age {
  display: block;
  width: 0;
  min-width: 100%;
  white-space: normal;
}

/* A resource caption whose reading is over an hour old (PfBodyResources).
   Only the dark theme sets --pfg-stale-text; the light one keeps Bootstrap's. */
.pf-resources-stale {
  color: var(--pfg-stale-text, var(--bs-warning-text-emphasis));
}

fieldset.pf-bound.pf-differs {
  border-left-color: var(--bs-warning);
}

.input-group.pf-bound {
  box-shadow: none;
}

/* The restore button hugs its field, 2px away so the two borders stay apart.
   The spacing the layout puts after a field - its own right margin, the flex
   gap of its container - would push the button off by up to 16px, so the
   field drops its margin while the button is there, and the button takes the
   gap back with a negative margin. The gap comes from a utility class or from
   a page's own CSS alike, so ProfileUi.markInput() reads it off the container
   into --pfg-flex-gap. */
.pf-reset {
  --pfg-reset-gap: 2px;
  margin-left: calc(var(--pfg-reset-gap) - var(--pfg-flex-gap, 0px));
  line-height: 1;
  color: var(--bs-warning-text-emphasis);
}

.pf-bound:has(+ .pf-reset) {
  margin-right: 0 !important;
}

/* A form control is a block, so the restore button after it would drop to the
   next line - in a table cell it always does. Inline, the two share the line. */
:is(.form-control, .form-select).pf-bound:has(+ .pf-reset) {
  display: inline-block;
  vertical-align: middle;
}

:has(> .form-control.pf-bound + .pf-reset, > .form-select.pf-bound + .pf-reset) {
  white-space: nowrap;
}

/* The QR code of a profile share link. ProfilesUi draws it at 4px or more per
   module, which a camera reads off a screen, and on a desktop it is shown at
   that size - scaled down, a large code blurs its modules together. A phone
   has no room for it: there it fits the screen, and the frame scrolls only if
   something still sticks out. The white quiet zone is part of the canvas. */
.pf-share-qr-frame {
  overflow-x: auto;
}

.pf-share-qr {
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
}

@media (max-width: 575.98px) {
  .pf-share-qr {
    max-width: 100%;
    height: auto;
  }
}

/* Phone layout (docs/patterns.md, "Phone layout").

   A wide table on a narrow screen scrolls sideways inside a .pfg-scroll-x
   wrapper, so the rest of the calculator - title, tabs, settings - stays on the
   screen. Below lg only: on a desktop the calculator is as wide as its widest
   table, nothing would scroll, and an overflow container would only clip the
   focus ring of a field at its edge. */
@media (max-width: 991.98px) {
  .pfg-scroll-x {
    max-width: 100%;
    overflow-x: auto;
  }

  /* The first column - the building, ship or research a row is about - stays
     in view while the rest of the row scrolls under it. A sticky cell has to
     be opaque, so the row stripe is laid over the page colour. */
  .pfg-sticky-col :is(td, th).pfg-sticky,
  .pfg-sticky-col tr > :is(td, th):first-child:not(.pfg-unsticky) {
    position: sticky;
    left: 0;
    z-index: 1;
  }

  .pfg-sticky-col tr > td:first-child:not(.pfg-unsticky),
  .pfg-sticky-col td.pfg-sticky {
    background-color: var(--bs-body-bg);
  }

  .pfg-sticky-col tr.odd > td:first-child:not(.pfg-unsticky),
  .pfg-sticky-col tr.odd > td.pfg-sticky {
    --pfg-stripe: color-mix(in srgb, var(--bs-body-color) 7%, transparent);
    background-image: linear-gradient(var(--pfg-stripe), var(--pfg-stripe));
  }

  /* A name column as wide as its longest name ("Fusion-powered production",
     on one line) would cover most of a phone's screen once it stays put, and
     leave the numbers a sliver to scroll through. A name cell marked
     .pfg-sticky is held to 8rem and wraps, hyphenated in the page's language. */
  .pfg-sticky-col :is(td, th).pfg-sticky {
    width: 8rem;
    min-width: 8rem;
    white-space: normal;
    overflow-wrap: anywhere;
    hyphens: auto;
  }
}

/* Safari on iOS zooms the page in whenever a field whose text is smaller than
   16px takes the focus, and leaves it zoomed. form-control-sm is 14px, so on a
   phone the fields get 16px. Element-qualified to outrank a calculator's own
   single-class font size (trade's .rate-input). */
@media (max-width: 575.98px) {
  input.form-control,
  select.form-select,
  textarea.form-control {
    font-size: 16px;
  }
}

/* A field with its unit ("%", "km", "systems") stays one piece. Bootstrap's
   .input-group wraps, so on a narrow screen a squeezed group dropped its unit
   under the field; the row it sits in wraps instead, the group whole. Every
   width, since a desktop has room and nothing changes there; groups holding a
   button rather than a unit (the MCP page's copy button) keep wrapping. */
.input-group:has(> .input-group-text) {
  flex-wrap: nowrap;
}

/* Layout tables that reflow below md instead of scrolling (docs/patterns.md,
   "Phone layout"): a form whose answers sit at the end of its rows would hide
   them past the right edge. The rows become display: contents, so the cells
   of every row share one grid on the tbody and stay aligned. Below md, not
   sm: these tables are some 650px wide, more than a 600px screen holds. */
@media (max-width: 767.98px) {
  table.pfg-energy-rows,
  table.pfg-pairs {
    display: block;
  }

  table.pfg-energy-rows tr,
  table.pfg-pairs tr {
    display: contents;
  }

  /* .pfg-energy-rows - "name | field | % | energy" rows: the name takes a
     line of its own and the field, the percentage and the energy go under
     it. A row with no field (a bonus) keeps its name and energy on one line,
     the energy in the same column as the plants'. */
  /* The field and percentage tracks are min-content - the width of the field
     and of the select, which do not shrink - so a bonus's name, spanning both,
     wraps inside them instead of widening them and squeezing the energy. */
  table.pfg-energy-rows > tbody {
    display: grid;
    grid-template-columns: min-content min-content 1fr;
    align-items: center;
  }

  table.pfg-energy-rows tr > td:first-child {
    grid-column: 1 / -1;
  }

  /* "283.935 Energy" is free to wrap at its space: the field and the
     percentage beside it do not shrink, so on a 360px screen with a wide font
     the unit is all that can give. The number, having no space, stays whole. */

  table.pfg-energy-rows tr:not(:has(input, select)) > td:first-child {
    grid-column: 1 / 3;
  }

  table.pfg-energy-rows tr:not(:has(input, select)) > td:not(:first-child, :last-child) {
    display: none;
  }

  /* .pfg-pairs - "label | value | label | value ..." rows: one pair a line.
     .pfg-order-N regroups the cells (one resource after another rather than
     one row after another), .pfg-phone-full spans a cell over both columns,
     .pfg-phone-hide drops a spacer, data-phone-label gives an empty spacer
     cell the label it stood under, and .pfg-phone-sub indents a label that
     belongs to the resource above it. */
  table.pfg-pairs > tbody {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: safe center;
    align-items: center;
  }

  table.pfg-pairs .pfg-phone-full {
    grid-column: 1 / -1;
  }

  table.pfg-pairs .pfg-phone-hide {
    display: none;
  }

  table.pfg-pairs td[data-phone-label]::before {
    content: attr(data-phone-label);
  }

  /* A margin, not padding: a calculator's own td padding rule is id-scoped. */
  table.pfg-pairs .pfg-phone-sub {
    margin-left: 1rem;
  }

  .pfg-order-1 { order: 1; }
  .pfg-order-2 { order: 2; }
  .pfg-order-3 { order: 3; }
  .pfg-order-4 { order: 4; }
  .pfg-order-5 { order: 5; }
  .pfg-order-6 { order: 6; }
  .pfg-order-7 { order: 7; }
  .pfg-order-8 { order: 8; }
  .pfg-order-9 { order: 9; }
}
