/* =====================================================================
   LEKTION (app/render/lesson-rail.js, tutorial-overlay.js).
   Gebaut wie das Puzzle-Loesen (puzzle-solve.css): Brett links, rechts eine
   ruhige Spalte. Oben die Karte des Lehrmeisters: die Katze sitzt auf der
   Oberkante (wie in der Akademie), darunter tippt sie Aufgabe und
   Erklaerung, unten Lektion, Spiel und Schritt-Rauten. Danach (nur in
   Faehigkeits-Lektionen) die eigene Leiste, zwei Knoepfe und die
   Figurenkarte, solange eine Figur gewaehlt ist. Am Handy und Tablet
   hochkant: Karte ueber, Knoepfe unter dem Brett. Nach der Lektion wird die
   Spalte zum Ergebnis, ohne Pop-up ueber dem Brett.
   Vokabular wie Puzzle und Akademie: Gold = dran, Teal = geschafft,
   dunkel = offen. Rauten, Knoepfe und Matt-Moment kommen aus
   puzzle-solve.css (.pzq-step, .pzq-act, .pzr-*, .pzm*).
   ===================================================================== */

/* ── Grundgeruest ── */
.tutorialRail { display: none; }
.tutorialCoachPanel[hidden],
.tutorialBar[hidden],
.tutorialLiveCard[hidden] { display: none !important; }
body.tutorial-active .tutorialRail:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  color: var(--mp-bone);
}
/* Kein Gegner-Panel: die Gegner-Leiste faellt weg, die eigene bleibt nur in
   Faehigkeits-Lektionen (dort IST ihr Chip der Ausloeser). */
body.tutorial-active #effectBarEnemy,
body.tutorial-active:not(.tutorial-has-abilities) #effectBar { display: none !important; }
body.tutorial-active #winnerBanner,
body.tutorial-active #pieceInfo,
body.tutorial-active #moveHistory,
body.tutorial-active .legend,
body.tutorial-active #statusLegend { display: none !important; }
/* Eigene Leiste in der Spalte: kompakte Karte statt Brett-Hoehe, ohne
   Friedhof und Fussleiste (Aufgeben/Remis gibt es in der Lektion nicht). */
body.tutorial-active .tutorialRail > #effectBar {
  width: 100%;
  min-width: 0;
  min-height: 0 !important;
  margin: 0;
  justify-content: flex-start !important;
  overflow: visible !important;
}
body.tutorial-active .tutorialRail > #effectBar .effectRailFooter,
body.tutorial-active .tutorialRail > #effectBar .effectGroup-graveyard { display: none !important; }
body.tutorial-active .tutorialLiveCard { width: 100%; min-width: 0; }

body.tutorial-active main {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.6vh, 18px);
}

/* ── Desktop und Tablet quer: Brett | Spalte, als Gruppe mittig ── */
@media (min-width: 1001px) {
  body.mode-demo.tutorial-active {
    --ls-rail: 264px;
    /* Hoehen-Reserve wie im Spiel (main-06): main-Padding + boardWrap-Huelle. */
    --board-size: max(340px, calc(min(
        calc(100dvh - 96px),
        calc(100vw - var(--side-nav-width) - var(--ls-rail) - 84px)
      ) * 0.98));
  }
  body.mode-demo.tutorial-active main {
    display: grid;
    grid-template-columns: minmax(0, auto) var(--ls-rail);
    grid-template-areas: "board right";
    align-content: center;
    justify-content: center;
    align-items: start;
    column-gap: 24px;
  }
  body.tutorial-active #boardStage { display: contents; }
  body.tutorial-active #boardWrap { grid-area: board; }
  body.tutorial-active .tutorialRail { grid-area: right; width: var(--ls-rail); }
  /* Nie hoeher als das Brett, auch unter 1367px (dort laedt rail-height.css
     nicht): mit eigener Leiste und Figurenkarte scrollt die Spalte, nie die
     Seite. 10px Luft oben fuer den Huepfer der Katze. */
  body.mode-demo.tutorial-active #tutorialRail {
    contain: size;
    align-self: stretch;
    overflow-x: hidden;
    overflow-y: auto;
    margin-top: -10px;
    padding-top: 10px;
    scrollbar-color: rgba(216, 177, 90, .22) transparent;
    scrollbar-width: thin;
  }
  body.mode-demo.tutorial-active #tutorialRail > * { flex-shrink: 0; }
}
@media (min-width: 1367px) {
  body.mode-demo.tutorial-active { --ls-rail: 296px; }
}

/* ── Schmal (Tablet hochkant, Handy): Karte ueber dem Brett, Knoepfe darunter ── */
@media (max-width: 1000px) {
  body.tutorial-active .tutorialRail:not([hidden]) { display: contents; }
  body.tutorial-active #tutorialCoachPanel { order: -1; }
  body.tutorial-active #tutorialCoachPanel,
  body.tutorial-active #tutorialBar,
  body.tutorial-active .tutorialRail > #effectBar {
    width: min(calc(var(--board-size) + 12px), calc(100vw - 16px));
    margin-inline: auto;
  }
}

/* Einzug einmal je Lektion */
.tutorialRail.reveal .lsq,
.tutorialRail.reveal .lsq-actions,
.tutorialRail.reveal > #effectBar { animation: pzqIn .55s cubic-bezier(.2, .8, .3, 1) backwards; }
.tutorialRail.reveal > #effectBar { animation-delay: .06s; }
.tutorialRail.reveal .lsq-actions { animation-delay: .12s; }

/* ── Karte des Lehrmeisters ── */
.lsq,
.lsr-head { --cat-w: 92px; }
.lsq {
  position: relative;
  display: flex;
  flex-direction: column;
  /* Platz fuer die sitzende Katze: ihre Pfotenlinie (viewBox y=94 von 120)
     liegt auf der Oberkante der Karte. */
  margin-top: calc(var(--cat-w) * 94 / 120);
  padding: 20px 16px 14px;
  border: 1px solid rgba(216, 177, 90, .2);
  background: linear-gradient(180deg, rgba(20, 23, 31, .8), rgba(9, 11, 15, .92));
  box-shadow: 0 14px 34px rgba(0, 0, 0, .36);
}
.lsq::before,
.lsq::after,
.lsr-head::before,
.lsr-head::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--mp-gold-1);
  pointer-events: none;
}
.lsq::before, .lsr-head::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.lsq::after, .lsr-head::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }

/* Die Katze: sitzt mittig auf der Kante, Pfoten ueber der Linie, atmet
   ruhig, der Schwanz schwingt (Muster der Akademie-Karte). */
.lsq-stage { position: static; }
.lsq-cat {
  position: absolute;
  left: 50%;
  top: calc(var(--cat-w) * -94 / 120 + 1px);
  z-index: 2;
  display: block;
  width: var(--cat-w);
  translate: -50% 0;
  color: #e9cf8a;
}
.lsq-cat .coachCat {
  display: block;
  width: 100%;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .6));
}
/* Niedrige Spezifitaet, damit Sprechen, Kopfschuetteln und Jubeln
   (main-10.css) gewinnen. */
:where(.lsq-cat) .coachCat {
  transform-origin: 50% 78%;
  animation: amBreathe 4.6s ease-in-out infinite;
}
.lsq-cat .coachCat-paws { display: inline; fill: #0b0d12; }
.lsq-cat .coachCat-tail {
  display: inline;
  transform-box: fill-box;
  transform-origin: 100% 100%;
  animation: amTail 5.4s ease-in-out infinite;
}
body.cat-muted .lsq-cat .coachCat-tail { animation-play-state: paused; }

/* Was die Katze sagt: Aufgabe gross, Erklaerung darunter. Die Hoehe steht
   ab dem ersten Zeichen (der ungetippte Rest liegt unsichtbar dahinter). */
.lsq-speech { min-height: 7.2em; }
.lsq-task {
  margin: 0;
  font-family: var(--mp-serif);
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.34;
  letter-spacing: .3px;
  color: var(--mp-bone);
}
.lsq-copy {
  margin: 9px 0 0;
  padding-top: 9px;
  font-family: var(--mp-serif-body, Georgia, serif);
  font-size: 16px;
  line-height: 1.45;
  color: rgba(236, 227, 203, .86);
  /* feine Linie zwischen Aufgabe und Erklaerung */
  background: linear-gradient(90deg, rgba(216, 177, 90, .32), transparent 70%) top left / 100% 1px no-repeat;
}
.lsq-rest { visibility: hidden; }
/* Farb-Akzente: die Figur gold, Brettfelder teal (nur Farbe — die Zeilen
   brechen fertig getippt genau wie beim Tippen). */
.lsq-hl-piece { color: var(--mp-gold-1); font-weight: inherit; }
.lsq-hl-square { color: var(--mp-teal-1); font-weight: inherit; }
/* Falscher Klick: die Korrektur steht in der Blase, warm statt alarmrot. */
.lsq-copy.is-correction { color: #eda494; }
/* Zwischen zwei Spielen: kurzes Lob, nach dem Matt erst, wenn der Koenig
   gefallen ist. */
.lsq-task.is-praise {
  font-size: 22px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  background: linear-gradient(180deg, #f6e1a4 0%, #d8b15a 55%, #a07a2c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: lsqPraise .55s cubic-bezier(.2, 1.3, .4, 1) backwards;
}
.lsq-copy.is-praise {
  font-style: italic;
  color: var(--mp-teal-1);
  animation: pzqIn .5s cubic-bezier(.2, .8, .3, 1) .15s backwards;
}
body.tut-mated .lsq-task.is-praise { animation-delay: .9s; }
body.tut-mated .lsq-copy.is-praise { animation-delay: 1.1s; }
@keyframes lsqPraise { from { opacity: 0; scale: .86; } }

/* Unten: Lektionsbild in der Raute, Lektion, Spiel mit Schritt-Rauten */
.lsq-head {
  order: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(216, 177, 90, .1);
}
.lsq-art,
.lsr-seal {
  position: relative;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
}
.lsq-art::before,
.lsr-seal::before {
  content: "";
  position: absolute;
  inset: 6px;
  rotate: 45deg;
  border: 1px solid var(--mp-gold-1);
  background: linear-gradient(135deg, #1d222c, #0b0d12);
  box-shadow: 0 0 0 3px #0b0d12, 0 0 0 4px rgba(216, 177, 90, .3), 0 4px 14px rgba(0, 0, 0, .6);
}
.lsq-art img,
.lsr-seal img {
  position: relative;
  width: 80%;
  height: 80%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .7));
}
.lsq-art.art-crystal::before,
.lsr-seal.art-crystal::before {
  border-color: rgba(110, 231, 216, .6);
  background: radial-gradient(circle at 50% 45%, rgba(77, 208, 196, .38), #0b1416 78%);
}
.lsq-art.art-crystal img,
.lsr-seal.art-crystal img { width: 60%; height: 60%; filter: drop-shadow(0 0 6px rgba(77, 208, 196, .55)); }
/* Portraits fuellen die Raute (der Rahmen liegt darueber). */
.lsq-art.art-portrait img,
.lsr-seal.art-portrait img {
  position: absolute;
  /* Raute = um 45 Grad gedrehtes Quadrat (inset 6px): seine Ecken ragen
     etwas ueber die Box hinaus, das Bild deckt genau die Raute. */
  --in: 6px;
  left: calc(50% - (50% - var(--in)) * 1.4142);
  top: calc(50% - (50% - var(--in)) * 1.4142);
  width: calc((100% - 2 * var(--in)) * 1.4142);
  height: calc((100% - 2 * var(--in)) * 1.4142);
  object-fit: cover;
  object-position: center 18%;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  filter: none;
}
.lsq-art.art-portrait::after,
.lsr-seal.art-portrait::after {
  content: "";
  position: absolute;
  inset: 6px;
  rotate: 45deg;
  border: 1px solid var(--mp-gold-1);
  pointer-events: none;
}
.lsq-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.lsq-lesson {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--mp-serif);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--mp-bone);
}
.lsq-num {
  font-family: var(--mp-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 1.8px;
  color: var(--mp-gold-1);
}
.lsq-game {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-family: var(--mp-serif-body, Georgia, serif);
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.2;
  color: var(--mp-teal-1);
}
.lsq-steps { display: inline-flex; flex-wrap: wrap; gap: 6px 12px; }
.lsq-game-steps { display: inline-flex; gap: 6px; }

/* Rauten: nur frisch geschaffte ploppen (sonst ploppte bei jedem Neuaufbau
   alles), die aktuelle atmet (data-anim-period, kein Neustart). */
.lsq .pzq-step.is-done,
.lsr .pzq-step.is-done { animation: none; }
.lsq .pzq-step.is-done.is-fresh,
.lsr .pzq-step.is-done.is-fresh { animation: pzqStepDone .5s cubic-bezier(.2, .8, .3, 1); }
/* Fehlversuch: die aktuelle Raute zuckt einmal rot (wie im Puzzle). */
.lsq.is-miss .pzq-step.is-now { animation: pzqMiss .62s ease-out; }
.lsq.is-miss .lsq-steps { animation: pzqMissShake .42s cubic-bezier(.36, .07, .19, .97); }

/* ── Zwei Knoepfe ── */
.lsq-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ── Ergebnis: die Katze jubelt auf der Karte ── */
.lsr-head {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: calc(var(--cat-w) * 94 / 120);
  padding: 24px 18px 20px;
  border: 1px solid rgba(216, 177, 90, .26);
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(216, 177, 90, .12), transparent 62%),
    linear-gradient(180deg, rgba(20, 23, 31, .82), rgba(9, 11, 15, .94));
  box-shadow: 0 14px 34px rgba(0, 0, 0, .4);
}
.lsr-seal { width: 64px; height: 64px; margin-bottom: 12px; }
.lsr-seal::before {
  inset: 9px;
  border-color: #f3dca0;
  box-shadow: 0 0 0 4px #0b0d12, 0 0 0 5px rgba(216, 177, 90, .4), 0 0 26px rgba(216, 177, 90, .32);
}
.lsr-seal.art-portrait img { --in: 9px; }
.lsr-seal.art-portrait::after { inset: 9px; border-color: #f3dca0; }
.lsr-eyebrow {
  margin: 0 0 6px;
  font-family: var(--mp-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  color: var(--mp-gold-1);
}
.lsr-title { font-size: 23px; }
.lsr-path {
  display: inline-flex;
  gap: 9px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(216, 177, 90, .12);
}
.lsr-body { display: flex; flex-direction: column; gap: 10px; }
.lsr-home:hover svg { rotate: 0deg; translate: 2px 0; }
.lsr-home svg { transition: translate .2s cubic-bezier(.22, .8, .24, 1); }

/* Auftritt: nach dem Matt erst, wenn der Koenig gefallen ist. */
.lsr { animation: pzrIn .6s cubic-bezier(.2, .8, .3, 1) .1s backwards; }
.lsr-body { animation-delay: .22s; }
.tutorialRail.is-mate .lsr-head { animation-delay: 1.08s; }
.tutorialRail.is-mate .lsr-body { animation-delay: 1.2s; }
.lsr .lsr-path .pzq-step.is-done.is-fresh { animation-delay: .7s; }
.tutorialRail.is-mate .lsr .lsr-path .pzq-step.is-done.is-fresh { animation-delay: 1.8s; }

/* ── Matt-Moment auf dem Brett (Ebene und Ringe: puzzle-solve.css) ──
   --mate-t (render/anim-clock.js, am Chip) haelt den kippenden Koenig bei
   jedem Neuaufbau des Bretts an seiner Stelle. */
body.tut-mated #board .sq.kingMated .chip {
  transform-origin: 50% 86%;
  animation: pzmTopple 1.05s cubic-bezier(.3, .1, .3, 1) both;
  animation-delay: var(--mate-t, 0ms);
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .62)) drop-shadow(0 0 14px rgba(226, 86, 86, .75)) saturate(.75);
}

/* ── Schmal: Karte als flacher Streifen ueber dem Brett (Katze links),
   Knoepfe darunter. Die Hoehe ist reserviert, damit das Brett zwischen
   den Schritten nicht springt; sehr lange Erklaerungen scrollen in der
   Blase. ── */
@media (max-width: 1000px) {
  body.tutorial-active #tutorialCoachPanel { min-height: 132px; display: flex; flex-direction: column; justify-content: flex-end; }
  .lsq,
  .lsr-head { --cat-w: 58px; }
  .lsq {
    display: grid;
    grid-template-columns: var(--cat-w) minmax(0, 1fr);
    grid-template-areas: "cat head" "cat speech";
    column-gap: 12px;
    margin-top: 0;
    padding: 10px 14px 12px 10px;
  }
  .lsq-stage,
  .lsr-head .lsq-stage { grid-area: cat; position: relative; align-self: start; }
  .lsq-cat { position: relative; left: auto; top: auto; translate: none; }
  .lsq-cat .coachCat-paws,
  .lsq-cat .coachCat-tail { display: none; }
  .lsq-head { grid-area: head; order: 0; margin: 0 0 7px; padding: 0; border: 0; gap: 8px; }
  .lsq-art { display: none; }
  .lsq-txt { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
  .lsq-lesson { flex-direction: row; }
  .lsq-lesson-title { display: none; }
  .lsq-num { font-size: 9px; }
  .lsq-game { font-size: 13.5px; }
  /* Hoehe nach dem Platz, den Brett und Knoepfe uebrig lassen; was nicht
     passt, scrollt in der Blase und blendet unten weich aus. */
  .lsq-speech {
    grid-area: speech;
    min-height: 0;
    max-height: clamp(5.6em, calc(100dvh - 610px), 14em);
    overflow-y: auto;
    scrollbar-color: rgba(216, 177, 90, .22) transparent;
    scrollbar-width: thin;
  }
  .lsq-speech.is-more {
    -webkit-mask-image: linear-gradient(#000 calc(100% - 20px), transparent);
    mask-image: linear-gradient(#000 calc(100% - 20px), transparent);
  }
  .lsq-task { font-size: 14px; }
  .lsq-copy { margin-top: 6px; padding-top: 6px; font-size: 15px; line-height: 1.38; }
  .lsq-task.is-praise { font-size: 18px; }
  .lsr-head {
    display: grid;
    grid-template-columns: var(--cat-w) minmax(0, 1fr);
    grid-template-areas: "cat title" "cat sub" "cat path";
    align-items: center;
    column-gap: 12px;
    margin-top: 0;
    padding: 12px 14px;
    text-align: left;
  }
  .lsr-seal,
  .lsr-eyebrow { display: none; }
  .lsr-title { grid-area: title; font-size: 20px; }
  .lsr-sub { grid-area: sub; margin-top: 2px; font-size: 13px; }
  .lsr-path { grid-area: path; margin-top: 8px; padding-top: 0; border-top: 0; }
  .lsr-head .lsq-cat .coachCat-paws,
  .lsr-head .lsq-cat .coachCat-tail { display: none; }
  .pzr-next { padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .tutorialRail.reveal .lsq,
  .tutorialRail.reveal .lsq-actions,
  .tutorialRail.reveal > #effectBar,
  :where(.lsq-cat) .coachCat,
  .lsq-cat .coachCat-tail,
  .lsq-task.is-praise,
  .lsq-copy.is-praise,
  .lsq.is-miss .lsq-steps,
  .lsr,
  .lsq .pzq-step,
  .lsr .pzq-step { animation: none !important; }
  body.tut-mated #board .sq.kingMated .chip { animation: none; rotate: -24deg; translate: -7% 4%; }
}
