/* Throttle-sweep simulation chart (partials/thrust-sim.njk + assets/js/thrust-sim.js).
   Loaded in the head only on pages whose features have a `chart:` (base.njk).
   Plot geometry comes from the template as unitless percentages: --x (0–100, left → right) and
   --y (0–100, bottom → top). Dataviz specs: 2 px lines, 8 px dots with a 2 px surface ring,
   hairline solid grid, text in text tokens (never the series colour), tabular figures in
   columns and axes. Mobile first. */

/* The data table scrolls inside its own box; min-width 0 keeps its width from pushing the
   feature column past the screen (grid items default to their content's min width). */
.feature__media--chart { min-width: 0; }
.feature__frame.thrust-sim {
  aspect-ratio: auto;
  overflow: visible;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  padding: var(--space-4);
  --surface: var(--color-bg-secondary);
}
@media (min-width: 640px) {
  .feature__frame.thrust-sim { padding: var(--space-5); }
}

/* -------------------------------------------------------------- Head */
.thrust-sim__head { display: grid; gap: var(--space-2); }
.thrust-sim__kicker, .thrust-sim__title { margin: 0; }
.thrust-sim__title {
  font-family: var(--font-family-display);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  line-height: 1.25;
  color: var(--color-text-primary);
  text-wrap: balance;
}
ul.thrust-sim__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* Series key: a short stroke of the series colour before the name (legend, readout). */
.thrust-sim__key { display: inline-flex; align-items: center; gap: var(--space-2); }
.thrust-sim__key::before {
  content: "";
  flex: none;
  width: 1rem;
  height: 2px;
  background: var(--key, var(--color-chart-compare));
}
.thrust-sim__key--morph { --key: var(--color-chart-highlight); }
.thrust-sim__key--fixed { --key: var(--color-chart-compare); }

/* -------------------------------------------------------------- Plot */
.thrust-sim__chart { display: grid; gap: var(--space-2); }
.thrust-sim__axis-title { margin: 0; }
.thrust-sim__axis-title--x { text-align: right; }

.thrust-sim__plot {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: var(--space-2);
  row-gap: var(--space-2);
  margin-top: var(--space-5); /* room for the top direct label */
}
.thrust-sim__y, .thrust-sim__x {
  position: relative;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-tertiary);
  line-height: 1;
}
.thrust-sim__y { grid-column: 1; grid-row: 1; min-width: 4.5ch; }
.thrust-sim__y span {
  position: absolute;
  right: 0;
  top: calc((100 - var(--y)) * 1%);
  translate: 0 -50%;
}
.thrust-sim__x { grid-column: 2; grid-row: 2; height: 1em; }
.thrust-sim__x span {
  position: absolute;
  left: calc(var(--x) * 1%);
  translate: -50% 0;
  white-space: nowrap;
}
.thrust-sim__x span:first-child { translate: 0 0; }

.thrust-sim__area {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  aspect-ratio: 4 / 3;
  touch-action: pan-y; /* horizontal drags pick a stop; vertical ones still scroll */
}
@media (min-width: 640px) {
  .thrust-sim__area { aspect-ratio: 16 / 10; }
}

.thrust-sim__grid {
  position: absolute;
  left: 0;
  right: 0;
  top: calc((100 - var(--y)) * 1%);
  height: 1px;
  background: var(--color-chart-grid);
}
.thrust-sim__cross {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--x) * 1%);
  width: 1px;
  background: var(--color-border-input);
}

/* Lines: revealed left → right by --reveal (0–100) during the sweep. */
.thrust-sim__lines {
  position: absolute;
  inset: 0;
  clip-path: inset(-0.5rem calc((100 - var(--reveal, 100)) * 1%) -0.5rem -0.5rem);
}
.thrust-sim__lines svg { display: block; width: 100%; height: 100%; overflow: visible; }
.thrust-sim__line {
  fill: none;
  stroke-width: 2px;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.thrust-sim__line--morph { stroke: var(--color-chart-highlight); }
.thrust-sim__line--fixed { stroke: var(--color-chart-compare); }

.thrust-sim__dot {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc((100 - var(--y)) * 1%);
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  translate: -50% -50%;
  background: var(--key);
  box-shadow: 0 0 0 2px var(--surface); /* surface ring, not a shadow */
  transition: scale var(--duration-fast) var(--easing-default), opacity var(--duration-fast) var(--easing-default);
}
.thrust-sim__dot--morph { --key: var(--color-chart-highlight); z-index: 1; }
.thrust-sim__dot--fixed { --key: var(--color-chart-compare); }
.thrust-sim__dot.is-active { scale: 1.5; }
.thrust-sim__dot.is-off { opacity: 0; }

/* Direct labels above each series' highest point. */
.thrust-sim__tag {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc((100 - var(--y)) * 1%);
  translate: -50% calc(-100% - 0.625rem);
  font-size: var(--font-size-xs);
  line-height: 1;
  white-space: nowrap;
  color: var(--color-text-secondary);
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--easing-default);
}
.thrust-sim__tag.is-off { opacity: 0; }

/* ----------------------------------------------------------- Readout */
.thrust-sim__readout {
  display: grid;
  gap: var(--space-4);
  padding-top: var(--space-4);
  border-top: var(--border-width-hairline) solid var(--color-border-primary);
}
.thrust-sim__now, .thrust-sim__power-line {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.thrust-sim__seg { white-space: nowrap; }
.thrust-sim__seg b {
  font-family: var(--font-family-mono);
  font-weight: var(--font-weight-medium);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
}
.thrust-sim__now { font-size: var(--font-size-base); }
.thrust-sim__power { display: grid; gap: var(--space-2); }
.thrust-sim__power-title { margin: 0; }

/* Power bars: one per propeller, 0–200 hp; the engine's available power is a mark on each. */
.thrust-sim__bars {
  padding-top: var(--space-4); /* room for the "Engine" label above the first mark */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2) var(--space-3);
}
.thrust-sim__bar-name { font-size: var(--font-size-xs); color: var(--color-text-secondary); white-space: nowrap; }
.thrust-sim__bar {
  position: relative;
  display: block;
  height: 0.625rem;
  background: var(--color-bg-tertiary);
}
.thrust-sim__fill {
  display: block;
  height: 100%;
  background: var(--key);
  transform-origin: left center;
  scale: calc(var(--w) / 100) 1;
  transition: scale var(--duration-normal) var(--easing-out);
}
.thrust-sim__bar--morph { --key: var(--color-chart-highlight); }
.thrust-sim__bar--fixed { --key: var(--color-chart-compare); }
.thrust-sim__engine-label {
  position: absolute;
  bottom: calc(100% + 0.125rem);
  left: 50%;
  translate: -50% 0;
  font-size: var(--font-size-xs);
  line-height: 1;
  color: var(--color-text-secondary);
  white-space: nowrap;
}
.thrust-sim__engine {
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  left: calc(var(--w) * 1%);
  width: 2px;
  translate: -1px 0;
  background: var(--color-chart-limit);
  transition: left var(--duration-normal) var(--easing-out);
}

/* ---------------------------------------------------------- Controls */
.thrust-sim__controls {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
}
/* Phones: label above the throttle; from 640 px beside it. */
.thrust-sim__throttle {
  flex: 1;
  min-width: 0;
  display: grid;
  align-items: center;
  column-gap: var(--space-3);
}
.thrust-sim__ends {
  margin-top: var(--space-2); /* clear of the throttle's focus ring */
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  white-space: nowrap;
}
@media (min-width: 640px) {
  .thrust-sim__throttle { grid-template-columns: auto minmax(0, 1fr); }
  .thrust-sim__ends { grid-column: 2; }
}
.thrust-sim__range {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: var(--tap-target-min);
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.thrust-sim__range::-webkit-slider-runnable-track { height: 2px; background: var(--color-border-input); }
.thrust-sim__range::-moz-range-track { height: 2px; background: var(--color-border-input); }
.thrust-sim__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 0.875rem;
  height: 1.75rem;
  margin-top: calc(-0.875rem + 1px);
  border-radius: var(--border-radius-sm);
  background: var(--color-accent-primary);
  box-shadow: 0 0 0 2px var(--surface);
}
.thrust-sim__range::-moz-range-thumb {
  width: 0.875rem;
  height: 1.75rem;
  border: 0;
  border-radius: var(--border-radius-sm);
  background: var(--color-accent-primary);
  box-shadow: 0 0 0 2px var(--surface);
}
.thrust-sim__range:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.thrust-sim__run svg { display: none; }
.thrust-sim__run[data-mode="replay"] .icon-replay,
.thrust-sim__run[data-mode="pause"] .icon-pause,
.thrust-sim__run[data-mode="play"] .icon-play { display: block; }

/* -------------------------------------------------------- Data table */
.thrust-sim__data { border-top: var(--border-width-hairline) solid var(--color-border-primary); }
.thrust-sim__summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target-min);
  cursor: pointer;
  list-style: none;
  color: var(--color-text-secondary);
}
.thrust-sim__summary::-webkit-details-marker { display: none; }
.thrust-sim__summary::before {
  content: "";
  width: 0;
  height: 0;
  border-block: 0.3125rem solid transparent;
  border-inline-start: 0.4375rem solid currentColor;
  transition: rotate var(--duration-fast) var(--easing-default);
}
.thrust-sim__data[open] > .thrust-sim__summary::before { rotate: 90deg; }
.thrust-sim__summary:hover { color: var(--color-text-primary); }
.thrust-sim__summary:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.thrust-sim__table-wrap { overflow-x: auto; padding-bottom: var(--space-2); }
.thrust-sim__table-wrap:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.thrust-sim__table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}
.thrust-sim__table-title {
  margin: 0 0 var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.thrust-sim__table th, .thrust-sim__table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-width-hairline) solid var(--color-border-primary);
  text-align: right;
  vertical-align: bottom;
}
.thrust-sim__table thead th {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1.3;
  color: var(--color-text-tertiary);
}
.thrust-sim__table thead th[scope="colgroup"] { text-align: center; color: var(--color-text-secondary); }
.thrust-sim__table td, .thrust-sim__table tbody th {
  font-family: var(--font-family-mono);
  font-weight: var(--font-weight-normal);
  color: var(--color-text-primary);
}
.thrust-sim__table th:first-child, .thrust-sim__table td:first-child { padding-left: 0; }
.thrust-sim__table th:last-child, .thrust-sim__table td:last-child { padding-right: 0; }

/* ----------------------------------------------------------- Caption */
.thrust-sim__caption {
  margin-top: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
  max-width: 60ch;
}

@media (prefers-reduced-motion: reduce) {
  .thrust-sim__dot, .thrust-sim__tag, .thrust-sim__fill, .thrust-sim__engine, .thrust-sim__summary::before { transition: none; }
}

/* Printed before the sweep ran: show the whole chart (beats the script's inline state). */
@media print {
  .thrust-sim__lines { clip-path: none !important; }
  .thrust-sim__dot.is-off, .thrust-sim__tag.is-off { opacity: 1 !important; }
  .thrust-sim__controls { display: none !important; }
}
