/* Fraindly Training. Farben, Schrift und Abstände kommen ausschliesslich aus design/tokens.css. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: var(--fs-body); line-height: 1.55;
  display: grid; grid-template-rows: auto 1fr; height: 100dvh; overflow: hidden;
}
a { color: inherit; text-underline-offset: 0.2em; text-decoration-color: var(--line-strong); }
a:hover { color: var(--accent-text); }
:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
strong, b { font-weight: 600; }
ul, ol { list-style: none; }
.ico { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-small); color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--control-h); padding: 0 var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: transparent; color: var(--text);
  font: 500 var(--fs-small)/1 var(--font-sans); cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover { background: var(--bg-sunk); }
.btn:active { background: var(--line); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn.ghost { border-color: transparent; }
.btn.sm { min-height: 32px; padding: 0 var(--s-2); }
.btn.icon-only { width: var(--control-h); padding: 0; }
.btn.fake { pointer-events: none; }
.btn.fake.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* Weiter: füllt sich, solange du liest, und lädt dann zum Drücken ein */
.next { position: relative; overflow: hidden; min-height: 48px; min-width: 9.5rem; margin-left: auto; font-size: var(--fs-body); }
.next::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent);
  transform: scaleX(0); transform-origin: left;
}
.next.ready {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  transition: background 300ms var(--ease) var(--fill, 1200ms), color 300ms var(--ease) var(--fill, 1200ms), border-color 300ms var(--ease) var(--fill, 1200ms);
}
.next.ready::before { transform: scaleX(1); transition: transform var(--fill, 1200ms) cubic-bezier(0.45, 0, 0.55, 1); }
.next.ready:hover { background: var(--accent-hover); transition-delay: 0s; }
.next.ready:active { background: var(--accent-press); }
.next.ready .ico { animation: nudge 1.6s var(--ease) calc(var(--fill, 1200ms) + 500ms) infinite; }
@keyframes nudge { 0%, 60%, 100% { transform: translateX(0); } 30% { transform: translateX(5px); } }

/* ---------- Kopf ---------- */
.top { display: flex; align-items: center; gap: var(--s-4); height: 56px; padding: 0 var(--page-pad); border-bottom: 1px solid var(--line); min-width: 0; }
.brand { font-weight: 600; text-decoration: none; white-space: nowrap; }
.brand span { font-weight: 300; color: var(--text-muted); }
.rail { display: flex; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; align-self: stretch; }
.rail::-webkit-scrollbar { display: none; }
.tab {
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted); cursor: pointer;
  padding: 2px var(--s-3) 0; font: 500 var(--fs-small)/1 var(--font-sans); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-current] { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Aufbau ---------- */
.app { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); min-height: 0; }
.tutor { display: flex; flex-direction: column; min-height: 0; padding: var(--s-4) var(--s-4) var(--s-3) var(--page-pad); border-right: 1px solid var(--line); }
.tutor-head { display: flex; align-items: center; gap: var(--s-3); }
.tutor-name { font-size: var(--fs-h3); font-weight: 500; }
.avatar { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.avatar .eyes { transform-origin: 24px 23px; animation: blink 5s infinite; }
.avatar .mouth { transform-origin: 24px 32px; }
.avatar.talking .mouth { animation: talk 0.32s ease-in-out infinite alternate; }
.avatar.talking .antenna { animation: wag 0.9s ease-in-out infinite alternate; transform-origin: 24px 10px; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }
@keyframes talk { from { transform: scaleX(1); } to { transform: scaleX(0.45); } }
@keyframes wag { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }

.tutor-log { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4) 0; scrollbar-width: none; -webkit-mask-image: linear-gradient(transparent, #000 2.5rem); mask-image: linear-gradient(transparent, #000 2.5rem); }
.tutor-log > :first-child { margin-top: auto; }
.say { font-size: 1.0625rem; max-width: 65ch; transition: color 400ms var(--ease); }
.say.old { color: var(--text-muted); }
.say.typing { cursor: pointer; }
.say.typing::after, .caret { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: -0.12em; background: var(--accent); animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.tutor-nav { display: flex; align-items: center; gap: var(--s-3); padding-top: var(--s-3); border-top: 1px solid var(--line); }
.counter { font-size: var(--fs-label); color: var(--text-muted); }

.stage { min-width: 0; overflow-y: auto; padding: var(--s-5) var(--page-pad) var(--s-6); }
.stage > * { max-width: 820px; }
h1 { font-size: var(--fs-h1); font-weight: 300; line-height: 1.12; letter-spacing: -0.01em; margin-bottom: var(--s-5); text-wrap: balance; }
h2 { font-size: var(--fs-h2); font-weight: 500; }
h3 { font-size: var(--fs-body); font-weight: 600; margin-bottom: var(--s-2); display: flex; align-items: center; gap: var(--s-2); }
.stage-body > * + * { margin-top: var(--s-5); }
.stage-body p { max-width: 65ch; }
.enter { animation: enter 600ms var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Bausteine ---------- */
.lead { font-size: var(--fs-h3); font-weight: 300; }
.quote { font-size: var(--fs-h3); font-weight: 300; padding-left: var(--s-3); border-left: 2px solid var(--line-strong); }
.quote:not(:last-child) { margin-bottom: var(--s-3); }
.stage-body > .quote + * { margin-top: var(--s-4); }

.state { display: inline-flex; align-items: baseline; gap: var(--s-1); font-size: var(--fs-small); font-weight: 500; }
.state .ico { align-self: center; }
.state.ok { color: var(--success); }
.state.warn { color: var(--warning); }
.state.err { color: var(--error); }
.state.info { color: var(--text-muted); }

.rows .row { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: var(--s-3); padding: var(--s-2) 0; border-top: 1px solid var(--line); }
.rows .row:last-child { border-bottom: 1px solid var(--line); }
.rows.wide .row { grid-template-columns: 17rem minmax(0, 1fr); }
.rows dt { font-weight: 500; display: flex; gap: var(--s-2); align-items: baseline; }
.rows dt .ico { align-self: center; color: var(--text-muted); }
.rows dd { color: var(--text-muted); }
.rows dd strong { color: var(--text); }
.entry { display: block; font-style: normal; margin-top: var(--s-1); padding: var(--s-1) var(--s-2); background: var(--bg-sunk); color: var(--text); font-size: var(--fs-small); }

.bars { display: grid; gap: var(--s-2); }
.bar-row { display: grid; grid-template-columns: 12rem minmax(0, 1fr) 4rem; align-items: center; gap: var(--s-3); font-size: var(--fs-small); }
.bar-t i { display: block; height: 8px; background: var(--text-muted); transform-origin: left; transition: background 400ms; }
.bar-row.enter .bar-t i, .enter .bar-row .bar-t i { animation: grow 900ms var(--ease) both; }
@keyframes grow { from { transform: scaleX(0); } }
.bar-row.is-hl .bar-l { font-weight: 600; }
.bar-row.is-hl .bar-t i { background: var(--accent); }
.bar-row .num { text-align: right; }
.bar-row.losable.on { color: var(--text-muted); }
.bar-row.losable.on .bar-l { text-decoration: line-through; }
.bar-row.losable.on .bar-t i { background: var(--line); }
.desk .bars { margin-bottom: var(--s-3); }

.meter { height: 8px; background: var(--line); margin: var(--s-3) 0 var(--s-2); }
.meter i { display: block; height: 100%; width: 0; background: var(--text); transition: width 700ms var(--ease); }
.meter.run i { width: 100%; transform-origin: left; animation: grow 1800ms cubic-bezier(0.45, 0, 0.55, 1) both; }

.sentence { font-size: clamp(1.5rem, 2.6vw, 2.125rem); font-weight: 300; line-height: 1.3; max-width: none !important; }
.sentence .word { font-weight: 500; }
.sentence .word.enter { animation-delay: var(--d); }

.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); }
.cols3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.cols3 > *, .merk { transition: opacity 400ms var(--ease); }
.cols3:has(> .hl) > :not(.hl), .stage-body:has(> .merk.hl) > .merk:not(.hl) { opacity: 0.55; }

.plain li { display: flex; gap: var(--s-2); align-items: baseline; padding: var(--s-1) 0; }
.plain li .ico { align-self: center; color: var(--text-muted); }
.tag { margin-left: var(--s-2); padding: 0 var(--s-1); border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: var(--fs-label); font-weight: 500; white-space: nowrap; }

.steps { counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 2rem minmax(0, 1fr); align-items: baseline; padding: var(--s-2) 0; border-top: 1px solid var(--line); }
.steps li:last-child { border-bottom: 1px solid var(--line); }
.steps li::before { content: counter(s); font-family: var(--font-mono); font-size: var(--fs-small); color: var(--text-muted); }
.steps li .tag { justify-self: start; grid-column: 2; margin: var(--s-1) 0 0; }
.steps li.hl { font-weight: 600; }
.steps li.hl::before { color: var(--accent-text); }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.node { padding: var(--s-2) var(--s-3); border: 1px solid var(--line-strong); border-radius: var(--radius); font-weight: 500; font-size: var(--fs-small); }
.flow-a { display: inline-flex; color: var(--text-muted); }
.loop-back { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-2); }

.chat { display: grid; gap: var(--s-2); margin-bottom: var(--s-2); }
.msg { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: var(--s-2); align-items: baseline; font-size: var(--fs-small); }
.msg-who { font-size: var(--fs-label); font-weight: 500; color: var(--text-muted); }
.msg > div { padding: var(--s-2) var(--s-3); }
.msg.me > div { background: var(--bg-sunk); }
.msg.ai > div { border-left: 1px solid var(--line-strong); }

.prompt { display: grid; gap: var(--s-2); justify-items: start; }
.prompt blockquote { padding: var(--s-3); background: var(--bg-sunk); max-width: 65ch; }

.win { border: 1px solid var(--line-strong); border-radius: var(--radius); transition: opacity 400ms var(--ease), border-color 300ms, box-shadow 300ms; }
.win-bar { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); font-size: var(--fs-small); font-weight: 500; }
.win-body { display: grid; gap: var(--s-3); padding: var(--s-3); }
.win-body > i { display: block; height: 8px; background: var(--line); }
.win-body > i.short { width: 55%; }
.win-body > i.right { margin-left: auto; }
.win.hl { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.relay { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); }
.stage-body[data-beat="1"] .relay .win.on { opacity: 0.3; }

.answer { padding-left: var(--s-3); border-left: 1px solid var(--line-strong); font-size: var(--fs-small); display: grid; gap: var(--s-2); margin-bottom: var(--s-2); }
.answer ul { padding-left: var(--s-3); list-style: disc; }
.ptext .pb b { font-weight: 600; }
mark { background: none; color: inherit; }
mark.gap { color: var(--warning); text-decoration: underline wavy; text-underline-offset: 0.2em; }
mark.plus { font-weight: 600; }

.log li.ask { padding: var(--s-2); margin: var(--s-1) calc(var(--s-2) * -1); background: var(--bg-sunk); }
.log .btn-row { display: flex; margin-top: var(--s-2); }

.drawer-row { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.skill { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border: 1px solid var(--line); border-radius: var(--radius); font-size: var(--fs-small); color: var(--text-muted); transition: all 400ms var(--ease); }
.skill.hl { border-color: var(--line-strong); color: var(--text); font-weight: 500; }
.skill.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.recipe { padding-left: var(--s-3); border-left: 2px solid var(--line-strong); }
.recipe .state { margin-top: var(--s-3); }

.lead-agent { padding-bottom: var(--s-4); border-bottom: 1px solid var(--line); display: grid; gap: var(--s-1); justify-items: start; }

.sock { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) 0; border-top: 1px solid var(--line); color: var(--text-muted); transition: color 400ms; }
.sock strong { font-weight: 500; margin-right: auto; }
.sock-s { font-size: var(--fs-small); }
.sock .sock-s.is, .sock.on .sock-s.off { display: none; }
.sock.on { color: var(--text); }
.sock.on .sock-s.is { display: inline-flex; }
.tasks .task { color: var(--text-muted); border-top: 1px solid var(--line); padding: var(--s-2) 0; transition: color 400ms; }
.tasks .task .ico { visibility: hidden; }
.tasks .task.on { color: var(--text); }
.tasks .task.on .ico { visibility: visible; color: var(--success); }

.hidden-text { display: flex; gap: var(--s-2); padding: var(--s-2) var(--s-3); background: var(--bg-sunk); border-left: 2px solid var(--warning); font-weight: 500; }
.hidden-text .ico { margin-top: 4px; }

.crits li { flex-wrap: wrap; border-top: 1px solid var(--line); padding: var(--s-2) 0; }
.crit { display: inline-flex; gap: var(--s-3); margin-left: auto; }
.merk h3 .muted { font-weight: 400; font-size: var(--fs-small); }

.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
.tbl th, .tbl td { text-align: left; padding: var(--s-2) var(--s-3) var(--s-2) 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl thead th { color: var(--text-muted); font-weight: 500; border-bottom-color: var(--line-strong); }
.tbl tbody th { font-weight: 600; }

.names .small { margin-top: var(--s-2); }

/* Treppe */
.stairs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-3); align-items: end; min-height: 15rem; }
.stair { display: grid; gap: var(--s-1); align-content: start; padding-top: var(--s-2); border-top: 1px solid var(--line-strong); font-size: var(--fs-small); min-height: calc(6.5rem + var(--n) * 2.75rem); }
.stair-n { font-size: var(--fs-h2); font-weight: 300; line-height: 1; margin-bottom: var(--s-1); }

/* Übungen */
.sorter { display: grid; gap: var(--s-3); justify-items: start; }
.prog { font-size: var(--fs-label); color: var(--text-muted); }
.sort-q { min-height: 4.5rem; display: grid; gap: var(--s-2); align-content: start; }
.sort-q strong { font-size: var(--fs-h3); font-weight: 500; display: block; max-width: 34ch; }
.sort-fb { min-height: 9rem; width: 100%; }
.fb { display: grid; gap: var(--s-2); justify-items: start; padding-top: var(--s-3); border-top: 1px solid var(--line); }

/* Tipps */
.tips section + section { margin-top: var(--s-5); }
.tips h3 { font-size: var(--fs-h3); font-weight: 500; margin-bottom: var(--s-3); }
.tip { display: grid; gap: var(--s-1); padding: var(--s-3) 0; border-top: 1px solid var(--line); }
.tip strong { font-weight: 600; }
.tip p { color: var(--text-muted); max-width: 65ch; }
.tip .prompt { margin-top: var(--s-2); }

.drawer { margin: 0 0 0 auto; width: min(600px, 100vw); height: 100dvh; max-height: none; max-width: none; border: 0; border-left: 1px solid var(--line); background: var(--bg-raised); color: var(--text); box-shadow: var(--shadow-overlay); padding: var(--s-4) var(--s-4) var(--s-5); overflow-y: auto; }
.drawer::backdrop { background: rgba(26, 24, 22, 0.35); }
.drawer[open] { animation: slide 320ms var(--ease); }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.drawer-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-4); }

/* ---------- Schmal ---------- */
@media (max-width: 900px) {
  body { display: block; height: auto; overflow: visible; padding-bottom: 80px; }
  .top { gap: var(--s-2); }
  #tipsBtn span { display: none; }
  .app { display: block; }
  .tutor { position: sticky; top: 0; z-index: 5; background: var(--bg); border-right: 0; border-bottom: 1px solid var(--line); padding: var(--s-3) var(--page-pad); }
  .tutor-head { display: none; }
  .tutor-log { padding: 0; max-height: 9.5rem; -webkit-mask-image: none; mask-image: none; }
  .say { font-size: var(--fs-body); }
  .say.old { display: none; }
  .tutor-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--bg); padding: var(--s-3) var(--page-pad); }
  .stage { overflow: visible; padding-top: var(--s-4); }
  .stage-body [data-b] { scroll-margin: 12rem 0 6rem; }
  h1 { margin-bottom: var(--s-4); }
  .stage-body > * + * { margin-top: var(--s-4); }
  .cols, .cols3 { grid-template-columns: 1fr; gap: var(--s-4); }
  .rows .row, .rows.wide .row { grid-template-columns: 1fr; gap: 0; }
  .bar-row { grid-template-columns: 8.5rem minmax(0, 1fr) 3.5rem; gap: var(--s-2); }
  .relay { gap: var(--s-2); }
  .relay .win-bar { font-size: var(--fs-label); padding: var(--s-1) var(--s-2); }
  .relay .win-bar .ico { display: none; }
  .stairs { grid-template-columns: 1fr; min-height: 0; }
  .stair { min-height: 0; grid-template-columns: 2rem 1fr; }
  .stair .muted { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
