/* Pop-up calculator (js/calculator.js), shared by the lessons and the Excel Lab. Uses --text/--bg/--muted/--mono from the page. */
.calc-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 900;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: var(--bg); color: var(--text); cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: transform 0.12s ease;
}
.calc-fab:hover { transform: translateY(-2px); }
.calc-fab.on { background: var(--text); color: var(--bg); }
.calc-fab:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

.calc-win {
  position: fixed; z-index: 901; left: 0; top: 0;
  width: 264px; max-width: calc(100vw - 16px);
  background: color-mix(in srgb, var(--bg) 94%, var(--text));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent);
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden; outline: none;
  user-select: none; -webkit-user-select: none;
}
.calc-win[hidden] { display: none; }
.calc-win:focus-visible { box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28), 0 0 0 2px var(--text); }
.calc-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 6px 6px 14px; cursor: grab; touch-action: none;
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
}
.calc-win.dragging .calc-bar { cursor: grabbing; }
.calc-close {
  width: 28px; height: 28px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.calc-close:hover { background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--text); }
.calc-screen { padding: 10px 16px 8px; text-align: right; font-family: var(--mono); }
.calc-expr { min-height: 1.1em; font-size: 0.78rem; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.calc-val { font-size: 2rem; line-height: 1.25; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; user-select: text; -webkit-user-select: text; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px 10px 12px; }
.calc-keys button {
  height: 46px; border-radius: 10px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  background: var(--bg); color: var(--text);
  font: 500 1.1rem/1 var(--mono);
  transition: background 0.1s ease;
  touch-action: manipulation;
}
.calc-keys button:hover { background: color-mix(in srgb, var(--text) 7%, var(--bg)); }
.calc-keys button.fn { color: var(--muted); font-size: 0.95rem; }
.calc-keys button.op { background: color-mix(in srgb, var(--text) 9%, var(--bg)); font-size: 1.25rem; }
.calc-keys button.eq { background: var(--text); color: var(--bg); font-size: 1.25rem; }
.calc-keys button:active, .calc-keys button.pressed { filter: brightness(0.85); transform: scale(0.97); }

/* the Calculator | Sheet switch in the title bar */
.calc-modes { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: color-mix(in srgb, var(--text) 7%, transparent); }
.calc-modes button {
  height: 24px; padding: 0 10px; border: 0; border-radius: 6px; background: none; cursor: pointer;
  color: var(--muted); font: 600 0.68rem/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
}
.calc-modes button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.calc-modes button:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.calc-pane[hidden] { display: none !important; }

/* sheet mode: a small spreadsheet (js/xl.js) that fills the pop-up; resized from the corner grip */
.calc-win.sheet-mode { display: flex; flex-direction: column; min-width: 280px; min-height: 260px; max-height: calc(100vh - 16px); user-select: text; -webkit-user-select: text; }
.calc-win.sheet-mode[hidden] { display: none; }
.calc-pane-sheet { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 6px 6px 0; }
.calc-sheet { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.calc-loading { margin: auto; color: var(--muted); font-size: 0.85rem; }
.calc-sheet.xl { font-size: 0.85rem; }
.calc-sheet .xl-tabs, .calc-sheet .xl-tools { display: none !important; }
.calc-sheet .xl-ribbon { position: relative; border: 0; padding: 0; margin: 0; min-height: 0; background: none; }
.calc-sheet .xl-bar { border-radius: 8px 8px 0 0; border-bottom: 1px solid var(--xl-grid); }
.calc-sheet .xl-scroll { flex: 1; min-height: 60px; max-height: none; border-top: 0; }
.calc-sheet .xl-sheets { flex: none; }
.calc-sheet .xl-status { flex: none; min-height: 1.5em; padding: 2px 8px; font-size: 0.7rem; }
.calc-sheet .xl-pop { z-index: 20; max-width: calc(100% - 12px); }
.calc-foot { flex: none; display: flex; align-items: center; gap: 8px; padding: 5px 18px 7px 2px; font-size: 0.7rem; color: var(--muted); }
.calc-tip { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.calc-tip code { font: 0.68rem var(--mono); }
.calc-saved { color: var(--muted); white-space: nowrap; }
.calc-clear {
  flex: none; height: 24px; padding: 0 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent); background: var(--bg); color: var(--text);
  font: 600 0.72rem/1 system-ui, sans-serif;
}
.calc-clear:hover { background: color-mix(in srgb, var(--text) 7%, var(--bg)); }
.calc-grip {
  position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, color-mix(in srgb, var(--text) 30%, transparent) 50%, transparent 62%, color-mix(in srgb, var(--text) 30%, transparent) 62%, transparent 74%);
  border-bottom-right-radius: 14px;
}

@media (max-width: 600px) {
  .calc-fab { right: 14px; bottom: 14px; width: 48px; height: 48px; }
  .calc-keys button { height: 50px; }
  .calc-tip { display: none; }
  .calc-foot { justify-content: flex-end; }
}
@media print { .calc-fab, .calc-win { display: none !important; } }
/* room at the bottom so the calculator button never covers the last line of a page */
body::after { content: ""; display: block; height: 76px; }
