/* Billy: a scorebook ledger. Paper, ink, one grass accent for action and gain, brick for loss.
   Type scale (rem): xs .75 · sm .875 · md 1 · lg 1.125 · xl 1.5 · 2xl 2.5. Spacing: 4 8 12 16 24 32 48. */
:root {
  --bar-h: 56px; --panel-w: 320px; --wrap: 1280px; --gutter: 20px;
  --paper: #f8f5ee; --ink: #15140f; --ink-2: #57554a; --rule: #d3cfc1; --rule-2: #e8e5da; --field: #fff;
  --grass: #1f6b3a; --grass-2: #dcebe0; --grass-3: #27824a; --brick: #9a3b22; --brick-2: #f4e5df; --gold: #7a5200; --gold-2: #f9eecf;
  --cover: #15140f; --cover-text: #f8f5ee; --cover-muted: #b8b4a6; --cover-rule: #6d6a5b; --cover-2: #45433a;   /* the binder: the sticky control bar */
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%2315140f' stroke-width='1.6'/></svg>");
}
* { box-sizing: border-box; }
html { color-scheme: light; scroll-padding-top: calc(var(--bar-h) + 16px); }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
::selection { background: var(--grass); color: var(--field); }
:focus-visible { outline: 2px solid var(--grass); outline-offset: 2px; border-radius: 2px; }
#results:focus { outline: none; }
#results, .explain, .whatif, .compare > article { scroll-margin-top: calc(var(--bar-h) + 16px); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.up { color: var(--grass); font-weight: 600; }
.down { color: var(--brick); font-weight: 600; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .18em; }
h1, h2 { margin: 0; text-wrap: balance; }
small { font-weight: 400; color: var(--ink-2); }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- masthead: scrolls away ---------- */
.masthead { border-bottom: 2px solid var(--ink); }
.masthead .wrap { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 28px; align-items: baseline; padding-top: 22px; padding-bottom: 18px; }
.brand { grid-row: 1 / 3; align-self: start; font-weight: 700; font-size: 2.5rem; line-height: 1; letter-spacing: -.03em; text-decoration: none; color: var(--ink); }
.tagline { margin: 0; font-size: 1.125rem; font-weight: 500; line-height: 1.35; letter-spacing: -.01em; text-wrap: pretty; max-width: 76ch; }
.hint { margin: 0; font-size: .875rem; color: var(--ink-2); max-width: 70ch; text-wrap: pretty; }

/* ---------- the bar: team, split, Calculate; sticky, in ink ---------- */
.bar { position: sticky; top: 0; z-index: 20; background: var(--cover); color: var(--cover-text); }
.bar .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding-top: 8px; padding-bottom: 8px; }
.bar :focus-visible { outline-color: var(--cover-text); }
.controls { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
select { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--rule); border-radius: 4px; padding: 8px 34px 8px 12px; appearance: none;
  background-image: var(--chevron); background-repeat: no-repeat; background-position: right 12px center; }
select:hover { border-color: var(--ink-2); }
.bar select { flex: 1 1 220px; max-width: 360px; min-width: 0; border-color: var(--field); font-weight: 500; }
.seg { display: flex; border: 0; padding: 0; margin: 0; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg span { display: block; padding: 8px 12px; border: 1px solid var(--cover-rule); color: var(--cover-text); cursor: pointer; white-space: nowrap; font-weight: 500; transition: background .15s, color .15s; }
.seg label:first-of-type span { border-radius: 4px 0 0 4px; }
.seg label:last-of-type span { border-radius: 0 4px 4px 0; margin-left: -1px; }
.seg span:hover { border-color: var(--cover-muted); position: relative; }
.seg input:checked + span { background: var(--paper); color: var(--ink); border-color: var(--paper); position: relative; }
.seg input:focus-visible + span { outline: 2px solid var(--cover-text); outline-offset: 2px; position: relative; z-index: 1; }
button { font: inherit; cursor: pointer; }
.primary { background: var(--grass); color: var(--field); border: 0; border-radius: 4px; padding: 9px 18px; font-weight: 600; white-space: nowrap; transition: transform .25s var(--ease), background .2s; }
.primary:hover { background: var(--grass-3); }
.primary:active { transform: translateY(1px); }
.primary:disabled { background: var(--cover-2); color: var(--cover-muted); cursor: progress; transform: none; }
#status { display: none; margin: 0 0 0 auto; font-size: .8125rem; color: var(--cover-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quiet { background: transparent; border: 1px solid var(--rule); border-radius: 4px; padding: 6px 12px; font-size: .875rem; font-weight: 500; color: var(--ink); transition: border-color .15s; }
.quiet:hover { border-color: var(--ink); }
.quiet:disabled { opacity: .5; cursor: default; border-color: var(--rule); }

/* ---------- main + side panel ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); grid-template-areas: "main panel"; gap: 0 40px; align-items: start; }
main { grid-area: main; min-width: 0; padding: 24px 0 64px; }
.panel { grid-area: panel; min-width: 0; position: sticky; top: var(--bar-h); max-height: calc(100vh - var(--bar-h)); overflow: auto; padding: 24px 0 24px 24px; border-left: 1px solid var(--rule); overscroll-behavior: contain; }
.panel-h { font-size: .875rem; font-weight: 600; margin: 24px 0 8px; }
.panel-h:first-child, .progress .panel-h { margin-top: 0; }
.panel-h small { font-size: .8125rem; margin-left: 4px; }
.run { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule); }
.error { margin: 0 0 20px; padding: 10px 14px; background: var(--brick-2); color: var(--brick); border-radius: 4px; font-weight: 500; max-width: 70ch; }

/* run steps */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .875rem; }
.steps li { display: grid; grid-template-columns: 16px 1fr; gap: 10px; align-items: start; color: var(--ink-2); }
.steps li div { display: grid; }
.steps li b { font-weight: 500; }
.steps li .detail { font-size: .8125rem; overflow-wrap: anywhere; line-height: 1.4; }
.steps li .detail:empty { display: none; }
.steps li.active, .steps li.done { color: var(--ink); }
.steps li.active b { font-weight: 600; }
.steps li.done .detail { color: var(--ink-2); }
.steps li.failed { color: var(--brick); }
.progress.done .detail { display: none; }   /* the finished run keeps its checklist; the log holds the numbers */
.ico { width: 16px; height: 16px; margin-top: 3px; border-radius: 50%; border: 1.5px solid var(--rule); position: relative; }
.active .ico { border-color: var(--grass); border-top-color: transparent; animation: spin .9s linear infinite; }
.done .ico { border-color: var(--grass); background: var(--grass); }
.done .ico::after { content: ""; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px; border: solid var(--field); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.failed .ico { border-color: var(--brick); background: var(--brick-2); }
.failed .ico::after { content: ""; position: absolute; left: 3px; top: 6px; width: 7px; height: 1.5px; background: var(--brick); }
@keyframes spin { to { transform: rotate(360deg); } }

/* models summary */
.summary { width: 100%; border-collapse: collapse; font-size: .875rem; }
.summary th, .summary td { padding: 7px 0 7px 8px; text-align: right; border-bottom: 1px solid var(--rule-2); white-space: nowrap; }
.summary th:last-child, .summary td:last-child { white-space: normal; max-width: 6rem; font-size: .75rem; }
.summary th { font-weight: 500; color: var(--ink-2); font-size: .75rem; padding-top: 0; }
.summary th:first-child, .summary td:first-child { text-align: left; padding-left: 0; }
.summary td:first-child button { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: .2em; }
.summary td:first-child button:hover { color: var(--ink); text-decoration-color: var(--ink); }
.summary tr.selected td { font-weight: 600; color: var(--ink); }
.summary tr.selected td:first-child button { color: var(--ink); text-decoration: none; font-weight: 600; }
.summary tr.pending td { color: var(--ink-2); font-weight: 400; }
.summary td small { font-size: .75rem; }
.panel .moves { margin: 0; padding: 0 0 0 1.1em; font-size: .875rem; color: var(--ink-2); }
.panel .moves li + li { margin-top: 2px; }
.panel .note { margin: 0; font-size: .875rem; color: var(--ink-2); }

/* calculation log */
.log { margin-top: 20px; font-size: .875rem; }
.progress.idle ~ .log { display: none; }
.log summary { cursor: pointer; color: var(--ink-2); list-style: none; display: flex; align-items: center; gap: 8px; width: max-content; }
.log summary::-webkit-details-marker { display: none; }
.log summary::before { content: ""; width: 10px; height: 7px; background: var(--chevron) center / contain no-repeat; transform: rotate(-90deg); transition: transform .2s var(--ease); }
.log[open] summary::before { transform: none; }
.log summary:hover { color: var(--ink); }
.log pre { margin: 8px 0 0; padding: 10px 12px; background: var(--field); border: 1px solid var(--rule-2); border-radius: 4px; max-height: 240px; overflow: auto; font: .75rem/1.5 var(--mono); white-space: pre-wrap; }

/* ---------- model tabs + the headline ---------- */
.switcher { display: flex; gap: 4px; margin: 0 0 20px; border-bottom: 1px solid var(--rule); }
.switcher button { background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; padding: 6px 12px 10px; font-weight: 600; color: var(--ink-2); display: grid; justify-items: start; gap: 1px; white-space: nowrap; }
.switcher button:first-child { padding-left: 0; }
.switcher button small { font-weight: 500; font-size: .8125rem; }
.switcher button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.switcher button:hover { color: var(--ink); }
.switcher button:focus-visible { outline-offset: -2px; }
.switcher button[aria-disabled="true"] { cursor: default; font-weight: 500; border-bottom-color: transparent; }   /* nothing is selected until a model exists */
.switcher button[aria-disabled="true"] small { font-weight: 400; }
.headline { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 20px; align-items: baseline; margin: 0 0 32px; }
.headline .figure { font-size: 2.5rem; font-weight: 700; line-height: 1; letter-spacing: -.03em; }
.headline .lede { font-size: 1.125rem; line-height: 1.4; max-width: 62ch; text-wrap: pretty; }
.headline .lede b { font-weight: 600; }
.headline.arrived .figure { animation: settle .5s var(--ease) both; }

/* ---------- lineup tables ---------- */
.compare { display: grid; gap: 32px; }
.compare > article { min-width: 0; }
.compare h2, .explain h2, .whatif h2 { font-size: 1.125rem; margin-bottom: 8px; }
.compare h2 small, .whatif h2 small { font-size: .875rem; display: inline-block; max-width: 60ch; text-wrap: pretty; }
.scroll { overflow-x: auto; background:   /* a right-edge shadow that the content covers once scrolled to the end */
  linear-gradient(270deg, var(--paper) 40%, rgba(248, 245, 238, 0)) 100% 0 / 32px 100% no-repeat local,
  linear-gradient(270deg, rgba(21, 20, 15, .16), rgba(21, 20, 15, 0)) 100% 0 / 12px 100% no-repeat scroll; }
table.lineup { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: .875rem; line-height: 1.3; }
.lineup th, .lineup td { padding: 6px 6px; text-align: right; border-bottom: 1px solid var(--rule-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: baseline; }
.lineup td:first-child, .lineup th:first-child { padding-left: 0; }
.lineup td:last-child, .lineup th:last-child { padding-right: 0; }
.lineup th { font-weight: 500; color: var(--ink-2); font-size: .75rem; padding-top: 0; padding-bottom: 5px; border-bottom: 1px solid var(--ink); }
.lineup th:nth-child(-n+3), .lineup td:nth-child(-n+3) { text-align: left; }
/* one column grid for both ledgers, so a stat sits under the same stat in the other table */
.lineup th:nth-child(1) { width: 1.75rem; }
.lineup th:nth-child(2) { width: 2.75rem; }
.lineup th:nth-child(4) { width: 4.75rem; }
.lineup th:nth-child(n+5) { width: 3.75rem; }
.lineup th:nth-child(9) { width: 3.5rem; }
.lineup th:nth-child(11) { width: 3.25rem; }
.lineup td.slot { color: var(--ink-2); }
.lineup tbody tr:nth-child(3) td, .lineup tbody tr:nth-child(6) td { border-bottom-color: var(--rule); }   /* thirds of the order, the way a card is read */
.lineup td.name { font-weight: 600; white-space: normal; text-overflow: clip; }
.lineup td.name .bats { font-weight: 400; color: var(--ink-2); }
.lineup td.agree { color: var(--ink-2); background: linear-gradient(90deg, var(--grass-2) calc(var(--v, 0) * 100%), transparent 0) no-repeat; padding-left: 8px; text-align: left; }
.lineup td.from { color: var(--ink-2); font-size: .8125rem; text-align: left; }
.lineup td.from.in { color: var(--grass); font-weight: 600; }
.badge { display: inline-block; font-size: .6875rem; font-weight: 500; line-height: 1.4; padding: 1px 6px; border-radius: 999px; vertical-align: 1px; margin-left: 4px; white-space: nowrap; }
.badge.small { background: var(--gold-2); color: var(--gold); }
.badge.off { background: var(--brick-2); color: var(--brick); }
.legend { font-size: .875rem; color: var(--ink-2); margin: 20px 0 0; max-width: 70ch; }
.legend b { color: var(--ink); font-weight: 600; }
#t-model tbody tr { animation: written .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 30ms); }
@keyframes written { from { opacity: 0; transform: translateY(4px); } }
@keyframes settle { from { opacity: 0; transform: translateY(6px); } }

/* ---------- explanation ---------- */
.explain { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--rule); }
.by { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 14px; font-size: .875rem; color: var(--ink-2); }
.by > span { flex: 1 1 24ch; }
.prose { max-width: 66ch; font-size: 1rem; line-height: 1.6; white-space: pre-wrap; min-height: 1.5em; }
.prose .h { display: block; font-weight: 600; margin-top: .25em; }
.prose.waiting::after { content: ""; display: inline-block; width: .5em; height: 1em; background: var(--grass); vertical-align: -.15em; animation: blink 1s steps(2) infinite; }
.prose.waiting:empty::before { content: "Writing the explanation…"; color: var(--ink-2); margin-right: .4em; }
@keyframes blink { to { opacity: 0; } }

/* ---------- what-if editor ---------- */
.whatif { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--rule); }
table.lineup.editable { table-layout: auto; }
.editable th:nth-child(n+2) { width: auto; }
.editable td.name { width: 100%; min-width: 15rem; }   /* the name column takes the slack, so the stats stay tight */
.editable select { padding: 6px 30px 6px 8px; font-size: .875rem; font-weight: 600; max-width: 100%; }
.editable tr[draggable] { cursor: grab; }
.editable tr.dragging { opacity: .4; }
.editable tr.over td { box-shadow: inset 0 2px 0 var(--grass); }
.editable .arrows { display: inline-flex; gap: 4px; }
.editable .arrows button { border: 1px solid var(--rule); background: var(--field); border-radius: 4px; width: 32px; height: 32px; padding: 0; display: grid; place-items: center; color: var(--ink); transition: border-color .15s; }
.editable .arrows button:hover { border-color: var(--ink); }
.editable .arrows button:disabled { opacity: .35; cursor: default; border-color: var(--rule); }
.editable .arrows svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.score { font-size: 1rem; margin: 14px 0 0; min-height: 1.5em; max-width: 70ch; }
.score .figure { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1; margin-right: 4px; }
.score .warn { color: var(--brick); }

footer { border-top: 2px solid var(--ink); font-size: .875rem; color: var(--ink-2); }
footer .wrap { padding-top: 20px; padding-bottom: 48px; }
footer p { max-width: 70ch; margin: 0; }

/* ---------- narrower than the two-column page ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "main" "panel"; }
  .panel { position: static; max-height: none; overflow: visible; padding: 20px 0 8px; border-left: 0; border-top: 1px solid var(--rule); }
  #status { display: block; flex-basis: 100%; }
  #status:empty { display: none; }
  main { padding-top: 20px; }
}
@media (max-width: 760px) {
  :root { --gutter: 16px; }
  .masthead .wrap { grid-template-columns: 1fr; gap: 6px; padding-top: 18px; padding-bottom: 14px; }
  .brand { grid-row: auto; font-size: 2rem; }
  .tagline { font-size: 1rem; }
  .bar .wrap { padding-top: 8px; padding-bottom: 8px; }
  .controls { flex-wrap: wrap; }
  .bar select { flex: 1 1 100%; max-width: none; }
  .seg { flex: 0 0 auto; }
  .bar .primary { flex: 1 1 auto; }
  .headline { grid-template-columns: 1fr; gap: 6px; }
  .headline .figure { font-size: 2.25rem; }
  .headline .lede { font-size: 1rem; }
  .switcher { overflow-x: auto; }
  .switcher button { padding: 6px 10px 10px; }
  table.lineup { min-width: 38rem; }
  /* slot, position (or arrows) and name stay put while the stats scroll */
  .lineup th:nth-child(-n+3), .lineup td:nth-child(-n+3) { position: sticky; z-index: 1; background: var(--paper); }
  .lineup th:nth-child(1), .lineup td:nth-child(1) { left: 0; }
  .lineup th:nth-child(2), .lineup td:nth-child(2) { left: 1.75rem; }
  .lineup th:nth-child(3) { width: 9rem; }
  .lineup th:nth-child(3), .lineup td:nth-child(3) { left: 4.5rem; box-shadow: 8px 0 8px -8px rgba(21, 20, 15, .25); }
  .editable th:nth-child(2), .editable td:nth-child(2) { width: 6.25rem; min-width: 6.25rem; }
  .editable th:nth-child(3), .editable td:nth-child(3) { left: 8rem; min-width: 0; }
  .editable td.name { min-width: 0; }
  .editable select { width: 12.5rem; text-overflow: ellipsis; }
}
@media (pointer: coarse) {
  .editable .arrows button { width: 40px; height: 40px; }
  .seg span { padding: 10px 14px; }
  .primary { padding: 11px 18px; }
  select { padding-top: 10px; padding-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .active .ico { animation: none; border-top-color: var(--grass); }
  .prose.waiting::after { animation: none; }
  #t-model tbody tr, .headline.arrived .figure { animation: none; }
  .primary, .quiet, .seg span, .editable .arrows button, .log summary::before { transition: none; }
}

/* deferred-items pass */
.primary.cancel { background: var(--ink-2); }
.primary.cancel:hover { background: var(--ink); }
.share { margin: 18px 0 0; font-size: .875rem; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.columns { margin: 12px 0 0; font-size: .875rem; color: var(--ink-2); }
.columns summary { cursor: pointer; width: max-content; }
.columns summary:hover { color: var(--ink); }
.columns dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0 0; max-width: 66ch; }
.columns dt { font-weight: 600; color: var(--ink); }
.columns dd { margin: 0; }
.prose:empty:not(.waiting)::before { content: "Written once the models finish."; color: var(--ink-2); }
