/*
 * rechnen.css – Der Rechenwagen auf dem Startbild, sein Zimmer und die
 * Spielfläche der Rechenspiele. Farben wie im Rechenwagen: die Wand
 * hellgelb, die Fünfer-Farben rot und blau, der Drache grün.
 */

/* --- Der Rechenwagen auf dem Startbild (wie der Lesewagen) --- */
.rechenwagen-knopf {
  position: absolute;
  z-index: 3;
  width: clamp(80px, 16vw, 210px);
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 6px 10px rgba(36, 48, 71, 0.22));
  transform-origin: 50% 80%;
  transition: opacity 0.4s ease, transform 0.15s ease;
}
.rechenwagen-knopf[hidden] { display: none; }
.rechenwagen-knopf[data-placed="0"] { opacity: 0; pointer-events: none; }
.rechenwagen-knopf:active { transform: scale(0.95); }
.rechenwagen-knopf:focus-visible { outline: 3px solid #6c5ce7; outline-offset: 4px; border-radius: 12px; }
.rechenwagen-knopf svg { display: block; width: 100%; height: auto; }
.train-stage[data-entering] .rechenwagen-knopf { opacity: 0; pointer-events: none; }
.train-stage[data-rechnen-ein] .rechenwagen-knopf { transform: scale(1.35); opacity: 0; transition: transform 0.42s ease-in, opacity 0.42s ease-in; }
.rechenwagen-svg .rw-birne { animation: rw-birne 2.4s ease-in-out infinite; }

/* --- Einbau in die Bühne (train-home.js, Ansicht "rechnen") --- */
.train-stage[data-view="rechnen"] .train-band { opacity: 0; pointer-events: none; }
.train-stage[data-view="rechnen"] .stage-layer { z-index: 4; }
.train-stage[data-view="rechnen"] .scene { visibility: hidden; }
.train-stage[data-view="rechnen"] .scene-bird { animation-play-state: paused; }
.train-stage[data-view="rechnen"] .train-band * { animation: none; }
/* Der Lautsprecher spricht im Rechenwagen, neben dem Zurück-Knopf. */
body[data-page="train"] .train-stage[data-view="rechnen"] ~ .help-voice {
  display: flex;
  left: calc(var(--safe-left) + 86px);
}

/* --- Das Zimmer --- */
.rechenecke {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: auto;
  background: linear-gradient(to bottom, #8a5a35 0, #8a5a35 5%, #fff1cf 5%, #fff1cf 70%, #d9a46c 70%);
  animation: rechenecke-ein 0.45s ease backwards;
}
@keyframes rechenecke-ein {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}
.rechenecke .rechenzimmer-svg { width: 100%; height: 100%; min-width: 0; min-height: 0; }

/* Die Dinge im Zimmer sind Knöpfe. Ihre Lage steht in den Zeichnungen, nicht
   am Knopf selbst – so darf das Hüpfen translate benutzen. */
.rechen-ort { cursor: pointer; transition: filter 0.15s ease; outline: none; }
.rechen-ort:hover, .rechen-ort:focus-visible { filter: brightness(1.06) drop-shadow(0 0 10px rgba(255, 217, 138, 0.95)); }
.rechen-ort:active { filter: brightness(0.94); }
.rechen-ort.is-locked .rechen-ort-bild { filter: saturate(0.55); }
.rechen-hitbox { fill: #000; fill-opacity: 0; stroke: none; }
.rechen-ort:focus-visible .rechen-hitbox { stroke: #6c5ce7; stroke-width: 4; stroke-dasharray: 10 8; }
.rechenzimmer-svg.is-huepfen .rechen-ort {
  animation: rechen-ort-huepft 2.2s linear var(--ort-verzug, 0.5s) 2 both;
}
@keyframes rechen-ort-huepft {
  0% { translate: 0 0; animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1); }
  11% { translate: 0 -14px; animation-timing-function: cubic-bezier(0.6, 0, 0.75, 0.4); }
  22% { translate: 0 0; animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1); }
  29% { translate: 0 -5px; animation-timing-function: cubic-bezier(0.6, 0, 0.75, 0.4); }
  36%, 100% { translate: 0 0; }
}
/* Die Einrichtung ist kein Knopf: Getippt wird hindurch. Was neu ist, leuchtet. */
.rw-ausbau { pointer-events: none; }
.rw-ausbau.is-neu { animation: rw-neu 1.6s ease-in-out 3; }
@keyframes rw-neu {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 10px #ffd166) brightness(1.15); }
}
.rw-birne { animation: rw-birne 2.4s ease-in-out infinite; }
.rw-birne:nth-child(2n) { animation-delay: -1.2s; }
@keyframes rw-birne { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* Der Drache: kommt nach einer Verwandlung mit einem Knall, verschwindet
   vorher kurz. */
.rw-platz { transform-box: fill-box; transform-origin: 50% 100%; }
.rw-platz.is-neu { animation: rw-auftauchen 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.rw-platz.is-weg { animation: rw-weg 0.45s ease-in both; }
@keyframes rw-auftauchen { from { transform: scale(0.2); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rw-weg { to { transform: scale(0.2); opacity: 0; } }
.rw-knall { pointer-events: none; transform-box: fill-box; transform-origin: center; animation: rw-knall 0.9s ease-out both; }
@keyframes rw-knall { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
.rw-ei { transform-box: fill-box; transform-origin: 50% 100%; animation: rw-wackeln 3s ease-in-out infinite; }
@keyframes rw-wackeln { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-6deg); } 82% { transform: rotate(5deg); } 88% { transform: rotate(-3deg); } }
.rw-feld-neu { animation: rw-feld 0.5s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes rw-feld { from { transform: scale(0.2); } 60% { transform: scale(1.3); } to { transform: none; } }

/* --- Die Auswahl hinter einem Ding (wie im Lesewagen, eigene Klassen) --- */
.rechen-wahl {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(36, 48, 71, 0.42);
  animation: rechen-wahl-ein 0.2s ease both;
}
@keyframes rechen-wahl-ein { from { opacity: 0; } to { opacity: 1; } }
.rechen-wahl-karte {
  position: relative;
  max-width: min(94vw, 900px);
  padding: clamp(12px, 3vh, 24px) clamp(14px, 3vw, 28px);
  border-radius: 28px;
  background: #fff6e0;
  box-shadow: 0 18px 40px rgba(36, 48, 71, 0.35);
}
.rechen-wahl-kopf { position: relative; display: flex; align-items: center; justify-content: center; min-height: 42px; margin-bottom: clamp(6px, 1.6vh, 12px); }
.rechen-wahl-titel {
  margin: 0 48px;
  color: #5b3a29;
  font-size: clamp(1.1rem, 5vh, 1.6rem);
  font-weight: 900;
  text-align: center;
}
.rechen-wahl-zu {
  position: absolute;
  top: 50%;
  right: -4px;
  transform: translateY(-50%);
  width: 40px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #5b3a29;
  font-size: 1.1rem;
  box-shadow: 0 3px 8px rgba(36, 48, 71, 0.2);
}
.rechen-wahl-spiele { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(8px, 2vw, 18px); }
.rechen-wahl-spiel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: clamp(92px, min(15vw, 26vh), 150px);
  min-height: 0;
  aspect-ratio: 1;
  padding: 6px;
  border: 4px solid #ffffff;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 6px 14px rgba(36, 48, 71, 0.18);
  color: #243047;
}
.rechen-wahl-spiel:hover, .rechen-wahl-spiel:focus-visible { border-color: #ffd166; }
.rechen-wahl-spiel:active { transform: scale(0.95); }
.rechen-wahl-bild { font-size: clamp(2rem, 10vh, 3.4rem); line-height: 1; }
.rechen-wahl-name { font-size: clamp(0.7rem, 2.6vh, 0.95rem); font-weight: 850; line-height: 1.1; text-align: center; }
.rechen-wahl-spiel.is-locked { filter: saturate(0.5); }
.rechen-wahl-schloss { position: absolute; top: -10px; right: -8px; font-size: 1.4rem; }

/* --- Die Spiele --- */
/* Zähler und Uhr der Bühne braucht hier niemand: Die Punkte über dem Bild
   zeigen, wie weit die Runde ist. */
.rechen-buehne .cm-count, .rechen-buehne .cm-time { display: none; }
.rechen-stage .cm-play { padding: 0 max(12px, var(--safe-left, 0px)) 0 max(12px, var(--safe-right, 0px)); }


.rechen-spielflaeche {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.4vh, 12px);
  padding-bottom: 4px;
}
.rechen-punkte { display: flex; justify-content: center; gap: 8px; min-height: 12px; }
.rechen-punkte i { width: 12px; height: 12px; border-radius: 50%; background: rgba(36, 48, 71, 0.18); }
.rechen-punkte i.is-fertig { background: #3fbf74; }
.rechen-punkte i.is-jetzt { background: #3d7be0; }
.rechen-szene-huelle { min-height: 0; container-type: size; display: grid; place-items: center; }
.rechen-szene {
  width: 100%;
  width: min(100cqw, calc(100cqh * 1000 / 560));
  max-width: 100%;
  aspect-ratio: 1000 / 560;
  border-radius: clamp(14px, 2.4vh, 24px);
  overflow: hidden;
  background: #fff1cf;
  box-shadow: 0 10px 26px rgba(36, 48, 71, 0.22);
}
.rechen-szene-svg { display: block; width: 100%; height: 100%; touch-action: none; -webkit-user-select: none; user-select: none; }
.rechen-unten { display: grid; justify-items: center; gap: clamp(6px, 1.2vh, 10px); }
.rechen-blase {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(760px, 100%);
  min-height: 48px;
  padding: 6px 6px 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(36, 48, 71, 0.16);
}
.rechen-blase-drache { flex: 0 0 auto; width: 40px; height: 40px; }
.rechen-blase-text { margin: 0; min-width: 0; font-size: clamp(1rem, 2.4vh, 1.25rem); font-weight: 800; color: #243047; line-height: 1.25; -webkit-user-select: none; user-select: none; cursor: pointer; }
.rechen-blase-text:focus-visible { outline: 3px solid #6c5ce7; outline-offset: 3px; border-radius: 6px; }
/* Der Lautsprecher neben dem Text: die Aufgabe noch einmal. Pulsiert, solange
   die Seite noch nicht sprechen darf (rechnen-spiel.js, darfSprechen). */
.rechen-blase-laut {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin-left: 2px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #3d7be0;
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(36, 48, 71, 0.22);
  transition: transform 0.12s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.rechen-blase-laut svg { width: 24px; height: 24px; display: block; }
.rechen-blase-laut:active { transform: scale(0.92); }
.rechen-blase-laut:focus-visible { outline: 3px solid #6c5ce7; outline-offset: 3px; }
.rechen-blase-laut.ist-am-sprechen { background: #2f63bd; }
.rechen-blase-laut.ist-stumm { animation: rechen-laut-puls 1.3s ease-in-out infinite; }
@keyframes rechen-laut-puls {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(61, 123, 224, 0.55); }
  50% { transform: scale(1.12); box-shadow: 0 0 0 12px rgba(61, 123, 224, 0); }
}
.rechen-antworten { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(6px, 1vw, 10px); min-height: clamp(46px, 8vh, 62px); }
.rechen-zahl {
  width: clamp(46px, 8vh, 62px);
  height: clamp(46px, 8vh, 62px);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #ffffff;
  color: #243047;
  font-family: "Baloo 2", Nunito, ui-rounded, system-ui, sans-serif;
  font-size: clamp(1.4rem, 4vh, 2rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(36, 48, 71, 0.16), 0 6px 14px rgba(36, 48, 71, 0.14);
  transition: transform 0.12s ease, background-color 0.2s ease;
}
.rechen-antworten[data-anzahl="4"] .rechen-zahl { width: clamp(58px, 10vh, 78px); height: clamp(58px, 10vh, 78px); }
.rechen-zahl:hover { transform: translateY(-2px); }
.rechen-zahl:active { transform: translateY(2px); }
.rechen-zahl:focus-visible { outline: 3px solid #243047; outline-offset: 3px; }
.rechen-zahl.ist-richtig { background: #3fbf74; color: #ffffff; }
.rechen-zahl.ist-daneben { background: #fff1e0; color: #8a8f9e; }
.rechen-zahl.ist-loesung { box-shadow: 0 0 0 4px #3fbf74, 0 6px 14px rgba(36, 48, 71, 0.14); }
.rechen-antworten.ist-zu .rechen-zahl { pointer-events: none; }
.rechen-wurf {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: clamp(50px, 8vh, 62px);
  padding: 0 24px 0 18px;
  border: none;
  border-radius: 999px;
  background: #3d7be0;
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #2f63bd;
}
.rechen-wurf svg { width: 30px; height: 30px; color: #3d7be0; }
.rechen-wurf:disabled { opacity: 0.6; cursor: default; }
.rechen-wurf:focus-visible { outline: 3px solid #243047; outline-offset: 3px; }

.rw-ziehbar { cursor: grab; }
.rw-ziehbar:active { cursor: grabbing; }
.rw-schubs { animation: rw-schubs 1s ease-in-out infinite; }
@keyframes rw-schubs { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-18px); } }
.rw-marke { transform-box: fill-box; transform-origin: center; animation: rw-marke 0.28s ease-out both; }
@keyframes rw-marke { from { transform: scale(0.2); opacity: 0; } to { transform: none; opacity: 1; } }
.rw-tippmich { cursor: pointer; }
.rw-tippmich > g { transform-box: fill-box; transform-origin: center; animation: rw-tipp 0.9s ease-in-out infinite; }
@keyframes rw-tipp { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* Quer auf dem Handy: das Bild links, Sprechblase und Antworten rechts. */
@media (max-height: 520px) and (min-aspect-ratio: 3/2) {
  .rechen-spielflaeche { grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) minmax(200px, 34%); }
  .rechen-punkte { grid-column: 1 / -1; }
  .rechen-unten { align-content: center; }
  .rechen-blase { border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .rechenecke, .rechen-wahl, .rechenzimmer-svg.is-huepfen .rechen-ort, .rw-ausbau.is-neu, .rw-birne, .rw-platz.is-neu, .rw-platz.is-weg,
  .rw-knall, .rw-ei, .rw-feld-neu, .rw-schubs, .rw-marke, .rw-tippmich > g, .rechenwagen-svg .rw-birne, .rechen-blase-laut.ist-stumm { animation: none; }
  .train-stage[data-rechnen-ein] .rechenwagen-knopf { transition: none; }
}

/* --- Elternbereich: die Karte «Rechenecke» (firebase.js) – wie die Karte
   «Leseecke», mit eigener Klasse --- */
.admin-rechnen { flex-direction: column; align-items: stretch; }
.admin-rechnen .card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-rechnen button[aria-pressed="true"] { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.5); }
.admin-rechnen .admin-lesen-frage { margin: 4px 0 -4px; color: var(--ink); font-weight: 900; }
.admin-rechnen .auth-hint { margin: 0; }

/* --- Elternbereich: die Plus-Tafel im Rechenbericht (firebase.js) --- */
.rechen-tafel-rahmen { overflow-x: auto; max-width: 100%; }
.rechen-tafel { border-collapse: separate; border-spacing: 2px; font-size: 0.72rem; font-variant-numeric: tabular-nums; margin: 2px 0 4px; }
.rechen-tafel th, .rechen-tafel td { width: 24px; height: 22px; padding: 0; text-align: center; border-radius: 5px; }
.rechen-tafel th { color: #5d6882; font-weight: 900; }
.rechen-tafel td { background: rgba(36, 48, 71, 0.07); color: #243047; font-weight: 800; }
.rechen-tafel td.ist-geuebt { background: #ffe8a3; }
.rechen-tafel td.ist-sitzt { background: #7fd6a0; }

/* --- Wahl ohne Zahlen (rechnen-spiel.js, waehle) --- */
.rechen-wahlknopf {
  min-height: clamp(50px, 8vh, 64px);
  min-width: clamp(64px, 10vh, 84px);
  padding: 4px 18px;
  border: none;
  border-radius: 999px;
  background: #ffffff;
  color: #243047;
  font-size: clamp(1rem, 2.6vh, 1.3rem);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(36, 48, 71, 0.16), 0 6px 14px rgba(36, 48, 71, 0.14);
  transition: transform 0.12s ease, background-color 0.2s ease;
}
.rechen-wahlknopf svg { display: block; width: clamp(54px, 9vh, 72px); height: auto; }
.rechen-wahlknopf:hover { transform: translateY(-2px); }
.rechen-wahlknopf:focus-visible { outline: 3px solid #243047; outline-offset: 3px; }
.rechen-wahlknopf.ist-richtig { background: #3fbf74; color: #ffffff; }
.rechen-wahlknopf.ist-daneben { background: #fff1e0; color: #8a8f9e; }
.rechen-wahlknopf.ist-loesung { box-shadow: 0 0 0 4px #3fbf74, 0 6px 14px rgba(36, 48, 71, 0.14); }
.rechen-antworten.ist-zu .rechen-wahlknopf { pointer-events: none; }
.rw-ziel { cursor: pointer; }
.rw-ziel:hover, .rw-ziel:focus-visible { filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.95)); outline: none; }
.rw-ziel-richtig { filter: drop-shadow(0 0 10px #3fbf74); }
.rw-ziel-daneben { opacity: 0.55; }
.rw-ziel-loesung { filter: drop-shadow(0 0 12px #3fbf74); }

/* --- Der Sternenhimmel (train-rechenecke.js) --- */
.rechen-himmel-karte { width: auto; max-width: min(920px, 96vw); }
/* Auf dem Handy quer bleibt die Karte so niedrig, dass ihr Kreuz unter den
   Knöpfen oben rechts hervorschaut. */
.rechen-himmel-svg { display: block; width: auto; height: min(460px, 60vh); max-width: 100%; margin: 0 auto; }
.rechen-stern { cursor: pointer; }
.rechen-stern.ist-an path { filter: drop-shadow(0 0 6px #ffd166); }

/* --- Das Sammelalbum und die Aufträge (train-rechenecke.js) --- */
.rechen-album-karte { width: min(900px, 96vw); }
.rechen-album-raster { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; max-height: 64vh; overflow: auto; }
.rechen-album-blatt {
  display: grid; justify-items: center; align-content: start; gap: 2px; min-height: 92px; padding: 6px 4px;
  border: 2px solid #f1d58a; border-radius: 14px; background: #fffbe9; cursor: pointer; font: inherit;
}
.rechen-album-blatt.ist-zu { color: #b8bfd0; font-size: 2rem; font-weight: 800; background: #f3f1ea; border-style: dashed; cursor: default; align-content: center; }
.rechen-album-zahl { font-family: "Baloo 2", Nunito, ui-rounded, system-ui, sans-serif; font-size: 1.4rem; font-weight: 800; color: #243047; line-height: 1; }
.rechen-album-dinge { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; font-size: clamp(0.7rem, 1.6vw, 1rem); line-height: 1.1; }
.rechen-taufe-name.ist-ja { background: #3fbf74; border-color: #2f9a5b; color: #ffffff; }

/* --- Die Taufe des Drachen (train-rechenecke.js) --- */
.rechen-taufe-namen { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 12px; }
.rechen-taufe-name {
  min-height: 48px; padding: 0 18px; border: 3px solid #ffd166; border-radius: 999px; cursor: pointer; box-shadow: 0 3px 0 rgba(36, 48, 71, 0.12);
  background: #fff6e0; color: #243047; font-family: "Baloo 2", Nunito, ui-rounded, system-ui, sans-serif; font-size: 1.15rem; font-weight: 800;
}
.rechen-taufe-name:hover, .rechen-taufe-name:focus-visible { border-color: #3d7be0; outline: none; }
.rechen-taufe-name.ist-wuerfel { background: #3d7be0; color: #ffffff; font-size: 1.4rem; }
.rechen-taufe-eigen { display: flex; justify-content: center; gap: 8px; }
.rechen-taufe-eigen input { min-height: 44px; width: min(220px, 60vw); padding: 0 12px; border: 2px solid #d6cfa8; border-radius: 12px; font: inherit; font-size: 1rem; }
.rechen-taufe-eigen button { min-height: 44px; padding: 0 18px; border: none; border-radius: 12px; background: #3fbf74; color: #ffffff; font-weight: 800; cursor: pointer; }

/* Die Tür des Rechenwagens fragt, wohin: Lese- oder Englischwagen
   (train-rechenecke.js, zeigeTueren). */
.rechen-tueren .rechen-wahl-bild svg { display: block; width: clamp(110px, 20vw, 170px); height: auto; }
