/*
 * Power Soccer Lab page layout (power-soccer/docs/08 §3 and §5.2).
 *
 * Layout-critical rules live here in plain CSS, so they hold even before a
 * Tailwind rebuild: the grid areas, the sticky scenario bench and its result
 * bar, the fixed bar below 1,024 px, the disclosure and caption styles.
 *
 * Every rule is scoped under `.pss`, a class on the lab controller's root:
 * `stylesheet_link_tag :app` loads this file on every page, and the two-class
 * selectors beat Tailwind's layered utilities and the unlayered rules in
 * tailwind.css, which loads after this file.
 *
 * The DOM order is the phone's reading order (header, stage, result,
 * experiments, scenario bench, saved, reference sections). From 1,024 px the
 * same sections take grid areas; the bench sits ahead of its DOM position, so
 * the "Skip to scenario" and "Back to the canvas" links bridge the gap.
 */

/* ------------------------------------------------------------------ layout */

.pss .pss-layout {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 1024px) {
  .pss .pss-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(320px, 28vw, 400px);
    grid-template-areas:
      "head bench"
      "stage bench"
      "result bench"
      "experiments bench"
      "saved bench"
      "analysis bench";
    gap: 1.5rem;
    align-items: start;
  }
  .pss .pss-head { grid-area: head; }
  .pss .pss-stage { grid-area: stage; }
  .pss .pss-result { grid-area: result; }
  .pss .pss-experiments { grid-area: experiments; }
  .pss .pss-saved { grid-area: saved; }
  .pss .pss-analysis { grid-area: analysis; }
}

.pss .pss-analysis {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Keyboard bridges: visually hidden until focused. */
.pss .pss-skip {
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  z-index: 60;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-accent);
  font-weight: 700;
  text-decoration: none;
}
.pss .pss-skip:focus {
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
}
/* "Back to the canvas" shows over the bench's heading (its containing block
 * is the bench), never over the result bar at the bench's foot. */
.pss .pss-skip--back {
  top: 0.5rem;
  left: 0.5rem;
}

/* ------------------------------------------------------------------ states */

/* docs/08 UI-21. These rules are unlayered, so they win over the layered
 * `input` utility (border, focus:border-accent, focus:outline-none); the
 * focus border is restated for that reason. The accent itself is a theme
 * token and is not overridden here. */

/* Fields: a border you can see against the card (about 3:1 in the light
 * theme; the theme's subtle border is 1.2:1), and placeholders at full
 * muted strength rather than Tailwind's half-transparent default. */
.pss .input {
  border-color: color-mix(in srgb, var(--color-text) 50%, transparent);
}
.pss .input:focus {
  border-color: var(--color-accent);
}
.pss input::placeholder,
.pss textarea::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

/* Focus: a 2 px accent ring, not a 1 px colour change. */
.pss input:focus-visible,
.pss select:focus-visible,
.pss textarea:focus-visible,
.pss button:focus-visible,
.pss summary:focus-visible,
.pss a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* A field the page will not send (UI-04): danger border and ring, and the
 * note under it (which joins the field's aria-describedby). */
.pss .input[aria-invalid="true"] {
  border-color: var(--color-danger);
}
.pss .input[aria-invalid="true"]:focus-visible {
  outline-color: var(--color-danger);
}
.pss .pss-field-error {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  line-height: 1rem;
  font-weight: 700;
  color: var(--color-danger);
}

/* Results that no longer match the form are dimmed until the next run. */
.pss .pss-stale {
  opacity: 0.45;
  transition: opacity 0.15s ease;
}
@media (prefers-reduced-motion: reduce) {
  .pss .pss-stale {
    transition: none;
  }
}

/* Disabled controls look disabled (the CSV button and Record looked live). */
.pss button:disabled,
.pss input:disabled,
.pss select:disabled,
.pss textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Table headers one step darker than muted. */
.pss .table-corp th {
  color: color-mix(in srgb, var(--color-text) 70%, var(--color-text-muted));
}

/* docs/08 UI-07: labels and headers in normal case. Uppercase turned μ into
 * a capital Mu (it reads as M) and "(kg)" into "(KG)". The unit is a quieter
 * suffix inside the label, so "(kg)" stays in the label's text. */
.pss .label,
.pss .table-corp th {
  text-transform: none;
  letter-spacing: normal;
}
.pss .pss-unit {
  font-weight: 400;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ----------------------------------------------------------- hint triggers */

/* docs/08 UI-05: the label, then its "About" button (a 28 px circle) at the
 * row's end, outside the label. */
.pss .pss-param-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.pss .pss-param-head .label {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
}
.pss .pss-help {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--color-text) 35%, transparent);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: help;
}
.pss .pss-help:hover,
.pss .pss-help[aria-expanded="true"] {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
/* The glyph in the bench caption ("Tap the ? beside any parameter"). */
.pss .pss-help--inline {
  width: 1.25rem;
  height: 1.25rem;
  font-size: 0.6875rem;
  vertical-align: text-bottom;
  cursor: default;
}

/* ----------------------------------------------------------- compare switch */

/* docs/08 UI-06: the native checkbox itself, drawn as a 44 × 28 px switch.
 * Never visually hidden (Selenium and `check "Compare with B"` need it
 * displayed); the label around it is the 44 px tap target. The thumb is a
 * background gradient, so no pseudo-element on an input is needed. */
.pss .pss-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  font-size: 0.875rem;
  cursor: pointer;
}
.pss input[role="switch"] {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 44px;
  height: 28px;
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--color-text) 50%, transparent);
  border-radius: 999px;
  background:
    radial-gradient(circle at 13px 50%, color-mix(in srgb, var(--color-text) 65%, transparent) 0 9px, transparent 10px),
    var(--color-surface);
  cursor: pointer;
}
.pss input[role="switch"]:checked {
  border-color: var(--color-accent);
  background:
    radial-gradient(circle at calc(100% - 13px) 50%, var(--color-surface) 0 9px, transparent 10px),
    var(--color-accent);
}
/* Forced colours drop backgrounds: fall back to the plain checkbox. */
@media (forced-colors: active) {
  .pss input[role="switch"] {
    -webkit-appearance: auto;
    appearance: auto;
    width: auto;
    height: auto;
  }
}

/* Engine warnings: body text with an amber bar, not amber text (3.19:1). */
.pss .pss-warnings ul {
  margin: 0.5rem 0 0;
  padding: 0.25rem 0 0.25rem 0.75rem;
  border-left: 4px solid var(--color-warning);
  list-style: none;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--color-text);
}
.pss .pss-warnings li + li {
  margin-top: 0.25rem;
}

/* The recording's progress, under Record while it runs. */
.pss .pss-export-progress {
  display: block;
  width: 100%;
  height: 0.5rem;
  margin-top: 0.5rem;
  accent-color: var(--color-accent);
}

/* ------------------------------------------------------------------ header */

/* Below 640 px the header is not a card: title and badge (36 px), chair and
 * units (44 px), About (44 px), two 8 px gaps = 140 px. */
.pss .pss-head {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
@media (min-width: 640px) {
  .pss .pss-head {
    padding: 1.5rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-surface) 100%);
    box-shadow: var(--shadow-md);
  }
}

.pss .pss-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 36px;
}
.pss .pss-title-row h1 {
  flex: none;
  margin: 0;
}

/* Two badge lines are reserved, so the first run (whose grade is longer) never
 * moves the page; the full grade is also written into About. */
.pss .pss-badge-slot {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 36px;
}
.pss .pss-badge {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  max-height: 36px;
  white-space: normal;
}
/* A grade short of calibrated is a caution, not a selected button: an amber
 * outline and a △ drawn by CSS. The glyph is generated content (with empty
 * alternative text), so the badge's text stays exactly the grade the tests
 * and screen readers read. */
.pss .pss-badge-caution {
  border: 1px solid var(--color-warning);
  background: var(--color-surface);
  color: var(--color-text);
}
.pss .pss-badge-caution::before {
  content: "△ ";
  content: "△ " / "";
  color: var(--color-warning);
}

.pss .pss-chair-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
}
.pss .pss-chair-select {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  min-height: 44px;
  text-overflow: ellipsis;
}
.pss .pss-units {
  display: flex;
  flex: none;
  align-items: center;
  white-space: nowrap;
}
.pss .pss-units button {
  min-height: 44px;
  border: 1px solid var(--color-border-subtle);
}
.pss .pss-units button:first-of-type {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.pss .pss-units button:last-of-type {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left-width: 0;
}
.pss .pss-units-label {
  margin-right: 0.5rem;
}
@media (min-width: 640px) {
  .pss .pss-chair-row {
    flex-wrap: wrap;
    column-gap: 0.75rem;
  }
  .pss .pss-chair-select {
    flex: 0 1 auto;
    max-width: 24rem;
  }
}

.pss .pss-about-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.25rem 0 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.25rem;
  color: var(--color-text-muted);
}

/* ------------------------------------------------------- disclosures */

.pss .pss-about > summary,
.pss .pss-fold > summary,
.pss .pss-section > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
}
.pss .pss-about > summary {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}
.pss .pss-fold > summary {
  font-weight: 700;
  font-size: 0.875rem;
}
.pss .pss-about > summary::-webkit-details-marker,
.pss .pss-fold > summary::-webkit-details-marker,
.pss .pss-section > summary::-webkit-details-marker,
.pss .pss-caption > summary::-webkit-details-marker {
  display: none;
}
.pss .pss-about > summary::before,
.pss .pss-fold > summary::before,
.pss .pss-section > summary::before {
  content: "";
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  margin: 0 0.3rem 0 0.1rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.pss .pss-about[open] > summary::before,
.pss .pss-fold[open] > summary::before,
.pss .pss-section[open] > summary::before {
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  .pss .pss-about > summary::before,
  .pss .pss-fold > summary::before,
  .pss .pss-section > summary::before {
    transition: none;
  }
}

/* Reference sections: a closed card is one 44 px row. */
.pss .pss-section {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}
.pss .pss-section[open] {
  padding-bottom: 1.5rem;
}

/* One-line captions with a "More" disclosure (UI-24). */
.pss .pss-caption > summary {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.75rem;
  line-height: 1.125rem;
  color: var(--color-text-muted);
}
.pss .pss-caption-line {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pss .pss-caption[open] > summary .pss-caption-line {
  white-space: normal;
}
.pss .pss-more {
  flex: none;
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.pss .pss-more::before {
  content: "More";
}
.pss .pss-caption[open] > summary .pss-more::before {
  content: "Less";
}
.pss .pss-caption > p {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  line-height: 1.125rem;
  color: var(--color-text-muted);
}
/* Body copy is at least 14 px on phones. */
@media (max-width: 639.98px) {
  .pss .pss-caption > summary,
  .pss .pss-caption > p,
  .pss .pss-caption-text,
  .pss .pss-about-body {
    font-size: 0.875rem;
    line-height: 1.25rem;
  }
}

/* ------------------------------------------------------------------- stage */

.pss .pss-canvas-card {
  position: relative;
}
/* A real button over the empty canvas; it hides after the first result. */
.pss .pss-empty-run {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  transform: translate(-50%, -50%);
  min-height: 44px;
  padding: 0.5rem 1.25rem;
  font-size: 1rem;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

.pss .pss-legend-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  margin-bottom: 0.5rem;
}
/* B over A below 768 px (docs/08 UI-11): card B never shows there, and the
 * A | B | Both switch keeps its place in the legend row at every state
 * (visibility, not display), so Compare never changes the stage's height. */
@media (max-width: 767px) {
  .pss .pss-stage-b {
    display: none !important;
  }
}
.pss .pss-canvas-card canvas {
  margin-inline: auto;
}
.pss .pss-view-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  visibility: hidden;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  overflow: hidden;
}
.pss .pss-view-toggle.is-shown {
  visibility: visible;
}
.pss .pss-view-toggle button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.6rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
}
.pss .pss-view-toggle button + button {
  border-left: 1px solid var(--color-border);
}
.pss .pss-view-toggle button[aria-pressed="true"] {
  color: var(--color-surface);
  background: var(--color-accent);
}
@media (min-width: 768px) {
  .pss .pss-view-toggle {
    display: none;
  }
}
.pss .pss-legend {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1rem;
  color: var(--color-text-muted);
}
.pss .pss-status {
  min-height: 2.5rem;
}

/* "↓ Back": shown after "See it ↑" until the operator scrolls. */
.pss .pss-back {
  position: fixed;
  z-index: 45;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
}

/* ------------------------------------------------------------- experiments */

.pss .pss-presets {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}
@media (min-width: 640px) {
  .pss .pss-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .pss .pss-presets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.pss .pss-preset {
  height: 100%;
}
@media (max-width: 1023.98px) {
  .pss .pss-preset-question {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }
}
@media (max-width: 639.98px) {
  .pss .pss-preset-question {
    font-size: 0.875rem;
    line-height: 1.25rem;
  }
}
/* The unavailable preset reads at full contrast; the dashed border says "not yet". */
.pss .pss-preset--off,
.pss .pss-preset--off:hover {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--color-text) 35%, transparent);
  cursor: not-allowed;
}

/* ---------------------------------------------------------- scenario bench */

.pss .pss-bench {
  position: relative;
}
.pss .pss-bench-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--color-border-subtle);
}
.pss .pss-bench-body {
  padding: 1rem 1.5rem 1.5rem;
}

/* --------------------------------------------------------- explained result */

.pss .pss-result-card {
  margin-top: 0.75rem;
}
.pss .pss-result-summary {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border-subtle);
}
.pss .pss-result-headline {
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.15;
  font-weight: 800;
  color: var(--color-text);
}
.pss .pss-result-headline span {
  margin-left: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
}
.pss .pss-result-change {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}
.pss .pss-result-compare {
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--color-accent);
  font: inherit;
  font-weight: 700;
}
.pss .pss-result-explanation {
  display: grid;
  gap: 0.875rem;
  margin-top: 0.875rem;
}
.pss .pss-result-explanation dt {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
}
.pss .pss-result-explanation dd {
  margin-top: 0.125rem;
}
.pss .pss-result-factor,
.pss .pss-result-link {
  display: inline;
  padding: 0;
  border: 0;
  border-bottom: 1px dotted currentColor;
  background: transparent;
  color: var(--color-accent);
  font: inherit;
  text-align: left;
}
.pss .pss-result-factor:hover,
.pss .pss-result-link:hover {
  border-bottom-style: solid;
}
.pss .pss-result-links {
  white-space: normal;
}
.pss [data-result-why],
.pss [data-result-lever] {
  overflow-wrap: anywhere;
}
.pss .pss-metric-group th {
  padding-top: 0.875rem;
  color: var(--color-text-muted);
  text-align: left;
}
.pss .pss-metric-extra,
.pss .pss-metric-turn {
  color: var(--color-text-muted);
  white-space: nowrap;
}
.pss tr[data-tone="good"] td[data-col="delta"] {
  color: var(--color-success);
}
.pss tr[data-tone="bad"] td[data-col="delta"] {
  color: var(--color-danger);
}

/* docs/08 3a: six subsystem groups, each a fieldset inside a responsive
 * disclosure whose summary is one live line (closed below 1,024 px). Each
 * parameter is one row: label and hint once, then the A field and, with
 * Compare on, the B field beside it; one range line. */
.pss .pss-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.pss .pss-group + .pss-group {
  border-top: 1px solid var(--color-border-subtle);
}
.pss .pss-group-fold > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-sizing: border-box;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  overflow: hidden;
  padding: 0.125rem 0;
  cursor: pointer;
  list-style: none;
}
.pss .pss-group-fold > summary::-webkit-details-marker {
  display: none;
}
.pss .pss-group-fold > summary::before {
  content: "";
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  margin: 0 0.3rem 0 0.1rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.pss .pss-group-fold[open] > summary::before {
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  .pss .pss-group-fold > summary::before {
    transition: none;
  }
}
.pss .pss-group-title {
  flex: none;
  font-weight: 700;
  font-size: 0.9375rem;
  white-space: nowrap;
}
.pss .pss-group-summary {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pss .pss-group-summary:not(:empty)::before {
  content: "· ";
}
/* A group holding an invalid field says so in its summary. */
.pss .pss-group-fold > summary[data-invalid] {
  box-shadow: inset 3px 0 0 var(--color-danger);
  padding-left: 0.5rem;
}
.pss .pss-group-fold > summary[data-invalid] .pss-group-summary {
  color: var(--color-danger);
  font-weight: 700;
}
.pss .pss-group-body {
  padding: 0 0 0.75rem;
}
/* A summary reads at 16 px on a phone (docs/08 §3.4 Capacity). */
@media (max-width: 639.98px) {
  .pss .pss-group-title,
  .pss .pss-group-summary {
    font-size: 1rem;
    line-height: 1.25rem;
  }
}
.pss .pss-row {
  padding: 0.375rem 0;
}
.pss .pss-row-cells {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}
.pss .pss-cols {
  display: none;
}
.pss .pss-bench.pss-compare-on .pss-row-cells,
.pss .pss-bench.pss-compare-on .pss-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.pss .pss-bench.pss-compare-on .pss-cols {
  display: grid;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
}
.pss .pss-bench:not(.pss-compare-on) .pss-cell--b {
  display: none;
}
/* B differs from A: its field is highlighted. */
.pss .pss-row.pss-diff .pss-cell--b .input {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
}

/* ------------------------------------------------------- physics modules */

/* docs/08 Batch 3b, docs/07 §4.2–§4.3. The Physics row: label and selector on
 * one line, the status (what each side runs) under it. */
/* Tight on purpose: the closed scenario must fit 560 px at 360 × 740 with
 * Compare on, in CI's wider fallback font too (docs/08 §3.4 Capacity). */
.pss .pss-physics-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.125rem 0.75rem;
  padding: 0 0 0.25rem;
  border-bottom: 1px solid var(--color-border-subtle);
}
.pss .pss-physics-label {
  flex: none;
  font-weight: 700;
  margin: 0;
}
.pss .pss-physics-select {
  flex: 1 1 10rem;
  min-width: 0;
  width: auto;
}
.pss .pss-physics-status {
  flex: 1 1 100%;
  min-width: 0;
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pss .pss-physics-status:empty {
  display: none;
}
.pss .pss-physics-missing {
  color: var(--color-text-muted);
}

/* A module row: title and hint, the A and B switches, then the v0.1 line
 * (off) or the chips (on), then its settings, collapsed to one line. */
.pss .pss-module {
  border-top: 1px dashed var(--color-border-subtle);
  margin-top: 0.25rem;
}
.pss .pss-module-title {
  font-weight: 700;
}
.pss .pss-module-off {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.25rem;
  color: var(--color-text-muted);
}
.pss .pss-module-status {
  margin-top: 0.25rem;
}
.pss .pss-module-state {
  margin: 0;
  min-width: 0;
  font-size: 0.8125rem;
  line-height: 1.25rem;
  overflow-wrap: anywhere;
}
.pss .pss-chip {
  display: inline-block;
  padding: 0 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--color-border-subtle);
  font-size: 0.75rem;
  line-height: 1.25rem;
  white-space: nowrap;
}
.pss .pss-chip[data-grade="measured"],
.pss .pss-chip[data-grade="manufacturer"],
.pss .pss-chip[data-grade="rule"] {
  border-color: var(--color-success);
}
.pss .pss-chip[data-grade="estimate"] {
  border-color: var(--color-warning);
}
.pss .pss-chip[data-grade="illustrative"] {
  border-style: dashed;
  border-color: var(--color-warning);
}
.pss .pss-module-headline {
  color: var(--color-text-muted);
}
/* Stored R-net profile: picker, Load, and the one-tap confirm, stacked in
 * the side's cell so Compare-off hides B and a 360 px screen does not scroll
 * sideways. The confirm wraps; the select cannot grow the column. */
.pss .pss-rnet-import {
  margin-top: 0.375rem;
  min-width: 0;
}
.pss .pss-rnet-import-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.375rem;
  min-width: 0;
}
.pss .pss-rnet-select,
.pss .pss-rnet-load,
.pss .pss-rnet-own {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
}
.pss .pss-rnet-own {
  height: auto;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
  line-height: 1.25rem;
}
.pss .pss-module-settings {
  margin-top: 0.25rem;
}
.pss .pss-module-settings > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.8125rem;
  color: var(--color-accent);
  cursor: pointer;
  list-style: none;
  overflow-wrap: anywhere;
}
.pss .pss-module-settings > summary::-webkit-details-marker {
  display: none;
}
.pss .pss-module-settings[open] > summary {
  color: var(--color-text-muted);
}
.pss .pss-module-uses {
  margin: 0 0 0.25rem;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.pss .pss-setting {
  padding-left: 0.75rem;
  border-left: 2px solid var(--color-border-subtle);
}
.pss .pss-cell-off {
  display: block;
  padding: 0.25rem 0;
  color: var(--color-text-muted);
}
.pss .pss-cell.pss-dormant .input {
  opacity: 0.55;
}
.pss .pss-dormant-note,
.pss .pss-cell-note {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  line-height: 1rem;
  color: var(--color-text-muted);
}
.pss .pss-cell.pss-superseded .input {
  opacity: 0.55;
  text-decoration: line-through;
}
/* A number list (the battery's five rest voltages): one row of small fields. */
.pss .pss-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(3.5rem, 1fr));
  gap: 0.25rem;
}

/* The Physics model section (docs/07 §4.9). */
.pss .pss-model-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}
.pss .pss-model-links a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  color: var(--color-accent);
  text-decoration: underline;
}
.pss .pss-model-research > summary {
  cursor: pointer;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-accent);
}
.pss .pss-model-modules {
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}
.pss .pss-model-module {
  padding: 0.5rem 0;
  border-top: 1px solid var(--color-border-subtle);
}
.pss .pss-model-module p {
  margin: 0.125rem 0;
}
.pss .pss-model-tag,
.pss .pss-model-sides {
  margin-left: 0.375rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.pss .pss-model-tag--planned {
  font-style: italic;
}
.pss .pss-model-residual > summary {
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--color-accent);
}
.pss .pss-model-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}
.pss .pss-model-used {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.pss .pss-model-outdated {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
}
.pss .pss-result-physics {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.5rem;
}
.pss .pss-result-side {
  font-weight: 700;
}
@media (pointer: coarse), (max-width: 639.98px) {
  .pss .pss-model-links a {
    min-height: 44px;
  }
}

/* The result bar: Run, two result lines of fixed height, "See it ↑". */
.pss .pss-runbar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-subtle);
}
.pss .pss-run {
  flex: none;
  min-height: 44px;
  min-width: 4.5rem;
  font-size: 1rem;
}
.pss .pss-run:disabled,
.pss .pss-empty-run:disabled {
  opacity: 0.6;
  cursor: progress;
}
.pss .pss-runbar-text {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.pss .pss-runbar-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pss .pss-runbar-line--1 {
  height: 1.375rem;
  line-height: 1.375rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}
.pss .pss-runbar-line--2 {
  height: 1.125rem;
  line-height: 1.125rem;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}
.pss .pss-runbar[data-state="error"] .pss-runbar-line--1 {
  color: var(--color-danger);
}
.pss .pss-see {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

/* Below 1,024 px the bar is fixed at the bottom of the screen: 64 px plus the
 * safe-area inset. The page reserves room for it, and every control keeps
 * clear of it when focused or scrolled to. */
@media (max-width: 1023.98px) {
  .pss {
    padding-bottom: calc(5rem + env(safe-area-inset-bottom));
  }
  .pss .pss-runbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    box-sizing: border-box;
    height: calc(64px + env(safe-area-inset-bottom));
    padding-bottom: calc(0.625rem + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 14px color-mix(in srgb, #000 12%, transparent);
  }
  .pss input,
  .pss select,
  .pss textarea,
  .pss button,
  .pss summary,
  .pss a {
    scroll-margin-bottom: 6rem;
  }
  .pss .pss-back {
    right: 1rem;
    bottom: calc(64px + env(safe-area-inset-bottom) + 0.75rem);
  }
}

/* From 1,024 px the scenario is a sticky bench in the right column: the
 * parameters scroll inside it and the bar is its non-scrolling foot, so
 * nothing scrolls under the bar. --pss-bench-reserve (set by the controller
 * from where the layout starts) keeps the bar inside the first screen. */
@media (min-width: 1024px) {
  .pss .pss-bench {
    grid-area: bench;
    position: sticky;
    top: 1rem;
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - var(--pss-bench-reserve, 6rem));
  }
  .pss .pss-bench-head {
    flex: none;
  }
  .pss .pss-bench-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .pss .pss-runbar {
    flex: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
  }
  /* Under the bench (left set by the controller), below the bar it was asked from. */
  .pss .pss-back {
    bottom: 1rem;
  }
}

/* ------------------------------------------------------------------- touch */

/* docs/08 UI-06: on a touch screen or a phone-width window, 16 px text in
 * fields (below that iOS Safari zooms on focus and stays zoomed) and 44 px
 * targets. The hint trigger stays a 28 px circle with a 44 px hit area, its
 * row tall enough that the hit area covers no neighbour. */
@media (pointer: coarse), (max-width: 639.98px) {
  .pss .input,
  .pss select,
  .pss textarea {
    min-height: 44px;
    font-size: 16px;
    line-height: 1.375;
  }
  .pss button:not(.pss-help),
  .pss .btn-primary,
  .pss .btn-secondary,
  .pss summary {
    min-height: 44px;
  }
  .pss a.btn-primary,
  .pss a.btn-secondary {
    display: inline-flex;
    align-items: center;
  }
  .pss .pss-caption > summary {
    align-items: center;
  }
  .pss input[type="range"] {
    height: 44px;
  }
  .pss .pss-param-head {
    min-height: 44px;
    margin-bottom: 0;
  }
  .pss .pss-help::after {
    content: "";
    position: absolute;
    inset: -8px;
  }
  .pss .pss-help--inline::after {
    content: none;
  }
}

/* ------------------------------------------------------ compare on a phone */

/* docs/08 UI-08: below 640 px each compare row is a block, the metric's
 * name, then "A 5.68 · B 5.51 · Δ −0.17 m/s" on one line (the unit once, on
 * the difference). renderMetrics() marks the cells with data-col, a row with
 * a difference with data-delta, and wraps each value's unit in
 * .pss-cell-unit; the thead stays for screen readers. */
@media (max-width: 639.98px) {
  .pss .pss-result {
    padding: 0.5625rem;
  }
  .pss .pss-result-card {
    margin-top: 0.25rem;
  }
  .pss .pss-result-summary {
    padding-bottom: 0.25rem;
  }
  .pss .pss-result-explanation {
    gap: 0.25rem;
    margin-top: 0.25rem;
  }
  .pss .pss-result-explanation dd {
    font-size: 0.875rem;
    line-height: 1.125rem;
  }
  .pss .pss-metrics--compare,
  .pss .pss-metrics--compare tbody,
  .pss .pss-metrics--compare tr {
    display: block;
    width: 100%;
  }
  .pss .pss-metrics--compare thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .pss .pss-metrics--compare tr {
    padding: 6px 0;
    border-top: 1px solid var(--color-border-subtle);
  }
  /* One tbody per group: only the table's first row loses its rule. */
  .pss .pss-metrics--compare tbody:first-of-type tr:first-child {
    border-top: 0;
  }
  /* Each value is an unbreakable inline block; the line may wrap between
   * them on a narrow screen rather than run off it. */
  .pss .pss-metrics--compare td {
    display: inline-block;
    padding: 0;
    border: 0;
    white-space: nowrap;
    text-align: left;
  }
  .pss .pss-metrics--compare td[data-col="metric"] {
    display: block;
    padding: 0 6px 2px;
    white-space: normal;
  }
  .pss .pss-metrics--compare td[data-col="a"] {
    padding-left: 6px;
  }
  .pss .pss-metrics--compare td[data-col="b"],
  .pss .pss-metrics--compare td[data-col="delta"] {
    padding-left: 0.4em;
  }
  .pss .pss-metrics--compare td[data-col="a"]::before { content: "A "; color: var(--color-text-muted); }
  .pss .pss-metrics--compare td[data-col="b"]::before { content: "· B "; color: var(--color-text-muted); }
  .pss .pss-metrics--compare td[data-col="delta"]::before { content: "· Δ "; color: var(--color-text-muted); }
  .pss .pss-metrics--compare td[data-col="delta"]:empty {
    display: none;
  }
  /* Only where the difference shows the unit: a row without one (one side
   * made no contact) keeps it on A and B. */
  .pss .pss-metrics--compare tr[data-delta] td[data-col="a"] .pss-cell-unit,
  .pss .pss-metrics--compare tr[data-delta] td[data-col="b"] .pss-cell-unit {
    display: none;
  }
  /* Keep UI-08's A · B · Δ phone row on one line. The result card carries
   * the headline's second unit and percentage; the full table keeps those
   * extras from 640 px upward. */
  .pss .pss-metrics--compare .pss-metric-extra {
    display: none;
  }
}
