@font-face {
  font-family: 'GrundschriftRegular';
  src: url('Grundschrift-Regular.otf') format('opentype');
  font-weight: normal; font-style: normal; font-display: swap;
}
:root {
  --primary-red: #992727;   /* RGB(153,39,39) ≈ iOS firstColor */
  --primary-blue: #992727;  /* iOS secondColor default identical RGB */
  --bg: #f2f2f2; --field-bg: #CDCDCD;
  --trenner: rgb(128,128,128); /* MalFeld trennerColor — 5er separator lines */
  --strat-a: rgba(51,153,153,0.8); --strat-b: rgba(230,128,38,0.8); --strat-ghost: rgba(204,51,51,0.6);
  --strat-total: rgba(85,85,85,0.9); /* dark grey total — Swift .darkGray */
  --font: 'GrundschriftRegular', -apple-system, system-ui, sans-serif;
  /* UI / chrome font (toolbar, settings & view menus, share + archive modals):
     the OS default (SF Pro on Apple). Content below the menus keeps --font. */
  --ui-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Segoe UI', Roboto, sans-serif;
  /* StellenwertPicker place-value colours */
  --sw-einer: #2F6961;
  --sw-zehner: #1D5AAB;
  --sw-hunderter: #992727;
  --sw-tausender: #3F8B81;
}
* { box-sizing: border-box; }
/* Default to the OS UI font for all chrome (toolbar, modals, menus — these live
   outside #app). #app re-applies the Grundschrift for the actual content. */
body { margin: 0; font-family: var(--ui-font); background: var(--bg); }
.hidden { display: none !important; }

/* ── Grundschrift optical vertical centering ───────────────────────────────
   The Grundschrift font sits a touch high within its line box, so flex-centred
   text looks top-heavy in the equation boxes, the heading, the strategy bubbles
   and the 1×1 table. Nudge text-bearing elements DOWN by a small fraction of
   their font size to optically centre them. (Tune via the translateY value.) */
/* Plain (border-less) text: translateY nudges the whole element — fine here. */
#buendelungstext,
#additionsaufgabe,
.malterm-operator,
.malterm-equals,
.sv-op,
.sv-anno,
.sv-text,
.sw-digit {
  transform: translateY(0.08em);
}
/* Bordered / filled boxes: translateY would move the BOX (border+fill) with the
   text, so the text stays high INSIDE the box. Instead push the text down within
   the box via asymmetric vertical padding (top-heavy → flex-centred text drops). */

/* ============================================================
   Layout
   Top-to-bottom column: toolbar, buendelungstext, field-area,
   malterm-row, additionsaufgabe, geteiltterm-row, strategie,
   mallinie. #field-area is a row (malfeld + table) on
   landscape/desktop and a column on portrait (table hidden in
   portrait via its own media query).
   ============================================================ */
html, body { height: 100%; }
body { display: flex; flex-direction: column; min-height: 100vh; }

/* Toolbar: white bar, black icons, flex row aligned to the right. */
#toolbar {
  background: #fff;
  color: #000;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid #e3e3e3;
}
/* Left group (settings, share) sits flush left; right group flush right. */
.toolbar-group { display: flex; align-items: center; gap: 4px; }
.toolbar-btn {
  background: none;
  border: none;
  color: #000;
  font-size: 22px;
  line-height: 1;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toolbar-btn svg { display: block; }
.toolbar-btn:hover { background: rgba(0, 0, 0, 0.06); }
.toolbar-btn:active { background: rgba(0, 0, 0, 0.12); }

/* App body: vertical flex column that fills remaining height.
   The content area uses the Grundschrift; chrome (toolbar/modals) stays on the
   OS UI font from body. Canvas components read --font directly via JS. */
#app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  /* Breathing room under the last row (usually the equation) so it doesn't sit
     on the bottom edge — plus the home-indicator inset on iOS. */
  padding-bottom: calc(clamp(14px, 3.5vh, 36px) + env(safe-area-inset-bottom, 0px));
  /* The rows below the field (Strategie, Gleichungen, Zahlenlinie) have fixed
     heights. With all of them switched on in a short window they used to eat
     the whole column and squeeze #field-area to a couple of pixels — the
     Malfeld simply vanished. It now keeps a floor (see #field-area
     min-height) and the column scrolls instead of collapsing. */
  overflow-y: auto;
  overflow-x: hidden;
}

/* Equation row + text rows: fixed-height, centred. */
/* #malterm-row now sits below #field-area; margin-top gives breathing room
   between the field bottom and the Tausch arrow / equation digits. */
#malterm-row { flex: 0 0 auto; display: flex; justify-content: center; padding: 6px 0; margin-top: 6px; }
#additionsaufgabe,
#buendelungstext {
  flex: 0 0 auto;
  text-align: center;
  font-family: var(--font);
  font-size: clamp(20px, 5vw, 34px);
  padding: 4px 8px;
}
/* #buendelungstext is now the top heading above the field; give it a small
   bottom margin so it sits apart from the field edge. */
#buendelungstext { margin-bottom: 4px; }
#strategie { flex: 0 0 auto; }
#geteiltterm-row { flex: 0 0 auto; display: flex; justify-content: center; padding: 6px 0; }

/* Field area is a row (malfeld + table) on landscape / desktop. */
#field-area { flex-direction: row; gap: 16px; }
@media (orientation: portrait) {
  #field-area { flex-direction: column; gap: 0; }
}

/* ============================================================
   StellenwertPicker (adapted from Rechenfeld)
   Note: component CSS is also self-injected by js/ui/StellenwertPicker.js;
   these rules are provided here for static-analysis tooling and as
   an authoritative reference / override point.
   ============================================================ */

.stellenwert-picker {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  background: transparent;
  border-radius: 10px;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sw-labels {
  display: flex;
  justify-content: center;
  gap: 0;
  font-family: 'GrundschriftRegular', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.9rem;
  color: #888;
  margin-bottom: 2px;
}

.sw-label {
  text-align: center;
  transition: opacity 0.3s ease, width 0.3s ease;
}

.sw-label.hidden {
  opacity: 0;
  width: 0 !important;
  overflow: hidden;
}

.sw-columns {
  display: flex;
  justify-content: center;
  gap: 0;
  position: relative;
}

.sw-column {
  position: relative;
  overflow: hidden;
  transition: width 0.3s ease, opacity 0.3s ease;
}

.sw-column.hidden-column {
  width: 0 !important;
  opacity: 0;
  overflow: hidden;
}

.sw-scroll {
  position: relative;
  width: 100%;
  will-change: transform;
  transition: none;
}

.sw-scroll.animating {
  transition: transform 0.15s ease-out;
}

.sw-digit {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'GrundschriftRegular', -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: ns-resize;
  transition: opacity 0.2s ease;
}

.sw-digit.faded {
  opacity: 0.3;
}

/* Farbcodierung pro Stellenwert */
.sw-col-e .sw-digit { color: var(--sw-einer, #2F6961); }
.sw-col-z .sw-digit { color: var(--sw-zehner, #1D5AAB); }
.sw-col-h .sw-digit { color: var(--sw-hunderter, #992727); }
.sw-col-t .sw-digit { color: var(--sw-tausender, #3F8B81); }

/* Führende Null transparent */
.sw-column.leading-zero .sw-digit {
  color: transparent !important;
}

/* Auswahlmarkierung */
.sw-indicator {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.03);
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  border-radius: 4px;
}

/* Gradient-Fade oben/unten bei mehreren sichtbaren Ziffern */
.stellenwert-picker.sw-multi-digit .sw-column::before,
.stellenwert-picker.sw-multi-digit .sw-column::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 40%;
  pointer-events: none;
  z-index: 2;
}

.stellenwert-picker.sw-multi-digit .sw-column::before {
  top: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);
}

.stellenwert-picker.sw-multi-digit .sw-column::after {
  bottom: 0;
  background: linear-gradient(to top, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);
}

/* Indikator nur bei mehreren sichtbaren Ziffern */
.stellenwert-picker:not(.sw-multi-digit) .sw-indicator {
  display: none;
}

/* Nicht-farbige Variante */
.stellenwert-picker.sw-monochrome .sw-col-e .sw-digit,
.stellenwert-picker.sw-monochrome .sw-col-z .sw-digit,
.stellenwert-picker.sw-monochrome .sw-col-h .sw-digit,
.stellenwert-picker.sw-monochrome .sw-col-t .sw-digit {
  color: black;
}

/* Einheitliche Plättchenfarbe (überschreibt Stellenwertfarben) */
.stellenwert-picker.sw-uniform-color .sw-col-e .sw-digit,
.stellenwert-picker.sw-uniform-color .sw-col-z .sw-digit,
.stellenwert-picker.sw-uniform-color .sw-col-h .sw-digit,
.stellenwert-picker.sw-uniform-color .sw-col-t .sw-digit {
  color: var(--sw-uniform-color, black);
}

/* Aktiver Drag-Zustand */
.sw-column.dragging {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 6px;
}

/* ============================================================
   Malterm  (equation row: rot × blau = ergebnis)
   ============================================================ */

.malterm {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.25em;
  font-family: var(--font);
  flex-wrap: nowrap;
  /* Room above the digits for the Tausch arc, and a positioning context. */
  position: relative;
  padding-top: 28px;
}

/* Each picker sits in a positioned slot so its Abdecker cover can overlay it */
.malterm-slot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.malterm-picker {
  display: inline-flex;
}
/* Read-only term (division): digits cannot be scrolled/changed — the task is
   driven only by the multiplication factors or the Malfeld. */
.malterm--readonly .malterm-picker {
  pointer-events: none;
}

/* Operator (・/÷) and equals sign — large, in Grundschrift */
.malterm-operator,
.malterm-equals {
  font-family: var(--font);
  font-size: 2.5rem;
  line-height: 1;
  color: #333;
  padding: 0 0.1em;
  user-select: none;
  -webkit-user-select: none;
}

/* Abdecker cover — tappable overlay that hides a picker value */
.malterm-cover {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--field-bg, #CDCDCD);
  border: 2px solid #999;
  border-radius: 10px;
  cursor: pointer;
  z-index: 5;
}

.malterm-cover.hidden {
  display: none !important;
}

/* Malterm Tausch arrow — curved double-headed arc overlay above the equation.
   Absolutely positioned (left/top set inline by JS) relative to .malterm. */
.malterm-tausch-arrow {
  position: absolute;
  pointer-events: auto;
  overflow: visible;
  cursor: pointer;
  z-index: 6;
}

.malterm-tausch-path {
  transition: stroke-width 0.1s ease;
}

.malterm-tausch-arrow:hover .malterm-tausch-path,
.malterm-tausch-arrow:focus .malterm-tausch-path {
  stroke-width: 3;
}

.malterm-tausch-arrow:focus {
  outline: none;
}

.malterm-tausch-arrow.hidden {
  display: none !important;
}

/* ============================================================
   Malfeld  (canvas grid of Plättchen — the central visual)
   The canvas sizes itself in JS (resize()): it sets explicit
   width/height in CSS px to the field's exact aspect ratio and
   a devicePixelRatio backing store. We only need it to lay out
   centred inside #field-area and never overflow its container.
   ============================================================ */

#field-area {
  display: flex;
  /* flex-direction set by the Layout section (row landscape / column portrait) */
  align-items: stretch;   /* children may take the full row height (square sizing) */
  justify-content: center;
  width: 100%;
  flex: 1 1 auto;
  /* The field is the point of this screen, so it never gets squeezed away by
     the optional rows below it. Below this floor #app scrolls instead. */
  min-height: clamp(180px, 32vh, 340px);
}

/* Portrait stacks vertically — re-centre the (single) child. */
@media (orientation: portrait) {
  #field-area { align-items: center; }
}

#malfeldCanvas {
  display: block;
  flex: 0 0 auto;     /* intrinsic square size set by resize() — don't grab the row */
  align-self: center; /* vertically centred within the stretched row */
  max-width: 100%;
  max-height: 100%;
  /* width/height set in device-independent px by Malfeld.resize() */
}

/* ============================================================
   Mallinie  (canvas number line — Zahlenlinie / Sprünge)
   Single canvas sized to the full app width with a fixed-ish
   band height. It scrolls internally (drag + wheel) by drawing
   with a horizontal offset; pinch-zoom from the iOS source is
   intentionally omitted (see js/ui/mallinie.js header).
   Starts hidden; app.js unhides it based on settings.
   ============================================================ */

#mallinieCanvas {
  display: block;
  width: 100%;
  height: 150px;        /* fixed band — matches BAND_HEIGHT in mallinie.js */
  flex: 0 0 auto;       /* never stretch to fill the #app flex column */
  background: #fff;
  overflow: hidden;
  touch-action: none;   /* allow two-finger pinch-zoom + drag-scroll on canvas */
  cursor: grab;
  /* width/height backing store set by Mallinie.resize() (dpr-aware) */
}

#mallinieCanvas:active {
  cursor: grabbing;
}

/* ============================================================
   TaskTable  (10×10 multiplication table)
   Visible only in landscape / desktop; hidden in portrait.
   Also hidden when the .hidden class is applied (settings toggle).
   ============================================================ */

#tasktable {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Take the remaining row width (after the Malfeld square + gap) and stretch
     to the full row height, so the grid can be the largest square that fits. */
  flex: 1 1 auto;
  min-width: 0;
  align-self: stretch;
  /* Side breathing room so the table isn't crammed against the field / edge. */
  padding: 6px 20px;
}

.tasktable-grid {
  display: grid;
  /* minmax(0, 1fr) — NOT plain 1fr: the cells are nowrap, so an auto minimum
     would let their text push the grid wider than the box and clip the last
     column off the screen. */
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: 2px;
  /* Fill the available box — NON-square allowed. When extra width is free, the
     cells get WIDER (not square) so the "n・m" task fits on one line. */
  width: 100%;
  height: 100%;
  /* Label size is set in px by TaskTable.fit() from the room actually left
     over next to the Malfeld; this is only the value before the first fit. */
  font-size: 14px;
}

.tasktable-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  /* The task "n・m" must stay on ONE line — never wrap. The size comes from
     the grid (buttons don't inherit font-size on their own); overflow is
     clipped as a safety so a tight cell never breaks the grid layout. */
  font-size: inherit;
  white-space: nowrap;
  overflow: hidden;
  color: #444;
  background: #fff;
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: pointer;
  /* top-heavy padding so the "n・m" task sits optically centred (Grundschrift) */
  padding: 0.26em 2px 0;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, border-color 0.1s;
}

/* Background colour groups — matching Swift's visual grouping */
.tasktable-cell--10  { background: rgba(184, 226, 151, 0.5); }  /* ×10 rows/cols: green */
.tasktable-cell--1   { background: rgba(209, 212, 212, 0.5); }  /* ×1  rows/cols: light grey */
.tasktable-cell--quad{ background: rgba(232, 122, 163, 0.5); }  /* square tasks: pink */
.tasktable-cell--5   { background: rgba(249, 217, 140, 0.5); }  /* ×5  rows/cols: yellow */
.tasktable-cell--2   { background: rgba(121, 214, 249, 1.0); }  /* ×2  rows/cols: light blue */

/* Hover / press feedback */
.tasktable-cell:hover {
  filter: brightness(0.92);
}

.tasktable-cell:active {
  filter: brightness(0.80);
  transform: scale(0.94);
}

/* Active (current task) highlight — dark border, matching Swift's dark-red border */
.tasktable-cell.active {
  border-color: #4f0422;
  border-width: 3px;
  z-index: 1;
}

/* Portrait: hide the table (matching iOS behaviour) */
@media (orientation: portrait) {
  #tasktable {
    display: none;
  }
}

/* Too little room left beside the Malfeld — TaskTable.fit() sets this rather
   than let the labels shrink into illegibility. The freed width goes back to
   the field, which then centres in the row. */
#tasktable.tasktable--cramped {
  display: none;
}

/* StrategieView */
/* Mirrors SprechblasenView.swift: two-line speech-bubble carousel with
   chevron circle arrows, a page indicator and tap-to-speak. */
/* Outer "thought bubble" (Denkblase): a rounded, very-light box that wraps the
   whole carousel (arrows + bubbles + indicator), making clear these are the
   strategy thoughts. A trailing trail of dots (.sv-dots) forms the tail. */
.strategieview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 110px;
  margin: 6px auto 18px; /* bottom space for the trailing thought dots */
  padding: 10px 12px;
  max-width: 100%;
  background: #fcfcfd;
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-radius: 18px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}
.strategieview.hidden { display: none; }

/* Trailing thought dots (Denkpunkte) off the bottom-RIGHT corner — decreasing
   size, same light style as the bubble (white fill, soft border). */
.sv-dots {
  position: absolute;
  right: 14px;
  bottom: -14px;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}
.sv-dot {
  display: block;
  border-radius: 50%;
  background: #fcfcfd;
  border: 2px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}
.sv-dot--lg { width: 14px; height: 14px; }
.sv-dot--md { width: 9px;  height: 9px;  margin-top: 5px; }
.sv-dot--sm { width: 6px;  height: 6px;  margin-top: 9px; }

/* Chevron circle arrow buttons — chevron.left/right.circle.fill, ~28pt, darkGray.
   Inset slightly from the bubble edges ("nicht ganz am Rand") with margin and a
   comfortable hit area. */
.sv-arrow {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: 0 4px;
  border: none;
  border-radius: 50%;
  background: rgba(85, 85, 85, 0.12);
  color: #555; /* darkGray */
  /* System font, not Grundschrift — its chevron glyph centres correctly. */
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 26px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sv-arrow[hidden] { visibility: hidden; display: flex; } /* keep layout stable */
.sv-arrow:active { background: rgba(85, 85, 85, 0.24); }

.sv-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  min-width: 0;
}

.sv-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* Horizontal row of step / operator / result columns */
.sv-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
  max-width: 100%;
}

/* Vertical column: task bubble (top) + result bubble (bottom) */
.sv-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: stretch;
}
.sv-col--op {
  justify-content: space-between;
  gap: 2px;
}

/* Speech bubble — rounded rect (cornerRadius 12), 2px border at 70% opacity,
   fill at 15% opacity (Swift SprechblaseView.draw). Built from the per-bubble
   --sv-bubble-color via color-mix so a single CSS var drives both layers. */
.sv-bubble {
  font-family: var(--font);
  font-size: clamp(20px, 5vw, 34px);
  line-height: 1.1;
  color: #000;
  text-align: center;
  border-radius: 12px;
  /* top-heavy vertical padding optically centres the Grundschrift glyphs */
  padding: 0.32em 10px 0.06em;
  border: 2px solid color-mix(in srgb, var(--sv-bubble-color, #999) 70%, transparent);
  background: color-mix(in srgb, var(--sv-bubble-color, #999) 15%, transparent);
  white-space: nowrap;
}
.sv-bubble--ghost {
  /* subtracted "ghost" part — driven by --strat-ghost via --sv-bubble-color */
}
.sv-bubble--total {
  /* total result uses dark grey */
  font-weight: 600;
}
/* Empty placeholder bubble above the total (Swift: invisible, alpha 0) */
.sv-bubble--empty {
  border-color: transparent;
  background: transparent;
  visibility: hidden;
}

/* Operator labels (+ / − / =) — two stacked rows matching the two bubble rows */
.sv-op {
  font-family: var(--font);
  font-size: clamp(20px, 5vw, 34px);
  line-height: 1.1;
  color: #555; /* darkGray */
  text-align: center;
  padding: 4px 0;
}

/* Verbal Gruppensprache description (strategieDarstellung = 'sprachlich').
   A wrapping sentence centred in the thought bubble; the meaningful group
   phrases get a subtle coloured background (.sv-seg) matching the equation
   colours, connectors stay plain black. */
.sv-text {
  font-family: var(--font);
  font-size: clamp(17px, 4.2vw, 28px);
  line-height: 1.55;
  color: #000;
  text-align: center;
  max-width: 100%;
  padding: 2px 4px;
  white-space: normal;
}

/* Coloured highlight behind a group phrase — fill at 18%, soft 55% border,
   like the equation bubbles. box-decoration-break keeps the pill intact when
   the phrase wraps across lines. */
.sv-seg {
  --sv-seg-color: #999;
  border-radius: 9px;
  padding: 0.06em 0.34em;
  background: color-mix(in srgb, var(--sv-seg-color) 18%, transparent);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--sv-seg-color) 55%, transparent);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  white-space: nowrap;
}
.sv-seg--a     { --sv-seg-color: var(--strat-a); }
.sv-seg--b     { --sv-seg-color: var(--strat-b); }
.sv-seg--ghost { --sv-seg-color: var(--strat-ghost); }

/* "verdoppeln!" annotation — farbeB (orange) */
.sv-anno {
  font-family: var(--font);
  font-size: clamp(16px, 4vw, 26px);
  color: var(--strat-b);
  align-self: flex-end;
  padding-bottom: 6px;
  white-space: nowrap;
}

/* Page indicator — "Strategie X von Y", small grey */
.sv-page {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: gray;
  text-align: center;
  /* Always reserve the indicator line so the bubble height is constant whether
     or not "Strategie X von Y" is shown (prevents the layout from jumping). */
  min-height: 15px;
  line-height: 15px;
  /* Drop it lower so it sits in the gap between the bubbles and the bottom edge. */
  margin-top: 10px;
}
.sv-page[hidden] { display: none; }

@media (max-width: 480px) {
  .strategieview { min-height: 96px; padding: 8px 8px; }
  .sv-arrow { width: 34px; height: 34px; font-size: 22px; margin: 0 2px; }
}

/* ============================================================
   Settings (full modal + quick view-settings popover)
   Modal visuals mirror the Rechenfeld Webapp
   (.modal-overlay / .modal-content). Markup is injected by
   js/ui/settings.js; rules below style it.
   ============================================================ */

/* --- Full settings modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.modal-overlay.open { display: flex; }

.modal-content {
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  max-width: 360px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  font-family: var(--ui-font);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: #333;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #999;
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: #333; }

/* color + selector rows */
.color-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 12px;
}
.color-label {
  font-weight: 500;
  color: #555;
}
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-input {
  width: 50px;
  height: 40px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
}
.color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.color-input::-webkit-color-swatch {
  border: 2px solid #ddd;
  border-radius: 6px;
}
.reset-color-btn {
  background: #e0e0e0;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  color: #666;
}
.reset-color-btn:hover { background: #d0d0d0; }

.set-select {
  font-family: var(--ui-font);
  font-size: 1rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #fff;
  cursor: pointer;
}

/* boolean toggle rows in the modal */
.set-toggle-group {
  margin-top: 4px;
  padding: 4px 12px;
  background: #f5f5f5;
  border-radius: 12px;
}
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #e3e3e3;
}
.set-row:last-child { border-bottom: none; }
.set-label {
  font-weight: 500;
  color: #555;
  cursor: pointer;
}
.set-row input[type="checkbox"],
.view-menu-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary-red);
  cursor: pointer;
}

.modal-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
.modal-done-btn {
  background: var(--primary-red);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--ui-font);
}
.modal-done-btn:hover { opacity: 0.9; }

/* --- Quick view-settings popover (Darstellungsmenü) --- */
.view-menu {
  display: none;
  position: fixed;
  z-index: 1100;
  min-width: 240px;
  background: #fff;
  border-radius: 14px;
  padding: 8px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  font-family: var(--ui-font);
}
.view-menu.open { display: block; }
.view-menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid #ececec;
}
.view-menu-row:last-child { border-bottom: none; }
.view-menu-label {
  font-size: 0.95rem;
  color: #444;
  cursor: pointer;
}

/* Archive ------------------------------------------------------------- */

/* Save receipt: shutter flash + the picture flying into the archive button.
   Both hang on <body> (not on #app) so they lie above the whole page, and
   both are purely decorative — never in the way of a tap. */
.archive-flash {
  position: fixed;
  inset: 0;
  z-index: 2500;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.archive-shot {
  position: fixed;
  z-index: 2501;
  box-sizing: border-box;
  pointer-events: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 6px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
}
.archive-shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
/* Toolbar button that just took / caught the picture. */
.toolbar-btn.is-active { background: rgba(0, 0, 0, 0.12); }

.archive-toast {
  position: fixed;
  left: 50%;
  bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-family: var(--ui-font);
  font-size: 0.95rem;
  padding: 10px 18px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 3000;
}
.archive-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.archive-toast svg { flex: 0 0 auto; }
.archive-toast-label { font-weight: 600; }
.archive-toast-hint { opacity: 0.75; white-space: nowrap; }
/* Only the "saved" toast is a shortcut into the archive — plain messages
   stay click-through.
   It also sits elsewhere: bottom-centre is exactly where the equation is, and
   this hint stands for 3.6 s. So it lands top-right, under the archive button
   that just caught the picture — which is also where it points. */
.archive-toast--action {
  cursor: pointer;
  left: auto;
  bottom: auto;
  right: 12px;
  top: 60px;
  transform: translateY(-14px);
}
.archive-toast--action.show {
  pointer-events: auto;
  transform: translateY(0);
}
.archive-toast--action:hover { background: rgba(0, 0, 0, 0.95); }
@media (max-width: 480px) {
  .archive-toast-hint { display: none; }
}

.archive-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #f9f9f9;
  z-index: 2000;
  flex-direction: column;
}
.archive-overlay.open { display: flex; }

.archive-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #000;
  color: #fff;
  flex-wrap: wrap;
}
.archive-toolbar-left,
.archive-toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.archive-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
}
.archive-btn:hover { background: rgba(255, 255, 255, 0.15); }
.archive-ctl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ui-font);
  font-size: 0.85rem;
  color: #fff;
}
.archive-sort {
  font-family: var(--ui-font);
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 6px;
  border: none;
}
.archive-slider { width: 120px; }

.archive-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: start;
}
.archive-cell {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}
.archive-cell:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); }
.archive-cell img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.archive-cell.dragging { opacity: 0.4; }
.archive-cell.drag-over { outline: 3px dashed #1a73e8; outline-offset: -3px; }
.archive-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #888;
  font-family: var(--ui-font);
  padding: 60px 20px;
  font-size: 1.05rem;
}

/* Per-item action menu */
.archive-action-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2100;
}
.archive-action-menu {
  background: #fff;
  border-radius: 14px 14px 0 0;
  width: 100%;
  max-width: 420px;
  padding: 8px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  font-family: var(--ui-font);
}
@media (min-width: 520px) {
  .archive-action-backdrop { align-items: center; }
  .archive-action-menu { border-radius: 14px; }
}
.archive-action-title {
  text-align: center;
  font-weight: bold;
  padding: 10px 0;
  color: #333;
  border-bottom: 1px solid #eee;
}
.archive-action-row {
  display: flex;
  align-items: center;
  width: 100%;
  background: transparent;
  border: none;
  font-family: var(--ui-font);
  font-size: 1rem;
  text-align: left;
  padding: 14px 12px;
  cursor: pointer;
  color: #222;
  border-radius: 8px;
}
.archive-action-row:hover { background: #f2f2f2; }
.archive-action-row.destructive { color: #c0211f; }
.ar-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin-right: 10px;
}
.ar-ico svg { width: 22px; height: 22px; display: block; }

/* Inline SVG icons inside archive icon-buttons inherit currentColor. */
.archive-btn svg { width: 22px; height: 22px; display: block; }
.archive-anno-tool svg { width: 20px; height: 20px; display: block; }

/* Annotation overlay */
.archive-anno {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 2200;
  display: flex;
  flex-direction: column;
}
.archive-anno-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #111;
  flex-wrap: wrap;
}
.archive-anno-color {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 0;
}
.archive-anno-color.active { border-color: #fff; box-shadow: 0 0 0 2px #1a73e8; }
.archive-anno-tool {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-family: var(--ui-font);
  font-size: 0.95rem;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.archive-anno-tool:hover { background: rgba(255, 255, 255, 0.3); }
.archive-anno-tool.active { background: #1a73e8; }
.archive-anno-tool.primary { background: #1a73e8; }
.archive-anno-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
  background: #ececec;
}
.archive-anno-canvas {
  max-width: 100%;
  max-height: 100%;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  touch-action: none;
}

/* Print container — hidden on screen, only shown when printing. */
.archive-print { display: none; }
.archive-print-header {
  grid-column: 1 / -1;
  font-family: var(--ui-font);
  font-weight: bold;
  font-size: 12pt;
  margin-bottom: 8px;
}
.archive-print-cell {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.archive-print-cell img { max-width: 100%; height: auto; display: block; }

@media print {
  body * { visibility: hidden !important; }
  .archive-print, .archive-print * { visibility: visible !important; }
  .archive-print {
    display: grid !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    gap: 10px;
    padding: 12px;
  }
  .archive-overlay { background: #fff !important; }
}

/* ============================================================
   Matheforscher embedding (js/matheforscher.js)
   ============================================================ */

/* Generic hide used by the embedded UI machinery (preset/show/hide). */
.mf-emb-hidden { display: none !important; }

/* Embedded mode: trim the outer chrome so the field fills the iframe. */
body.embedded { min-height: 100vh; }

/* Reveal toggle (⋯): floats top-right, shows hidden toolbar on demand.
   Hidden by default; matheforscher.js sets display when something is hidden. */
#mf-reveal-btn {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 1000;
  width: 36px;
  height: 36px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  color: #000;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #d9d9d9;
  border-radius: 18px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
#mf-reveal-btn:hover { background: #fff; }
body.mf-revealed #mf-reveal-btn { background: #fff; }

/* lockAufgabe: the task (factors) cannot be changed by the student. Disable
   every interaction surface that would change rot/blau, and visually mute the
   random button. (The division row is already display-only.) */
body.mf-locked-task #malfeldCanvas,
body.mf-locked-task #tasktable,
body.mf-locked-task .malterm-picker,
body.mf-locked-task .malterm-tausch-arrow,
body.mf-locked-task #tb-random {
  pointer-events: none !important;
}
body.mf-locked-task #tb-random { opacity: 0.35; }

/* ============================================================
   Teilen / Share modal (js/share.js) — reuses .modal-overlay/.modal-content
   ============================================================ */
.share-content { text-align: center; max-width: 320px; }
.share-hint {
  font-size: 0.95rem;
  color: #555;
  margin: 0 0 16px;
  text-align: left;
}
.share-qr-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  margin-bottom: 16px;
}
.share-qr {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  border-radius: 8px;
}
.share-qr-fallback { color: #999; font-size: 0.9rem; padding: 24px; }
.share-link-row { display: flex; gap: 8px; }
.share-link {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--ui-font);
  font-size: 0.9rem;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #f5f5f5;
  color: #333;
}
.share-copy-btn {
  flex: 0 0 auto;
  background: var(--primary-red);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-family: var(--ui-font);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.share-copy-btn:hover { opacity: 0.9; }
