/* Lommeregneren ved opgaven (F5 §4.6, FS-R5, FS-R6, A5; _calculator.html.erb, calculator_controller.js).
   In the layout with the other task styles (so Turbo never shows it unstyled); every rule is scoped to
   .calculator-help or .calc-*, which only the calculator renders. Its own sheet with the formula sheet's
   layout (FS-K4): below 700 px from the bottom at most 80 % high, 700–1099 px at most 70 %, from 1100 px
   a panel on the right, min(42 %, 480 px), and the task moves left so the answer stays in view.
   A light panel also in the dark themes (FS-M1); the display is dark with light digits. Keys in a grid of
   4 columns, at least 48 × 48 px (FS-R6), shorter on a low screen so every key is in view. */
.calculator-help { margin: 0; padding: 0; border: 0; }
.calculator-help > summary { list-style: none; }
.calculator-help > .calc-scrim, .calculator-help > .calc-sheet { display: none; }
.calculator-help[open] > .calc-scrim { display: block; position: fixed; inset: 0; z-index: 60; background: rgb(10 26 26 / 30%); }
.calculator-help[open] > .calc-sheet { display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-height: 80dvh; overflow: hidden; background: var(--panel); color: var(--ink); border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 30px rgb(10 42 40 / 22%); padding-bottom: env(safe-area-inset-bottom); text-align: left; font-size: 16px; font-weight: 500;
  animation: calc-rise .25s ease; }
html:has(.calculator-help[open]) { overflow: hidden; }
.calculator-help.calc-still[open] > .calc-sheet { animation: none; }
@media (prefers-reduced-motion: reduce) { .calculator-help[open] > .calc-sheet { animation: none; } }
@keyframes calc-rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.calc-grab { flex: 0 0 auto; width: 46px; height: 5px; border-radius: 3px; background: #8b9a9a; margin: 8px auto 0; }
.calc-head { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 16px; }
.calc-head h2 { margin: 0 auto 0 0; font-size: 1.2rem; outline: none; color: var(--ink); }
.calc-close { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; min-width: 44px; padding: 6px 14px; border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--theme-strong, var(--ink)); font: inherit; font-weight: 750; cursor: pointer; }
.calc-close .luxi-icon { width: 20px; height: 20px; }
.calc-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 16px; display: grid; gap: 10px; align-content: start;
  width: 100%; max-width: 440px; margin: 0 auto; box-sizing: border-box; }

.calc-screen { background: #172a31; color: #fffefa; border-radius: 16px; padding: 8px 14px 10px; text-align: right; min-width: 0; }
.calc-expr { min-height: 1.4em; font-size: 17px; color: #d7e4e2; overflow-wrap: anywhere; line-height: 1.4; }
.calc-out { font-size: 32px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.calc-out.calc-error { font-size: 20px; font-weight: 750; color: #ffd9a8; }

.calc-keys { display: grid; grid-template-columns: repeat(4, minmax(48px, 1fr)); gap: 8px; }
.calc-key { min-height: 56px; min-width: 48px; padding: 0; border-radius: 14px; border: 1.5px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-size: 22px; font-weight: 800; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.calc-key.calc-num { background: #f3f1ea; color: #172a31; }
.calc-key.calc-clear { color: #8a2a1a; }
.calc-key.calc-eq { background: var(--theme-primary, var(--purple)); border-color: var(--theme-primary, var(--purple)); color: #fff; }
.calc-keys-young .calc-key.calc-eq { grid-column: span 2; }
.calc-key:active { transform: translateY(1px); }
.calc-key:hover { border-color: var(--theme-primary, var(--purple)); }
.calc-sheet :focus-visible { outline: 3px solid var(--theme-primary, var(--purple)); outline-offset: 2px; }
.calc-note { margin: 0 4px; color: var(--muted); font-size: 15px; }

/* A low screen (a phone in landscape, a short sheet): keys stay at least 48 px but no taller than fits. */
@media (max-height: 760px) { .calc-key { min-height: 48px; font-size: 20px; } .calc-out { font-size: 26px; } }

@media (min-width: 700px) {
  .calculator-help[open] > .calc-sheet { max-height: 70dvh; }
  .calc-body { padding: 0 20px 20px; }
}
@media (min-width: 1100px) {
  html:has(.calculator-help[open]) { overflow: auto; }
  .calculator-help[open] > .calc-scrim { background: transparent; pointer-events: none; }
  .calculator-help[open] > .calc-sheet { top: 0; left: auto; width: min(42%, 480px); max-height: none; border-radius: 20px 0 0 20px;
    border-left: 1.5px solid var(--line); box-shadow: -8px 0 28px rgb(10 42 40 / 18%); animation: none; }
  .task-screen:has(.calculator-help[open]) .app-shell { margin-right: min(42%, 480px); }
  .calc-grab { display: none; }
  .calc-body { padding: 0 14px 24px; }
}

/* The button by »Kladde« (the user 29.11): the same look as Kladde, side by side, wrapping on a narrow screen. */
.scratchpad-launch:has(.calculator-toggle) { gap: 10px; flex-wrap: wrap; }
.scratchpad-launch .calculator-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; border-color: var(--purple); color: var(--purple-dark); }
.scratchpad-launch .calculator-toggle[aria-expanded="true"] { background: var(--lavender); }
.scratchpad-launch .calculator-toggle .luxi-icon { width: 24px; height: 24px; }

/* The same button in Kladde's tool bar (luxi_c_cos 29.11). Seven tools of at least 44 px are tight on a phone: in a
   narrow Kladde the tools sit closer, and on the narrowest phones the row wraps rather than push »Luk« out of view. */
.scratchpad-tools:has(> .calculator-toggle) { flex-wrap: wrap; row-gap: 6px; }
@container (max-width: 420px) {
  .scratchpad-tools:has(> .calculator-toggle) { gap: 2px; padding-inline: 4px; }
  .scratchpad-tools:has(> .calculator-toggle) .scratchpad-modes { gap: 2px; margin-right: 0; }
  .scratchpad-tools:has(> .calculator-toggle) .scratchpad-tool { padding-inline: 5px; gap: 3px; }
  /* »Tegn« and »Skriv« keep their words and give up their icons, so »Luk« stays on the row at 390 px. */
  .scratchpad-tools:has(> .calculator-toggle) .scratchpad-modes .scratchpad-tool:has(> span:not(.scratchpad-tool-label)) .luxi-icon { display: none; }
}
