:root {
  --grund: #f5f2ea; --flaeche: #ffffff; --flaeche2: #ece8dc; --text: #1c1a15; --leise: #5c574b;
  --akzent: #1f5f4a; --auf-akzent: #ffffff; --akzent-zart: #dcebe4; --rand: #cfc9b8;
  --gefahr: #a8261c; --gefahr-zart: #f8e1dd; --warn: #7a5200; --warn-zart: #fbefcf;
  --radius: 16px; --ziel: 60px; --leiste: 76px;
  font-size: 18px; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --grund: #141310; --flaeche: #201e19; --flaeche2: #2b2822; --text: #eeeadf; --leise: #aaa497;
    --akzent: #7fd1b3; --auf-akzent: #06281d; --akzent-zart: #1d3a31; --rand: #45413a;
    --gefahr: #ff9c8f; --gefahr-zart: #45201c; --warn: #ffd27a; --warn-zart: #3d3113;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--grund); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; text-wrap: balance; }
a { color: var(--akzent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--akzent); outline-offset: 3px; border-radius: 6px; }
.sprung { position: absolute; left: -999px; top: 8px; background: var(--flaeche); padding: 12px 16px; z-index: 50; }
.sprung:focus { left: 8px; }
svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Grundgerüst */
.app { display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; }
.kopf {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--flaeche); border-bottom: 1px solid var(--rand); min-height: 64px;
}
.kopf h1 { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kopf-aktionen { display: flex; gap: 8px; }
.verbrauch {
  display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 44px; padding: 4px 12px;
  border-radius: 12px; background: var(--flaeche2); color: var(--text); text-decoration: none;
  font-size: .8rem; font-weight: 600; line-height: 1.25; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.verbrauch[hidden] { display: none; }
.verbrauch .knapp { color: var(--warn); }
.verbrauch .voll { color: var(--gefahr); }
/* Auf dem Handy reicht der Platz neben Titel und Knöpfen nicht (erst recht bei großer Schrift):
   dort steht der Verbrauch als schmale eigene Zeile unter dem Titel, statt die Seite zu breit zu machen. */
@media (max-width: 600px) {
  .kopf { flex-wrap: wrap; row-gap: 0; }
  .verbrauch { order: 3; flex: 0 0 100%; flex-direction: row; justify-content: flex-end; gap: 16px; min-height: 36px;
    padding: 0 2px; background: none; }
}
main { overflow-y: auto; min-height: 0; grid-row: 2; display: flex; flex-direction: column; }
main:focus { outline: none; }
.leiste {
  grid-row: 3; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--flaeche);
  border-top: 1px solid var(--rand); padding-bottom: env(safe-area-inset-bottom);
}
.leiste > a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--leiste);
  color: var(--leise); text-decoration: none; font-size: .85rem; font-weight: 600;
}
.leiste > a[aria-current="page"] { color: var(--akzent); box-shadow: inset 0 3px 0 var(--akzent); }
.chatliste { display: none; }
@media (min-width: 900px) {
  .app { grid-template-columns: 290px 1fr; grid-template-rows: auto 1fr; }
  .kopf { grid-column: 1 / -1; }
  .leiste { grid-row: 2; grid-column: 1; display: flex; flex-direction: column; min-height: 0; border-top: 0; border-right: 1px solid var(--rand); padding: 12px; gap: 6px; }
  .leiste > a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 16px; min-height: var(--ziel); border-radius: var(--radius); font-size: 1rem; }
  .leiste > a[aria-current="page"] { background: var(--akzent-zart); box-shadow: none; }
  /* Chatliste wie bei ChatGPT/Claude: unter den Bereichen, scrollt für sich */
  .chatliste { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; overflow-y: auto;
    overflow-x: hidden; margin: 10px -12px 0; padding: 12px 12px 4px; border-top: 1px solid var(--rand); }
  .chatliste .knopf { width: 100%; justify-content: flex-start; margin-bottom: 6px; }
  .chatliste h2 { font-size: .8rem; font-weight: 700; color: var(--leise); text-transform: uppercase; letter-spacing: .04em; margin: 12px 8px 4px; }
  .chatliste h2.unsichtbar { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .chatliste ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .chatliste a { display: flex; flex-direction: column; justify-content: center; min-height: 52px; padding: 6px 12px;
    border-radius: 12px; color: var(--text); text-decoration: none; }
  .chatliste a:hover { background: var(--flaeche2); }
  .chatliste a[aria-current="page"] { background: var(--akzent-zart); }
  .chatliste .titel { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chatliste small { color: var(--leise); font-size: .8rem; }
  .kopf .nur-handy { display: none; }
  main { grid-column: 2; }
}
.seite { width: 100%; max-width: 820px; margin: 0 auto; padding: 20px 16px 32px; }

/* Knöpfe und Felder */
.knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: var(--ziel); padding: 0 20px;
  border: 2px solid var(--rand); border-radius: var(--radius); background: var(--flaeche); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
}
.knopf:active { transform: translateY(1px); }
.knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: var(--auf-akzent); }
.knopf.gefahr { color: var(--gefahr); border-color: var(--gefahr); }
.knopf.klein { min-height: 48px; padding: 0 14px; font-size: .95rem; }
.knopf.voll { width: 100%; }
.knopf[disabled] { opacity: .5; cursor: default; }
.knopf.nur-zeichen { padding: 0; width: var(--ziel); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--flaeche); border: 2px solid var(--rand); border-radius: var(--radius);
  padding: 14px 16px; width: 100%; min-height: var(--ziel);
}
textarea { resize: vertical; line-height: 1.45; }
label { display: block; font-weight: 600; margin: 16px 0 6px; }
.fehler { color: var(--gefahr); font-weight: 600; min-height: 1.5em; margin: 8px 0; }
.leise { color: var(--leise); }
.reihe { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Anmeldung */
.anmeldung { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.anmeldung form { width: 100%; max-width: 420px; background: var(--flaeche); border: 1px solid var(--rand); border-radius: 24px; padding: 28px; }
.anmeldung h1 { margin: 0 0 8px; }
.anmeldung .knopf { width: 100%; margin-top: 8px; }

/* Chat */
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.verlauf { flex: 1; overflow-y: auto; padding: 16px; }
.verlauf-innen { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.blase { max-width: 92%; padding: 12px 16px; border-radius: var(--radius); overflow-wrap: anywhere; }
.blase.luca { align-self: flex-end; background: var(--akzent); color: var(--auf-akzent); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.blase.ki { align-self: flex-start; background: var(--flaeche); border: 1px solid var(--rand); border-bottom-left-radius: 4px; }
.blase.hinweis { align-self: stretch; max-width: none; background: var(--warn-zart); color: var(--text); border: 1px solid var(--warn); }
.blase .marke { display: block; font-size: .8rem; opacity: .85; margin-bottom: 2px; }
.anhaenge { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.anhaenge img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; display: block; }
.anhang { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--flaeche2); color: var(--text); font-size: .9rem; text-decoration: none; }
.schritte { margin: 0 0 8px; font-size: .9rem; color: var(--leise); }
.schritte summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.schritte ol { margin: 4px 0 8px; padding-left: 1.4em; }
.arbeitet { display: flex; align-items: center; gap: 10px; color: var(--leise); font-size: .95rem; min-height: 32px; }
.punkt { width: 12px; height: 12px; border-radius: 50%; background: var(--akzent); animation: puls 1.2s ease-in-out infinite; flex: none; }
@keyframes puls { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .punkt, .mikro.nimmt-auf { animation: none !important; } }
.vorschlaege { display: grid; gap: 10px; margin-top: 12px; }
.leer { text-align: center; padding: 6vh 8px 0; }
.leer h2 { margin: 0 0 8px; font-size: 1.5rem; }
.leer .vorschlaege { max-width: 420px; margin: 24px auto 0; }

.schreiben { background: var(--flaeche); border-top: 1px solid var(--rand); padding: 10px 12px; }
.schreiben-innen { max-width: 820px; margin: 0 auto; display: grid; gap: 10px; }
.schreiben textarea { min-height: var(--ziel); max-height: 40vh; resize: none; }
.schreiben .tasten { display: grid; grid-template-columns: var(--ziel) 1fr var(--ziel); gap: 10px; align-items: center; }
.mikro { min-height: 68px; font-size: 1.1rem; }
.mikro.nimmt-auf { background: var(--gefahr); border-color: var(--gefahr); color: var(--grund); animation: puls-rand 1.4s ease-in-out infinite; }
@keyframes puls-rand { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--gefahr) 50%, transparent); } 50% { box-shadow: 0 0 0 10px transparent; } }
.wartend { display: flex; flex-wrap: wrap; gap: 8px; }

/* Listen */
.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.zeile {
  display: flex; align-items: center; gap: 12px; min-height: var(--ziel); padding: 10px 16px; background: var(--flaeche);
  border: 1px solid var(--rand); border-radius: var(--radius); color: var(--text); text-decoration: none; width: 100%;
  font: inherit; text-align: left; cursor: pointer;
}
.zeile .haupttext { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.zeile small { color: var(--leise); display: block; font-weight: 400; }
details.ordner { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); }
details.ordner > summary { min-height: var(--ziel); padding: 0 16px; display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; list-style: none; }
details.ordner > summary::-webkit-details-marker { display: none; }
details.ordner > summary::before { content: "▸"; color: var(--leise); width: 1em; }
details.ordner[open] > summary::before { content: "▾"; }
details.ordner > summary .zahl { margin-left: auto; color: var(--leise); font-weight: 400; }
details.ordner .innen { padding: 0 10px 10px; display: grid; gap: 8px; }
details.ordner details.ordner { border-style: dashed; }
details.ordner .zeile { border: 0; background: var(--flaeche2); }
.treffer mark { background: var(--akzent-zart); color: inherit; border-radius: 4px; padding: 0 2px; }

/* Notiz und gerenderter Text */
.pfad { color: var(--leise); font-size: .9rem; margin: 0 0 4px; overflow-wrap: anywhere; }
.notiz-titel { margin: 0 0 12px; font-size: 1.7rem; }
.text > :first-child { margin-top: 0; }
.notiztext > h1:first-child { display: none; }
.notiztext > h1:first-child + * { margin-top: 0; }
.text > :last-child { margin-bottom: 0; }
.text { overflow-wrap: anywhere; }
.text h1 { font-size: 1.5rem; } .text h2 { font-size: 1.25rem; margin-top: 1.6em; } .text h3 { font-size: 1.08rem; margin-top: 1.3em; }
.text p, .text ul, .text ol { max-width: 68ch; }
.text ul, .text ol { padding-left: 1.3em; }
.text li { margin: .25em 0; }
.text img { max-width: 100%; height: auto; border-radius: 12px; }
.text code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; background: var(--flaeche2); padding: 1px 5px; border-radius: 6px; }
.text pre { background: var(--flaeche2); padding: 12px 14px; border-radius: 12px; overflow-x: auto; }
.text pre code { background: none; padding: 0; }
.text table { display: block; overflow-x: auto; border-collapse: collapse; max-width: 100%; }
.text th, .text td { border: 1px solid var(--rand); padding: 8px 10px; text-align: left; vertical-align: top; }
.text blockquote { margin: 1em 0; padding: 8px 14px; border-left: 4px solid var(--rand); color: var(--leise); }
.text .kasten { background: var(--akzent-zart); border: 0; border-left: 4px solid var(--akzent); border-radius: 0 12px 12px 0; padding: 10px 14px; color: var(--text); margin: 1em 0; }
.text .kasten-titel, .text details.kasten summary { font-weight: 700; }
.text details.kasten summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.text details.kasten-quote { background: var(--flaeche2); border-left-color: var(--rand); color: var(--leise); }
.text a.fehlt { color: var(--leise); text-decoration-style: dashed; }
.karte { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); padding: 18px; margin: 0 0 16px; }
.karte h2 { margin: 0 0 8px; font-size: 1.15rem; }
.karte p { margin: 6px 0; }
.balken { height: 14px; background: var(--flaeche2); border-radius: 999px; overflow: hidden; margin: 6px 0 2px; }
.balken > span { display: block; height: 100%; background: var(--akzent); border-radius: 999px; }
.code-gross .ziffer { color: var(--akzent); }
.code-gross { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 2rem; letter-spacing: .12em; font-weight: 700; padding: 12px 0; user-select: all; }
.zustand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.zustand::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--leise); }
.zustand.gut::before { background: #2e9b6d; } .zustand.schlecht::before { background: var(--gefahr); }
.editorrahmen { max-width: 72ch; }
.editorrahmen.bearbeitbar { background: var(--flaeche); border: 2px solid var(--akzent); border-radius: var(--radius); padding: 14px 16px; max-width: none; }
.editorrahmen .cm-editor { min-height: 4em; }

.meldung {
  position: fixed; left: 50%; bottom: calc(var(--leiste) + 90px); transform: translateX(-50%); background: var(--text); color: var(--grund);
  padding: 12px 18px; border-radius: 12px; max-width: min(90vw, 520px); z-index: 40; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.meldung.sichtbar { opacity: 1; }

.postfach { border-top: 1px solid var(--rand); padding: 10px 0; }
.postfach .zustand { overflow-wrap: anywhere; }
.aufklappen { border-top: 1px solid var(--rand); margin-top: 6px; }
.aufklappen summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; font-weight: 600; }
