/* optimizer.css — the Flip Optimizer's allocation desk.

   The optimizer is one screen, not a document: the shared head, rail, search and
   drawer stay around it, and the whole workspace is pinned to the glass. Nothing
   below the masthead scrolls. The planner is a compact control column on the
   left; the basket is a ledger on the right whose summary stays put and whose
   position rows share exactly the height that is left. */

/* The document never scrolls while this screen is up. The body is fixed rather
   than only `overflow: hidden`: a hidden root is still programmatically
   scrollable, and the workspace's own overflow used to drag the masthead out of
   the shell. */
html:has(.shell[data-screen="optimizer"]),
body:has(.shell[data-screen="optimizer"]) {
  overflow: hidden;
  overscroll-behavior: none;
}
body:has(.shell[data-screen="optimizer"]) {
  position: fixed;
  inset: 0;
}

.shell[data-screen="optimizer"] .main { min-height: 0; }

/* The workspace is the frame, not a scroller. It hands the whole remainder of
   the viewport to the screen, which splits it between the two panels. */
.shell[data-screen="optimizer"] .workspace {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  min-height: 0;
  overflow: hidden;
  scrollbar-gutter: auto;
  /* This workspace never scrolls, so it has no scrollbar lane of its own. Every
     other screen ends one lane inside the page; reserve the same lane here so
     the basket's right edge and the head stay on the shared page edge. */
  padding-right: calc(var(--page-pad) + var(--shell-gutter, 0px));
  padding-bottom: 16px;
  overscroll-behavior: none;
}
.shell[data-screen="optimizer"] .col-main,
.shell[data-screen="optimizer"] .col-side { display: none; }

.opt-screen {
  --opt-sheet: #0c0e0e;
  --opt-well: #090b0b;
  --opt-rule: rgba(255, 255, 255, .075);
  --opt-rule-strong: rgba(255, 255, 255, .15);
  --opt-row-hover: rgba(255, 255, 255, .025);
  /* One inset for both panels: the planner and ledger are one desk, and they
     used to drift two pixels apart at every desktop breakpoint. 16px is the
     shared dense-card pad; narrow screens tighten it in one place below. */
  --opt-panel-pad: 16px;

  display: none;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  grid-template-columns: minmax(290px, 344px) minmax(0, 1fr);
  gap: var(--col-gap);
}
.shell[data-screen="optimizer"] .opt-screen { display: grid; }
.opt-screen [hidden] { display: none !important; }

/* Both panels are the same sheet: a bordered plate that fills its track, with
   the same inset on both sides of the desk. */
.opt-planner,
.opt-basket {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--opt-rule);
  border-radius: 8px;
  background: var(--opt-sheet);
  animation: opt-rise 260ms var(--ease) both;
}

/* ------------------------------------------------------------------ planner --- */
.opt-planner {
  position: relative;
  padding: var(--opt-panel-pad);
  background-image:
    linear-gradient(rgba(255, 255, 255, .015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .015) 1px, transparent 1px);
  background-size: 28px 28px;
}
.opt-planner::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 72px;
  height: 2px;
  background: var(--accent);
}

.opt-planner-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 13px;
  border-bottom: 1px solid var(--opt-rule);
}
.opt-eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.opt-planner-head h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.025em;
  line-height: 1.15;
}

.opt-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.opt-deck {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.opt-cell {
  min-width: 0;
  padding-top: 11px;
  border-top: 1px solid var(--opt-rule);
}
.opt-budget { padding-top: 0; border-top: 0; }

.opt-cell-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  margin-bottom: 7px;
}
.opt-index {
  flex: 0 0 auto;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1;
}
.opt-cell-head label,
.opt-cell-head .opt-label,
.opt-label {
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -.01em;
}
.opt-cell-note {
  margin-left: auto;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1.4;
  text-align: right;
  white-space: nowrap;
}

.opt-input-wrap { position: relative; }
.opt-input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--opt-rule);
  border-radius: 6px;
  outline: none;
  background: var(--opt-well);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  transition: border-color var(--t-quick), box-shadow var(--t-quick), background var(--t-quick);
}
.opt-input:hover { border-color: var(--opt-rule-strong); }
.opt-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.opt-input-cash {
  height: 48px;
  padding-right: 40px;
  background: #080a0a;
  font-family: var(--mono);
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -.05em;
}
.opt-input::placeholder { color: #5f6565; }
.opt-suffix {
  position: absolute;
  top: 50%;
  right: 12px;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 9px;
  pointer-events: none;
  transform: translateY(-50%);
}
.opt-select-wrap { position: relative; }
.opt-select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 13px;
  width: 6px;
  height: 6px;
  border-right: 1px solid var(--ink-4);
  border-bottom: 1px solid var(--ink-4);
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}
.opt-select-wrap select {
  appearance: none;
  padding-right: 32px;
  cursor: pointer;
}

.opt-budget-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 7px;
}
.opt-help {
  color: var(--ink-4);
  font-size: 10px;
  line-height: 1.4;
}
.opt-lede {
  margin-bottom: 12px;
  font-size: 10.5px;
  line-height: 1.5;
}
.opt-lede a {
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.opt-strategy-help {
  min-height: 2.9em;
  margin-top: 6px;
  color: var(--ink-3);
  font-size: 9.5px;
}
.opt-quick-budgets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.opt-chip {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--opt-rule);
  border-radius: 4px;
  background: transparent;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 9.5px;
  cursor: pointer;
  transition: color var(--t-quick), border-color var(--t-quick), background var(--t-quick);
}
.opt-chip:hover { color: var(--ink-2); border-color: var(--opt-rule-strong); }
.opt-chip[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-2);
}

.opt-slot-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
}
.opt-slot {
  position: relative;
  height: 32px;
  padding: 0;
  border: 1px solid var(--opt-rule);
  border-radius: 4px;
  background: var(--opt-well);
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 10.5px;
  cursor: pointer;
  transition: color var(--t-quick), border-color var(--t-quick), background var(--t-quick);
}
.opt-slot:hover { color: var(--ink); border-color: var(--opt-rule-strong); }
.opt-slot[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-2);
}
.opt-slot[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 4px;
  left: 6px;
  height: 2px;
  background: var(--accent);
}
.opt-choice .opt-help { margin-top: 6px; }

.opt-submit-cell {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 13px;
}
.opt-run {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #17120b;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-quick), opacity var(--t-quick);
}
.opt-run:hover { background: var(--accent-2); color: #17120b; }
.opt-run:disabled { opacity: .55; cursor: default; }
.opt-run-short { display: none; }
.opt-btn-arrow { font-family: var(--mono); font-size: 16px; line-height: 1; }
.opt-error {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 92, 102, .35);
  border-radius: 6px;
  background: var(--down-soft);
  color: var(--ink);
  font-size: 11px;
}
.opt-noscript {
  margin-top: 12px;
  color: var(--ink-4);
  font-size: 11px;
}

/* ------------------------------------------------------------------- basket --- */
.opt-basket {
  position: relative;
  padding: var(--opt-panel-pad);
}
.opt-basket-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--opt-rule);
}
.opt-basket-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
}
.opt-basket-title h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.025em;
  white-space: nowrap;
}
.opt-status {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The offer names the newer basket itself, so the snapshot line steps out of
   its way rather than wrapping the header onto a second line. */
.opt-basket-head:has(.opt-update:not([hidden])) .opt-status { display: none; }

.opt-skipped {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--opt-rule-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  font: inherit;
  font-size: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.opt-skipped:hover { color: var(--ink); border-color: var(--accent-line); }
.opt-skipped span { color: var(--accent-2); font-family: var(--mono); }

.opt-skipped-menu {
  position: absolute;
  top: 42px;
  right: 14px;
  z-index: 8;
  width: min(300px, calc(100% - 28px));
  max-height: calc(100% - 56px);
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--opt-rule-strong);
  border-radius: 8px;
  background: #101313;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .45);
}
.opt-skipped-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--opt-rule);
}
.opt-skipped-head p {
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.opt-skipped-clear {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-2);
  font: inherit;
  font-size: 9.5px;
  cursor: pointer;
}
.opt-skipped-clear:hover { color: var(--ink); }
.opt-skipped-list { display: flex; flex-direction: column; }
.opt-skipped-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 0;
  border-bottom: 1px solid var(--opt-rule);
}
.opt-skipped-row:last-child { border-bottom: 0; }
.opt-skipped-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opt-skipped-restore {
  flex: 0 0 auto;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--opt-rule);
  border-radius: 4px;
  background: transparent;
  color: var(--ink-3);
  font: inherit;
  font-size: 9px;
  cursor: pointer;
}
.opt-skipped-restore:hover { color: var(--ink); border-color: var(--opt-rule-strong); }

.opt-update {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 1 auto;
  min-width: 0;
  padding: 3px 4px 3px 9px;
  border: 1px solid var(--accent-line);
  border-left: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
}
.opt-update-copy {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
}
.opt-update-title {
  color: var(--ink-2);
  font-size: 10px;
  font-weight: 500;
}
.opt-update-note {
  overflow: hidden;
  color: var(--accent-2);
  font-family: var(--mono);
  font-size: 9.5px;
  text-overflow: ellipsis;
}
.opt-update-btn {
  flex: 0 0 auto;
  height: 24px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #17120b;
  font: inherit;
  font-size: 9.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-quick);
}
.opt-update-btn:hover { background: var(--accent-2); }
.opt-update-btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.opt-update-btn span { font-family: var(--mono); font-size: 12px; }

.opt-preview {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  border: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}
.opt-preview-mark {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 34px;
  line-height: 1;
  opacity: .85;
}
.opt-preview-title {
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -.015em;
}
.opt-preview-note {
  max-width: 360px;
  margin-top: 4px;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.5;
}
.opt-preview-method { display: none; }
.opt-explainer {
  max-width: 430px;
  margin-top: 14px;
  padding-top: 11px;
  border-top: 1px solid var(--opt-rule);
  text-align: left;
}
.opt-explainer h3 {
  margin: 0 0 6px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -.01em;
}
.opt-explainer ol {
  margin: 0;
  padding-left: 17px;
  color: var(--ink-3);
  font-size: 10.5px;
  line-height: 1.5;
}
.opt-explainer li { margin: 0 0 5px; }
.opt-explainer b { color: var(--ink-2); font-weight: 500; }
.opt-explainer details { border-top: 1px solid var(--opt-rule); }
.opt-explainer summary {
  padding: 8px 0 7px;
  color: var(--ink-2);
  font-size: 10.5px;
  line-height: 1.35;
  cursor: pointer;
  list-style: none;
}
.opt-explainer summary::-webkit-details-marker { display: none; }
.opt-explainer summary::after {
  content: "+";
  float: right;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1;
}
.opt-explainer details[open] summary::after { content: "−"; }
.opt-explainer p {
  margin: 0 0 9px;
  color: var(--ink-3);
  font-size: 10.5px;
  line-height: 1.5;
}
.opt-explainer a {
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.opt-summary {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns:
    minmax(150px, 1.2fr) repeat(3, minmax(64px, .5fr)) minmax(140px, .75fr);
  align-items: center;
  gap: 4px 16px;
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--opt-rule);
}
.opt-summary-lead { min-width: 0; }
.opt-summary-lead .opt-label {
  display: block;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8.5px;
}
.opt-summary-lead #opt-profit {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: clamp(24px, 2.5vw, 34px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.055em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opt-stat {
  min-width: 0;
  padding-left: 14px;
  border-left: 1px solid var(--opt-rule);
}
.opt-stat span {
  display: block;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.3;
}
.opt-stat b {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.025em;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opt-usage {
  min-width: 0;
  padding-left: 14px;
  border-left: 1px solid var(--opt-rule);
}
.opt-usage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 7px;
}
.opt-usage-head .opt-label {
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8px;
}
.opt-slot-line {
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8px;
  white-space: nowrap;
}
.opt-slot-line b { color: var(--ink-2); font-weight: 500; }
.opt-slot-meter {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
  margin-top: 5px;
}
.opt-slot-meter span {
  height: 5px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: #1a1d1d;
}
.opt-slot-meter .is-used { background: var(--accent); }
.opt-slot-meter .is-spare { background: transparent; border-color: var(--opt-rule-strong); }
.opt-slot-meter .is-empty { background: #0a0c0c; border-color: #171a1a; }
.opt-announce {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.opt-up { color: var(--up) !important; }
.opt-down { color: var(--down) !important; }

.opt-empty {
  flex: 1 1 auto;
  min-height: 0;
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border: 0;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

/* The positions share what the summary leaves. The row track grows to 64px on a
   tall window and shrinks to 42px on a short one, so eight positions are on the
   glass without a page scroll; a window shorter than that gets a scroll inside
   the ledger only, never under the masthead. */
.opt-results {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 8px;
}
.opt-list-head {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 5px;
}
.opt-list-head h3 {
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.opt-method {
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1.4;
  text-align: right;
  white-space: nowrap;
}
.opt-trades {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-auto-rows: minmax(42px, 76px);
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--opt-rule);
  scrollbar-width: thin;
  scrollbar-color: #2a2e2e transparent;
}
.opt-trades.is-full { grid-auto-rows: minmax(42px, 1fr); }
.opt-trade {
  display: grid;
  grid-template-columns:
    26px minmax(130px, 1.7fr) repeat(4, minmax(44px, .55fr)) minmax(76px, .8fr) 54px;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px;
  border-bottom: 1px solid var(--opt-rule);
  transition: background var(--t-quick);
}
.opt-trade:last-child { border-bottom: 0; }
.opt-trade:hover { background: var(--opt-row-hover); }
.opt-trade-slot {
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.opt-trade-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.opt-icon-box {
  display: grid;
  flex: 0 0 26px;
  place-items: center;
  width: 26px;
  height: 26px;
}
.opt-icon[hidden],
.opt-icon-fallback[hidden] { display: none !important; }
.opt-icon,
.opt-icon-fallback {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 4px;
  background: var(--field);
  image-rendering: pixelated;
  object-fit: contain;
}
.opt-icon-fallback {
  display: grid;
  place-items: center;
  color: var(--ink-4);
  font-size: 9px;
}
.opt-trade-id {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.opt-trade-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opt-trade-window {
  flex: 0 0 auto;
  padding: 1px 4px;
  border: 1px solid var(--opt-rule);
  border-radius: 3px;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.35;
  white-space: nowrap;
}
.opt-trade-facts { display: contents; }
.opt-fact { min-width: 0; }
.opt-fact dt {
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.3;
}
.opt-fact dd {
  overflow: hidden;
  margin: 2px 0 0;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opt-fact-cost dd {
  color: var(--ink);
  font-weight: 500;
}
.opt-trade-profit {
  min-width: 0;
  text-align: right;
}
.opt-trade-profit b {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.opt-trade-profit span {
  display: block;
  margin-top: 1px;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8px;
  white-space: nowrap;
}
.opt-trade-buy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  height: 26px;
  padding: 0 4px;
  border: 1px solid var(--opt-rule);
  border-radius: 4px;
  background: transparent;
  color: var(--ink-4);
  font: inherit;
  font-size: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--t-quick), border-color var(--t-quick), background var(--t-quick);
}
.opt-trade-buy:hover {
  color: var(--accent-2);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.opt-trade-buy:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.opt-trade-buy-mark { font-family: var(--mono); font-size: 11px; line-height: 1; }
.opt-trade-buy-lbl { font-size: 9px; }

@keyframes opt-rise {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------- responsive --- */

/* A narrower desk keeps the two panels but gives the ledger the difference. */
@media (max-width: 1200px) {
  .opt-screen {
    --opt-panel-pad: 14px;
    grid-template-columns: minmax(280px, 314px) minmax(0, 1fr);
    gap: 12px;
  }
  .opt-summary {
    grid-template-columns:
      minmax(130px, 1.1fr) repeat(3, minmax(56px, .5fr)) minmax(120px, .7fr);
    gap: 4px 12px;
  }
  .opt-stat, .opt-usage { padding-left: 10px; }
  .opt-trade {
    grid-template-columns:
      24px minmax(110px, 1.5fr) repeat(4, minmax(40px, .55fr)) minmax(70px, .8fr) 50px;
    gap: 8px;
  }
  .opt-trade-name { font-size: 11.5px; }
}

/* Below a desk's width the planner becomes a compact strip above the ledger
   instead of a column beside it. It is still on the glass; the ledger simply
   takes the rest of the window. */
@media (min-width: 901px) {
  /* The action anchors the deck rather than sitting under the last field with
     half a panel of empty glass beneath it. */
  .opt-deck { flex: 1 1 auto; }
}

@media (max-width: 900px) {
  .shell[data-screen="optimizer"] .workspace { padding-bottom: 10px; }
  .opt-screen {
    --opt-panel-pad: 10px 12px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
  }
  .opt-planner-head { display: none; }
  .opt-form { flex: 0 0 auto; }
  .opt-deck {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 116px;
    gap: 8px 12px;
    align-items: start;
  }
  .opt-cell,
  .opt-submit-cell {
    padding-top: 0;
    border-top: 0;
  }
  .opt-budget { grid-column: 1; grid-row: 1; }
  .opt-choice { grid-column: 2; grid-row: 1; }
  .opt-submit-cell {
    grid-column: 3;
    grid-row: 1;
    padding-top: 20px;
    margin-top: 0;
  }
  .opt-field {
    grid-row: 2;
    padding-top: 8px;
    border-top: 1px solid var(--opt-rule);
  }
  .opt-field:nth-child(3) { grid-column: 1; }
  .opt-field:nth-child(4) { grid-column: 2 / span 2; }
  .opt-cell-note { display: none; }
  .opt-choice .opt-help,
  .opt-strategy-help { display: none; }
  .opt-strategy-help { min-height: 0; }
  .opt-input-cash { height: 44px; font-size: 23px; }
  .opt-run { height: 38px; }
  .opt-summary { grid-template-columns: minmax(140px, 1.2fr) repeat(3, minmax(58px, .5fr)) minmax(132px, .8fr); }
  .opt-trades { grid-auto-rows: minmax(42px, 58px); }
  .opt-trade { grid-template-columns: 24px minmax(100px, 1.5fr) repeat(4, minmax(40px, .55fr)) minmax(70px, .8fr) 36px; }
  .opt-trade-buy { width: 26px; height: 24px; padding: 0; }
  .opt-trade-buy-lbl { display: none; }
}

/* A hand-held window is one column: budget, slots, the two choices, the action.
   Every height here is chosen so the ledger below still shows eight positions at
   a phone's 844px. The root never scrolls; the ledger is the only fallback. */
@media (max-width: 620px) {
  .opt-screen { gap: 8px; }
  /* The action rides beside the cash field: the 45px that bought puts the whole
     eight-position ledger on an 844px phone. The other controls keep their
     rows, so nothing is hidden. */
  .opt-deck {
    grid-template-columns: repeat(2, minmax(0, 1fr)) 104px;
    gap: 7px 8px;
    align-items: start;
  }
  .opt-budget { grid-column: 1 / span 2; grid-row: 1; }
  .opt-submit-cell {
    grid-column: 3;
    grid-row: 1;
    margin-top: 22px;
    padding-top: 0;
  }
  .opt-run { height: 40px; padding: 0 8px; font-size: 11px; }
  .opt-run-long {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
  .opt-run-short { display: inline; }
  .opt-choice { grid-column: 1 / -1; grid-row: 2; }
  .opt-field { grid-column: span 1; grid-row: 3; padding-top: 6px; }
  .opt-field:nth-child(3) { grid-column: 1; }
  .opt-field:nth-child(4) { grid-column: 2 / span 2; }
  .opt-cell-head { margin-bottom: 5px; }
  .opt-input { height: 34px; }
  .opt-input-cash { height: 40px; font-size: 22px; }
  .opt-budget-foot { margin-top: 5px; }
  .opt-chip { height: 22px; padding: 0 7px; font-size: 9px; }
  .opt-slot-grid { gap: 3px; }
  .opt-slot { height: 27px; font-size: 9.5px; }
  .opt-select-wrap select { height: 32px; padding-left: 8px; font-size: 10.5px; }
  .opt-error { font-size: 10.5px; }

  .opt-basket-head {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding-bottom: 7px;
  }
  .opt-basket-title { gap: 8px; }
  .opt-basket-title h2 { font-size: 14px; }
  .opt-status { font-size: 8.5px; }
  .opt-update { flex: 0 1 auto; min-width: 0; padding: 2px 3px 2px 7px; gap: 6px; }
  .opt-update-title { display: none; }
  .opt-update-note { font-size: 9px; }
  .opt-update-btn { height: 20px; padding: 0 6px; font-size: 9px; }
  .opt-slot-spare { display: none; }
  .opt-basket-head:has(.opt-skipped:not([hidden])) .opt-status { display: none; }
  .opt-skipped-menu { top: 38px; right: 12px; width: min(300px, calc(100% - 24px)); }
  .opt-skipped { height: 18px; padding: 0 6px; font-size: 8.5px; }

  .opt-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px 10px;
    padding: 6px 0 5px;
  }
  .opt-summary-lead { grid-column: 1 / span 2; }
  .opt-summary-lead #opt-profit { font-size: clamp(21px, 6.4vw, 28px); }
  .opt-usage {
    grid-column: 3;
    padding-left: 0;
    border-left: 0;
  }
  .opt-stat { padding-left: 0; border-left: 0; }
  .opt-stat b { font-size: 11px; }

  .opt-preview {
    flex-direction: column;
    gap: 10px;
    padding: 16px 8px;
    text-align: center;
  }
  .opt-preview-mark { display: none; }
  .opt-preview-note { max-width: 300px; font-size: 10.5px; }

  .opt-results { padding-top: 6px; }
  .opt-list-head { padding-bottom: 3px; }
  .opt-trades { grid-auto-rows: minmax(37px, 1fr); }
  .opt-trades.is-full { grid-auto-rows: minmax(37px, 1fr); }
  .opt-trade {
    grid-template-columns: 18px 24px minmax(0, 1fr) auto 24px;
    grid-template-areas:
      "slot icon id profit action"
      "facts facts facts facts facts";
    gap: 1px 6px;
    padding: 3px 2px;
  }
  .opt-trade-buy { grid-area: action; width: 24px; height: 24px; }
  .opt-trade-slot { grid-area: slot; font-size: 8px; }
  .opt-trade-head { display: contents; }
  .opt-icon-box { grid-area: icon; width: 22px; height: 22px; flex-basis: 22px; }
  .opt-icon,
  .opt-icon-fallback { width: 22px; height: 22px; flex-basis: 22px; }
  .opt-trade-id { grid-area: id; }
  .opt-trade-name { font-size: 11px; }
  .opt-trade-window { display: none; }
  .opt-trade-facts {
    grid-area: facts;
    display: flex;
    align-items: baseline;
    gap: 9px;
    min-width: 0;
    overflow: hidden;
  }
  .opt-fact {
    display: flex;
    align-items: baseline;
    gap: 3px;
    min-width: 0;
  }
  .opt-fact dt { font-size: 7.5px; }
  .opt-fact dd { margin: 0; font-size: 9px; }
  .opt-trade-profit { grid-area: profit; }
  .opt-trade-profit b { font-size: 11px; }
  .opt-trade-profit span { display: none; }
}

@media (max-width: 380px) {
  .opt-deck { grid-template-columns: repeat(2, minmax(0, 1fr)) 92px; }
  .opt-input-cash { font-size: 19px; }
}

@media (max-width: 430px) {
  .opt-basket-title h2 { font-size: 13px; }
  .opt-summary-lead #opt-profit { font-size: 20px; }
  .opt-fact-cost { display: none; }
  .opt-trade-facts { gap: 8px; }
}

/* A short laptop must not push the ledger off the glass: tighten the planner's
   help copy before taking height from the positions. */
@media (min-width: 901px) and (max-height: 760px) {
  .opt-screen { --opt-panel-pad: 10px 14px; }
  .opt-planner-head { padding-bottom: 8px; margin-bottom: 8px; }
  .opt-eyebrow { display: none; }
  .opt-deck { gap: 9px; }
  .opt-cell { padding-top: 8px; }
  .opt-input-cash { height: 42px; font-size: 23px; }
  .opt-budget-foot { margin-top: 5px; }
  .opt-slot { height: 28px; }
  .opt-strategy-help { display: none; }
  .opt-run { height: 38px; }
  .opt-summary { padding: 7px 0 6px; }
  .opt-trade-window { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .opt-planner, .opt-basket { animation: none; }
  .opt-input, .opt-chip, .opt-slot, .opt-run, .opt-update-btn, .opt-trade, .opt-trade-buy { transition: none; }
}
