/* Aussehen der Kochapp.
   Richtet sich nach den Apple Human Interface Guidelines:
   Systemschrift, große Titel, gruppierte Listen, Tab-Leiste unten,
   Tippflächen mindestens 44 Punkt, heller und dunkler Modus. */

:root {
  color-scheme: light dark;
  --hg: #F2F2F7;
  --karte: #FFFFFF;
  --text: #000000;
  --text2: rgba(60, 60, 67, 0.68);
  --text3: rgba(60, 60, 67, 0.3);
  --linie: rgba(60, 60, 67, 0.18);
  --fuell: rgba(120, 120, 128, 0.14);
  --fuell-stark: rgba(120, 120, 128, 0.24);
  --wahl: #FFFFFF;
  --akzent: #0A7A3B;
  --akzent-hell: rgba(10, 122, 59, 0.12);
  --auf-akzent: #FFFFFF;
  --angebot: #A8480A;
  --angebot-hg: rgba(255, 149, 0, 0.18);
  --rot: #D70015;
  --leiste: rgba(249, 249, 249, 0.86);
  --schatten: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.04);
  --rund: 12px;
  --rand: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --hg: #000000;
    --karte: #1C1C1E;
    --text: #FFFFFF;
    --text2: rgba(235, 235, 245, 0.66);
    --text3: rgba(235, 235, 245, 0.3);
    --linie: rgba(84, 84, 88, 0.6);
    --fuell: rgba(120, 120, 128, 0.24);
    --fuell-stark: rgba(120, 120, 128, 0.36);
    --wahl: #636366;
    --akzent: #30D158;
    --akzent-hell: rgba(48, 209, 88, 0.18);
    --auf-akzent: #00210C;
    --angebot: #FFB340;
    --angebot-hg: rgba(255, 159, 10, 0.2);
    --rot: #FF453A;
    --leiste: rgba(22, 22, 24, 0.84);
    --schatten: 0 3px 8px rgba(0, 0, 0, 0.4);
  }
}

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

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

body {
  margin: 0;
  background: var(--hg);
  color: var(--text);
  font: 1.0625rem/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.blatt-offen { overflow: hidden; }

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; }
:focus-visible { outline: 3px solid var(--akzent); outline-offset: 2px; border-radius: 8px; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 var(--rand) calc(84px + env(safe-area-inset-bottom));
  padding-left: max(var(--rand), env(safe-area-inset-left));
  padding-right: max(var(--rand), env(safe-area-inset-right));
}
body.einrichtung #app { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

/* ----- Schrift ----- */

h1 { font-size: 2.125rem; line-height: 1.2; font-weight: 700; letter-spacing: 0.01em; margin: 0; }
.kopf { padding: calc(env(safe-area-inset-top) + 28px) 4px 14px; }
.ueber { margin: 0 0 2px; font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text2); }
.neben { font-size: 0.8125rem; line-height: 1.35; color: var(--text2); }
.unter { margin: 6px 0 0; font-size: 0.9375rem; }
.abschnitt { font-size: 1.375rem; line-height: 1.25; font-weight: 700; margin: 34px 4px 10px; }
.frage { font-size: 0.9375rem; font-weight: 600; margin: 20px 4px 8px; }
.gruppe { font-size: 0.8125rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text2); margin: 26px 16px 7px; }
.fuss { font-size: 0.8125rem; line-height: 1.4; color: var(--text2); margin: 8px 16px 0; }
.erklaerung { font-size: 0.9375rem; color: var(--text2); margin: -4px 4px 12px; }

/* ----- Karten und Listen ----- */

.karte { display: block; width: 100%; background: var(--karte); border-radius: var(--rund); padding: 14px 16px; }
.liste { background: var(--karte); border-radius: var(--rund); overflow: hidden; }

.zeile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
}
.zeile + .zeile::before {
  content: "";
  position: absolute;
  top: 0; left: 16px; right: 0;
  height: 1px;
  background: var(--linie);
  transform: scaleY(0.5);
  transform-origin: top;
}
.zeile.rezept + .zeile.rezept::before,
.zeile.angebotzeile + .zeile.angebotzeile::before { left: 80px; }
button.zeile:active { background: var(--fuell); }
.zeile.aktion .titel { color: var(--akzent); }

.mitte { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.titel { font-size: 1.0625rem; line-height: 1.3; overflow-wrap: anywhere; }
.rezept .titel { font-weight: 600; }
.rechts { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; text-align: right; flex-shrink: 0; max-width: 42%; }
.preis { font-weight: 600; font-variant-numeric: tabular-nums; }
.wertrechts { color: var(--text2); text-align: right; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pfeil, .winkel {
  width: 8px; height: 8px; flex-shrink: 0;
  border-right: 2px solid var(--text3); border-bottom: 2px solid var(--text3);
  transform: rotate(-45deg);
}
.winkel { transform: rotate(45deg); margin: -4px 2px 0 4px; border-color: currentColor; }
.winkel.links { transform: rotate(135deg); margin: 0 4px 0 2px; width: 11px; height: 11px; border-width: 2.5px; }

.gewaehlt {
  width: 7px; height: 13px; flex-shrink: 0; margin-right: 4px;
  border-right: 2.5px solid var(--akzent); border-bottom: 2.5px solid var(--akzent);
  transform: rotate(45deg) translateY(-2px);
}

.kachel {
  display: grid; place-items: center; flex-shrink: 0;
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--fuell); font-size: 1.75rem; line-height: 1; overflow: hidden;
}
.kachel.riesig { width: 96px; height: 96px; border-radius: 22px; font-size: 3.25rem; }
.kachel.bild img { width: 100%; height: 100%; object-fit: contain; background: #FFFFFF; }

.rang { width: 20px; flex-shrink: 0; margin-right: -4px; text-align: center; font-size: 0.9375rem; font-weight: 600; color: var(--text2); font-variant-numeric: tabular-nums; }

.logo {
  display: grid; place-items: center; flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 6px;
  color: #fff; font-size: 0.8125rem; font-weight: 700;
}
.logo.gross { width: 40px; height: 40px; border-radius: 10px; font-size: 1.25rem; }

.marken { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.marken:empty { display: none; }
.marke {
  display: inline-block; max-width: 100%;
  padding: 2px 7px; border-radius: 6px;
  background: var(--fuell); color: var(--text2);
  font-size: 0.75rem; line-height: 1.35; font-weight: 600;
}
.marke.angebot { background: var(--angebot-hg); color: var(--angebot); }
.marke.gruen { background: var(--akzent-hell); color: var(--akzent); }

.leer { background: var(--karte); border-radius: var(--rund); padding: 28px 20px; text-align: center; color: var(--text2); font-size: 0.9375rem; }

.hinweis {
  background: var(--karte); border-radius: var(--rund);
  padding: 12px 16px; margin: 0 0 12px;
  font-size: 0.9375rem; line-height: 1.4; color: var(--text2);
}
.hinweis strong { color: var(--text); font-weight: 600; }
.hinweis.lade { display: flex; align-items: center; gap: 10px; }

/* ----- Knöpfe ----- */

.knopf {
  display: block; width: 100%; min-height: 50px; margin-top: 16px; padding: 12px 20px;
  border-radius: 14px; background: var(--akzent); color: var(--auf-akzent);
  font-weight: 600; text-align: center;
}
.knopf.grau { background: var(--fuell); color: var(--akzent); margin-top: 10px; }
.knopf:active { opacity: 0.7; }

.textknopf { display: inline-block; min-height: 44px; padding: 10px 0 0; color: var(--akzent); font-size: 0.9375rem; font-weight: 500; }
.hinweis .textknopf { display: block; min-height: 34px; padding-top: 8px; }
.textknopf.frei { padding: 12px 4px; font-size: 1.0625rem; }

.ladenknopf {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; margin-top: 4px; padding: 0 4px 0 0;
  color: var(--akzent); font-weight: 500; max-width: 100%;
}
.ladenknopf span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Budget ----- */

.budgetkarte { display: flex; flex-direction: column; gap: 6px; }
.budgetkarte:active { opacity: 0.75; }
.reihe { display: flex; justify-content: space-between; align-items: baseline; }
.aendern { color: var(--akzent); font-size: 0.9375rem; }
.summe { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.summe .von { font-size: 1.0625rem; font-weight: 400; color: var(--text2); }
.balken { display: block; height: 8px; border-radius: 4px; background: var(--fuell); overflow: hidden; margin: 2px 0 4px; }
.balken span { display: block; height: 100%; border-radius: 4px; background: var(--akzent); transition: width 0.35s ease; }
.balken.ueber span { background: var(--rot); }

.geldfeld { display: flex; align-items: center; gap: 6px; color: var(--text2); }
.geldfeld input {
  width: 6.5ch; min-height: 36px; padding: 4px 8px; text-align: right;
  border: 0; border-radius: 8px; background: var(--fuell); color: var(--text);
  font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield;
}
.geldfeld input::-webkit-outer-spin-button, .geldfeld input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; }
.chips button { min-height: 44px; padding: 0 16px; border-radius: 22px; background: var(--karte); font-size: 0.9375rem; font-weight: 500; }
.chips button[aria-pressed="true"] { background: var(--akzent); color: var(--auf-akzent); }

.zaehler { display: flex; align-items: center; gap: 12px; }
.zaehler .wert { min-width: 1.5ch; text-align: right; color: var(--text2); font-variant-numeric: tabular-nums; }
.tasten { display: flex; border-radius: 9px; background: var(--fuell); overflow: hidden; }
.tasten button { width: 47px; height: 34px; font-size: 1.375rem; line-height: 1; text-align: center; position: relative; }
.tasten button + button::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 1px; background: var(--text3); }
.tasten button:active { background: var(--fuell-stark); }
/* Tippfläche auf 44 Punkt vergrößern, ohne das Aussehen zu ändern */
.tasten button::after { content: ""; position: absolute; inset: -5px 0; }

/* ----- Auswahl mit mehreren Feldern (Segmented Control) ----- */

.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px; border-radius: 10px; background: var(--fuell); }
.segment button { min-height: 40px; padding: 4px 6px; border-radius: 8px; text-align: center; font-size: 0.9375rem; font-weight: 500; }
.segment button[aria-pressed="true"] { background: var(--wahl); font-weight: 600; box-shadow: var(--schatten); }

/* ----- Schalter ----- */

.schalter {
  -webkit-appearance: none; appearance: none; flex-shrink: 0;
  width: 51px; height: 31px; border-radius: 16px; margin: 0;
  background: var(--fuell-stark); position: relative; cursor: pointer; transition: background 0.2s;
}
.schalter::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.schalter:checked { background: #34C759; }
.schalter:checked::after { transform: translateX(20px); }

/* ----- Suchfeld ----- */

.suchfeld { margin: 0 0 10px; }
.suchfeld input {
  width: 100%; min-height: 40px; padding: 6px 12px 6px 36px;
  border: 0; border-radius: 10px; color: var(--text);
  background: var(--fuell) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='m15.5 15.5 5 5'/%3E%3C/svg%3E") 10px center / 18px no-repeat;
  -webkit-appearance: none; appearance: none;
}
.suchfeld input::placeholder { color: var(--text2); }
.suchfeld + .segment { margin-bottom: 14px; }

/* ----- Rezeptseite ----- */

.leiste {
  position: sticky; top: 0; z-index: 5;
  margin: 0 calc(var(--rand) * -1); padding: env(safe-area-inset-top) 8px 0;
  background: var(--leiste); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.zurueck { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px 0 6px; color: var(--akzent); }
.rezeptkopf { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 14px 8px 18px; }
.rezeptkopf h1 { font-size: 1.75rem; }
.rezeptkopf .neben { margin: 0; font-size: 0.9375rem; }

.zahlen { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 14px 8px; }
.zahlen div { display: flex; flex-direction: column; gap: 2px; }
.zahlen div + div { border-left: 1px solid var(--linie); }
.zahl { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.zahl.spar { color: var(--angebot); }

.zutat { align-items: flex-start; }
.menge { width: 76px; flex-shrink: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.schritte { list-style: none; counter-reset: schritt; margin: 0; padding: 0; background: var(--karte); border-radius: var(--rund); }
.schritte li { position: relative; counter-increment: schritt; padding: 14px 16px 14px 56px; line-height: 1.4; }
.schritte li::before {
  content: counter(schritt); position: absolute; left: 16px; top: 13px;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--akzent-hell); color: var(--akzent); font-size: 0.9375rem; font-weight: 700;
}
.schritte li + li { border-top: 1px solid var(--linie); }

/* ----- Einkaufsliste ----- */

.hakenzeile { align-items: flex-start; }
.haken { width: 24px; height: 24px; flex-shrink: 0; margin-top: 1px; border-radius: 50%; border: 2px solid var(--text3); position: relative; }
.erledigt .haken { background: var(--akzent); border-color: var(--akzent); }
.erledigt .haken::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 5px; height: 10px;
  border-right: 2.5px solid var(--auf-akzent); border-bottom: 2.5px solid var(--auf-akzent); transform: rotate(45deg);
}
.erledigt .titel { color: var(--text2); text-decoration: line-through; }
.erledigt .marken, .erledigt .preis { opacity: 0.5; }

/* ----- Tab-Leiste ----- */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--leiste); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--linie);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tabs-innen { display: grid; grid-template-columns: repeat(5, 1fr); max-width: 640px; margin: 0 auto; }
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 50px; color: var(--text2); font-size: 0.625rem; font-weight: 500; }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.aktiv { color: var(--akzent); }

/* ----- Blatt von unten ----- */

.blatt-hg { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.4); }
.blatt {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 640px; margin: 0 auto; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--hg); border-radius: 14px 14px 0 0; outline: none;
}
.blatt-hg.neu { animation: einblenden 0.25s ease; }
.blatt.neu { animation: hochfahren 0.38s cubic-bezier(0.32, 0.72, 0, 1); }
.blatt-kopf { position: relative; display: flex; align-items: center; justify-content: center; min-height: 56px; padding-top: 8px; flex-shrink: 0; }
.blatt-kopf h2 { margin: 0; font-size: 1.0625rem; font-weight: 600; }
.griff { position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--text3); }
.fertig { position: absolute; right: 8px; top: 10px; min-height: 44px; padding: 0 10px; color: var(--akzent); font-weight: 600; }
.blatt-inhalt { overflow-y: auto; padding: 4px var(--rand) calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }

@keyframes hochfahren { from { transform: translateY(100%); } to { transform: none; } }
@keyframes einblenden { from { opacity: 0; } to { opacity: 1; } }

/* ----- Willkommen ----- */

.willkommen { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px 12px; }
.willkommen p { margin: 0 0 12px; color: var(--text2); max-width: 30em; line-height: 1.45; }
.willkommen .knopf { max-width: 340px; }

/* ----- Kurzmeldung und Ladekreisel ----- */

#toast {
  position: fixed; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 22px;
  background: rgba(40, 40, 42, 0.94); color: #fff; font-size: 0.9375rem; font-weight: 500;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.sichtbar { opacity: 1; transform: translate(-50%, 0); }

.kreisel { display: inline-block; width: 18px; height: 18px; flex-shrink: 0; border-radius: 50%; border: 2.5px solid var(--text3); border-top-color: var(--text2); animation: drehen 0.8s linear infinite; vertical-align: -4px; }
@keyframes drehen { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Am PC: etwas Luft nach oben, damit es nicht am Fensterrand klebt */
@media (min-width: 700px) {
  .kopf { padding-top: 44px; }
}

/* ---------- Zuhause & Kassenbetrag (Version 0.2) ---------- */
.textknopf.klein { min-height: 32px; padding: 6px 0 0; font-size: 0.8125rem; }
.textknopf.klein[aria-pressed="true"] { color: var(--text2); }
.zeile.zutat.zuhause .titel { color: var(--text2); }
.zeile.zutat.zuhause .menge { color: var(--text2); }
.kopf + section .leer, section > .leer { margin-bottom: 8px; }
