:root {
  --bg: #f6f3ee;
  --flaeche: #ffffff;
  --flaeche-2: #efeae2;
  --text: #1f1c18;
  --text-2: #5d564d;
  --rand: #d9d1c5;
  --akzent: #8a4b14;
  --akzent-text: #ffffff;
  --akzent-weich: #f5e6d6;
  --ich: #e3edf7;
  --ich-text: #13283d;
  --gut: #2f6b3a;
  --gut-weich: #e2f0e4;
  --stopp: #a3271f;
  --stopp-weich: #fbe5e2;
  --aus: #b9b1a6;
  --radius: 12px;
  --schatten: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171512;
    --flaeche: #221f1b;
    --flaeche-2: #2c2823;
    --text: #f1ece4;
    --text-2: #b5ac9f;
    --rand: #3d3730;
    --akzent: #e0a35c;
    --akzent-text: #1b140c;
    --akzent-weich: #3a2c1c;
    --ich: #1f3347;
    --ich-text: #dbe9f7;
    --gut: #7cc78a;
    --gut-weich: #1f3324;
    --stopp: #f08a80;
    --stopp-weich: #3d1f1c;
    --aus: #5a534a;
    --schatten: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #171512;
  --flaeche: #221f1b;
  --flaeche-2: #2c2823;
  --text: #f1ece4;
  --text-2: #b5ac9f;
  --rand: #3d3730;
  --akzent: #e0a35c;
  --akzent-text: #1b140c;
  --akzent-weich: #3a2c1c;
  --ich: #1f3347;
  --ich-text: #dbe9f7;
  --gut: #7cc78a;
  --gut-weich: #1f3324;
  --stopp: #f08a80;
  --stopp-weich: #3d1f1c;
  --aus: #5a534a;
  --schatten: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0.2em 0 0.4em; }
h2 { font-size: 1.25rem; margin: 0 0 0.6em; }
p { margin: 0.4em 0; }
a { color: var(--akzent); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.klein { font-size: 0.88rem; color: var(--text-2); }
.lead { color: var(--text-2); max-width: 60ch; }
.fehler { color: var(--stopp); font-size: 0.92rem; }
.zeile { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.zeile.rechts { justify-content: flex-end; }

/* ---------- Kopf ---------- */

.kopf {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 16px; border-bottom: 1px solid var(--rand); background: var(--flaeche);
}
.marke {
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem;
}
.kopf nav a { font-size: 0.9rem; }

main { max-width: 1080px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

/* ---------- Elemente ---------- */

button {
  font: inherit; cursor: pointer; border: 1px solid var(--akzent);
  background: var(--akzent); color: var(--akzent-text);
  padding: 0.5rem 1rem; border-radius: 8px; font-weight: 600;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.zweit { background: transparent; color: var(--akzent); }
button.link {
  background: none; border: none; padding: 0; color: var(--akzent);
  font-weight: 500; text-decoration: underline; text-underline-offset: 2px;
}
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid var(--akzent); outline-offset: 2px;
}

input, textarea {
  font: inherit; color: var(--text); background: var(--flaeche);
  border: 1px solid var(--rand); border-radius: 8px; padding: 0.5rem 0.7rem;
  min-width: 0;
}
textarea { width: 100%; resize: vertical; }

.karte {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--schatten);
}

/* ---------- Start ---------- */

.start { max-width: 560px; margin: 1rem auto; text-align: center; padding: 1.5rem; }
.start .lead { margin-inline: auto; }
.portrait { display: block; margin: 0 auto 0.5rem; }
.ki-hinweis { color: var(--text-2); }
.hinweis {
  background: var(--akzent-weich); border-radius: 8px; padding: 0.7rem 0.9rem;
  margin: 1rem 0; font-size: 0.95rem; text-align: left;
}
.code-form { text-align: left; margin-top: 1rem; }
.code-form label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.code-form input { flex: 1; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Stufen ---------- */

.stufen-liste {
  list-style: none; padding: 0; margin: 1rem 0;
  display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.stufe {
  width: 100%; height: 100%; display: flex; gap: 0.8rem; align-items: flex-start; text-align: left;
  background: var(--flaeche); color: var(--text); border: 1px solid var(--rand);
  border-radius: var(--radius); padding: 0.9rem; font-weight: 400; box-shadow: var(--schatten);
}
.stufe:not(:disabled):hover { border-color: var(--akzent); }
.stufe .nr {
  flex: none; width: 2.2rem; height: 2.2rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--akzent-weich); color: var(--akzent); font-weight: 700;
}
.stufe .text { flex: 1; display: flex; flex-direction: column; gap: 0.15rem; }
.stufe .status { flex: none; font-size: 0.8rem; color: var(--text-2); white-space: nowrap; }
.stufe.geschafft .nr { background: var(--gut-weich); color: var(--gut); }
.stufe.geschafft .status { color: var(--gut); font-weight: 600; }

/* ---------- Chat ---------- */

.chat-kopf h1 { margin-top: 0.4rem; margin-bottom: 0.1rem; }

.pipeline {
  list-style: none; padding: 0; margin: 0.8rem 0 1rem;
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: stretch;
}
.glied {
  display: flex; flex-direction: column; padding: 0.35rem 0.7rem; border-radius: 8px;
  border: 1px solid var(--rand); background: var(--flaeche); font-size: 0.85rem; min-width: 7.5rem;
  position: relative;
}
.glied span { color: var(--text-2); font-size: 0.78rem; }
.glied.aus { border-style: dashed; color: var(--aus); }
.glied.aus span { color: var(--aus); }
.glied.an { border-color: var(--akzent); }
.glied.blockiert { background: var(--stopp-weich); border-color: var(--stopp); }
.glied + .glied::before {
  content: "→"; position: absolute; left: -0.45rem; top: 50%; transform: translate(-50%, -50%);
  color: var(--text-2); font-size: 0.8rem;
}

.chat-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }

.chat {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius);
  box-shadow: var(--schatten); display: flex; flex-direction: column; min-height: 420px;
}
.verlauf {
  flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.7rem;
  max-height: 60vh; min-height: 300px;
}
.blase { display: flex; gap: 0.5rem; align-items: flex-start; max-width: 85%; }
.blase p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.blase > div { padding: 0.55rem 0.8rem; border-radius: 12px; }
.blase.waechter > div { background: var(--flaeche-2); border-top-left-radius: 4px; }
.blase.ich { align-self: flex-end; }
.blase.ich > div { background: var(--ich); color: var(--ich-text); border-top-right-radius: 4px; }
.blase img { flex: none; margin-top: 2px; }
.blase.warten p { animation: puls 1.2s ease-in-out infinite; }
@keyframes puls { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .blase.warten p { animation: none; } }

.tag {
  display: inline-block; margin-top: 0.4rem; font-size: 0.78rem; font-weight: 600;
  padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--flaeche); color: var(--text-2);
}
.tag.eingabe, .tag.ausgabe, .tag.kontrolleur { background: var(--stopp-weich); color: var(--stopp); }

.chat-form { border-top: 1px solid var(--rand); padding: 0.7rem; display: grid; gap: 0.4rem; }
.chat-form .zeile { justify-content: flex-end; }
.chat-form #zeichen { margin-right: auto; }

.seite { display: grid; gap: 1rem; }
.seite form label { display: block; margin-bottom: 0.4rem; }
.seite input { flex: 1; text-transform: uppercase; }
.tipps { padding-left: 1.2rem; margin: 0.5rem 0; font-size: 0.95rem; }
.tipps li + li { margin-top: 0.4rem; }

@media (max-width: 800px) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .verlauf { max-height: 55vh; }
  .blase { max-width: 95%; }
  .glied { min-width: 0; flex: 1 1 40%; }
  .glied + .glied::before { display: none; }
}

/* ---------- Erklär-Karte ---------- */

.dialog {
  border: none; border-radius: var(--radius); padding: 1.4rem; max-width: 560px; width: calc(100% - 32px);
  background: var(--flaeche); color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.erklaerung dt { font-weight: 700; color: var(--akzent); margin-top: 0.8rem; font-size: 0.9rem; }
.erklaerung dd { margin: 0.2rem 0 0; }
.dialog .zeile { margin-top: 1.2rem; }

/* ---------- Status & Textseiten ---------- */

.text-seite { max-width: 720px; }
.tabelle { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tabelle th, .tabelle td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--rand); }
.tabelle td.zahl, .tabelle th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
.kennzahlen { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin: 1rem 0; }
.kennzahlen .karte strong { display: block; font-size: 1.5rem; }
.tabelle-wrap { overflow-x: auto; }
.schmal { max-width: 420px; }
.abstand { margin-top: 0.4rem; }
.schmal input { flex: 1; }
