:root {
  --grund: #f5f6f3;
  --karte: #ffffff;
  --text: #1c2420;
  --leise: #5f6b65;
  --linie: #dfe3dd;
  --haupt: #1f7a4d;
  --haupt-hell: #e3f1e8;
  --auf-haupt: #ffffff;
  --gruen: #2e9e5b;
  --gelb: #d99a1b;
  --rot: #d64545;
  --schatten: 0 1px 3px rgba(0, 0, 0, .08);
  --rund: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #121614;
    --karte: #1b211e;
    --text: #e6ebe8;
    --leise: #9aa7a0;
    --linie: #2c3530;
    --haupt: #4cc387;
    --haupt-hell: #1d3328;
    --auf-haupt: #0d1a13;
    --gruen: #4cc387;
    --gelb: #f0b43c;
    --rot: #f06a6a;
    --schatten: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--grund);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
}

.laden { color: var(--leise); text-align: center; margin-top: 30vh; }

h1 { font-size: 1.35rem; margin: 4px 0 14px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 14px 0 6px; color: var(--leise); font-weight: 600; }
p { margin: 0 0 10px; }
.leise { color: var(--leise); font-size: .9rem; }
.klein { font-size: .82rem; }

.karte {
  background: var(--karte);
  border: 1px solid var(--linie);
  border-radius: var(--rund);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--schatten);
}

/* Navigation */
#navi {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  background: var(--karte);
  border-top: 1px solid var(--linie);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
#navi button {
  flex: 1;
  border: 0;
  background: none;
  color: var(--leise);
  padding: 8px 0 10px;
  font-size: .75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
#navi .ico { font-size: 1.35rem; line-height: 1.2; }
#navi button.aktiv { color: var(--haupt); font-weight: 600; }

/* Formulare */
label { display: block; font-size: .85rem; color: var(--leise); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--grund);
  border: 1px solid var(--linie);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--haupt); outline-offset: -1px; }
input[type="range"] { padding: 0; min-height: 32px; background: none; border: 0; accent-color: var(--haupt); }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--haupt); }
.reihe { display: flex; gap: 10px; align-items: flex-end; }
.reihe > * { flex: 1; min-width: 0; }
.reihe > .fix { flex: 0 0 auto; }

button { font: inherit; cursor: pointer; }
.knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  min-height: 46px;
  background: var(--haupt);
  color: var(--auf-haupt);
  font-weight: 600;
}
.knopf.zweit { background: var(--haupt-hell); color: var(--haupt); }
.knopf.leer { background: none; color: var(--haupt); border: 1px solid var(--linie); }
.knopf.gefahr { background: none; color: var(--rot); border: 1px solid var(--linie); }
.knopf.breit { width: 100%; }
.knopf:disabled { opacity: .5; }
.ikon {
  border: 0;
  background: var(--haupt-hell);
  color: var(--haupt);
  width: 46px;
  height: 46px;
  border-radius: 10px;
  font-size: 1.3rem;
  flex: 0 0 46px;
}

/* KI-Eingabe */
.eingabe { display: flex; gap: 8px; }
.eingabe input { flex: 1; }
.beispiele { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.beispiele button {
  border: 1px solid var(--linie);
  background: none;
  color: var(--leise);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .8rem;
}

/* Tageskopf */
.tag-kopf { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tag-kopf button { border: 0; background: none; color: var(--haupt); font-size: 1.4rem; padding: 4px 12px; }
.tag-kopf strong { font-size: 1.05rem; }

.budget { display: flex; gap: 16px; align-items: center; }
.ring { flex: 0 0 132px; position: relative; }
.ring svg { display: block; }
.ring .mitte { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .zahl { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.ring .wort { font-size: .75rem; color: var(--leise); }
.zahlen { flex: 1; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: .92rem; }
.zahlen span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.balken { height: 8px; border-radius: 99px; background: var(--linie); overflow: hidden; margin-top: 4px; }
.balken > div { height: 100%; background: var(--haupt); border-radius: 99px; }

/* Listen */
.liste { list-style: none; margin: 0; padding: 0; }
.liste li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--linie);
}
.liste li:last-child { border-bottom: 0; }
.liste .haupt { flex: 1; min-width: 0; }
.liste .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste .wert { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.liste li.tippbar { cursor: pointer; }

.mahlzeit-kopf { display: flex; justify-content: space-between; margin: 12px 0 0; font-weight: 600; font-size: .9rem; color: var(--leise); }

/* Ampel */
.ampel { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; background: var(--linie); }
.ampel.gruen { background: var(--gruen); }
.ampel.gelb { background: var(--gelb); }
.ampel.rot { background: var(--rot); }
.ns {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  color: #fff;
  text-transform: uppercase;
  vertical-align: 1px;
}
.ns-a { background: #038141; } .ns-b { background: #85bb2f; } .ns-c { background: #e6b400; }
.ns-d { background: #ee8100; } .ns-e { background: #e63e11; }
.marke { color: var(--leise); font-size: .82rem; }

/* Blatt (Dialog von unten) */
dialog#blatt {
  border: 0;
  padding: 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  margin: auto auto 0;
  border-radius: 18px 18px 0 0;
  background: var(--karte);
  color: var(--text);
}
dialog#blatt::backdrop { background: rgba(0, 0, 0, .45); }
#blatt-inhalt { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.blatt-kopf { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.blatt-kopf h2 { margin: 0; }
.zu { border: 0; background: none; font-size: 1.5rem; color: var(--leise); padding: 0 6px; }

.posten { border: 1px solid var(--linie); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.posten.aus { opacity: .5; }
.posten-kopf { display: flex; gap: 10px; align-items: center; }
.posten-kopf .name { flex: 1; font-weight: 600; }
.posten-kopf .wert { font-weight: 700; font-variant-numeric: tabular-nums; }
.antwort { background: var(--haupt-hell); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.sicherheit { font-size: .72rem; border-radius: 4px; padding: 1px 6px; border: 1px solid var(--linie); color: var(--leise); }

.video-rahmen { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.video-rahmen video { width: 100%; height: 100%; object-fit: cover; }
.video-rahmen .ziel { position: absolute; inset: 30% 12%; border: 2px solid rgba(255, 255, 255, .8); border-radius: 8px; }

/* Gewicht */
.diagramm svg { width: 100%; height: auto; display: block; }
.diagramm .achse { stroke: var(--linie); }
.diagramm .beschriftung { fill: var(--leise); font-size: 10px; }
.diagramm .punkt { fill: var(--leise); opacity: .6; }
.diagramm .trend { stroke: var(--haupt); stroke-width: 2.5; fill: none; }
.diagramm .ziel { stroke: var(--gruen); stroke-dasharray: 4 4; }
.kennzahlen { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kennzahl { background: var(--grund); border-radius: 10px; padding: 10px; }
.kennzahl .zahl { font-size: 1.25rem; font-weight: 700; }
.kennzahl .wort { font-size: .78rem; color: var(--leise); }

/* Meldung */
#meldung {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--grund);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: .9rem;
  max-width: 90vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 30;
}
#meldung.sichtbar { opacity: 1; }

.fehler { color: var(--rot); font-size: .9rem; margin-top: 8px; }
.hinweis { border-left: 3px solid var(--haupt); padding: 8px 12px; background: var(--haupt-hell); border-radius: 0 10px 10px 0; font-size: .9rem; margin-bottom: 12px; }
.warten { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: drehen .8s linear infinite; }
@keyframes drehen { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }

/* Anmeldung – Vollbild wie die Pool App: Person wählen, dann PIN */
.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  background: linear-gradient(160deg, #145c39 0%, #1f7a4d 45%, #2a9d8f 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.login h1 { color: #fff; font-size: 1.6rem; margin: 14px 0 4px; }
.login-unter { color: rgba(255, 255, 255, .75); font-size: .95rem; margin: 0 0 22px; }
.login-fehler { color: #ffd2d2; font-size: .9rem; min-height: 1.3em; margin: 6px 0; }

.personen { display: flex; flex-direction: column; gap: 12px; }
.person {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  text-align: left;
  transition: background .12s, transform .08s;
}
.person:active { background: rgba(255, 255, 255, .28); transform: scale(.98); }
.person .kreis {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  background: #fff;
  color: #1f7a4d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
}
.person .name { flex: 1; }
.person .pfeil { opacity: .6; font-size: 1.5rem; }

.pin-punkte { display: flex; gap: 14px; justify-content: center; margin: 4px 0 6px; }
.pin-punkte span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .75);
  transition: transform .12s, background .12s;
}
.pin-punkte span.voll { background: #fff; transform: scale(1.15); }
.pin-feld { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px auto 0; max-width: 300px; }
.pin-feld button {
  height: 74px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 1.7rem;
  font-weight: 600;
  transition: background .1s, transform .08s;
}
.pin-feld button:active { background: rgba(255, 255, 255, .35); transform: scale(.93); }
.pin-feld .leer { visibility: hidden; }
.login .zurueck {
  margin-top: 22px;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, .8);
  font-size: .95rem;
  padding: 10px 16px;
}
.wackeln { animation: wackeln .35s; }
@keyframes wackeln {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

/* Mikrofon hört zu */
.ikon.hoert { background: var(--rot); color: #fff; animation: pulsieren 1.2s ease-in-out infinite; }
@keyframes pulsieren { 50% { opacity: .6; } }
