/* Sichten der Multiplikation: Fläche (fl-), Malkreuz (mk-), Notation (mn-).
   Nur Variablen aus styles.css; eigene Variablen tragen das Präfix der Sicht. */

/* ---------- Fläche ---------- */

.fl-root {
  width: 100%;
  display: grid;
  place-items: center;
}

/* Breite und Höhe setzt FlaechenView passend zur Tafel; dies ist nur der Ausgangswert. */
.fl-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.fl-svg text { font-family: var(--digit-font); }

.fl-side { fill: var(--fl-ink, var(--ink)); }
.fl-side-zero { fill: var(--muted); }
.fl-dim { fill: none; stroke: var(--muted); stroke-width: 0.8; }
.fl-outline { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 2; }

.fl-cell { cursor: pointer; outline: none; transition: opacity 0.2s; }
.fl-hit { fill: transparent; }
.fl-is-active .fl-hit { fill: color-mix(in srgb, var(--focus) 8%, transparent); }

.fl-piece,
.fl-mat,
.fl-area { fill: var(--fl-fill); stroke: var(--fl-stroke); stroke-width: 0.8; }
.fl-area { stroke-width: 1.4; }
.fl-face-side { fill: color-mix(in srgb, var(--fl-stroke) 45%, var(--fl-fill)); }
.fl-marks { fill: none; stroke: var(--fl-stroke); stroke-width: 0.45; opacity: 0.55; pointer-events: none; }

/* Noch offen: nur blasse Umrisse. */
.fl-is-pending .fl-piece,
.fl-is-pending .fl-mat { fill: var(--paper); stroke: var(--line); }
.fl-is-pending .fl-marks { opacity: 0; }
.fl-is-pending .fl-area { fill: none; stroke: var(--line); stroke-dasharray: 4 3; }

/* Teil mit Ziffer 0: keine Fläche, nur eine gestrichelte Linie. */
.fl-zero { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 3 3; }
.fl-is-pending .fl-zero { stroke: var(--line); }
.fl-is-active .fl-zero { stroke: var(--focus); stroke-width: 2.6; }

.fl-region { fill: none; stroke: none; }
.fl-frame { fill: none; stroke: var(--focus); stroke-width: 2.6; }

.fl-label { pointer-events: none; }
.fl-pill { fill: var(--paper); fill-opacity: 0.94; stroke: var(--fl-ink, var(--ink)); stroke-width: 0.8; }
.fl-num { fill: var(--fl-ink, var(--ink)); }

/* Gekoppelte Hervorhebung: Auswahl kräftig und gestrichelt umrandet, Rest abgedunkelt. */
.fl-has-highlight .fl-cell:not(.fl-is-picked) { opacity: 0.2; }
.fl-has-highlight .fl-is-picked .fl-region { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 3; }
.fl-cell:focus-visible .fl-region { stroke: var(--green); stroke-width: 2.2; stroke-dasharray: none; }

/* Gruppen in der Stellenwerttafel */
.fl-head { fill: var(--fl-fill); stroke: none; }
.fl-headtext { fill: var(--fl-ink, var(--ink)); font-weight: 600; }
.fl-rownum { fill: var(--muted); }
.fl-grid { fill: none; stroke: var(--line); stroke-width: 0.7; }
.fl-grid-strong { fill: none; stroke: var(--muted); stroke-width: 0.9; }
.fl-tableframe { fill: none; stroke: var(--strong-line); stroke-width: 1.1; }
.fl-collabel { fill: var(--ink); }
.fl-is-active .fl-collabel { fill: var(--focus); }

/* ---------- Malkreuz ---------- */

.mk-root {
  width: 100%;
  container-type: inline-size;
  display: flex;
  justify-content: center;
}

.mk-table {
  --mk-fs: max(12px, min(20px, var(--mk-hmax, 20px)));
  border-collapse: collapse;
  font-family: var(--digit-font);
  font-size: var(--mk-fs);
  line-height: 1.15;
  color: var(--ink);
}
/* Schrift so groß, dass die ganze Tabelle in die Tafel passt: Breite über --mk-em (Breite in em),
   Höhe über --mk-hmax (setzt MalkreuzView aus der Tafelhöhe). */
@supports (width: 1cqw) {
  .mk-table { --mk-fs: clamp(12px, min(calc(100cqw / var(--mk-em)), var(--mk-hmax, 30px)), 30px); }
}

.mk-table th,
.mk-table td {
  padding: 0.3em 0.45em;
  height: 1.9em;
  text-align: center;
  white-space: nowrap;
  font-weight: 400;
  border: 1px solid var(--line);
}

/* Das Kreuz: kräftige Linien unter dem Kopf und rechts neben der Kopfspalte. */
.mk-table thead th,
.mk-table thead td { border-top: 0; border-bottom: 2.5px solid var(--strong-line); }
.mk-corner,
.mk-head-row,
.mk-sumhead { border-left: 0; border-right: 2.5px solid var(--strong-line); }
.mk-corner { color: var(--muted); font-size: 1.15em; }
.mk-head { color: var(--mk-ink, var(--ink)); }
.mk-zero { color: var(--muted); }
.mk-head-active { text-decoration: underline 3px var(--focus); text-underline-offset: 0.2em; }

.mk-cell,
.mk-sum,
.mk-total { color: var(--mk-ink, var(--ink)); transition: opacity 0.2s, background-color 0.2s; }
.mk-cell,
.mk-sum { cursor: pointer; }
.mk-cell.mk-is-done { background: color-mix(in srgb, var(--mk-soft, transparent) 55%, var(--paper)); }
.mk-cell.mk-is-active {
  background: color-mix(in srgb, var(--focus) 12%, var(--paper));
  box-shadow: inset 0 0 0 3px var(--focus);
}
.mk-cell:focus-visible,
.mk-sum:focus-visible { outline: 2px solid color-mix(in srgb, var(--green) 60%, transparent); outline-offset: -2px; }

.mk-spacer { border: 0 !important; background: transparent; }

/* Spaltensummen = Teilproduktzeilen der Notation */
.mk-sums th,
.mk-sums td { border-top: 2.5px solid var(--strong-line); border-bottom: 0; }
.mk-sum,
.mk-total { position: relative; }
.mk-total { border: 2px solid var(--strong-line); }
.mk-is-final { border-bottom: 4px double var(--ink); }
.mk-plus::before,
.mk-eq::before {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 0 0.12em;
  background: var(--paper);
  color: var(--muted);
  font-size: 0.8em;
  line-height: 1;
}
.mk-plus::before { content: "+"; }
.mk-eq::before { content: "="; }

/* Gekoppelte Hervorhebung */
.mk-has-highlight .mk-cell:not(.mk-is-picked),
.mk-has-highlight .mk-sum:not(.mk-is-picked),
.mk-has-highlight .mk-total { opacity: 0.28; }
.mk-has-highlight .mk-cell.mk-is-picked,
.mk-has-highlight .mk-sum.mk-is-picked { outline: 2px dashed var(--ink); outline-offset: -5px; }
.mk-has-highlight .mk-head.mk-is-picked { background: var(--surface-2); }

/* ---------- Notation ---------- */

.mn-root {
  width: 100%;
  container-type: inline-size;
  display: flex;
  justify-content: center;
}

/* Kariertes Papier: Raster aus Hintergrundlinien, je ein halbes Kästchen Rand. */
.mn-sheet {
  --mn-cell: max(18px, min(var(--cell), var(--mn-hmax, 999px)));
  display: grid;
  grid-auto-rows: var(--mn-cell);
  padding: calc(var(--mn-cell) / 2);
  background-color: var(--paper);
  background-image:
    linear-gradient(to bottom, var(--line) 1px, transparent 1px),
    linear-gradient(to right, var(--line) 1px, transparent 1px);
  background-size: var(--mn-cell) var(--mn-cell);
  background-position: calc(var(--mn-cell) / 2) calc(var(--mn-cell) / 2);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--digit-font);
  font-size: calc(var(--mn-cell) * 0.68);
  line-height: 1;
  color: var(--ink);
}
/* Lange Aufgaben: Kästchen verkleinern, damit das Raster in der Tafel bleibt (Breite über
   Containereinheiten, Höhe über --mn-hmax aus MultNotationView). */
@supports (width: 1cqw) {
  .mn-sheet {
    --mn-cell: max(18px, min(var(--cell), calc((100cqw - 4px) / var(--mn-cols)), var(--mn-hmax, 999px)));
  }
}

.mn-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--mn-n), var(--mn-cell));
  height: var(--mn-cell);
  transition: opacity 0.2s;
}
.mn-cell {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 3px;
}
.mn-digit { color: var(--mn-ink, var(--ink)); }
.mn-sign { color: var(--ink); }
.mn-ghost { opacity: 0.3; }
/* Gemerkter Übertrag klein oben links im Kästchen (oben rechts sähe er wie eine Hochzahl aus). */
.mn-carry {
  position: absolute;
  top: 3%;
  left: 8%;
  font-size: 0.42em;
  color: var(--mn-ink, var(--muted));
}

/* Striche: einfach unter der Aufgabe und vor der Summe, doppelt unter dem Ergebnis. */
.mn-line::after,
.mn-double::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}
.mn-line::after { bottom: -1px; height: 2px; background: var(--ink); }
.mn-double::after { bottom: -5px; height: 7px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }

/* Fokus des Schritts */
.mn-cell.mn-is-focus {
  background: color-mix(in srgb, var(--focus) 15%, transparent);
  box-shadow: inset 0 0 0 2px var(--focus);
}
.mn-cell.mn-col-focus { background: color-mix(in srgb, var(--focus) 8%, transparent); }
.mn-cell.mn-factor-focus::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 2px solid var(--focus);
  border-radius: 50%;
}

.mn-partial { cursor: pointer; border-radius: 3px; }
.mn-partial:focus-visible { outline: 2px solid color-mix(in srgb, var(--green) 60%, transparent); outline-offset: 1px; }

/* Gekoppelte Hervorhebung */
.mn-has-highlight .mn-partial:not(.mn-is-picked),
.mn-has-highlight .mn-sum { opacity: 0.28; }
.mn-has-highlight .mn-partial.mn-is-picked { outline: 2px dashed var(--ink); outline-offset: -1px; }
.mn-has-highlight .mn-factors .mn-cell:not(.mn-is-picked) { opacity: 0.4; }
.mn-has-highlight .mn-factors .mn-cell.mn-is-picked { background: var(--surface-2); }

/* ---------- Animationen ----------
   Einsatz und Dauer setzen die Sichten inline (style.animation, fill-mode backwards) nach dem
   gemeinsamen Takt TIMING. Keyframes ohne Endbild laufen in den normalen Stil, das Endbild ist
   also immer der Zustand des Snapshots. Animiert werden nur innere Elemente, damit die
   gekoppelte Hervorhebung (Deckkraft der Zellen und Zeilen) unberührt bleibt. */

.fl-piece,
.fl-mat,
.fl-label { transform-box: fill-box; transform-origin: center; }
.fl-area { transform-box: fill-box; transform-origin: 0 0; }
.fl-glow,
.fl-rowglow { fill: var(--focus); opacity: 0; pointer-events: none; }

/* Teil wechselt vom blassen Umriss zur Farbe seiner Stelle. */
@keyframes fl-fill { from { fill: var(--paper); stroke: var(--line); } }
@keyframes fl-fade { from { opacity: 0; } }
@keyframes fl-grow { from { transform: scale(0); } }
@keyframes fl-pop { from { opacity: 0; transform: scale(0.85); } }
@keyframes fl-flash { 40% { fill: color-mix(in srgb, var(--focus) 30%, transparent); } }
@keyframes fl-zeroflash { 0% { stroke: var(--line); stroke-width: 1.2; } 40% { stroke-width: 4.4; } }
@keyframes fl-rowglow { 0% { opacity: 0; } 35% { opacity: 0.2; } 100% { opacity: 0; } }
@keyframes fl-glow { 0% { opacity: 0; } 40% { opacity: 0.1; } 100% { opacity: 0; } }
@keyframes fl-outline-glow { 40% { stroke: var(--focus); stroke-width: 2.4; } }

.mk-val { display: inline-block; }
@keyframes mk-in { from { opacity: 0; transform: scale(0.8); } }
@keyframes mk-fade { from { opacity: 0; } }
@keyframes mk-flash { 40% { background-color: color-mix(in srgb, var(--focus) 30%, var(--paper)); } }
@keyframes mk-final {
  0% { border-bottom-color: transparent; }
  40% { background-color: color-mix(in srgb, var(--focus) 14%, transparent); }
}
.mk-anim-sign::before { animation: mk-fade 300ms ease-out var(--mk-d, 0ms) backwards; }

.mn-digit,
.mn-carry { transform-origin: center; }
@keyframes mn-in { from { opacity: 0; transform: translateY(-0.18em); } }
@keyframes mn-pulse { 45% { transform: scale(1.3); } }
@keyframes mn-pulse-carry { 45% { transform: scale(2); } }
/* Übertrag: erscheint neben seiner Ziffer in Zifferngröße, dann klein in die Ecke. */
@keyframes mn-fly {
  0% { opacity: 0; transform: translate(var(--mn-fx, 0), var(--mn-fy, 0)) scale(var(--mn-fs, 1)); }
  25% { opacity: 1; transform: translate(var(--mn-fx, 0), var(--mn-fy, 0)) scale(var(--mn-fs, 1)); }
  100% { opacity: 1; transform: translate(0, 0) scale(1); }
}
@keyframes mn-wash { 35% { background-color: color-mix(in srgb, var(--focus) 16%, transparent); } }
@keyframes mn-draw { from { transform: scaleX(0); } }
.mn-anim-draw::after {
  transform-origin: left center;
  animation: mn-draw 480ms cubic-bezier(0.22, 0.61, 0.36, 1) var(--mn-d, 0ms) backwards;
}

/* Die Sichten prüfen das selbst; dies fängt die Pseudoelemente ab, die „*“ nicht erfasst. */
@media (prefers-reduced-motion: reduce) {
  .mk-anim-sign::before,
  .mn-anim-draw::after { animation: none; }
}

/* ---------- Selbst eintragen ---------- */
.mk-slot { min-width: 2.4em; min-height: 1.35em; font-size: 1em; }
/* Die Lücke bleibt auch bei Hervorhebung voll sichtbar. */
.mk-root.mk-has-highlight td.mk-has-slot { opacity: 1; }
.mn-slot {
  position: absolute;
  inset: 7%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 4px;
  font-size: 1em;
}
.mn-slot-carry {
  inset: auto;
  top: 1%;
  left: 2%;
  width: 46%;
  height: 46%;
  border-width: 1.5px;
  border-radius: 3px;
  font-size: 0.42em;
}
.mn-sheet.mn-has-highlight .mn-row.mn-has-slot { opacity: 1; }

/* Beim Eintragen: Markierungen des gezeigten Schritts treten zurück, markiert ist der nächste. */
.fl-cueing .fl-frame { display: none; }
.fl-cueing .fl-is-active .fl-hit { fill: transparent; }
.fl-cueing .fl-is-active .fl-zero { stroke: var(--muted); stroke-width: 1.2; }
.fl-cueing .fl-is-active .fl-collabel { fill: var(--ink); }
.fl-cue .fl-hit { fill: color-mix(in srgb, var(--focus) 8%, transparent); }
.fl-cue .fl-region { stroke: var(--focus); stroke-width: 2.6; }
.mk-cueing .mk-cell.mk-is-active {
  background: color-mix(in srgb, var(--mk-soft, transparent) 55%, var(--paper));
  box-shadow: none;
}
.mk-cueing .mk-head-active:not(.mk-cue) { text-decoration: none; }
.mk-head.mk-cue { text-decoration: underline 3px var(--focus); text-underline-offset: 0.2em; }
.mn-cueing .mn-cell.mn-is-focus { background: none; box-shadow: none; }
.mn-cueing .mn-cell.mn-col-focus:not(.mn-cue-col) { background: none; }
.mn-cueing .mn-cell.mn-factor-focus:not(.mn-cue)::before { display: none; }
.mn-cell.mn-cue::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 2px solid var(--focus);
  border-radius: 50%;
}
.mn-cell.mn-cue-col { background: color-mix(in srgb, var(--focus) 8%, transparent); }
