:root {
  --akzent: #0f766e;
  --bg: #f6f7f8;
  --karte: #ffffff;
  --text: #16181d;
  --leise: #6b7280;
  --rand: #e3e6ea;
  --erledigt: #9aa3ad;
  --gefahr: #b91c1c;
  --radius: 14px;
  --eingabe-hoehe: 74px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --akzent: #2dd4bf;
    --bg: #0b1220;
    --karte: #151c2b;
    --text: #e8ecf2;
    --leise: #94a3b8;
    --rand: #253044;
    --erledigt: #64748b;
    --gefahr: #f87171;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Das hidden-Attribut muss staerker sein als jede Klassenregel mit display.
   Sonst zeigt sich zum Beispiel die Rueckgaengig-Leiste dauerhaft, obwohl
   das Markup sie versteckt. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--eingabe-hoehe) + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: max(env(safe-area-inset-top), 12px) 16px 0;
  border-bottom: 1px solid var(--rand);
}

.kopfzeile { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.4rem; margin: 0 0 10px; letter-spacing: -0.01em; }
.wer { color: var(--leise); font-size: 0.85rem; white-space: nowrap; }

.reiter { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.reiter::-webkit-scrollbar { display: none; }
.reiter button {
  flex: 0 0 auto;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--leise); font: inherit; font-size: 0.95rem;
  padding: 8px 12px 10px; cursor: pointer;
}
.reiter button.aktiv { color: var(--akzent); border-bottom-color: var(--akzent); font-weight: 600; }
.reiter .zahl {
  margin-left: 6px; font-size: 0.75rem; background: var(--rand);
  color: var(--leise); border-radius: 999px; padding: 1px 7px;
}

main { padding: 12px 16px 24px; max-width: 720px; margin: 0 auto; }

.liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.liste li {
  display: flex; align-items: center; gap: 12px;
  background: var(--karte); border: 1px solid var(--rand);
  border-radius: var(--radius); padding: 14px 14px;
  cursor: pointer; user-select: none;
  transition: opacity .15s, transform .06s;
}
.liste li:active { transform: scale(0.985); }

.haken {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 7px;
  border: 2px solid var(--rand); display: grid; place-items: center;
}
.liste li.ab .haken { background: var(--akzent); border-color: var(--akzent); }
.haken svg { opacity: 0; color: #fff; }
.liste li.ab .haken svg { opacity: 1; }

.inhalt { flex: 1; min-width: 0; }
.titel { display: block; word-break: break-word; }
.liste li.ab .titel { color: var(--erledigt); text-decoration: line-through; }
.meta { display: block; color: var(--leise); font-size: 0.78rem; margin-top: 2px; }

.leer { color: var(--leise); text-align: center; margin: 48px 0; }

.fehler {
  background: var(--gefahr); color: #fff; border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; font-size: 0.9rem;
}

.aufraeumen {
  display: block; margin: 20px auto 0; background: none; border: 1px solid var(--rand);
  color: var(--leise); font: inherit; font-size: 0.85rem;
  border-radius: 999px; padding: 8px 16px; cursor: pointer;
}

.filter { display: flex; gap: 6px; padding: 2px 0 8px; overflow-x: auto; scrollbar-width: none; }
.filter::-webkit-scrollbar { display: none; }
.filter button {
  flex: 0 0 auto; background: none; border: 1px solid var(--rand);
  color: var(--leise); font: inherit; font-size: 0.8rem;
  border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.filter button.aktiv { background: var(--akzent); border-color: var(--akzent); color: #fff; }

.schritt { display: block; font-size: 0.82rem; color: var(--akzent); margin-top: 3px; }
.liste li.ab .schritt { display: none; }

.faellig {
  flex: 0 0 auto; font-size: 0.75rem; color: var(--leise);
  background: var(--bg); border: 1px solid var(--rand);
  border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.faellig.warnung { color: #fff; background: var(--gefahr); border-color: var(--gefahr); }

.eingabe {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--karte); border-top: 1px solid var(--rand);
}
.eingabe .zeile { display: flex; gap: 10px; align-items: center; }
.eingabe input[type="text"], .eingabe input:not([type]) {
  flex: 1; min-width: 0; font: inherit; font-size: 1rem;
  padding: 13px 15px; border-radius: 999px;
  border: 1px solid var(--rand); background: var(--bg); color: var(--text);
}
.eingabe input:focus, .eingabe select:focus { outline: 2px solid var(--akzent); outline-offset: -1px; }
.eingabe .zeile button {
  flex: 0 0 auto; width: 48px; height: 48px; border-radius: 50%;
  border: none; background: var(--akzent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.eingabe button:disabled { opacity: .45; }

.zuweisung { display: flex; flex-wrap: wrap; gap: 8px; }
.zuweisung select, .zuweisung input {
  flex: 1 1 140px; min-width: 0; font: inherit; font-size: 0.85rem;
  padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--rand); background: var(--bg); color: var(--text);
}

@media (min-width: 720px) {
  .eingabe { position: sticky; max-width: 720px; margin: 0 auto; border-radius: var(--radius) var(--radius) 0 0; }
  body { padding-bottom: 0; }
}

/* --------------------------------------------------------------------------
   Loeschen gibt es nur bei abgehakten Eintraegen. Ein offener Eintrag laesst
   sich ausschliesslich abhaken, damit neben dem Haken nichts liegt, was den
   Eintrag ungefragt verschwinden laesst.
   -------------------------------------------------------------------------- */

.weg {
  flex: 0 0 auto; background: none; border: none; color: var(--leise);
  font-size: 1.3rem; line-height: 1; padding: 6px 8px; cursor: pointer;
}
.weg:hover { color: var(--gefahr); }

.zurueck {
  flex: 0 0 auto; background: none; border: 1px solid var(--rand);
  color: var(--leise); border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 0.78rem; padding: 5px 11px; white-space: nowrap;
}
.zurueck:hover { color: var(--akzent); border-color: var(--akzent); }

/* Kurzes Aufblinken beim Abhaken, damit die Geste quittiert wird. */
@keyframes quittung {
  0%   { background: var(--karte); }
  35%  { background: color-mix(in srgb, var(--akzent) 22%, var(--karte)); }
  100% { background: var(--karte); }
}
.liste li.quittung { animation: quittung .45s ease-out; }

/* --------------------------------------------------------------------------
   Erledigt-Bereich, zusammengeklappt am Listenende.
   -------------------------------------------------------------------------- */

.erledigtbereich { margin-top: 22px; border-top: 1px solid var(--rand); padding-top: 10px; }

.erledigtkopf {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; cursor: pointer;
  color: var(--leise); font: inherit; font-size: 0.9rem; padding: 6px 2px;
}
.erledigtkopf .pfeil { transition: transform .16s; font-size: 1.1rem; line-height: 1; }
.erledigtkopf[aria-expanded="true"] .pfeil { transform: rotate(90deg); }
.erledigtkopf .zahl {
  background: var(--rand); color: var(--leise);
  border-radius: 999px; padding: 1px 8px; font-size: 0.75rem;
}
#erledigtliste { margin-top: 10px; }

.hinweis { color: var(--leise); font-size: 0.76rem; text-align: center; margin: 14px 0 0; }

/* --------------------------------------------------------------------------
   Rueckgaengig-Leiste. Sitzt ueber dem Eingabefeld und verschwindet allein.
   -------------------------------------------------------------------------- */

.undo {
  position: fixed; z-index: 30;
  left: 16px; right: 16px;
  bottom: calc(var(--eingabe-hoehe) + env(safe-area-inset-bottom) + 12px);
  max-width: 688px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 0.9rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
  animation: reinschieben .18s ease-out;
}
@keyframes reinschieben { from { opacity: 0; transform: translateY(10px); } }
.undo button {
  flex: 0 0 auto; background: none; border: none; cursor: pointer;
  color: var(--akzent); font: inherit; font-weight: 600; padding: 2px 4px;
}

@media (prefers-reduced-motion: reduce) {
  .erledigtkopf .pfeil { transition: none; }
  .liste li.quittung, .undo { animation: none; }
}

/* Eine Klausur ist kein Haken auf einer Liste, sondern ein Termin, der
   naeherrueckt. Deshalb faellt sie aus der Reihe. */
.liste li.klausur { border-left: 3px solid var(--akzent); }
.liste li.klausur .titel { font-weight: 600; }


/* Ist das Eingabefeld ausgeblendet, braucht der Seitenfuss auch keinen
   Platz mehr dafuer. */
body.ohne-eingabe { padding-bottom: env(safe-area-inset-bottom); }

/* Unauffaellige Fussnote mit der laufenden Fassung. */
.fassung {
  color: var(--leise); font-size: 0.7rem; text-align: center;
  padding: 18px 0 6px; opacity: .6;
}

/* ------------------------------------------------------ Schulbereich */

/* Zweite Ebene: erst das Kind, dann worum es geht. */
.bereich { padding-top: 0; }
.bereich button { font-size: 0.78rem; }

/* Wochentage im Stundenplan. Schmaler als die Leiste darueber, sonst wird
   der Kopf auf dem Handy zu hoch. */
.tage { padding-top: 0; }
.tage button { font-size: 0.75rem; padding: 4px 12px; }

/* Stundenplan und Noten sind Anzeigen, keine Aufgaben: kein Haken, kein
   Antippen, ruhigere Darstellung. */
.liste li.nurlesen { cursor: default; }
.liste li.nurlesen:active { transform: none; }

/* Feste Spalte fuer die Zeit, damit die Faecher untereinander auf einer
   Kante stehen. Ohne das lief Uhrzeit, Fach und Raum in einer Zeile
   ineinander und war nicht zu lesen. */
.planzeile {
  display: grid;
  grid-template-columns: 4.2em 1fr auto;
  align-items: baseline;
  gap: 2px 12px;
}
.planzeile .zeit { display: flex; flex-direction: column; line-height: 1.2; }
.planzeile .zeit b { font-weight: 600; font-size: 0.88rem; }
.planzeile .zeit small { color: var(--leise); font-size: 0.7rem; }
.planzeile .planfach { font-weight: 600; }
.planzeile .ort {
  color: var(--leise); font-size: 0.76rem; white-space: nowrap;
  justify-self: end; text-align: right;
}

/* Karte fuer Hausaufgaben, Klausuren und Noten: das Fach ist die
   Ueberschrift, alles andere steht klein darunter. Die Zeilen sind spans,
   deshalb muessen sie ausdruecklich als Bloecke gesetzt werden. */
.liste li.karte { align-items: flex-start; }
.karte .fachkopf, .karte .auftrag, .karte .wann, .karte .mehr { display: block; }
.karte .fachkopf { font-weight: 700; font-size: 1.02rem; }
.liste li.karte.ab .fachkopf {
  color: var(--erledigt); text-decoration: line-through;
}
/* Haken und Faelligkeit stehen auf Hoehe der Ueberschrift, nicht mittig zur
   ganzen Karte: bei einer aufgeklappten Aufgabe rutschen sie sonst weit nach
   unten. */
.karte .haken, .karte .faellig { margin-top: 1px; }
.karte .auftrag {
  font-size: 0.86rem; opacity: .85;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.karte .wann { color: var(--leise); font-size: 0.76rem; }
.karte .mehr {
  white-space: pre-wrap; font-size: 0.86rem; line-height: 1.45;
  margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--rand);
}
/* Aufgeklappt darf der Auftrag ueber mehrere Zeilen laufen. */
.karte.offen .auftrag { white-space: normal; overflow: visible; }
.karte.klappbar { cursor: pointer; }
/* Nur das Kaestchen hakt ab. Damit klar ist, wo man druecken muss, bekommt
   es etwas mehr Flaeche als der Haken selbst breit ist. */
.karte .haken { padding: 6px; margin: -6px; }

/* Note als Marke rechts. Rot und gruen nur, wenn das Portal selbst eine
   Richtung angibt. */
.note {
  flex: 0 0 auto; font-weight: 700; border-radius: 8px;
  padding: 3px 10px; font-size: 0.9rem; align-self: center;
  background: var(--bg); border: 1px solid var(--rand);
}
.note.schwach { background: var(--gefahr); border-color: var(--gefahr); color: #fff; }
.note.gut { background: var(--akzent); border-color: var(--akzent); color: #fff; }
