/* KI-Lernbegleiter – Gestaltung
   Links ein heller, ruhiger Chat, rechts das dunkle "Obsidian-Gehirn". */

:root {
  --papier: #f6f4ef;
  --karte: #ffffff;
  --tinte: #1d2130;
  --gedimmt: #6b7080;
  --linie: #e4e1d8;
  --akzent: #7c5cff;
  --akzent-hell: #efeaff;
  --akzent-tief: #5b3de0;
  --leuchten: #a78bfa;
  --cyan: #38e1f5;
  --gut: #15a35a;
  --warn: #f59e0b;
  --fehler: #e5484d;
  --nacht: #0f0e1a;
  --nacht-2: #17152a;
  --nacht-linie: #2a2745;
  --nacht-text: #b9b5d6;
  --rund: 18px;
  --schatten: 0 1px 2px rgba(20, 18, 40, .06), 0 6px 24px rgba(20, 18, 40, .06);
  font-family: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--tinte);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--papier); }
body { overflow: hidden; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.unsichtbar { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Login ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 70% 20%, #2a2160 0%, var(--nacht) 60%);
}
.login-karte {
  width: min(380px, 100%); padding: 36px 28px; border-radius: 24px; text-align: center;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); color: #fff;
}
.login-logo { font-size: 56px; filter: drop-shadow(0 0 24px rgba(167,139,250,.7)); }
.login h1 { margin: 8px 0 4px; font-size: 26px; letter-spacing: -.02em; }
.login p { margin: 0 0 22px; color: var(--nacht-text); font-size: 14px; }
.login input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.25); color: #fff; font-size: 17px; outline: none;
}
.login input:focus { border-color: var(--leuchten); box-shadow: 0 0 0 4px rgba(124,92,255,.3); }
.login button {
  width: 100%; margin-top: 12px; padding: 14px; border: 0; border-radius: 14px; font-size: 17px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--akzent), #9b7bff);
}
.login-fehler { min-height: 20px; margin: 12px 0 0 !important; color: #ffb4b6 !important; }

/* ---------- Grundgerüst ---------- */
.app { height: 100dvh; display: flex; flex-direction: column; }
.kopf {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--karte); border-bottom: 1px solid var(--linie); z-index: 3;
}
.marke { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marke-logo { font-size: 28px; }
.marke strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.marke-unter { display: block; font-size: 12.5px; color: var(--gedimmt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kopf-aktionen { display: flex; align-items: center; gap: 10px; }
.knopf-leise {
  border: 1px solid var(--linie); background: var(--karte); color: var(--tinte);
  padding: 8px 12px; border-radius: 12px; font-size: 14px; white-space: nowrap;
}
.knopf-leise:hover { background: var(--papier); }

.schalter { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.schalter input { position: absolute; opacity: 0; pointer-events: none; }
.schalter-bahn {
  width: 44px; height: 26px; border-radius: 99px; background: #d4d1c8; position: relative; transition: background .25s;
}
.schalter-knopf {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .25s;
}
.schalter input:checked + .schalter-bahn { background: var(--akzent); }
.schalter input:checked + .schalter-bahn .schalter-knopf { transform: translateX(18px); }
.schalter input:focus-visible + .schalter-bahn { box-shadow: 0 0 0 3px rgba(124,92,255,.35); }
.schalter-text { font-size: 14px; font-weight: 600; min-width: 74px; }

.haupt { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 420px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; position: relative; }
.verlauf {
  flex: 1; overflow-y: auto; padding: 24px max(16px, 4%) 12px;
  display: flex; flex-direction: column; gap: 14px;
}
.nachricht { display: flex; gap: 10px; max-width: 760px; width: 100%; animation: rein .35s ease both; }
.nachricht.agent { align-self: flex-start; }
.nachricht.ich { align-self: flex-end; justify-content: flex-end; }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 12px; display: grid; place-items: center; font-size: 18px;
  background: var(--nacht); box-shadow: 0 0 0 2px var(--akzent-hell);
}
.nachricht.ohne .avatar { background: #8a8a96; filter: grayscale(1); }
.blase {
  padding: 12px 16px; border-radius: var(--rund); background: var(--karte); box-shadow: var(--schatten);
  min-width: 0; max-width: 100%; line-height: 1.55; font-size: 16.5px;
}
.nachricht.agent .blase { border-top-left-radius: 6px; }
.nachricht.ich .blase {
  background: linear-gradient(135deg, var(--akzent), #8f72ff); color: #fff; border-top-right-radius: 6px;
  max-width: 80%; white-space: pre-wrap; word-wrap: break-word;
}
.nachricht.ohne .blase { background: #fbfbfc; border: 1px dashed #c9c9d3; box-shadow: none; }
.hinweis-zeile { align-self: center; font-size: 13px; color: var(--gedimmt); background: var(--karte); padding: 6px 12px; border-radius: 99px; border: 1px solid var(--linie); }
.fehler-zeile { align-self: center; font-size: 14px; color: var(--fehler); background: #fff1f1; padding: 8px 14px; border-radius: 12px; border: 1px solid #ffd2d3; }

@keyframes rein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.tippt { display: inline-flex; gap: 5px; padding: 4px 2px; }
.tippt i { width: 7px; height: 7px; border-radius: 50%; background: var(--leuchten); animation: hupf 1.1s infinite ease-in-out; }
.tippt i:nth-child(2) { animation-delay: .15s; } .tippt i:nth-child(3) { animation-delay: .3s; }
@keyframes hupf { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Text im Chat (Markdown) */
.nachricht-text > :first-child { margin-top: 0; }
.nachricht-text > :last-child { margin-bottom: 0; }
.nachricht-text p { margin: .55em 0; }
.nachricht-text ul, .nachricht-text ol { padding-left: 1.3em; margin: .5em 0; }
.nachricht-text li { margin: .2em 0; }
.nachricht-text strong { font-weight: 650; }
.nachricht-text h1, .nachricht-text h2, .nachricht-text h3 { font-size: 1.05em; margin: .9em 0 .4em; }
.nachricht-text code { background: var(--papier); padding: .1em .35em; border-radius: 6px; font-size: .9em; }
.nachricht-text pre { background: var(--papier); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.nachricht-text blockquote { margin: .6em 0; padding: .2em .9em; border-left: 3px solid var(--leuchten); color: var(--gedimmt); }
.nachricht-text table { border-collapse: collapse; margin: .6em 0; font-size: .95em; display: block; overflow-x: auto; }
.nachricht-text th, .nachricht-text td { border: 1px solid var(--linie); padding: 6px 10px; text-align: center; }
.nachricht-text th { background: var(--papier); }
.nachricht-text .katex { font-size: 1.12em; }
.nachricht-text .katex-display { margin: .7em 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* Eingabe */
.eingabe {
  display: flex; gap: 10px; align-items: flex-end; margin: 0 max(16px, 4%) max(16px, env(safe-area-inset-bottom));
  padding: 8px 8px 8px 16px; background: var(--karte); border-radius: 22px; box-shadow: var(--schatten);
  border: 1px solid var(--linie);
}
.eingabe:focus-within { border-color: var(--leuchten); box-shadow: 0 0 0 4px rgba(124,92,255,.12), var(--schatten); }
.eingabe textarea {
  flex: 1; border: 0; outline: 0; resize: none; font: inherit; font-size: 16.5px; line-height: 1.45;
  padding: 8px 0; max-height: 160px; background: transparent; color: var(--tinte);
}
.eingabe button {
  flex: none; width: 44px; height: 44px; border-radius: 15px; border: 0; color: #fff;
  background: linear-gradient(135deg, var(--akzent), #9b7bff); display: grid; place-items: center;
  transition: transform .15s, opacity .2s;
}
.eingabe button:active { transform: scale(.94); }
.eingabe button:disabled { opacity: .45; cursor: default; }

/* ---------- Zeichnungen ---------- */
.zeichnung {
  margin: .7em 0; padding: 12px; border-radius: 14px; background: #fbfaff; border: 1px solid #e7e1ff;
  overflow-x: auto; animation: rein .4s ease both;
}
.zeichnung svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.zeichnung-titel { font-size: 13px; font-weight: 600; color: var(--akzent-tief); margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.zeichnung.laedt { color: var(--gedimmt); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.zeichnung.laedt::before { content: "✏️"; animation: hupf 1.1s infinite; }
.vft { border-collapse: separate !important; border-spacing: 0; margin: 0 auto !important; display: table !important; font-size: 15px; }
.vft th, .vft td { border: 0 !important; border-bottom: 1px solid #e7e1ff !important; border-right: 1px solid #e7e1ff !important; padding: 10px 14px !important; min-width: 64px; }
.vft th { background: transparent !important; color: var(--gedimmt); font-weight: 600; font-size: 13.5px; }
.vft td.summe { background: #f4f1ff; font-weight: 600; }
.vft td.markiert { background: #ffe8a3 !important; box-shadow: inset 0 0 0 2px var(--warn); border-radius: 8px; }
.frage { color: var(--akzent); font-weight: 700; }

/* ---------- Gehirn ---------- */
.gehirn {
  display: flex; flex-direction: column; min-height: 0; color: var(--nacht-text); overflow-y: auto;
  background: radial-gradient(600px 420px at 50% 18%, #231d4a 0%, var(--nacht) 70%);
  border-left: 1px solid #000;
}
.gehirn h2 { margin: 0; font-size: 15px; color: #fff; letter-spacing: .02em; }
.gehirn-zu { display: none; background: none; border: 0; color: #fff; font-size: 20px; }
.graph-rahmen { position: relative; flex: 1 1 auto; min-height: 280px; }
.graph { position: absolute; inset: 0; width: 100%; height: 100%; }
.gehirn.aus .graph { filter: grayscale(1) brightness(.45); transition: filter .5s; }
.gehirn-aus {
  position: absolute; inset: auto 16px 16px; padding: 12px 14px; border-radius: 14px; font-size: 13px;
  background: rgba(15,14,26,.85); border: 1px solid var(--nacht-linie); display: grid; gap: 4px;
}
.gehirn-aus strong { color: #fff; }

.kante { stroke: #3a3660; stroke-width: 1; }
.knoten circle { fill: #59557a; transition: fill .4s, r .4s; }
.knoten text { fill: #9d99bf; font-size: 11px; pointer-events: none; transition: fill .4s; }
.knoten { cursor: pointer; }
.knoten .treffer { fill: transparent; }
.knoten.leer circle { fill: none; stroke: #59557a; stroke-dasharray: 2 2; }
.knoten.hub circle { fill: #2f2b52; stroke: #4a4578; }
.knoten.hub text { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; fill: #6f6a99; }
.knoten.immer circle { fill: #7d6bd6; }
.knoten.zuletzt circle { fill: #8f7be8; }
.knoten.aktiv circle { fill: #fff; filter: url(#glut); }
.knoten.aktiv text { fill: #fff; font-weight: 600; }
.knoten:hover text { fill: #fff; }
.agent-kern { fill: url(#kern-verlauf); filter: url(#glut); }
.agent-ring { fill: none; stroke: var(--leuchten); stroke-opacity: .5; }
.agent-text { fill: #fff; font-size: 11px; font-weight: 700; letter-spacing: .1em; }
.strahl { stroke: var(--cyan); stroke-width: 2; stroke-linecap: round; fill: none; filter: url(#glut); }
.funke { fill: #fff; filter: url(#glut); }

.lage { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.5fr) minmax(0, 1fr); gap: 8px; padding: 0 16px 12px; flex: none; }
.lage-feld { background: var(--nacht-2); border: 1px solid var(--nacht-linie); border-radius: 12px; padding: 8px 10px; }
.lage-feld.breit { grid-column: 1 / -1; }
.lage-feld span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7d79a3; }
.lage-feld strong { display: block; margin-top: 2px; color: #fff; font-size: 15px; transition: color .3s; }
.lage-feld strong.blitz { animation: blitz .8s; }
@keyframes blitz { 0% { color: var(--cyan); transform: scale(1.12); } 100% { color: #fff; transform: none; } }
.punkte { letter-spacing: .15em; }

.protokoll {
  list-style: none; margin: 0; padding: 0 16px 16px; height: 90px; flex: none; overflow-y: auto;
  font-size: 12.5px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.protokoll li { margin-bottom: 4px; padding: 5px 8px; border-radius: 8px; background: rgba(255,255,255,.03); animation: rein .3s both; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.protokoll li b { color: #fff; font-weight: 600; }
.protokoll li.neu { background: rgba(56,225,245,.09); }

/* ---------- Lernstand ---------- */
.lernstand { padding: 16px 16px 10px; flex: none; transition: opacity .4s; }
.gehirn.aus .lernstand { opacity: .4; }
.lernstand-kopf { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.lernstand-oben { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.ring { position: relative; width: 104px; height: 104px; flex: none; }
.ring svg { width: 100%; height: 100%; display: block; }
.ring-bahn { fill: none; stroke: rgba(255,255,255,.09); stroke-width: 10; }
.ring-fuellung { fill: none; stroke: var(--leuchten); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .9s cubic-bezier(.2,.8,.2,1), stroke .4s; }
.lernstand.fertig .ring-fuellung { stroke: var(--gut); }
.ring-mitte { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-mitte strong { font-size: 24px; color: #fff; line-height: 1; transition: color .3s; }
.ring-mitte strong.blitz { animation: blitz .8s; }
.ring-mitte span { margin-top: 4px; font-size: 9px; text-transform: uppercase; letter-spacing: .04em; color: #7d79a3; }
.lernstand-test { flex: 1; display: grid; gap: 4px; padding: 9px 11px; border-radius: 12px; font-size: 12.5px; line-height: 1.35;
  background: var(--nacht-2); border: 1px dashed var(--nacht-linie); color: #8e8ab3; }
.lernstand-test.aktiv { border: 1px solid var(--leuchten); color: #fff; }
.lernstand-test.abgebrochen { border-color: var(--warn); color: #fcd9a0; }
.t-punkte { letter-spacing: .2em; color: var(--cyan); font-size: 16px; }
.t-punkte:empty { display: none; }

.bereiche { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.bereich.ruhend { opacity: .55; }
.bereiche .hinweis { padding: 10px 12px; border-radius: 12px; font-size: 12.5px; line-height: 1.45; color: #fcd9a0; background: rgba(245,158,11,.1); border: 1px dashed var(--warn); }
.b-zeile { display: flex; align-items: baseline; gap: 8px; font-size: 13px; margin-bottom: 3px; }
.b-name { color: #fff; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-stufe { font-size: 11.5px; color: #7d79a3; white-space: nowrap; }
.b-prozent { min-width: 3.4em; text-align: right; color: #fff; font-variant-numeric: tabular-nums; }
.b-prozent.blitz { animation: blitz .8s; }
.b-tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.b-tag:empty { display: none; }
.bereich.ueben .b-tag { background: rgba(245,158,11,.18); color: var(--warn); }
.bereich.erreicht .b-tag { background: rgba(21,163,90,.2); color: #4ade80; }
.balken { height: 8px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; }
.fuellung { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--akzent), var(--cyan)); transition: width .9s cubic-bezier(.2,.8,.2,1), background .4s; }
.bereich.ueben .fuellung { background: linear-gradient(90deg, #d97706, var(--warn)); }
.bereich.erreicht .fuellung { background: linear-gradient(90deg, #15a35a, #4ade80); }

/* ---------- Gehirn, klein und einklappbar ---------- */
.gehirn-block { flex: 1 0 auto; display: flex; flex-direction: column; border-top: 1px solid var(--nacht-linie); }
.gehirn-block.zu { flex: none; }
.gehirn-klappe {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 12px 16px;
  background: none; border: 0; color: var(--nacht-text); text-align: left; cursor: pointer;
}
.klappe-titel { display: grid; gap: 2px; }
.klappe-titel b { color: #fff; font-size: 14px; }
.klappe-titel small { font-size: 12px; }
.klappe-pfeil { font-size: 16px; transition: transform .25s; }
.gehirn-block.zu .klappe-pfeil { transform: rotate(-90deg); }
.gehirn-inhalt { flex: 1 1 auto; display: flex; flex-direction: column; }
.gehirn-block.zu .gehirn-inhalt { display: none; }

/* ---------- Glückwunsch ---------- */
.feier { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(15,14,26,.55); backdrop-filter: blur(3px); animation: rein .3s both; }
.feier[hidden] { display: none; }
.feier-leinwand { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.feier-karte {
  position: relative; max-width: min(420px, calc(100% - 32px)); padding: 28px 26px 24px; text-align: center;
  background: var(--karte); color: var(--tinte); border-radius: 24px; box-shadow: 0 24px 70px rgba(0,0,0,.4);
  animation: aufpoppen .5s cubic-bezier(.2,1.3,.4,1) both;
}
.feier-karte h2 { margin: 6px 0 8px; font-size: 26px; color: var(--akzent-tief); }
.feier-karte p { margin: 0 0 18px; line-height: 1.5; color: var(--gedimmt); }
.feier-emoji { font-size: 54px; line-height: 1; }
.feier-karte button {
  padding: 11px 26px; border: 0; border-radius: 14px; font-size: 16px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--akzent), #9b7bff); cursor: pointer;
}
@keyframes aufpoppen { from { opacity: 0; transform: scale(.8) translateY(12px); } to { opacity: 1; transform: none; } }

/* Notiz-Ansicht */
.notiz-dialog {
  width: min(640px, calc(100% - 24px)); max-height: min(80dvh, 720px); border: 0; padding: 0; border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); color: var(--tinte);
}
.notiz-dialog::backdrop { background: rgba(15,14,26,.55); backdrop-filter: blur(3px); }
.notiz-kopf { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px 8px; position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--linie); }
.notiz-kopf small { color: var(--akzent-tief); font-size: 12px; }
.notiz-kopf h3 { margin: 2px 0 6px; }
.notiz-kopf button { background: none; border: 0; font-size: 20px; color: var(--gedimmt); }
.notiz-inhalt { padding: 8px 20px 20px; font-size: 15px; line-height: 1.55; }

/* Leiste fürs Handy (statt Gehirn-Spalte) */
.gehirn-leiste { display: none; }

/* ---------- Kleine Bildschirme ---------- */
@media (max-width: 1100px) { .haupt { grid-template-columns: minmax(0, 1fr) 360px; } }
@media (max-width: 860px) {
  .haupt { grid-template-columns: minmax(0, 1fr); }
  .gehirn {
    position: fixed; inset: 0; z-index: 10; transform: translateY(100%); transition: transform .35s cubic-bezier(.2,.8,.2,1);
    padding-top: env(safe-area-inset-top);
  }
  .gehirn.offen { transform: none; }
  .gehirn-zu { display: block; }
  .gehirn-leiste {
    display: flex; align-items: center; gap: 10px; margin: 0; padding: 9px 16px; border: 0; width: 100%;
    background: var(--nacht); color: var(--nacht-text); font-size: 13.5px; text-align: left;
  }
  .gehirn-leiste #leiste-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .leiste-puls { width: 9px; height: 9px; border-radius: 50%; background: #59557a; flex: none; }
  .gehirn-leiste.liest .leiste-puls { background: var(--cyan); box-shadow: 0 0 12px var(--cyan); animation: hupf 1s infinite; }
  .gehirn-leiste.liest #leiste-text { color: #fff; }
  .schalter-text { display: none; }
  .blase { font-size: 16px; }
}
/* Handy (375 px): die Vierfeldertafel brauchte 324 px bei 265 px Platz, die Spalte "Summe" war abgeschnitten */
@media (max-width: 480px) {
  .vft { font-size: 13.5px; }
  .vft th, .vft td { padding: 8px 6px !important; min-width: 44px; }
  .vft th { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
