:root {
  --boden: #E8EEF0;        /* kühler, staubfreier Bodenton */
  --flaeche: #FFFFFF;      /* freie Fläche der Karte, Bedienflächen */
  --tinte: #1F2A36;        /* Wände, Text */
  --tinte-leise: #5B6875;
  --gruenspan: #2F7D6D;    /* Aktionen, Roboter */
  --gruenspan-tief: #23604F;
  --warnung: #C2410C;
  --linie: #C9D3D8;
  --karte-grund: #D9E2E6;  /* unbekanntes Gelände um die Wohnung */
  --radius-gross: 18px;
  --radius-klein: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--boden);
  color: var(--tinte);
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

main[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

button {
  min-height: 48px;
  padding: 0 18px;
  border: 1.5px solid var(--tinte);
  border-radius: var(--radius-klein);
  background: var(--flaeche);
  cursor: pointer;
  font-weight: 700;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primaer { background: var(--gruenspan); border-color: var(--gruenspan); color: #fff; }
button.primaer:hover:not(:disabled) { background: var(--gruenspan-tief); }
button.leise { border-color: var(--linie); font-weight: 400; }

:focus-visible { outline: 3px solid var(--gruenspan); outline-offset: 2px; }

.fehler { color: var(--warnung); margin: .5rem 0 0; min-height: 1.2em; }

/* ---------- Anmeldung ---------- */
.anmeldung {
  max-width: 24rem;
  margin: 0 auto;
  padding: 18vh 20px 40px;
}
.anmeldung h1 { font-size: 2.1rem; line-height: 1.1; margin: 0 0 .4rem; letter-spacing: -.01em; }
.anmeldung p { color: var(--tinte-leise); margin: 0 0 1.6rem; }
.anmeldung form { display: grid; gap: .6rem; }
.anmeldung label { font-weight: 700; }
.anmeldung input {
  min-height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--linie);
  border-radius: var(--radius-klein);
  background: var(--flaeche);
}

/* ---------- App-Rahmen ---------- */
.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(84px + env(safe-area-inset-bottom));
}
.app[hidden] { display: none !important; }
.kopf { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.name { font-weight: 700; font-size: 1.05rem; }
.roboterwahl {
  font: inherit; font-weight: 700; min-height: 40px; padding: 0 10px;
  border: 1.5px solid var(--linie); border-radius: var(--radius-klein); background: var(--flaeche);
}
.roboterwahl[hidden], .name[hidden] { display: none; }

.verbindung { color: var(--tinte-leise); font-size: .95rem; display: inline-flex; align-items: center; gap: .45em; }
.verbindung::before {
  content: ""; width: .6em; height: .6em; border-radius: 50%;
  background: var(--tinte-leise);
}
.verbindung[data-zustand="an"] { color: var(--gruenspan-tief); }
.verbindung[data-zustand="an"]::before { background: var(--gruenspan); }
.verbindung[data-zustand="aus"]::before { background: var(--warnung); }

.ansicht { display: grid; gap: 18px; }
.ansicht[hidden] { display: none; }
.ansicht h2 { font-size: 1.15rem; margin: .4rem 0 0; }

/* Untere Reiter-Leiste */
.navigation {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  background: var(--flaeche); border-top: 1.5px solid var(--linie);
}
.navigation button {
  flex: 1 1 0; max-width: 200px; min-height: 44px;
  border: 0; background: transparent; font-weight: 400; color: var(--tinte-leise);
}
.navigation button[aria-current="page"] { color: var(--tinte); font-weight: 700; box-shadow: inset 0 -3px 0 var(--gruenspan); border-radius: 0; }

/* ---------- Steuerung ---------- */
.steuerung { grid-template-columns: 1fr; grid-template-areas: "kennzahlen" "karte" "zustand" "bedienung"; }

.kennzahlen { grid-area: kennzahlen; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.kennzahlen div { display: flex; flex-direction: column-reverse; }
.kennzahlen dd { margin: 0; font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kennzahlen dt { color: var(--tinte-leise); font-size: .85rem; }

/* Die Karte ist das eine große Element der Seite. */
.karte {
  grid-area: karte;
  margin: 0;
  background: var(--karte-grund);
  border-radius: var(--radius-gross);
  padding: 10px;
  min-height: 220px;
  display: grid;
  place-items: center;
}
.karte canvas { width: 100%; display: block; touch-action: manipulation; cursor: pointer; }
.karte canvas[hidden] { display: none; }
.karte figcaption { color: var(--tinte-leise); text-align: center; padding: 2rem 0; }
.karte figcaption:empty { display: none; }

.zustand { grid-area: zustand; }
.zustand h1 { font-size: 1.7rem; line-height: 1.15; margin: 0; letter-spacing: -.01em; }

.bedienung { grid-area: bedienung; display: grid; gap: 14px; }
.haupt { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.gross { min-height: 58px; font-size: 1.1rem; }

.modi { display: grid; grid-template-columns: 1fr 1fr; background: var(--linie); border-radius: var(--radius-klein); padding: 3px; gap: 3px; }
.modi .modus { border: 0; min-height: 42px; background: transparent; font-weight: 400; }
.modi .modus[aria-selected="true"] { background: var(--flaeche); font-weight: 700; box-shadow: 0 1px 2px rgba(31, 42, 54, .18); }
.panel[hidden] { display: none; }
.hinweis { margin: 0; color: var(--tinte-leise); }

.saugstufe { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; gap: 0; }
.saugstufe legend { font-weight: 700; margin-bottom: .45rem; padding: 0; }
.saugstufe label { position: relative; }
.saugstufe input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.saugstufe span {
  display: grid; place-items: center; min-height: 46px;
  border: 1.5px solid var(--linie); background: var(--flaeche);
  margin-left: -1.5px;
}
.saugstufe label:first-of-type span { border-radius: var(--radius-klein) 0 0 var(--radius-klein); margin-left: 0; }
.saugstufe label:last-of-type span { border-radius: 0 var(--radius-klein) var(--radius-klein) 0; }
.saugstufe input:checked + span { background: var(--tinte); border-color: var(--tinte); color: #fff; font-weight: 700; position: relative; }
.saugstufe input:disabled + span { opacity: .45; cursor: not-allowed; }
.saugstufe input:focus-visible + span { outline: 3px solid var(--gruenspan); outline-offset: 2px; position: relative; }

.schalter { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; }
.schalter input { width: 22px; height: 22px; accent-color: var(--gruenspan); }

.rueckmeldung { margin: 0; min-height: 1.4em; color: var(--tinte-leise); }

@media (min-width: 860px) {
  .steuerung {
    grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
    grid-template-areas:
      "karte kennzahlen"
      "karte zustand"
      "karte bedienung";
    align-items: start;
    column-gap: 32px;
  }
  .karte { min-height: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.modi .modus[hidden] { display: none; }
.modi:has(.modus[hidden]) { display: none; }
