/* calc-core base styles. Everything lives under .cc and is driven by custom properties.
   Theme from an engine: .cc.cc-<site> { --cc-accent: #0f766e; }  (two classes, wins regardless of load order)
   Rules: no url(), no :is()/:where(), no unscoped selectors except the print helper at the bottom. */

.cc {
  --cc-accent: #1d4ed8;
  --cc-accent-ink: #ffffff;
  --cc-accent-soft: #e8efff;
  --cc-bg: #ffffff;
  --cc-card: #f4f6f9;
  --cc-text: #1b2430;
  --cc-muted: #5a6472;
  --cc-border: #d3d9e2;
  --cc-radius: 10px;
  --cc-gap: 12px;
  --cc-pad: 14px;
  --cc-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --cc-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --cc-ok: #137a3d;
  --cc-warn: #9a5b00;
  --cc-err: #b42318;
  --cc-s0: var(--cc-accent);
  --cc-s1: #d97706;
  --cc-s2: #0f9d8a;
  --cc-s3: #9333ea;
  --cc-s4: #dc2626;
  --cc-s5: #64748b;
  --cc-out-min: 14rem;

  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 1.25em 0;
  padding: var(--cc-pad);
  background: var(--cc-bg);
  color: var(--cc-text);
  font-family: var(--cc-font);
  font-size: 16px;
  line-height: 1.45;
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius);
  text-align: left;
  overflow-wrap: break-word;
}
.cc *, .cc *::before, .cc *::after { box-sizing: border-box; }
.cc div, .cc span, .cc form, .cc label, .cc ul, .cc li, .cc details, .cc summary, .cc code, .cc caption { font-family: inherit; }

/* ---- layout ---- */
.cc .cc-in { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--cc-gap); margin: 0; padding: 0; border: 0; }
.cc .cc-out { min-height: var(--cc-out-min); margin-top: var(--cc-gap); padding-top: var(--cc-gap); border-top: 1px solid var(--cc-border); min-width: 0; }
.cc .cc-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: var(--cc-gap); }
.cc .cc-status { color: var(--cc-muted); font-size: 14px; min-height: 1.4em; }
.cc .cc-line { margin: 0 0 6px; }
.cc .cc-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- fields ---- */
.cc .cc-field { display: block; min-width: 0; margin: 0; }
.cc .cc-lab { display: block; margin: 0 0 4px; font-size: 14px; font-weight: 600; color: var(--cc-text); }
.cc .cc-hint { display: block; margin-top: 4px; font-size: 13px; color: var(--cc-muted); font-weight: 400; }
.cc .cc-ctl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cc .cc-unit { color: var(--cc-muted); font-size: 14px; white-space: nowrap; }
.cc .cc-input {
  box-sizing: border-box; display: block; width: 100%; min-width: 0; height: 44px; margin: 0; padding: 8px 10px;
  font: inherit; font-size: 16px; color: var(--cc-text); background: var(--cc-bg);
  border: 1px solid var(--cc-border); border-radius: calc(var(--cc-radius) - 2px); box-shadow: none; outline: 0;
}
.cc .cc-input:focus { border-color: var(--cc-accent); box-shadow: 0 0 0 3px var(--cc-accent-soft); }
.cc .cc-sl-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.cc .cc-sl-top .cc-lab { margin: 0; }
.cc .cc-sl-top .cc-ctl { flex: 0 0 auto; width: 9.5rem; max-width: 55%; }
.cc .cc-sl-top .cc-input { height: 38px; text-align: right; }
.cc .cc-range { display: block; width: 100%; height: 32px; margin: 4px 0 0; padding: 0; accent-color: var(--cc-accent); background: transparent; }

.cc .cc-toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.cc .cc-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cc .cc-tr { position: relative; flex: 0 0 auto; width: 42px; height: 24px; border-radius: 12px; background: var(--cc-border); }
.cc .cc-tr::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; }
.cc .cc-toggle input:checked + .cc-tr { background: var(--cc-accent); }
.cc .cc-toggle input:checked + .cc-tr::after { left: 21px; }
.cc .cc-toggle input:focus-visible + .cc-tr { box-shadow: 0 0 0 3px var(--cc-accent-soft); outline: 2px solid var(--cc-accent); }
.cc .cc-tl { font-size: 15px; }

/* ---- buttons (themes leak button styles, so reset first) ---- */
.cc button, .cc .cc-btn, .cc .cc-b {
  all: unset;
  box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; cursor: pointer; text-align: center;
  font-family: var(--cc-font); font-size: 15px; font-weight: 600; line-height: 1.2; letter-spacing: 0; text-transform: none; text-decoration: none;
  color: var(--cc-text); background: var(--cc-card); border: 1px solid var(--cc-border); border-radius: calc(var(--cc-radius) - 2px);
  -webkit-tap-highlight-color: transparent;
}
.cc .cc-btn:hover, .cc .cc-b:hover { border-color: var(--cc-accent); }
.cc .cc-btn:focus-visible, .cc .cc-b:focus-visible, .cc button:focus-visible { outline: 2px solid var(--cc-accent); outline-offset: 2px; }
.cc .cc-b[aria-pressed="true"] { background: var(--cc-accent); border-color: var(--cc-accent); color: var(--cc-accent-ink); }
.cc .cc-chips, .cc .cc-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.cc .cc-chips .cc-b, .cc .cc-presets .cc-b { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 999px; }
.cc .cc-seg { display: flex; width: 100%; max-width: 100%; border-radius: calc(var(--cc-radius) - 2px); }
.cc .cc-seg .cc-b { flex: 1 1 0; min-width: 0; padding: 0 8px; border-radius: 0; margin-left: -1px; }
.cc .cc-seg .cc-b:first-child { margin-left: 0; border-radius: calc(var(--cc-radius) - 2px) 0 0 calc(var(--cc-radius) - 2px); }
.cc .cc-seg .cc-b:last-child { border-radius: 0 calc(var(--cc-radius) - 2px) calc(var(--cc-radius) - 2px) 0; }
.cc .cc-units { max-width: 16rem; }

/* ---- combobox ---- */
.cc .cc-combo { position: relative; }
.cc .cc-list { position: absolute; z-index: 20; left: 0; right: 0; margin: 2px 0 0; padding: 4px 0; list-style: none; max-height: 14rem; overflow-y: auto; background: var(--cc-bg); border: 1px solid var(--cc-border); border-radius: calc(var(--cc-radius) - 2px); box-shadow: 0 6px 18px rgba(0, 0, 0, .12); }
.cc .cc-list[hidden] { display: none; }
.cc .cc-list li { display: block; margin: 0; padding: 9px 12px; cursor: pointer; list-style: none; }
.cc .cc-list li[aria-selected="true"], .cc .cc-list li:hover { background: var(--cc-accent-soft); }

/* ---- results ---- */
.cc .cc-answer { margin: 0 0 var(--cc-gap); padding: 12px 14px; font-size: 21px; font-weight: 700; line-height: 1.3; color: var(--cc-text); background: var(--cc-accent-soft); border-left: 4px solid var(--cc-accent); border-radius: calc(var(--cc-radius) - 2px); overflow-wrap: anywhere; }
.cc .cc-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 var(--cc-gap); }
.cc .cc-stat { min-width: 0; padding: 10px 12px; background: var(--cc-card); border-radius: calc(var(--cc-radius) - 2px); }
.cc .cc-stat-v { font-size: 22px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cc .cc-stat-u { font-size: 14px; font-weight: 500; color: var(--cc-muted); }
.cc .cc-stat-l { margin-top: 2px; font-size: 13px; color: var(--cc-muted); }
.cc .cc-stat-s { margin-top: 2px; font-size: 12px; color: var(--cc-muted); }
.cc .cc-rows { margin: 0 0 var(--cc-gap); }
.cc .cc-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--cc-border); }
.cc .cc-rl { flex: 1 1 9rem; min-width: 0; color: var(--cc-muted); font-size: 15px; }
.cc .cc-rv { flex: 0 1 auto; min-width: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cc .cc-rn { flex: 1 1 100%; font-size: 13px; color: var(--cc-muted); }
.cc .cc-note { margin: 0 0 var(--cc-gap); padding: 10px 12px; font-size: 14px; border-left: 4px solid var(--cc-accent); background: var(--cc-card); border-radius: calc(var(--cc-radius) - 2px); }
.cc .cc-note-warn { border-left-color: var(--cc-warn); }
.cc .cc-note-error { border-left-color: var(--cc-err); color: var(--cc-err); }
.cc .cc-math { margin: 0 0 var(--cc-gap); border: 1px solid var(--cc-border); border-radius: calc(var(--cc-radius) - 2px); }
.cc .cc-math summary { display: block; padding: 10px 12px; font-weight: 600; font-size: 15px; cursor: pointer; }
.cc .cc-math-body { padding: 0 12px 10px; }
.cc .cc-ml { display: block; font-size: 13px; color: var(--cc-muted); }
.cc .cc-mc { display: block; font-family: var(--cc-mono); font-size: 13px; background: var(--cc-card); padding: 4px 6px; border-radius: 4px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- tables: the wrapper scrolls, never the page ---- */
.cc .cc-tablewrap { max-width: 100%; margin: 0 0 var(--cc-gap); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cc .cc-table { display: table; width: 100%; min-width: 100%; border-collapse: collapse; font-size: 14px; margin: 0; background: transparent; border: 0; }
.cc .cc-table thead { display: table-header-group; }
.cc .cc-table tbody { display: table-row-group; }
.cc .cc-table tr { display: table-row; background: transparent; }
.cc .cc-table caption { display: table-caption; padding: 0 0 6px; font-size: 13px; color: var(--cc-muted); text-align: left; }
.cc td, .cc th, .cc .cc-table td, .cc .cc-table th { display: table-cell; padding: 8px 10px; text-align: left; vertical-align: top; border: 0; border-bottom: 1px solid var(--cc-border); background: transparent; font-size: 14px; color: var(--cc-text); white-space: nowrap; }
.cc th, .cc .cc-table th { font-weight: 700; background: var(--cc-card); }

/* ---- meters and charts ---- */
.cc .cc-bar { margin: 0 0 var(--cc-gap); }
.cc .cc-bar svg { display: block; width: 100%; height: auto; }
.cc .cc-m-bg { stroke: var(--cc-card); fill: var(--cc-card); }
.cc .cc-ring .cc-m-bg { fill: none; stroke: var(--cc-card); }
.cc .cc-m-fg { fill: var(--cc-accent); stroke: none; }
.cc .cc-ring .cc-m-fg { fill: none; stroke: var(--cc-accent); }
.cc .cc-m-l { display: block; font-size: 13px; color: var(--cc-muted); }
.cc .cc-ring { position: relative; display: inline-block; width: 110px; margin: 0 var(--cc-gap) var(--cc-gap) 0; text-align: center; }
.cc .cc-ring svg { display: block; width: 100%; height: auto; }
.cc .cc-ring-v { position: absolute; left: 0; right: 0; top: 36px; font-size: 20px; font-weight: 700; }
.cc .cc-chart { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 0 var(--cc-gap); overflow: visible; }
.cc .cc-ch-ax { stroke: var(--cc-muted); stroke-width: 1; }
.cc .cc-ch-g { stroke: var(--cc-border); stroke-width: 1; }
.cc .cc-ch-t { fill: var(--cc-muted); font-family: var(--cc-font); }
.cc .cc-ch-mt { fill: var(--cc-text); font-weight: 700; }
.cc .cc-ch-m { stroke: var(--cc-text); stroke-width: 1; stroke-dasharray: 4 3; }
.cc .cc-ch-dot { fill: var(--cc-bg); stroke: var(--cc-text); stroke-width: 2; }
.cc .cc-ch-l { stroke-linejoin: round; stroke-linecap: round; }
.cc .cc-s0 { stroke: var(--cc-s0); } .cc .cc-s1 { stroke: var(--cc-s1); } .cc .cc-s2 { stroke: var(--cc-s2); }
.cc .cc-s3 { stroke: var(--cc-s3); } .cc .cc-s4 { stroke: var(--cc-s4); } .cc .cc-s5 { stroke: var(--cc-s5); }
.cc .cc-ch-sw.cc-s0 { fill: var(--cc-s0); } .cc .cc-ch-sw.cc-s1 { fill: var(--cc-s1); } .cc .cc-ch-sw.cc-s2 { fill: var(--cc-s2); }
.cc .cc-ch-sw.cc-s3 { fill: var(--cc-s3); } .cc .cc-ch-sw.cc-s4 { fill: var(--cc-s4); } .cc .cc-ch-sw.cc-s5 { fill: var(--cc-s5); }

/* ---- sticky answer bar (built by JS on small screens; fixed, so no layout shift) ---- */
.cc .cc-sticky { display: none; }
.cc .cc-sticky:not([hidden]) {
  position: fixed; z-index: 999; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 10px; margin: 0;
  padding: 10px calc(14px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
  background: var(--cc-bg); color: var(--cc-text); border-top: 1px solid var(--cc-border); box-shadow: 0 -4px 14px rgba(0, 0, 0, .14);
}
@media (min-width: 768px) {
  .cc .cc-sticky:not([hidden]) { right: auto; bottom: 12px; border: 1px solid var(--cc-border); border-radius: var(--cc-radius); }
}
.cc .cc-sticky-t { flex: 1 1 auto; min-width: 0; font-size: 14px; font-weight: 700; line-height: 1.3; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.cc .cc-sticky-b { flex: 0 0 auto; white-space: nowrap; background: var(--cc-accent); border-color: var(--cc-accent); color: var(--cc-accent-ink); }

/* ---- embed mode ---- */
.cc .cc-credit { display: none; margin-top: var(--cc-gap); font-size: 13px; color: var(--cc-muted); }
.cc .cc-credit a { color: var(--cc-accent); text-decoration: underline; }
.cc.cc-embed { margin: 0; border: 0; border-radius: 0; }
.cc.cc-embed .cc-credit { display: block; }
.cc.cc-embed .cc-actions .cc-btn[data-act="embed"] { display: none; }
.cc.cc-embed .cc-sticky { display: none !important; }

/* ---- wider screens ---- */
@media (min-width: 640px) {
  .cc { --cc-pad: 20px; --cc-gap: 16px; }
  .cc .cc-in { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); align-items: start; }
  .cc .cc-in .cc-sl, .cc .cc-in .cc-presets, .cc .cc-in .cc-chips, .cc .cc-in .cc-toggle { grid-column: 1 / -1; }
  .cc .cc-stats { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
  .cc .cc-answer { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .cc *, .cc *::before, .cc *::after { animation: none; transition: none; scroll-behavior: auto; }
}

/* ---- print ---- */
@media print {
  .cc { margin: 0; padding: 0; border: 0; box-shadow: none; color: #000; background: #fff; break-inside: avoid; }
  .cc .cc-actions, .cc .cc-list, .cc .cc-credit, .cc .cc-sticky { display: none !important; }
  .cc .cc-out { min-height: 0; }
  .cc .cc-answer, .cc .cc-stat, .cc .cc-note { background: none; border: 1px solid #999; }
  .cc .cc-b[aria-pressed="true"] { color: #000; background: none; border: 2px solid #000; }
  .cc .cc-input { border-color: #999; }
  .cc-print-hide { display: none !important; }
}
