/* Helper calculators on guide pages (guides.json "calculator": "<name>", SiteBuilder): a toggle in the guide's header
   bar (the pro theme's #context, 56 px) and a panel under it. Light: the guide's own palette tokens (set by the viewer's
   theme on <html>); dark: the header's colours. Loaded only on guides that declare a calculator. */
.bwc {
  --bwc-bg: var(--panel, #fff); --bwc-ink: var(--ink, #26282d); --bwc-sub: var(--sub, #52565d);
  --bwc-rule: var(--panel-edge, #deddd7); --bwc-field: var(--canvas, #f4f3f0); --bwc-accent: var(--accent, #e5ae39);
  --bwc-on-accent: var(--on-accent, #26282d); --bwc-strong: var(--accent-text, #81590b);
  --bwc-ok: #2f7a3e; --bwc-warn: #a86a00; --bwc-bad: #b3361b;
  position: fixed; top: 0; right: 0; z-index: 4; font-family: var(--font, "Inter", Arial, sans-serif);
}
@media (prefers-color-scheme: dark) {
  .bwc {
    --bwc-bg: var(--context, #2d3036); --bwc-ink: var(--on-context, #fff); --bwc-sub: rgba(255, 255, 255, .74);
    --bwc-rule: rgba(255, 255, 255, .2); --bwc-field: rgba(255, 255, 255, .08); --bwc-strong: var(--accent, #e5ae39);
    --bwc-ok: #86d197; --bwc-warn: #f2c14e; --bwc-bad: #ff9a7a;
  }
}
/* room for the toggle at the right end of the header */
#context { padding-right: 160px; }

.bwc-toggle {
  display: flex; align-items: center; height: 36px; min-height: 36px; margin: 10px 20px 0 0; padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, .45); border-radius: 4px; color: var(--on-context, #fff);
  font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer; list-style: none; user-select: none;
}
.bwc-toggle::-webkit-details-marker { display: none; }
/* the calculator's mark before its name (data-mark, e.g. the portal's "÷8") */
.bwc-toggle[data-mark]::before { content: attr(data-mark); margin-right: 8px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--bwc-accent); }
.bwc-pop[open] > .bwc-toggle { background: var(--bwc-accent); border-color: var(--bwc-accent); color: var(--bwc-on-accent); }
.bwc-pop[open] > .bwc-toggle::before { color: inherit; }
.bwc-toggle:focus-visible, .bwc-check > summary:focus-visible { outline: 2px solid var(--bwc-accent); outline-offset: 2px; }

.bwc-panel {
  position: fixed; top: 64px; right: 20px; width: min(420px, calc(100vw - 24px));
  max-height: calc(100vh - 64px - 96px); max-height: calc(100dvh - 64px - 96px); overflow: auto; overscroll-behavior: contain;
  padding: 16px; background: var(--bwc-bg); color: var(--bwc-ink); border: 1px solid var(--bwc-rule); border-radius: 4px;
  box-shadow: 0 14px 36px rgba(20, 22, 26, .22); font-size: 14px; line-height: 1.45; font-variant-numeric: tabular-nums;
}
.bwc-panel p { margin: 0; }

.bwc-dir { display: flex; margin-bottom: 14px; }
.bwc-dir input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.bwc-dir label { flex: 1; padding: 8px 6px; border: 1px solid var(--bwc-rule); text-align: center; font-size: 13px; font-weight: 500; cursor: pointer; }
.bwc-dir label:first-of-type { border-radius: 4px 0 0 4px; }
.bwc-dir label:last-of-type { border-radius: 0 4px 4px 0; margin-left: -1px; }
.bwc-dir input:checked + label { background: var(--bwc-accent); border-color: var(--bwc-accent); color: var(--bwc-on-accent); }
.bwc-dir input:focus-visible + label { outline: 2px solid var(--bwc-ink); outline-offset: 2px; }

.bwc-label { display: block; margin: 0 0 6px; font-size: 12.5px; font-weight: 500; color: var(--bwc-sub); }
.bwc-xyz { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.bwc-xyz label { display: grid; gap: 2px; font-size: 12px; font-weight: 600; color: var(--bwc-sub); }
.bwc-xyz input, .bwc-len input {
  width: 100%; min-width: 0; padding: 7px 8px; border: 1px solid var(--bwc-rule); border-radius: 4px;
  background: var(--bwc-field); color: var(--bwc-ink); font: inherit; font-size: 16px; font-weight: 500;
  -moz-appearance: textfield; appearance: textfield;
}
.bwc-xyz input::-webkit-inner-spin-button, .bwc-xyz input::-webkit-outer-spin-button,
.bwc-len input::-webkit-inner-spin-button, .bwc-len input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.bwc-xyz input::placeholder { color: var(--bwc-sub); opacity: .55; }
.bwc-xyz input:focus-visible, .bwc-len input:focus-visible { outline: 2px solid var(--bwc-accent); outline-offset: 0; border-color: var(--bwc-accent); }

.bwc-out { display: block; margin-top: 12px; padding: 10px 12px; border-left: 3px solid var(--bwc-accent); border-radius: 0 4px 4px 0; background: var(--bwc-field); }
.bwc-out .bwc-label { margin-bottom: 2px; }
.bwc-big { display: block; font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
.bwc-big b { font-weight: 600; color: var(--bwc-strong); }
.bwc-big i { font-style: normal; color: var(--bwc-sub); }
.bwc-work { display: block; margin-top: 4px; font-size: 12.5px; color: var(--bwc-sub); }
.bwc-below { display: block; margin-top: 4px; font-size: 12.5px; font-weight: 600; }
.bwc-panel .bwc-note { margin-top: 10px; font-size: 13px; color: var(--bwc-sub); }

.bwc-check { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--bwc-rule); }
.bwc-check > summary { font-size: 14px; font-weight: 600; cursor: pointer; }
.bwc-panel .bwc-check > .bwc-note { margin-bottom: 4px; }
.bwc-check .bwc-label { margin-top: 10px; }
.bwc-verdicts { display: grid; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.bwc-verdicts li { position: relative; padding-left: 16px; font-size: 13.5px; }
.bwc-verdicts li::before { content: ""; position: absolute; left: 1px; top: .5em; width: 8px; height: 8px; border-radius: 50%; background: var(--bwc-sub); }
.bwc-verdicts li[data-state="ok"]::before { background: var(--bwc-ok); }
.bwc-verdicts li[data-state="warn"]::before { background: var(--bwc-warn); }
.bwc-verdicts li[data-state="bad"]::before { background: var(--bwc-bad); }

/* a number with its unit, a checkbox, a table of counts (ice-highway) */
.bwc-len > div { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--bwc-sub); }
.bwc-len input { width: 9em; }
.bwc-panel .bwc-len + .bwc-note { margin-top: 6px; font-size: 12.5px; }
.bwc-note + .bwc-dir { margin-top: 12px; }
.bwc-opt { display: flex; align-items: center; gap: 8px; margin-top: -4px; font-size: 14px; font-weight: 500; cursor: pointer; }
.bwc-opt input { width: 18px; height: 18px; margin: 0; accent-color: var(--bwc-accent); }
.bwc-opt input:focus-visible { outline: 2px solid var(--bwc-accent); outline-offset: 2px; }
.bwc-table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 13.5px; }
.bwc-table th, .bwc-table td { padding: 6px 0; border-bottom: 1px solid var(--bwc-rule); text-align: left; vertical-align: top; }
.bwc-table thead th { padding-top: 0; font-size: 12px; font-weight: 500; color: var(--bwc-sub); }
.bwc-table thead th + th, .bwc-table td { padding-left: 12px; text-align: right; white-space: nowrap; }
.bwc-table tbody th { font-weight: 600; }
.bwc-table td { font-weight: 600; }
.bwc-table td + td { font-weight: 500; color: var(--bwc-strong); }
.bwc-table small { display: block; margin-top: 1px; font-size: 12px; font-weight: 400; color: var(--bwc-sub); }
.bwc-panel .bwc-sum { margin-top: 8px; font-size: 13.5px; font-weight: 600; }
.bwc-panel .bwc-sum:empty { display: none; }

@media (max-width: 640px) {
  #context { padding-right: 132px; }
  .bwc-toggle { height: 34px; min-height: 34px; margin: 11px 12px 0 0; padding: 0 10px; font-size: 13px; }
  .bwc-toggle[data-mark]::before { margin-right: 6px; }
  .bwc-panel { top: 62px; left: 12px; right: 12px; width: auto; max-height: calc(100vh - 62px - 92px); max-height: calc(100dvh - 62px - 92px); padding: 14px 12px; }
  .bwc-big { font-size: 20px; }
}
