/* Scientific calculator (calculator.js): a floating window styled like Google's calculator */
.sc-calc {
  --sc-bg: #202124; --sc-screen: #202124; --sc-line: #5f6368; --sc-ink: #e8eaed; --sc-dim: #9aa0a6;
  --sc-fn: #2d303d; --sc-num: #3c3f48; --sc-hover: #474b56; --sc-eq: #4a72e8; --sc-on: #a8c7fa;
  position: fixed; top: 84px; right: 20px; z-index: 900; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 100px); max-height: calc(100dvh - 100px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--sc-bg); color: var(--sc-ink); border-radius: 22px; box-shadow: 0 18px 50px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.06);
  padding: 0 14px 14px; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; outline: none;
}
.sc-calc[hidden] { display: none; }
.sc-bar { display: flex; align-items: center; gap: 8px; padding: 10px 2px 8px; cursor: grab; user-select: none; touch-action: none; position: sticky; top: 0; background: var(--sc-bg); z-index: 1; }
.sc-bar:active { cursor: grabbing; }
.sc-grip { color: var(--sc-dim); font-size: 1rem; }
.sc-bar strong { font-size: .95rem; font-weight: 600; }
.sc-flags { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.sc-flags span { font-size: .72rem; font-weight: 700; color: #202124; background: var(--sc-on); padding: 2px 8px; border-radius: 99px; }
.sc-close { border: none; background: transparent; color: var(--sc-dim); font-size: 1.05rem; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }
.sc-close:hover { background: var(--sc-fn); color: var(--sc-ink); }

.sc-screen { position: relative; border: 1px solid var(--sc-line); border-radius: 18px; padding: 10px 16px 10px 48px; min-height: 92px; margin-bottom: 12px;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-end; gap: 2px; background: var(--sc-screen); }
.sc-hist-btn { position: absolute; left: 10px; top: 10px; border: none; background: transparent; color: var(--sc-dim); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.sc-hist-btn:hover { background: var(--sc-fn); color: var(--sc-ink); }
.sc-expr { min-height: 1.2em; font-size: .92rem; color: var(--sc-dim); text-align: right; word-break: break-all; }
.sc-out { font-size: 2.1rem; line-height: 1.2; text-align: right; word-break: break-all; font-variant-numeric: tabular-nums; }
.sc-typed { display: block; font-size: 1.55rem; }
.sc-preview { display: block; font-size: 1rem; color: var(--sc-dim); }
.sc-err { color: #f28b82; font-size: 1.5rem; }
.sc-x10 sup, .sc-out sup { font-size: .55em; }
.sc-frac { display: inline-flex; align-items: center; gap: 1px; }
.sc-frac sup { font-size: .7em; vertical-align: .55em; }
.sc-frac sub { font-size: .7em; vertical-align: -.25em; }
.sc-caret { display: inline-block; width: 2px; height: 1em; margin: 0 1px; vertical-align: -.12em; background: var(--sc-on); animation: scBlink 1s steps(1) infinite; }
@keyframes scBlink { 50% { opacity: 0; } }
.sc-hist { position: absolute; inset: 0; z-index: 2; background: var(--sc-bg); border-radius: 18px; padding: 44px 8px 8px; overflow-y: auto; display: grid; align-content: start; gap: 4px; }
.sc-hist[hidden] { display: none; }
.sc-hist-row { border: none; background: var(--sc-fn); color: var(--sc-ink); border-radius: 10px; padding: 8px 10px; text-align: right; cursor: pointer; font: inherit; display: grid; gap: 2px; }
.sc-hist-row span { color: var(--sc-dim); font-size: .82rem; }
.sc-hist-row:hover { background: var(--sc-hover); }
.sc-hist-clear { border: none; background: transparent; color: var(--sc-on); font: inherit; font-size: .82rem; cursor: pointer; justify-self: end; padding: 6px; }
.sc-hist-none { color: var(--sc-dim); font-size: .85rem; text-align: center; margin: 8px 0; }

.sc-keys { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.sc-key { border: none; cursor: pointer; font: inherit; font-size: 1rem; font-weight: 600; color: var(--sc-ink); background: var(--sc-fn); border-radius: 99px; height: 46px; padding: 0 4px;
  touch-action: manipulation; transition: background .12s; white-space: nowrap; overflow: hidden; }
.sc-key:hover { background: var(--sc-hover); }
.sc-key:active { transform: scale(.97); }
.sc-key.is-num { background: var(--sc-num); font-size: 1.15rem; }
.sc-key.is-num:hover { background: var(--sc-hover); }
.sc-key.is-eq { background: var(--sc-eq); color: #fff; font-size: 1.3rem; }
.sc-key.is-eq:hover { background: #5b82f0; }
.sc-key.is-on { background: var(--sc-on); color: #202124; }
.sc-key sup { font-size: .65em; }
.sc-key sub { font-size: .65em; }
.sc-angle { grid-column: span 2; display: flex; align-items: center; background: var(--sc-fn); border-radius: 99px; overflow: hidden; height: 46px; }
.sc-angle button { flex: 1; height: 100%; border: none; background: transparent; color: var(--sc-ink); font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; }
.sc-angle button + button { box-shadow: -1px 0 0 var(--sc-line); }
.sc-angle button.is-on { color: var(--sc-on); }
.sc-angle button:hover { background: var(--sc-hover); }

.sc-more { margin-top: 12px; }
.sc-more summary { cursor: pointer; color: var(--sc-dim); font-size: .82rem; font-weight: 600; padding: 4px 2px 8px; }
.sc-keys.is-more .sc-key { height: 40px; font-size: .9rem; }

@media (max-width: 640px) {
  .sc-calc { top: auto; bottom: 0; right: 0; left: 0; width: 100%; border-radius: 22px 22px 0 0; max-height: 78vh; max-height: 78dvh; padding: 0 10px 12px; }
  .sc-bar { cursor: default; }
  .sc-keys { gap: 6px; }
  .sc-key { height: 42px; font-size: .9rem; }
  .sc-key.is-num { font-size: 1.05rem; }
  .sc-angle { height: 42px; }
  .sc-angle button { font-size: .82rem; }
  .sc-keys.is-more .sc-key { height: 36px; font-size: .8rem; }
  .sc-out { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) { .sc-caret { animation: none; } }

/* the button that opens it, on calculator papers: on the right, just above "Show steps to solve" */
.ex-calc-row { margin-top: 14px; text-align: right; }
.ex-calc-row + .ex-feedback .ex-stuck { margin-top: 8px; }
.ex-calcbtn { display: inline-flex; align-items: center; gap: 8px; border: 0; cursor: pointer; font: inherit; font-weight: 800; font-size: .86rem; color: #fff;
  padding: 5px 13px; border-radius: 999px; background: linear-gradient(180deg, #5b82f0, #4a72e8); box-shadow: 0 3px 0 #2f55c9, 0 6px 14px rgba(74, 114, 232, .3); transition: transform .12s, box-shadow .12s; }
.ex-calcbtn:hover { transform: translateY(-1px); }
.ex-calcbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #2f55c9; }
.ex-calcbtn[aria-pressed="true"] { background: #2d303d; box-shadow: 0 3px 0 #15171d; }
.ex-calcbtn svg { flex: none; width: 18px; height: 18px; }
