/* Nova – ruhig, warm, gut lesbar. Systemschrift, keine fremden Server. Hell und dunkel über Farbtokens.
   Kontraste geprüft: Text mindestens 4,5 : 1, Ränder und Fokus mindestens 3 : 1. */

:root {
  color-scheme: light dark;
  --grund: #f6f1ea;
  --flaeche: #fffdfa;
  --flaeche-2: #efe7dc;
  --tinte: #2a231d;
  --tinte-2: #675b50;
  --linie: #ddd1c3;
  --rahmen: #8f8173;
  --akzent: #a9471f;
  --akzent-tinte: #ffffff;
  --akzent-flaeche: #f3e0d3;
  --akzent-text: #9a3f1b;
  --fehler: #a8261b;
  --fokus: #a9471f;
  --schatten: 0 1px 2px rgb(42 35 29 / 0.06), 0 6px 24px rgb(42 35 29 / 0.07);
  --schrift: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --breite: 46rem;
  --rand-l: max(1rem, env(safe-area-inset-left));
  --rand-r: max(1rem, env(safe-area-inset-right));
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #171310;
    --flaeche: #221d19;
    --flaeche-2: #2c2520;
    --tinte: #f3ece4;
    --tinte-2: #b8ab9e;
    --linie: #3b322b;
    --rahmen: #7a6c60;
    --akzent: #e88b5d;
    --akzent-tinte: #1f140e;
    --akzent-flaeche: #3e2a1e;
    --akzent-text: #f0a57e;
    --fehler: #f29a8f;
    --fokus: #f0a57e;
    --schatten: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 24px rgb(0 0 0 / 0.25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-size: 106.25%; /* 17 px wie der Fließtext auf dem iPhone */
  background: var(--grund);
}

/* iPhone: Textgröße aus den Einstellungen übernehmen (Dynamic Type) */
@supports (font: -apple-system-body) {
  @media (pointer: coarse) {
    html { font: -apple-system-body; }
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--grund);
  color: var(--tinte);
  font-family: var(--schrift);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p { margin: 0; }
img { display: block; }

code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--flaeche-2);
  border-radius: 0.35rem;
  padding: 0.05em 0.35em;
  overflow-wrap: anywhere;
}

:focus-visible {
  outline: 3px solid var(--fokus);
  outline-offset: 2px;
}
[tabindex="-1"]:focus { outline: none; }
.frage-feld:focus-visible, .code-feld:focus-visible, .schluessel-feld:focus-visible, .auswahl:focus-visible {
  outline: 2px solid var(--fokus);
  outline-offset: 0;
  border-color: var(--fokus);
}

.nur-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.leise { color: var(--tinte-2); font-size: 0.9375rem; }

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

.knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem; /* 44 px */
  min-width: 2.75rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.knopf:active:not(:disabled) { transform: scale(0.97); }
.knopf:disabled { cursor: not-allowed; opacity: 0.55; }

.knopf-haupt { background: var(--akzent); color: var(--akzent-tinte); }
.knopf-zweit { background: var(--flaeche); color: var(--tinte); border-color: var(--linie); }
.knopf-leise { background: transparent; color: var(--akzent-text); padding-inline: 0.5rem; text-decoration: underline; text-underline-offset: 0.2em; }
.knopf-breit { width: 100%; }
.knopf-stopp { background: var(--flaeche); color: var(--akzent-text); border-color: var(--akzent); }

@media (hover: hover) {
  .knopf-haupt:hover:not(:disabled) { background: color-mix(in srgb, var(--akzent) 88%, var(--tinte)); }
  .knopf-zweit:hover:not(:disabled), .knopf-stopp:hover { border-color: var(--rahmen); }
}

.stopp-zeichen {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  background: currentColor;
}

.pfeil {
  width: 0.55rem;
  height: 0.55rem;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-left: 0.15rem;
}

/* ---------- Ansichten in der Mitte (Laden, Anmeldung) ---------- */

.mitte {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) var(--rand-r) max(1.5rem, env(safe-area-inset-bottom)) var(--rand-l);
}

.karte {
  width: 100%;
  max-width: 26rem;
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: 1.5rem;
  box-shadow: var(--schatten);
  padding: 1.75rem 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.9rem;
  justify-items: center;
  text-align: center;
}
.karte-laden { gap: 1rem; }
.logo-gross { width: 4rem; height: 4rem; border-radius: 1.1rem; }
.titel-gross { font-size: 1.75rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
.unterzeile { color: var(--tinte-2); }
.laden-text { color: var(--tinte-2); }
.fehler .laden-text { color: var(--tinte); }

.anmelde-form { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.6rem; text-align: left; margin-top: 0.25rem; }
.feld-label { font-weight: 600; font-size: 0.9375rem; }

.code-feld {
  width: 100%;
  min-height: 3.25rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--rahmen);
  border-radius: 0.9rem;
  background: var(--grund);
  color: var(--tinte);
  font-family: var(--mono);
  font-size: max(1.375rem, 16px);
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}
.code-feld::placeholder { color: var(--tinte-2); opacity: 0.7; letter-spacing: 0.12em; }
.code-feld[aria-invalid="true"] { border-color: var(--fehler); }

.meldung { font-size: 0.9375rem; color: var(--tinte-2); }
.meldung:empty { display: none; }
.meldung.fehler { color: var(--fehler); font-weight: 600; }

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

.spalte {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.kopf {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--grund);
  border-bottom: 1px solid var(--linie);
  padding-top: env(safe-area-inset-top);
}

.kopf-innen {
  max-width: var(--breite);
  margin: 0 auto;
  min-height: 3.5rem;
  padding: 0.35rem var(--rand-r) 0.35rem var(--rand-l);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.marke {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.marke img { width: 1.85rem; height: 1.85rem; border-radius: 0.5rem; }

.kopf-aktionen { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.35rem; margin-left: auto; }

#ansicht-mehr .kopf-innen {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
}
#ansicht-mehr .kopf-innen > .knopf { justify-self: start; }
.kopf-titel { font-size: 1.125rem; font-weight: 700; }

/* Schalter „Vorlesen“: echtes Kontrollkästchen mit role="switch", liegt unsichtbar über der ganzen Fläche */
.schalter {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  user-select: none;
  -webkit-user-select: none;
}
.schalter input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.schalter input:disabled { cursor: not-allowed; }
.schalter-bahn {
  position: relative;
  flex: none;
  width: 2.6rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--rahmen);
  transition: background-color 0.15s;
}
.schalter-bahn::after {
  content: "";
  position: absolute;
  top: 0.175rem;
  left: 0.175rem;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.15s;
}
.schalter input:checked + .schalter-bahn { background: var(--akzent); }
.schalter input:checked + .schalter-bahn::after { transform: translateX(1.05rem); }
.schalter input:focus-visible + .schalter-bahn { outline: 3px solid var(--fokus); outline-offset: 2px; }
.schalter:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }

/* ---------- Gespräch ---------- */

.inhalt {
  flex: 1;
  width: 100%;
  max-width: var(--breite);
  margin: 0 auto;
  padding: 1rem var(--rand-r) 1.25rem var(--rand-l);
}

.hinweis-zeile {
  margin-bottom: 0.75rem;
  padding: 0.55rem 0.8rem;
  border-radius: 0.8rem;
  background: var(--flaeche-2);
  color: var(--tinte-2);
  font-size: 0.875rem;
}

.leer {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  text-align: center;
  color: var(--tinte-2);
  padding: 2.5rem 0.5rem 1rem;
  max-width: 24rem;
  margin: 0 auto;
}
.leer img { width: 3.5rem; height: 3.5rem; border-radius: 1rem; margin-bottom: 0.25rem; }
.leer-titel { color: var(--tinte); font-size: 1.25rem; font-weight: 700; }

.verlauf {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nachricht { display: flex; flex-direction: column; max-width: 88%; }
.von-nutzer { align-self: flex-end; align-items: flex-end; }
.von-nova { align-self: flex-start; align-items: flex-start; }

.blase {
  padding: 0.6rem 0.9rem;
  border-radius: 1.25rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  max-width: 100%;
}
.von-nutzer .blase { background: var(--akzent-flaeche); border-bottom-right-radius: 0.4rem; }
.von-nova .blase { background: var(--flaeche); border: 1px solid var(--linie); border-bottom-left-radius: 0.4rem; box-shadow: 0 1px 2px rgb(42 35 29 / 0.04); }
.ohne-antwort .blase { opacity: 0.7; }

.meta {
  margin: 0.25rem 0.5rem 0;
  font-size: 0.8125rem;
  color: var(--tinte-2);
  font-variant-numeric: tabular-nums;
}

.hinweis {
  align-self: stretch;
  padding: 0.55rem 0.85rem;
  border: 1px dashed var(--rahmen);
  border-radius: 0.9rem;
  color: var(--tinte-2);
  font-size: 0.9375rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.trenner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--tinte-2);
  font-size: 0.8125rem;
  margin: 0.25rem 0;
}
.trenner::before, .trenner::after { content: ""; flex: 1; height: 1px; background: var(--linie); }

.denkt .blase { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--tinte-2); }
.punkte { display: inline-flex; gap: 0.25rem; }
.punkte span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--akzent);
  animation: puls 1.2s ease-in-out infinite;
}
.punkte span:nth-child(2) { animation-delay: 0.15s; }
.punkte span:nth-child(3) { animation-delay: 0.3s; }
@keyframes puls {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- Eingabe ---------- */

.eingabe {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--grund);
  border-top: 1px solid var(--linie);
  padding: 0.5rem 0 max(0.65rem, env(safe-area-inset-bottom));
}
.eingabe-innen {
  max-width: var(--breite);
  margin: 0 auto;
  padding: 0 var(--rand-r) 0 var(--rand-l);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}
.eingabe-aktionen { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; }
.eingabe-aktionen .knopf { min-height: 2.75rem; }

.frage-form { display: flex; align-items: flex-end; gap: 0.5rem; }
.frage-feld {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  min-height: 2.9rem;
  max-height: 40vh;
  padding: 0.65rem 1rem;
  border: 1px solid var(--rahmen);
  border-radius: 1.45rem;
  background: var(--flaeche);
  color: var(--tinte);
  font: inherit;
  font-size: max(1rem, 16px);
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
}
.frage-feld::placeholder { color: var(--tinte-2); opacity: 0.85; }
.frage-form .knopf { min-height: 2.9rem; flex: none; }
.frage-form.wartet .knopf-haupt { opacity: 0.55; }

.zaehler, .eingabe-hinweis { font-size: 0.875rem; color: var(--tinte-2); padding: 0 0.5rem; }
.zaehler { text-align: right; font-variant-numeric: tabular-nums; }
.zaehler.fehler, .eingabe-hinweis.fehler { color: var(--fehler); font-weight: 600; }

/* ---------- Mehr ---------- */

.mehr { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-content: start; }

.bereich {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: 1.25rem;
  padding: 1.1rem 1.1rem 1.2rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  justify-items: start;
  min-width: 0;
}
.bereich > * { max-width: 100%; }
.bereich h2 { font-size: 1.0625rem; font-weight: 700; scroll-margin-top: 6rem; }

.zeile { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; width: 100%; }

#kosten-inhalt { width: 100%; max-width: 30rem; }
.werte { margin: 0; display: grid; gap: 0.35rem; width: 100%; }
.werte div { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.werte dt { color: var(--tinte-2); }
.werte dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.tabelle { width: 100%; border-collapse: collapse; font-size: 0.875rem; font-variant-numeric: tabular-nums; margin-top: 0.5rem; }
.tabelle caption { text-align: left; color: var(--tinte-2); font-size: 0.8125rem; padding-bottom: 0.35rem; caption-side: top; }
.tabelle th, .tabelle td { padding: 0.4rem 0.3rem; border-top: 1px solid var(--linie); text-align: right; }
.tabelle th:first-child, .tabelle td:first-child { text-align: left; padding-left: 0; }
.tabelle th:last-child, .tabelle td:last-child { padding-right: 0; }
.tabelle thead th { color: var(--tinte-2); font-weight: 600; border-top: 0; }
.tabelle tbody th { font-weight: 600; }

.auswahl {
  flex: 1 1 12rem;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rahmen);
  border-radius: 0.8rem;
  background: var(--grund);
  color: var(--tinte);
  font: inherit;
  font-size: max(1rem, 16px);
}

.rueckfrage {
  width: 100%;
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: 1rem;
  background: var(--akzent-flaeche);
  grid-template-columns: minmax(0, 1fr);
}
.rueckfrage p { font-weight: 600; }

.schluessel-box { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.schluessel-feld {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--rahmen);
  border-radius: 0.8rem;
  background: var(--grund);
  color: var(--tinte);
  font-family: var(--mono);
  font-size: max(1rem, 16px);
  line-height: 1.45;
  word-break: break-all;
  resize: none;
}
.warnung {
  padding-left: 0.8rem;
  border-left: 3px solid var(--akzent);
  font-size: 0.9375rem;
}

.schritte { margin: 0; padding-left: 1.4rem; display: grid; gap: 0.35rem; font-size: 0.9375rem; }

@media (max-width: 23.5rem) {
  :root { --rand-l: max(0.75rem, env(safe-area-inset-left)); --rand-r: max(0.75rem, env(safe-area-inset-right)); }
  .kopf-innen { gap: 0.25rem; }
  .marke { font-size: 1.125rem; gap: 0.45rem; }
  .marke img { width: 1.6rem; height: 1.6rem; }
  .kopf-aktionen { gap: 0.15rem; }
  .schalter { gap: 0.35rem; padding: 0 0.2rem; font-size: 0.875rem; }
  .schalter-bahn { width: 2.35rem; height: 1.45rem; }
  .schalter-bahn::after { width: 1.1rem; height: 1.1rem; }
  .schalter input:checked + .schalter-bahn::after { transform: translateX(0.9rem); }
  #mehr-oeffnen { padding-inline: 0.7rem; }
  .eingabe-aktionen .knopf { padding-inline: 0.9rem; }
}

@media (min-width: 40rem) {
  .inhalt { padding-top: 1.5rem; }
  .bereich { padding: 1.4rem 1.5rem 1.5rem; }
  .karte { padding: 2.25rem 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .punkte span { opacity: 0.6; }
}
