/* views-div.css – Sichten der Division: Verteiltafel (vt-), Schrittliste (sl-), Notation (dn-).
   Größen passen sich über Container-Abfragen (cqw) an die Tafelbreite an; die Höhe wird grob
   aus der Fensterhöhe abgeschätzt (Aufteilung der Bühne in styles.css). */

/* ---------------------------------------------------------------- Verteiltafel */

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

.vt-table {
  /* --vt-u ist die Grundeinheit der Materialteile. VerteilView.js setzt --vt-kw und --vt-kh
     (Bedarf der Tafel in u) sowie --vt-gap, --vt-group-gap und --vt-pad. */
  --vt-label-w: 64px;
  --vt-head-h: clamp(28px, 4vh, 44px);
  --vt-u-max: clamp(8px, 1.15vw, 18px);
  --vt-avail-h: calc(100dvh - 290px);
  --vt-field-min: 28px;
  --vt-u: var(--vt-u-max);
  --vt-stock-bg: color-mix(in srgb, var(--surface-2) 70%, var(--paper));
  position: relative;
  display: grid;
  width: 100%;
  max-width: 1400px;
  font-size: clamp(13px, calc(var(--vt-head-h) * 0.42), 18px);
  color: var(--ink);
}
@supports (width: 1cqw) {
  .vt-table {
    --vt-label-w: clamp(52px, 9cqw, 84px);
    --vt-u: min(
      var(--vt-u-max),
      calc((100cqw - var(--vt-label-w) - 16px) / var(--vt-kw)),
      max(5px, calc((var(--vt-avail-h) - var(--vt-head-h) - 20px) / var(--vt-kh)))
    );
  }
}
@media (max-width: 820px) {
  /* Tafeln untereinander: volle Breite, die Seite scrollt */
  .vt-table { --vt-avail-h: 80dvh; --vt-u-max: clamp(8px, 2.2vw, 18px); }
}

.vt-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  padding: calc(var(--vt-pad) * var(--vt-u));
}

.vt-head {
  align-items: flex-end;
  justify-content: center;
  padding: 0 4px 5px;
  border-bottom: 3px solid var(--vt-c);
  color: var(--vt-c);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vt-name-short { display: none; }
.vt-n5 .vt-name-long { display: none; }
.vt-n5 .vt-name-short { display: inline; }
@container (max-width: 440px) {
  .vt-n4 .vt-name-long { display: none; }
  .vt-n4 .vt-name-short { display: inline; }
}
@container (max-width: 340px) {
  .vt-n3 .vt-name-long { display: none; }
  .vt-n3 .vt-name-short { display: inline; }
}

.vt-label {
  display: flex;
  align-items: center;
  gap: 0.3em;
  min-width: 0;
  padding: 0 0.45em;
  color: var(--muted);
  font-size: 0.92em;
}
.vt-label--stock {
  background: var(--vt-stock-bg);
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--ink);
  font-weight: 600;
}
.vt-label--field { border-bottom: 1px solid var(--line); }
.vt-label-num { font-family: var(--digit-font); font-size: 1.15em; color: var(--ink); }
.vt-person { flex: none; width: 1.15em; height: 1.15em; fill: currentColor; }

.vt-stock {
  align-items: flex-start;
  background: var(--vt-stock-bg);
  border-left: 2px solid var(--paper);
}
.vt-stock.vt-cell--last { border-radius: 0 var(--radius) var(--radius) 0; }
.vt-field {
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.vt-field.vt-cell--last { border-right: 1px solid var(--line); }
.vt-field.vt-row-first,
.vt-label--field.vt-row-first { border-top: 1px solid var(--line); }

/* Vorrat: Zehnergruppen als Zehnerfelder, Anzahl in der Ecke */
.vt-frames {
  display: grid;
  gap: calc(var(--vt-group-gap) * var(--vt-u));
  align-items: start;
  justify-content: start;
}
.vt-frame {
  display: grid;
  gap: calc(var(--vt-gap) * var(--vt-u));
  justify-content: start;
  border-radius: 3px;
}
.vt-frame--neu {
  outline: 2px dashed var(--focus);
  outline-offset: max(2px, calc(0.25 * var(--vt-u)));
}
.vt-count {
  position: absolute;
  top: 2px;
  right: 3px;
  padding: 0 0.3em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  font-family: var(--digit-font);
  font-size: clamp(11px, calc(1.2 * var(--vt-u)), 18px);
  line-height: 1.25;
  color: var(--ink);
}

/* Felder: eine Reihe, nach dem fünften Teil etwas Abstand */
.vt-pieces {
  display: flex;
  align-items: center;
  gap: calc(var(--vt-gap) * var(--vt-u));
}
.vt-zero {
  font-family: var(--digit-font);
  font-size: clamp(12px, calc(1.5 * var(--vt-u)), 22px);
  line-height: 1;
  color: var(--muted);
}

/* Materialteile: Rand in Stellenfarbe, helle Füllung */
.vt-piece {
  display: block;
  flex: none;
  border: max(1px, calc(0.12 * var(--vt-u))) solid var(--vt-c);
  border-radius: max(1px, calc(0.15 * var(--vt-u)));
  background-color: var(--vt-s);
}
.vt-piece--zehner {
  border-width: max(1px, calc(0.08 * var(--vt-u)));
  background-image: repeating-linear-gradient(to bottom,
    transparent 0 calc(10% - 1px),
    color-mix(in srgb, var(--vt-c) 35%, transparent) calc(10% - 1px) 10%);
}
.vt-piece--hunderter {
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--vt-c) 20%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--vt-c) 20%, transparent) 1px, transparent 1px);
  background-size: 10% 10%;
}
.vt-piece--chip {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  color: var(--vt-c);
  font-size: calc(0.85 * var(--vt-u));
  font-weight: 700;
  line-height: 1;
}
.vt-cube { display: block; flex: none; overflow: visible; }
.vt-cube polygon,
.vt-cube rect { stroke: var(--vt-c); stroke-width: 1.5; stroke-linejoin: round; }
.vt-cube-front { fill: var(--vt-s); }
.vt-cube-top { fill: color-mix(in srgb, var(--vt-s) 50%, var(--paper)); }
.vt-cube-side { fill: color-mix(in srgb, var(--vt-s) 70%, var(--vt-c)); }

/* Aktuelle Spalte: Rahmen und leichte Tönung; im Tausch die abgebende Spalte gestrichelt */
.vt-focus {
  grid-row: 1 / -1;
  z-index: 2;
  margin: -3px -1px;
  border: 3px solid var(--focus);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--focus) 6%, transparent);
  pointer-events: none;
}
.vt-focus--from {
  border-width: 2px;
  border-style: dashed;
  background: none;
}

/* Antippbare Stellenspalten (Kopf, Vorrat und Felder); durchsichtig, ohne Einfluss aufs Layout.
   Die Auswahl hat einen dunklen Doppelrahmen und hebt sich so vom rosa Schritt-Fokus ab. */
.vt-pick {
  grid-row: 1 / -1;
  z-index: 3;
  margin: -6px 0;
  border: 5px double transparent;
  border-radius: calc(var(--radius) + 3px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.vt-pick:focus { outline: none; }
.vt-pick:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.vt-pick--on { border-color: var(--ink); }

/* Animation: Überlagerungsebene für vorübergehende Klone (getauschte Teile, alte Zählmarken) */
.vt-anim {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: visible;
  pointer-events: none;
}
.vt-ghost { position: absolute; margin: 0; }
.vt-anim .vt-count { right: auto; }

/* Zweistelliger Divisor: ruhiger Hinweis statt Tafel */
.vt-hint {
  max-width: 30em;
  margin: auto;
  padding: 1.2em 1.4em;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  font-size: clamp(15px, 1.4vw, 21px);
  line-height: 1.45;
}
.vt-hint p { margin: 0; }
.vt-hint .vt-hint-frage { margin-top: 0.5em; color: var(--ink); }

/* ---------------------------------------------------------------- Schrittliste */

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

.sl-table {
  /* SchrittlisteView.js setzt --sl-em (Tabellenbreite in em) und --sl-lines (Höhe in em). */
  --sl-avail-h: calc(46dvh - 160px);
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--digit-font);
  font-size: 18px;
  color: var(--ink);
}
@supports (width: 1cqw) {
  .sl-table {
    /* Die Breite darf bis 10px verkleinern: Sechsstellige Zahlen neben offener Forscherkarte
       wurden sonst links und rechts abgeschnitten (210.000 erschien als 10.000). */
    font-size: clamp(10px, min(calc((100cqw - 2px) / var(--sl-em)), max(13px, calc(var(--sl-avail-h) / var(--sl-lines)))), 28px);
  }
}
@media (max-width: 820px) {
  .sl-table { --sl-avail-h: 60dvh; }
}

.sl-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sl-table .sl-head {
  padding: 0.25em 0.55em 0.35em;
  border-bottom: 2px solid var(--strong-line);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.64em;
  font-weight: 600;
  line-height: 1.15;
  color: var(--muted);
  text-align: right;
  vertical-align: bottom;
}

.sl-table td {
  height: 1.75em;
  padding: 0 0.5em;
  border: 2px solid transparent;
  box-shadow: inset 0 -1px 0 var(--line);
  line-height: 1;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}
.sl-table td + td { box-shadow: inset 1px 0 0 var(--line), inset 0 -1px 0 var(--line); }

.sl-table .sl-row--focus td {
  border-top-color: var(--focus);
  border-bottom-color: var(--focus);
  background: color-mix(in srgb, var(--focus) 10%, var(--paper));
}
.sl-table .sl-row--focus td:first-child { border-left-color: var(--focus); border-radius: 6px 0 0 6px; }
.sl-table .sl-row--focus td:last-child { border-right-color: var(--focus); border-radius: 0 6px 6px 0; }
.sl-nachher { font-weight: 700; }

.sl-table .sl-sum:not(.sl-row--empty) td { box-shadow: inset 0 2px 0 var(--strong-line); }
.sl-table .sl-sum-label {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.68em;
  font-weight: 600;
  color: var(--muted);
}
.sl-table .sl-sum-value { text-align: left; }
.sl-quotient { font-weight: 700; }
.sl-table .sl-probe td {
  box-shadow: none;
  font-size: 0.9em;
  text-align: left;
}
.sl-probe-label {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.8em;
  font-weight: 600;
  color: var(--muted);
}

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

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

.dn-paper {
  /* DivNotationView.js setzt --dn-cols und --dn-rows (Rastergröße in Kästchen). */
  --dn-cell: var(--cell);
  --dn-avail-h: calc(53dvh - 175px);
  --dn-line: color-mix(in srgb, var(--place-3) 14%, var(--line));
  --dn-stroke: max(2px, calc(var(--dn-cell) * 0.08));
  display: grid;
  border-top: 1px solid var(--dn-line);
  border-left: 1px solid var(--dn-line);
  background: var(--paper);
  font-family: var(--digit-font);
  font-size: calc(var(--dn-cell) * 0.7);
  line-height: 1;
  color: var(--ink);
}
@supports (width: 1cqw) {
  .dn-paper {
    /* Kästchen höchstens --cell groß, notfalls kleiner, damit das Raster in die Tafel passt.
       Untergrenze 16px: Mit 22px liefen sechsstellige Dividenden auf dem iPad mini unten aus der Tafel. */
    --dn-cell: min(
      var(--cell),
      calc((100cqw - 2px) / var(--dn-cols)),
      max(16px, calc(var(--dn-avail-h) / var(--dn-rows)))
    );
  }
}
@media (max-width: 820px) {
  .dn-paper { --dn-avail-h: 100dvh; }
}

.dn-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  border-right: 1px solid var(--dn-line);
  border-bottom: 1px solid var(--dn-line);
}
.dn-op { color: var(--ink); }
.dn-slot { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

.dn-word {
  z-index: 1;
  display: grid;
  place-items: center;
  font-size: 0.9em;
  color: var(--ink);
}
.dn-rule {
  z-index: 1;
  align-self: end;
  height: max(2px, calc(var(--dn-cell) * 0.07));
  margin: 0 2px -1px;
  border-radius: 1px;
  background: var(--strong-line);
  transform-origin: left center;   /* Animation: Strich wird von links gezogen */
}

/* Ziffern stehen in einem span, damit Animationen die Kästchenlinien nicht mitbewegen. */
.dn-d { display: block; }

/* Antippbare Dividendenziffern; die Auswahl ist ein dunkler Doppelrahmen (Schritt-Fokus: rosa). */
.dn-pick { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.dn-pick:focus { outline: none; }
.dn-pick:focus-visible { outline: 2px solid var(--ink); outline-offset: -3px; }
.dn-pickmark {
  z-index: 4;
  margin: -3px;
  border: max(4px, calc(var(--dn-cell) * 0.12)) double var(--ink);
  border-radius: calc(var(--dn-cell) * 0.22);
  pointer-events: none;
}

/* Hervorhebungen: Rahmen, nicht nur Farbe */
.dn-box {
  z-index: 2;
  margin: 1px;
  border: var(--dn-stroke) solid var(--focus);
  border-radius: calc(var(--dn-cell) * 0.2);
  pointer-events: none;
}
.dn-box--focus { background: color-mix(in srgb, var(--focus) 10%, transparent); }
.dn-box--slots { border-style: dashed; }
.dn-box--teil { border-style: dashed; border-width: max(1.5px, calc(var(--dn-cell) * 0.05)); }
.dn-box--result { background: color-mix(in srgb, var(--focus) 7%, transparent); }

.dn-ring {
  z-index: 3;
  margin: 9%;
  border: var(--dn-stroke) solid var(--focus);
  border-radius: 50%;
  pointer-events: none;
}
.dn-ring--source { border-style: dashed; border-width: max(1.5px, calc(var(--dn-cell) * 0.05)); }

/* Pfeil „herunterholen“ von der Ziffer im Dividenden bis über die neue Ziffer */
.dn-arrow {
  position: relative;
  z-index: 3;
  justify-self: center;
  width: var(--dn-stroke);
  margin: calc(var(--dn-cell) * 0.08) 0 calc(var(--dn-cell) * 0.3);
  background: repeating-linear-gradient(to bottom,
    var(--focus) 0 calc(var(--dn-cell) * 0.18),
    transparent calc(var(--dn-cell) * 0.18) calc(var(--dn-cell) * 0.3));
  pointer-events: none;
}
.dn-arrow::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(var(--dn-cell) * -0.28);
  transform: translateX(-50%);
  border-left: calc(var(--dn-cell) * 0.16) solid transparent;
  border-right: calc(var(--dn-cell) * 0.16) solid transparent;
  border-top: calc(var(--dn-cell) * 0.28) solid var(--focus);
}

/* ---------------------------------------------------------------- Selbst eintragen */
.dn-entry {
  z-index: 3;
  min-width: 0;
  min-height: 0;
  margin: 7%;
  padding: 0;
  border-radius: 4px;
  font-size: 1em;
}
.dn-entry-sign { z-index: 1; display: grid; place-items: center; }
.sl-slot { min-width: 2.6em; min-height: 1.35em; font-size: 1em; }
.sl-table .sl-row--entry td { background: color-mix(in srgb, var(--focus) 5%, var(--paper)); }
.sl-table .sl-row--entry:has(.is-latent) td { background: transparent; }

/* Beim Eintragen: Markierungen des gezeigten Schritts treten zurück, markiert ist der nächste. */
.vt-cueing .vt-focus:not(.vt-cue) { display: none; }
.dn-cueing .dn-box--focus,
.dn-cueing .dn-box--teil,
.dn-cueing .dn-ring:not(.dn-cue),
.dn-cueing .dn-arrow { display: none; }
.sl-cueing .sl-table .sl-row--focus td { border-color: transparent; background: none; }
