/* MathCompute: the abacus page. Builds on mathpages.css (tokens --mp-*). */
:root {
  --mp-product: #5f7487;         /* slate: middle stripe of the MathCompute mark */
  --cp-bead: #302b28;
  --cp-bead-text: #fffdf9;
  --cp-box: #fffdf9;
  --cp-box-line: #8d7f71;
  --cp-hook: #f3d2c4;           /* arm and leg */
  --cp-corner: #bb5237;         /* the box itself, and the move */
  --cp-on-corner: #fff;
  --cp-rim: #cde8e2;            /* the rim hook removed */
  --cp-rim-line: #2f8f83;
  --cp-link: #2f8f83;           /* the same position in both pictures */
  --cp-line: #e9e2da;           /* a row or column being looked at */
  --cp-candidate: #bb5237;
  --cp-path: #ecdccf;
  --cp-add: #e2f1ee;            /* boxes a move would add */
}
html[data-theme="dark"] {
  --cp-bead: #f3eee9;
  --cp-bead-text: #15191d;
  --cp-box: #22282d;
  --cp-box-line: #7e8a8f;
  --cp-hook: #5a3529;
  --cp-corner: #e8a484;
  --cp-on-corner: #15191d;
  --cp-rim: #1d4a43;
  --cp-rim-line: #6cc5b6;
  --cp-link: #6cc5b6;
  --cp-line: #2f373d;
  --cp-candidate: #f5b08c;
  --cp-path: #3a3330;
  --cp-add: #1d3a35;
}

.cp-main { padding-block: 28px 48px; }
.cp-sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.cp-heading { max-width: 60rem; margin-bottom: 20px; }
.cp-heading h1 { margin: 0 0 8px; font: 700 2rem/1.2 var(--mp-serif); letter-spacing: -.02em; }
.cp-eyebrow { margin: 0 0 6px; color: var(--mp-muted); font-size: .8125rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.cp-lede { margin: 0; color: var(--mp-ink); font-size: 1.0625rem; line-height: 1.55; }
.cp-sym { font-family: var(--mp-serif); font-style: italic; }

/* Controls */
.cp-controls { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px 24px; margin: 0 0 20px; padding: 16px 18px;
  border: 1px solid var(--mp-border); border-radius: var(--mp-radius-lg); background: var(--mp-surface); }
.cp-field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.cp-field-wide { flex: 1 1 22rem; }
.cp-field > label { font-size: .875rem; font-weight: 700; }
.cp-inline { display: flex; gap: .5rem; }
.cp-controls input[type="text"], .cp-controls input[type="number"] { min-height: var(--mp-control-height); margin: 0; padding: .55rem .75rem;
  border: 1px solid var(--mp-control-border); border-radius: var(--mp-radius); background: var(--mp-surface); color: var(--mp-ink); font: 400 1rem/1.4 var(--mp-sans); }
.cp-controls input[type="text"] { flex: 1 1 auto; min-width: 0; font-variant-numeric: tabular-nums; }
.cp-controls input[type="number"] { width: 6rem; }
.cp-controls input[aria-invalid="true"] { border-color: var(--mp-error-ink); }
.cp-help { margin: 0; color: var(--mp-muted); font-size: .8125rem; }
.cp-error { margin: 0; padding: .4rem .6rem; border-radius: var(--mp-radius-sm); background: var(--mp-error-bg); color: var(--mp-error-ink); font-size: .875rem; }
.cp-error[hidden] { display: none; }
.cp-options { display: grid; gap: 6px; align-self: center; font-size: .9375rem; }
.cp-options label { display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.cp-options input { margin: 0; }   /* size and colour from mathpages.css */
.cp-chip { margin: 0 2px; padding: 1px 8px; border: 1px solid var(--mp-border); border-radius: var(--mp-radius-pill); background: var(--mp-surface-soft);
  color: var(--mp-link); font: 600 .8125rem/1.6 var(--mp-sans); cursor: pointer; }
.cp-chip:hover { border-color: var(--mp-link); }
.cp-button { display: inline-flex; align-items: center; justify-content: center; min-height: var(--mp-control-height-compact); margin: 0; padding: .45rem .95rem;
  border: 1px solid var(--mp-control-border); border-radius: var(--mp-radius); background: var(--mp-surface); color: var(--mp-link);
  font: 700 var(--mp-button-font)/1.2 var(--mp-sans); cursor: pointer; }
.cp-button:hover:not(:disabled) { background: var(--mp-surface-soft); }
.cp-button:disabled { opacity: .5; cursor: default; }
.cp-button[hidden] { display: none; }
.cp-primary { border-color: var(--mp-accent); background: var(--mp-accent); color: var(--mp-on-accent); }
.cp-primary:hover:not(:disabled) { border-color: var(--mp-accent-hover); background: var(--mp-accent-hover); }
.cp-quiet { border-color: transparent; background: transparent; }

/* Home and section pages: cards linking to each tool */
.cp-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 16px; margin: 8px 0 0; padding: 0; list-style: none; }
.cp-card > a, .cp-card > div { display: block; height: 100%; padding: 18px 20px; border: 1px solid var(--mp-border); border-top: 4px solid var(--mp-product);
  border-radius: var(--mp-radius-lg); background: var(--mp-surface); color: var(--mp-ink); text-decoration: none; box-shadow: var(--mp-shadow); }
.cp-card > a:hover { border-color: var(--mp-link); border-top-color: var(--mp-product); }
.cp-card > a:hover h2 { color: var(--mp-link); text-decoration: underline; }
.cp-card h2 { margin: 0 0 6px; font: 700 1.2rem/1.3 var(--mp-serif); }
.cp-card p { margin: 0; color: var(--mp-muted); line-height: 1.5; }
.cp-soon { display: inline-block; margin-top: 10px; padding: 1px 8px; border-radius: var(--mp-radius-pill); background: var(--mp-surface-muted); color: var(--mp-muted); font-size: .8125rem; font-weight: 600; }

.cp-section { margin: 28px 0 12px; font: 700 1.35rem/1.3 var(--mp-serif); }

/* The two pictures */
.cp-stage { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; }
.cp-panel { min-width: 0; padding: 14px 16px 18px; border: 1px solid var(--mp-border); border-radius: var(--mp-radius-lg); background: var(--mp-surface); }
.cp-panel h2 { margin: 0 0 10px; font: 700 1.125rem/1.3 var(--mp-serif); }
.cp-sub { margin-left: .4rem; color: var(--mp-muted); font: 400 .9375rem var(--mp-sans); font-variant-numeric: tabular-nums; }
.cp-figure { display: flex; justify-content: center; overflow-x: auto; }
.cp-svg { display: block; max-width: 100%; height: auto; font-family: var(--mp-sans); user-select: none; -webkit-user-select: none; }

/* Young diagram */
.cp-box { fill: var(--cp-box); stroke: var(--cp-box-line); stroke-width: 1; }
.cp-cell { cursor: pointer; outline: none; }
.cp-cell:hover .cp-box { fill: var(--cp-line); }
.cp-cell.in-line .cp-box { fill: var(--cp-line); }
.cp-cell.in-rim .cp-box { fill: var(--cp-rim); }
.cp-cell.in-hook .cp-box { fill: var(--cp-hook); }
.cp-cell.in-hook.in-rim .cp-box { fill: var(--cp-hook); stroke: var(--cp-rim-line); stroke-width: 2.5; }
.cp-cell.in-rim:not(.in-hook) .cp-box { stroke: var(--cp-rim-line); stroke-width: 2.5; }
.cp-cell.is-corner .cp-box { fill: var(--cp-corner); }
.cp-cell:focus-visible .cp-box { stroke: var(--mp-focus); stroke-width: 3; }
.cp-hooklen { fill: var(--mp-ink); font-size: 16px; font-weight: 600; text-anchor: middle; pointer-events: none; }
.cp-cell.is-corner .cp-hooklen { fill: var(--cp-on-corner); }
.cp-emark { fill: var(--cp-rim-line); pointer-events: none; }
.cp-zero-rows { fill: var(--cp-line); opacity: .6; }
.cp-ghost { fill: var(--cp-rim); stroke: var(--cp-rim-line); stroke-width: 2; pointer-events: none; }
.cp-addcell { pointer-events: none; }
.cp-addcell .cp-box { fill: var(--cp-add); stroke: var(--cp-rim-line); stroke-width: 2; stroke-dasharray: 5 4; }
.cp-addcell.is-corner .cp-box { fill: var(--cp-corner); stroke: var(--cp-corner); }
.cp-addcell.is-corner .cp-hooklen { fill: var(--cp-on-corner); }

.cp-step { cursor: pointer; }
.cp-step-hit { stroke: transparent; stroke-width: 14; }
.cp-step-line { stroke: var(--mp-muted); stroke-width: 2.5; stroke-linecap: round; }
.cp-step.is-bead .cp-step-line { stroke: var(--cp-bead); }
.cp-step.is-gap .cp-step-line { stroke: var(--mp-border-strong); stroke-dasharray: 2 4; }
.cp-step.in-path .cp-step-line { stroke: var(--cp-rim-line); stroke-width: 4; stroke-dasharray: none; }
.cp-step.is-candidate .cp-step-line { stroke: var(--cp-candidate); stroke-dasharray: none; }
.cp-step.is-chosen .cp-step-line { stroke: var(--cp-corner); stroke-width: 5; stroke-dasharray: none; }
.cp-step.is-linked .cp-step-line { stroke: var(--cp-link); stroke-width: 6; stroke-dasharray: none; }
.cp-steplabel { fill: var(--mp-muted); font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none; }
.cp-step.is-linked .cp-steplabel, .cp-step.is-chosen .cp-steplabel { fill: var(--mp-ink); font-weight: 700; }

/* Abacus */
.cp-runner { stroke: var(--mp-border-strong); stroke-width: 2; }
.cp-runnerlabel { fill: var(--mp-muted); font-size: 12px; font-weight: 600; }
.cp-slot { cursor: pointer; outline: none; }
.cp-slot-hit { fill: transparent; }
.cp-slot:hover .cp-slot-hit, .cp-slot:focus-visible .cp-slot-hit { fill: var(--cp-line); }
.cp-slot:focus-visible .cp-slot-hit { stroke: var(--mp-focus); stroke-width: 3; }
.cp-bead { fill: var(--cp-bead); }
.cp-beadlabel { fill: var(--cp-bead-text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: none; }
.cp-gapdot { fill: var(--mp-border-strong); }
.cp-gaplabel { fill: var(--mp-muted); font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none; }
.cp-slot.in-path .cp-slot-hit { fill: var(--cp-path); }
.cp-slot.in-path.is-bead .cp-bead { stroke: var(--cp-rim-line); stroke-width: 3; }
.cp-slot.is-candidate .cp-slot-hit { stroke: var(--cp-candidate); stroke-width: 2; stroke-dasharray: 3 3; }
.cp-slot.is-addcandidate .cp-slot-hit { stroke: var(--cp-rim-line); stroke-width: 2; stroke-dasharray: 3 3; }
/* Dragging a bead */
.cp-slot.is-bead { cursor: grab; touch-action: none; }
.cp-slot.is-dragging { opacity: .25; }
.cp-slot.is-drop .cp-slot-hit { fill: var(--mp-surface-soft); stroke: var(--cp-corner); stroke-width: 3; stroke-dasharray: none; }
.cp-slot.is-drop .cp-gapdot { fill: var(--cp-corner); }
.cp-dragbead { pointer-events: none; cursor: grabbing; filter: drop-shadow(0 3px 4px rgb(0 0 0 / 25%)); }
.cp-slot.is-chosen .cp-slot-hit { stroke: var(--cp-corner); stroke-width: 3; fill: var(--mp-surface-soft); }
.cp-slot.is-chosen.is-gap .cp-gapdot { fill: var(--cp-corner); r: 6; }
.cp-slot.is-linked .cp-slot-hit { stroke: var(--cp-link); stroke-width: 4; stroke-dasharray: none; }
.cp-slot.is-linked.is-gap .cp-gapdot { fill: var(--cp-link); }
.cp-slot.is-linked .cp-gaplabel { fill: var(--mp-ink); font-weight: 700; }
.cp-eup { fill: none; stroke: var(--cp-rim-line); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.cp-move { fill: none; stroke: var(--cp-corner); stroke-width: 3; pointer-events: none; }
.cp-arrowhead { fill: var(--cp-corner); }

/* Explanation */
.cp-explain { margin-top: 20px; padding: 16px 18px; border: 1px solid var(--mp-border); border-left: 4px solid var(--cp-rim-line);
  border-radius: var(--mp-radius-lg); background: var(--mp-surface); }
.cp-hover { min-height: 1.4em; margin: 0 0 8px; color: var(--cp-rim-line); font-size: .9375rem; font-weight: 600; }
.cp-explain-text { max-width: 70rem; font-size: 1.0625rem; line-height: 1.6; }
.cp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.cp-facts { margin: 12px 0 0; color: var(--mp-muted); font-size: .875rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cp-notes { margin-top: 20px; padding: 12px 18px; border: 1px solid var(--mp-border); border-radius: var(--mp-radius-lg); background: var(--mp-surface); }
.cp-notes summary { font-weight: 700; cursor: pointer; }
.cp-notes ol { margin: 10px 0 4px; padding-left: 1.3rem; line-height: 1.6; }
.cp-notes li + li { margin-top: 6px; }

@media (max-width: 960px) {
  .cp-stage { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .cp-heading h1 { font-size: 1.6rem; }
  .cp-controls { padding: 12px; }
}
