/* Gymihorst Mini-App — eigenständig (kein /pro/*-Zugriff im Telegram-Webview).
   Kind-freundlich: hell, rund, farbig, grosse Tap-Ziele. */
:root {
  --bg: #f6f7fb; --card: #ffffff; --ink: #22283a; --dim: #6b7280;
  --accent: #6c5ce7; --accent2: #00b894; --warn: #e17055; --gold: #fdcb6e;
  --red: #e74c3c; --green: #27ae60; --radius: 16px;
  --shadow: 0 2px 10px rgba(34,40,58,.08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; font-size: 16px; }
#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.view { flex: 1; padding: 14px 14px 84px; max-width: 640px; margin: 0 auto; width: 100%; }

/* Tabbar */
#tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid #e8eaf1; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 50; }
#tabbar button { flex: 1; background: none; border: 0; font: inherit; font-size: 11px; color: var(--dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 12px; }
#tabbar button span { font-size: 22px; }
#tabbar button.active { color: var(--accent); background: #f0edff; }

/* Karten & Buttons */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0;
  border-radius: 14px; padding: 12px 18px; font: inherit; font-weight: 700; cursor: pointer;
  background: #edeff5; color: var(--ink); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-green { background: var(--accent2); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 8px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
h1 { font-size: 22px; margin: 8px 0 12px; }
h2 { font-size: 17px; margin: 14px 0 8px; }
.dim { color: var(--dim); font-size: 14px; }
.center { text-align: center; }

/* Horst-Kopf */
.horst { display: flex; gap: 10px; align-items: flex-start; }
.horst-face { font-size: 34px; line-height: 1; }

/* Horst-Hero (Start): grosse Horst-Fläche mit Direkteingabe */
.hero { background: linear-gradient(135deg, #f0edff 0%, #e8f4ff 100%); padding: 16px; }
.hero-top { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.hero-face { font-size: 52px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(60,50,150,.25)); }
.hero-bubble { background: var(--card, #fff); border-radius: 4px 16px 16px 16px; padding: 12px 14px;
  flex: 1; font-size: 15px; line-height: 1.45; box-shadow: 0 2px 8px rgba(30,30,80,.08); }
.hero-input { display: flex; gap: 6px; align-items: flex-end; background: var(--card, #fff);
  border-radius: 14px; padding: 6px; box-shadow: 0 2px 8px rgba(30,30,80,.08); }
.hero-input textarea { flex: 1; border: 0; resize: none; font: inherit; outline: none;
  background: transparent; padding: 8px; max-height: 90px; }
.hero-input .send { background: var(--accent); color: #fff; }
.hero-chips { margin: 10px 0 0; }
.hero-chips .chip { background: rgba(255,255,255,.75); }

/* Coach-Rezept (Markdown+LaTeX+SVG in der Coach-Bubble) */
.coach-steps { margin-top: 8px; background: #fff; border-radius: 10px; padding: 8px 10px;
  border: 1.5px solid #e2ddfa; overflow-x: auto; }
.bubble { background: #f0edff; border-radius: 4px 16px 16px 16px; padding: 10px 14px; flex: 1; }
.bubble.me { background: #e3f9f0; border-radius: 16px 4px 16px 16px; }

/* Chat */
.chatlog { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.chatlog .msg { display: flex; }
.chatlog .msg.user { justify-content: flex-end; }
.chatlog .msg .bubble { max-width: 85%; flex: initial; }
.inputbar { position: sticky; bottom: 78px; display: flex; gap: 6px; background: var(--card);
  border-radius: 16px; box-shadow: var(--shadow); padding: 8px; align-items: flex-end; }
.inputbar textarea { flex: 1; border: 0; resize: none; font: inherit; outline: none; max-height: 110px;
  background: transparent; padding: 8px; }
.iconbtn { border: 0; background: #edeff5; border-radius: 12px; width: 42px; height: 42px;
  font-size: 19px; cursor: pointer; flex-shrink: 0; }
.iconbtn.rec { background: var(--red); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 2px solid #e8eaf1; }

/* Lektions-Karten */
.lesson-card { display: flex; align-items: center; gap: 12px; }
.lesson-emoji { font-size: 28px; width: 48px; height: 48px; border-radius: 14px; display: flex;
  align-items: center; justify-content: center; background: #f0edff; flex-shrink: 0; }
.lesson-emoji.deutsch { background: #fff3e0; }
.badge { display: inline-block; border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #e3f9f0; color: var(--green); }
.badge.mid { background: #fff6df; color: #b7791f; }
.badge.low { background: #fdecea; color: var(--red); }
.badge.neutral { background: #edeff5; color: var(--dim); }

/* Fragen */
.q { border-top: 1px dashed #e8eaf1; padding-top: 12px; margin-top: 12px; }
.q-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.q-nr { font-weight: 800; color: var(--accent); }
.choice { display: block; width: 100%; text-align: left; margin: 6px 0; background: #f4f5fa;
  border: 2px solid transparent; border-radius: 12px; padding: 10px 14px; font: inherit; cursor: pointer; }
.choice.sel { border-color: var(--accent); background: #f0edff; }
.choice.right { border-color: var(--green); background: #e3f9f0; }
.choice.wrong { border-color: var(--red); background: #fdecea; }
.answer-row { display: flex; gap: 8px; margin-top: 8px; }
.answer-row input, .answer-row textarea { flex: 1; border: 2px solid #e8eaf1; border-radius: 12px;
  padding: 10px 12px; font: inherit; outline: none; }
.answer-row input:focus, .answer-row textarea:focus { border-color: var(--accent); }
.verdict { border-radius: 12px; padding: 10px 12px; margin-top: 8px; font-weight: 600; }
.verdict.ok { background: #e3f9f0; color: var(--green); }
.verdict.no { background: #fdecea; color: var(--red); }
.solution { background: #f8f9fc; border-left: 4px solid var(--accent); border-radius: 8px;
  padding: 8px 12px; margin-top: 8px; font-size: 15px; }
.hintbox { background: #fff6df; border-radius: 12px; padding: 10px 12px; margin-top: 8px; }

/* Fortschritt */
.skillbar { margin: 10px 0; }
.skillbar .lbl { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.track { height: 12px; border-radius: 8px; background: #edeff5; overflow: hidden; }
.fill { height: 100%; border-radius: 8px; background: var(--accent2); transition: width .4s; }
.fill.low { background: var(--red); } .fill.mid { background: var(--gold); }

/* Progressbar (Bauen) */
.buildbar { margin: 12px 0; }
.buildbar .track { height: 16px; }
.buildbar .fill { background: var(--accent); }

/* Coach-Sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--card);
  border-radius: 20px 20px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.18); padding: 14px 16px
  calc(14px + env(safe-area-inset-bottom)); max-height: 75vh; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-close { border: 0; background: #edeff5; border-radius: 10px; width: 34px; height: 34px;
  font-size: 16px; cursor: pointer; }
.sheet-log { overflow-y: auto; flex: 1; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }

/* Reicher Inhalt */
.rich img, .rich svg { max-width: 100%; height: auto; }
.rich .svg-fig { margin: 10px 0; text-align: center; }
.rich .svg-fig svg { max-width: 320px; }
.rich .math-block { overflow-x: auto; padding: 4px 0; }
.rich table { border-collapse: collapse; } .rich td, .rich th { border: 1px solid #e8eaf1; padding: 4px 8px; }
.rich pre { overflow-x: auto; background: #f4f5fa; border-radius: 8px; padding: 8px; }

/* Toast */
#toast { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; gap: 6px; width: min(92vw, 480px); }
#toast .t { background: #22283a; color: #fff; border-radius: 12px; padding: 10px 14px;
  font-size: 14px; box-shadow: var(--shadow); animation: fadein .2s; }
#toast .t.err { background: var(--red); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } }

.speak { border: 0; background: #f0edff; color: var(--accent); border-radius: 10px;
  padding: 6px 10px; font-size: 14px; font-weight: 700; cursor: pointer; }
.confetti { font-size: 44px; }
.score-big { font-size: 48px; font-weight: 800; color: var(--accent); }

/* ---------- Frage-Knöpfe (vordefinierte Fragen) & Starter-Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { border: 1.5px solid #dfe3ee; background: #f4f5fa; color: var(--text, #1c1f2a);
  border-radius: 999px; padding: 7px 12px; font: inherit; font-size: 13.5px; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:active { background: #e8eaf5; }
.chip:disabled { opacity: .5; }

/* ---------- Vollbild-Antwortblatt (Frage-Knopf -> Blatt, ← / BackButton zurück) ---------- */
.fullsheet { position: fixed; inset: 0; z-index: 80; background: var(--bg, #f6f7fb);
  overflow-y: auto; padding: 12px 14px calc(24px + env(safe-area-inset-bottom));
  animation: fs-in .18s ease-out; }
@keyframes fs-in { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.fs-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.fs-back { border: 0; background: #edeff5; border-radius: 12px; width: 42px; height: 42px;
  font-size: 20px; cursor: pointer; flex: none; }
.fs-title { font-size: 16px; line-height: 1.25; }
.fs-body { background: var(--card, #fff); border-radius: 14px; padding: 14px;
  box-shadow: 0 1px 4px rgba(20,24,40,.06); margin-bottom: 14px; }

/* ---------- Grosse Multimodal-Eingabe (Chat) ---------- */
.inputbar.big { align-items: flex-end; padding: 8px; }
.iconbtn.tall { width: 52px; height: 52px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; font-size: 20px; }
.iconbtn.tall span { font-size: 9px; line-height: 1; color: #6a6f80; }
.iconbtn.tall.send { background: var(--accent); color: #fff; }
.iconbtn.tall.send span { color: #fff; }
.inputbar.big textarea { min-height: 44px; }

/* ---------- 🔊/🔇-Schalter oben rechts ---------- */
#voicefab { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 10px; z-index: 70;
  width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--card, #fff);
  box-shadow: 0 2px 8px rgba(20,24,40,.14); font-size: 17px; cursor: pointer; }
#voicefab.off { opacity: .55; filter: grayscale(1); }

/* ---------- Prüfungs-Simulation (echte ZAP) ---------- */
.examhead { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.timerchip { flex-shrink: 0; background: #1d2233; color: #fff; border-radius: 12px;
  padding: 8px 12px; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; }
.timerchip.low { background: var(--red, #d64545); animation: timerpulse 1s infinite; }
@keyframes timerpulse { 50% { opacity: .65; } }
.examrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #eef0f6; }
.examrow:last-child { border-bottom: 0; }
.examrow-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.choice.picked { border-color: var(--accent); background: #f0edff; font-weight: 700; }
.qstate { font-size: 12px; font-weight: 700; color: var(--green, #23a06c); }

/* ---------- Beschäftigt-Zustand (Doppelklick-Schutz via G.guard) ---------- */
.busy { pointer-events: none; }
.btn.busy, .chip.busy { opacity: .75; }
.btn.busy::before, .chip.busy::before { content: ''; width: 13px; height: 13px; flex: none;
  display: inline-block; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
.chip.busy::before { margin-right: 6px; }
.iconbtn.busy { opacity: .55; animation: pulse 1s infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Aufklappbare Horst-Eingabe (Tipp = gross, ✕/Escape/daneben = zu) ---------- */
/* .inputbar bleibt sticky (Original-Regel) — sticky verankert den absoluten ✕ genauso */
.hero-input { position: relative; }
.hero-input, .inputbar { transition: box-shadow .22s ease; }
.hero-input textarea, .inputbar textarea { transition: min-height .22s ease; }
.hero-input textarea { min-height: 24px; }
.hero-input.open, .inputbar.open { box-shadow: 0 0 0 2.5px var(--accent), 0 10px 30px rgba(60,50,150,.2); }
.hero-input.open textarea, .inputbar.open textarea { min-height: 96px; max-height: 200px; }
.composer-close { position: absolute; top: -12px; right: -8px; width: 30px; height: 30px;
  border: 0; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px;
  line-height: 1; cursor: pointer; display: none; z-index: 5; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.hero-input.open .composer-close, .inputbar.open .composer-close { display: block; animation: fadein .15s; }

/* ---------- Scan-Einsendung (Blatt einschicken) ---------- */
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin: 6px 0; }
.pagechips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pagechip { border-radius: 8px; padding: 3px 9px; font-size: 12px; font-weight: 700;
  background: #edeff5; color: var(--dim); }
.pagechip.got { background: #e3f9f0; color: var(--green); }
.tipbox { background: #fff8e1; border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.tipbox .lbl { font-weight: 800; font-size: 12px; }

/* ================= Spiel-Schicht: XP, Rang, Streak, Monster, Abzeichen ================= */
.gamestrip { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; }
.rankchip { background: rgba(255,255,255,.8); border-radius: 999px; padding: 5px 10px;
  font-size: 13px; white-space: nowrap; box-shadow: var(--shadow); }
.xpbar { flex: 1; min-width: 0; }
.xptrack { height: 10px; border-radius: 6px; background: rgba(255,255,255,.6); overflow: hidden; }
.xpfill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--gold), #f39c12);
  transition: width .5s; }
.xplbl { font-size: 11px; color: var(--dim); display: block; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.streakchip { background: rgba(255,255,255,.8); border-radius: 999px; padding: 5px 10px;
  font-size: 13px; font-weight: 800; box-shadow: var(--shadow); }
.streakchip.hot { background: #fff0e6; color: #d35400; }
.streakchip.risk { animation: streakpulse 1.6s infinite; }
@keyframes streakpulse { 50% { transform: scale(1.12); } }

.plancard h2 { margin-bottom: 6px; }
.planrow { display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-top: 1px solid #f0f1f7; }
.planrow:first-of-type { border-top: 0; }
.planicon { font-size: 22px; width: 28px; text-align: center; flex: none; }
.planrow .btn { flex: none; }

.mfaces { display: flex; }
.mface { font-size: 22px; margin-left: -6px; }
.mface.ready { animation: mwiggle 1.2s infinite; }
@keyframes mwiggle { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }

.monstercard { display: flex; gap: 12px; align-items: flex-start; }
.monstercard.ready { border: 2px solid var(--gold); box-shadow: 0 4px 14px rgba(253,203,110,.35); }
.mbig { font-size: 34px; flex: none; }
.mshelf { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.mtrophy { font-size: 26px; filter: grayscale(.4); opacity: .85; }

.xpchip { display: inline-block; background: #fff6dd; color: #b7791f; font-weight: 800;
  border-radius: 999px; padding: 3px 10px; font-size: 12px; margin: 6px 6px 0 0;
  animation: xppop .4s; }
.xpchip.big { font-size: 16px; padding: 6px 16px; }
.xpchip.streak { background: #fff0e6; color: #d35400; }
@keyframes xppop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.15); } }

.monsterbanner { display: flex; align-items: center; gap: 10px; background: #f3e8ff;
  border-radius: 10px; padding: 8px 10px; margin-top: 8px; font-size: 13px;
  animation: xppop .45s; }
.monsterbanner .mbig { font-size: 28px; }

.gamecard { display: flex; align-items: center; gap: 12px; text-align: left; }
.gamecard.defeated { background: #e3f9f0; }
.gamecard.spawned { background: #f3e8ff; }
.gamecard.levelup { background: #fff6dd; }
.gamecard.badge { background: #eef4ff; }

.badgeshelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px; margin-top: 8px; }
.badgecard { background: #f8f9fc; border-radius: 10px; padding: 8px; display: flex;
  flex-direction: column; gap: 2px; font-size: 12px; }
.badgecard .bemoji { font-size: 24px; }
.badgecard.t2 { background: #eef4ff; }
.badgecard.t3 { background: #fff6dd; border: 1.5px solid var(--gold); }

.readycard.pass { border: 2px solid var(--accent2); }
.readynote { font-size: 34px; font-weight: 800; color: var(--accent); }

.action-chips { margin: 8px 0 0; }
.chip.act { background: #fff; border-color: var(--accent); color: var(--accent); font-weight: 700; }
.chip.act:active { background: #f0edff; }
/* gamestrip auf weissen Karten (Fortschritt): Kontrast statt Hero-Transparenz */
.card .xptrack { background: #edeff5; }
.card .rankchip, .card .streakchip { background: #f4f5fa; box-shadow: none; }

/* ================= Web-Modus (app.html im normalen Browser) ================= */
/* Tab «Bericht» nur im Web zeigen */
.webonly { display: none !important; }
body.web .webonly { display: flex !important; }

/* Breiteres Layout am Desktop */
body.web .view { max-width: 860px; }
@media (min-width: 900px) {
  body.web #tabbar { position: sticky; top: 0; bottom: auto; border-top: 0;
    border-bottom: 1px solid #e8eaf1; padding: 6px 12px; justify-content: center; gap: 4px; }
  body.web #tabbar button { flex: 0 0 auto; flex-direction: row; gap: 8px; font-size: 14px;
    padding: 8px 16px; }
  body.web #tabbar button span { font-size: 18px; }
  body.web .view { padding: 20px 20px 40px; }
  body.web #voicefab { top: 64px; }
}

/* QR-Login-Gate */
body.gate #tabbar, body.gate #voicefab { display: none; }
.logingate { padding-top: 48px; }
.logingate h1 { margin: 6px 0 10px; }
.logingate .btn { margin-top: 10px; text-decoration: none; }
.qrbox { width: 240px; height: 240px; margin: 18px auto; background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; display: flex; align-items: center; justify-content: center; }
.qrbox svg { width: 100%; height: 100%; }

/* Eingebettete Blatt-PDFs */
.pdfcard .pdfframe { width: 100%; height: 70vh; min-height: 420px; border: 1px solid #e8eaf1;
  border-radius: 10px; margin-top: 10px; background: #fff; }

/* Bericht (D3-Grafiken) */
.chartcard .chart { margin-top: 6px; }
.chartcard .axis { font-size: 11px; color: var(--dim); }
.chartcard .axis path, .chartcard .axis line { stroke: #d5d8e2; }
.chartcard .barlbl { font-size: 12px; fill: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 8px; font-size: 13px; color: var(--dim); }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.legend .lg i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.report h3 { margin: 14px 0 6px; font-size: 14px; }
.paperrow .btn { flex: 0 0 auto; }

/* Druck: nur der Berichts-/Seiteninhalt, weiss, ohne Navigation */
@media print {
  #tabbar, #voicefab, #toast, .no-print { display: none !important; }
  body { background: #fff; }
  .view { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .chartcard { break-inside: avoid; }
}
