/* Best-Fit Model Finder: the Best-Fit Model Finder tab in the Engineering & Statistics Calculator.
 Light tokens on #bfm-tool; dark tokens under html[data-theme="dark"]. */
/* Layout: a workbench. Data in, leaderboard, then one selected model in detail.
   Light values here; dark values at the end of this file. */
#bfm-tool {
  --bfm-bg: #eef3f7; --bfm-panel: #ffffff; --bfm-panel2: #e3ecf2; --bfm-ink: #0b1b2e; --bfm-muted: #44586b;
  --bfm-line: #c3d2de; --bfm-grid: #dbe5ec; --bfm-accent: #0b6782; --bfm-accent-ink: #ffffff; --bfm-signal: #8a4f00;
  --bfm-good: #1c6a44; --bfm-bad: #a3352a; --bfm-point: #0b6782; --bfm-fit: #8a4f00; --bfm-alt: #6b5ba8;
  --bfm-display: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --bfm-body: 'IBM Plex Sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --bfm-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  color-scheme: light dark; background: var(--bfm-bg); color: var(--bfm-ink); font-family: var(--bfm-body);
  font-size: 16px; line-height: 1.6; padding-bottom: 28px;
}
#bfm-tool *, #bfm-tool *::before, #bfm-tool *::after { box-sizing: border-box; }
#bfm-tool [hidden] { display: none !important; }
.bfm-wrap { max-width: 1200px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
#bfm-tool h1, #bfm-tool h2, #bfm-tool h3 { font-family: var(--bfm-display); color: var(--bfm-ink); line-height: 1.12; text-wrap: balance; }
#bfm-tool h1 { font-size: clamp(2.2rem, 4.8vw, 3.3rem); margin: 0 0 10px; }
#bfm-tool h2 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin: 0 0 10px; }
#bfm-tool h3 { font-size: 1.3rem; margin: 18px 0 8px; }
#bfm-tool a { color: var(--bfm-accent); }
#bfm-tool :focus-visible { outline: 3px solid var(--bfm-accent); outline-offset: 2px; }
#bfm-tool code, .bfm-mono { font-family: var(--bfm-mono); font-size: .9em; }
.bfm-eyebrow { font-family: var(--bfm-mono); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--bfm-accent); margin: 0 0 8px; }
.bfm-hero { padding-block: 36px 22px; border-bottom: 1px solid var(--bfm-line); }
.bfm-lead { max-width: 78ch; font-size: 1.08rem; margin: 0 0 12px; }
.bfm-badge { display: inline-block; font-family: var(--bfm-mono); font-size: .75rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--bfm-signal); color: var(--bfm-signal); vertical-align: middle; margin-left: 8px; }
.bfm-section { padding-block: 30px 6px; }
.bfm-panel { background: var(--bfm-panel); color: var(--bfm-ink); border: 1px solid var(--bfm-line); border-radius: 10px; padding: 16px; }
.bfm-grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.bfm-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.bfm-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.bfm-field { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--bfm-muted); min-width: 0; }
.bfm-field input, .bfm-field select, .bfm-field textarea { font: 500 .95rem var(--bfm-body); padding: 7px 9px; border-radius: 6px; border: 1px solid var(--bfm-line); background: var(--bfm-panel); color: var(--bfm-ink); min-height: 40px; }
.bfm-field textarea { font-family: var(--bfm-mono); font-size: .85rem; min-height: 150px; resize: vertical; width: 100%; }
.bfm-field input[type=number] { width: 130px; font-family: var(--bfm-mono); }
.bfm-check { display: flex; gap: 8px; align-items: center; font-size: .92rem; color: var(--bfm-ink); }
.bfm-btn { font: 600 .92rem var(--bfm-body); border-radius: 8px; padding: 9px 14px; min-height: 40px; cursor: pointer; border: 1px solid var(--bfm-accent); background: var(--bfm-accent); color: var(--bfm-accent-ink); }
.bfm-btn.bfm-ghost { background: transparent; color: var(--bfm-accent); }
.bfm-btn:disabled { opacity: .55; cursor: not-allowed; }
.bfm-note { font-size: .85rem; color: var(--bfm-muted); margin: 6px 0 0; }
.bfm-error { color: var(--bfm-bad); font-weight: 600; }
.bfm-callout { border-left: 4px solid var(--bfm-signal); background: var(--bfm-panel); color: var(--bfm-ink); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 12px 0; }
.bfm-callout.is-good { border-left-color: var(--bfm-good); }
.bfm-callout ul { margin: 6px 0 0; padding-left: 1.2em; }
.table-scroll { overflow-x: auto; border: 1px solid var(--bfm-line); border-radius: 8px; background: var(--bfm-panel); margin: 10px 0; }
.bfm-table { border-collapse: collapse; width: 100%; font-size: .88rem; color: var(--bfm-ink); background: var(--bfm-panel); }
.bfm-table caption { text-align: left; padding: 8px 10px 4px; font-weight: 600; color: var(--bfm-ink); }
.bfm-table th, .bfm-table td { padding: 7px 10px; border-bottom: 1px solid var(--bfm-line); text-align: left; vertical-align: top; white-space: nowrap; }
.bfm-table td.bfm-wrapcell { white-space: normal; min-width: 220px; }
.bfm-table thead th { font-family: var(--bfm-mono); font-weight: 500; font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; color: var(--bfm-muted); background: var(--bfm-panel2); position: sticky; top: 0; }
#bfm-tool .bfm-table tbody th { background: transparent; color: var(--bfm-ink); font-family: var(--bfm-body); font-size: .88rem; font-weight: 600; text-transform: none; letter-spacing: 0; }
.bfm-table tbody tr.is-selected { background: var(--bfm-panel2); box-shadow: inset 4px 0 0 var(--bfm-accent); }
.bfm-num { font-family: var(--bfm-mono); font-variant-numeric: tabular-nums; text-align: right !important; }
.bfm-tag { display: inline-block; font-size: .74rem; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; margin: 0 4px 2px 0; }
.bfm-tag.is-good { color: var(--bfm-good); }
.bfm-tag.is-bad { color: var(--bfm-bad); border-style: dashed; }
.bfm-pick { font: 600 .8rem var(--bfm-body); padding: 4px 10px; border-radius: 6px; border: 1px solid var(--bfm-accent); background: transparent; color: var(--bfm-accent); cursor: pointer; min-height: 30px; }
.bfm-pick[aria-pressed="true"] { background: var(--bfm-accent); color: var(--bfm-accent-ink); }
.bfm-plot { margin: 0; background: var(--bfm-panel); border: 1px solid var(--bfm-line); border-radius: 8px; padding: 6px; min-width: 0; color: var(--bfm-ink); }
.bfm-plot figcaption { font-family: var(--bfm-mono); font-size: .74rem; color: var(--bfm-muted); padding: 4px 6px 0; }
.bfm-plot svg { width: 100%; height: auto; display: block; }
.bfm-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--bfm-muted); padding: 2px 6px; list-style: none; margin: 0; }
.bfm-legend span { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--bfm-fit); vertical-align: middle; margin-right: 5px; }
.bfm-legend .is-alt { border-top: 2px dashed var(--bfm-alt); }
.bfm-axis { stroke: var(--bfm-muted); stroke-width: 1; }
.bfm-gridline { stroke: var(--bfm-grid); stroke-width: 1; }
.bfm-tick { fill: var(--bfm-muted); font-family: var(--bfm-mono); font-size: 10px; }
.bfm-axlabel { fill: var(--bfm-ink); font-family: var(--bfm-body); font-size: 11px; }
.bfm-pt { fill: var(--bfm-point); fill-opacity: .75; stroke: var(--bfm-panel); stroke-width: .8; }
.bfm-fitline { fill: none; stroke: var(--bfm-fit); stroke-width: 2.6; }
.bfm-altline { fill: none; stroke: var(--bfm-alt); stroke-width: 1.8; stroke-dasharray: 6 4; }
.bfm-zero { stroke: var(--bfm-fit); stroke-width: 1.4; stroke-dasharray: 5 4; }
.bfm-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; margin: 10px 0 0; }
.bfm-stat { background: var(--bfm-panel); border: 1px solid var(--bfm-line); border-radius: 8px; padding: 8px 12px; }
.bfm-stat dt { font-family: var(--bfm-mono); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--bfm-muted); }
.bfm-stat dd { margin: 2px 0 0; font-family: var(--bfm-mono); font-size: 1rem; color: var(--bfm-ink); font-variant-numeric: tabular-nums; word-break: break-word; }
.bfm-eq { font-family: var(--bfm-mono); background: var(--bfm-panel2); color: var(--bfm-ink); padding: 8px 12px; border-radius: 6px; overflow-x: auto; white-space: nowrap; }
.bfm-steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.bfm-steps li { background: var(--bfm-panel); border: 1px solid var(--bfm-line); border-radius: 8px; padding: 10px 12px; font-size: .92rem; }
.bfm-steps li::before { counter-increment: s; content: counter(s); font-family: var(--bfm-display); font-weight: 700; font-size: 1.4rem; color: var(--bfm-accent); margin-right: 8px; }
.bfm-formula { background: var(--bfm-panel); color: var(--bfm-ink); border: 1px solid var(--bfm-line); border-radius: 8px; padding: 8px 12px; margin: 10px 0; overflow-x: auto; max-width: 78ch; }
.bfm-prose { max-width: 78ch; }
details.bfm-details { margin: 10px 0; }
details.bfm-details summary { cursor: pointer; font-weight: 600; }
@media (max-width: 900px) { .bfm-grid2, .bfm-grid3, .bfm-steps { grid-template-columns: minmax(0, 1fr); } }
@media (prefers-reduced-motion: reduce) { #bfm-tool * { transition: none !important; animation: none !important; } }

html[data-theme="dark"] #bfm-tool {
--bfm-bg: #071120; --bfm-panel: #0d1b30; --bfm-panel2: #132743; --bfm-ink: #e4eef6; --bfm-muted: #a3b8cb;
--bfm-line: #26405f; --bfm-grid: #172b47; --bfm-accent: #3fb6d8; --bfm-accent-ink: #04121f; --bfm-signal: #f0b35a;
--bfm-good: #63d39c; --bfm-bad: #f3907e; --bfm-point: #3fb6d8; --bfm-fit: #f0b35a; --bfm-alt: #b9a8f0;
color-scheme: dark;
}

/* Embedded in the Engineering & Statistics Calculator: inherit its fonts and ground. */
#bfm-tool.bfm-embedded { --bfm-display: var(--calc-disp, 'Barlow Condensed', 'Arial Narrow', sans-serif); background: transparent; padding-bottom: 0; }
#bfm-tool.bfm-embedded .bfm-wrap { max-width: none; padding-left: 0; padding-right: 0; }
#bfm-tool.bfm-embedded .bfm-section:first-child { padding-top: 6px; }
#bfm-tool #bfm-best-reasons { padding-left: 1.25em; margin: 10px 0; }

/* Live transformation explorer */
.bfm-xcontrols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 24px; }
.bfm-xcontrols .bfm-row { grid-column: 1 / -1; }
.bfm-rungs { border: 0; padding: 0; margin: 0 0 6px; min-width: 0; }
.bfm-rungs legend { font-family: var(--bfm-mono); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--bfm-muted); padding: 0; margin-bottom: 6px; }
.bfm-rung-set { display: flex; flex-wrap: wrap; gap: 6px; }
.bfm-rung { position: relative; }
.bfm-rung input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.bfm-rung span { display: inline-block; min-width: 54px; min-height: 36px; text-align: center; padding: 6px 10px; border: 1px solid var(--bfm-line); border-radius: 6px; font-family: var(--bfm-mono); font-size: .88rem; background: var(--bfm-panel); color: var(--bfm-ink); cursor: pointer; }
.bfm-rung input:checked + span { background: var(--bfm-accent); border-color: var(--bfm-accent); color: var(--bfm-accent-ink); font-weight: 500; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.bfm-rung input:focus-visible + span { outline: 3px solid var(--bfm-accent); outline-offset: 2px; }
.bfm-verdict { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; padding: 6px 12px; border-radius: 999px; border: 2px solid currentColor; background: var(--bfm-panel); }
.bfm-verdict.is-good { color: var(--bfm-good); }
.bfm-verdict.is-bad { color: var(--bfm-bad); border-style: dashed; }
@media (max-width: 900px) { .bfm-xcontrols { grid-template-columns: minmax(0, 1fr); } }
