:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --surface-2: #e7ebef;
  --text: #182028;
  --muted: #5f6a75;
  --line: #d9dfe5;
  --accent: #2f6a8a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebf3;
  --gruen: #2e8b57;
  --gruen-soft: #dff2e7;
  --red: #c2372b;
  --red-soft: #fbe7e4;
  --warn-soft: #fff3d6;
  --warn-ink: #6b4b00;
  --gold: #d99a1e;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121519;
    --surface: #1b2026;
    --surface-2: #252c33;
    --text: #e7ecf0;
    --muted: #9aa6b1;
    --line: #2f3841;
    --accent: #6fb3d6;
    --accent-ink: #0b1e29;
    --accent-soft: #1d3442;
    --gruen: #5cc08a;
    --gruen-soft: #1c3a2a;
    --red: #f07366;
    --red-soft: #3a211e;
    --warn-soft: #3a3016;
    --warn-ink: #f5d68a;
    --gold: #f0b54a;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.klein { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Kopf ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { border-radius: 7px; }
.brand h1 { font-size: 1.25rem; margin: 0; white-space: nowrap; }
.sync { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-state="live"] .dot { background: #2fb36d; }
.sync[data-state="off"] .dot { background: var(--red); }
.sync[data-state="demo"] .dot { background: #e0a423; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 12px; background: transparent; font-size: 1.3rem;
}
.icon-btn svg { fill: currentColor; }
.icon-btn:active { background: var(--surface-2); }

main, .login { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.ansicht > .card { padding: 16px; margin-bottom: 14px; }
.ansicht h2.abschnitt { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; }
.ansicht h2.abschnitt:first-child { margin-top: 6px; }

.banner { max-width: 608px; margin: 4px auto 12px; padding: 10px 14px; border-radius: 12px; font-size: .92rem; }
.banner.demo { background: var(--warn-soft); color: var(--warn-ink); margin: 4px 16px 12px; }
@media (min-width: 640px) { .banner.demo { margin: 4px auto 12px; } }
.hinweis { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; font-size: .92rem; margin-bottom: 14px; }
.hinweis.warn { background: var(--warn-soft); color: var(--warn-ink); }

/* ---------- Reiter unten ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 150px; border: 0; background: none; border-radius: 12px; padding: 4px 0 2px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: .74rem; color: var(--muted);
}
.tabs .tab-icon { font-size: 1.25rem; line-height: 1.3; }
.tabs button[aria-selected="true"] { color: var(--accent); font-weight: 700; }
.tabs button[aria-selected="true"] .tab-icon { background: var(--accent-soft); border-radius: 99px; padding: 0 16px; }

/* ---------- Heute ---------- */
.heute-kopf { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 86px; height: 86px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring .bahn { stroke: var(--surface-2); }
.ring .wert { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ring.fertig .wert { stroke: var(--gruen); }
.ring-text { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.ring-text b { font-size: 1.3rem; }
.ring-text span { font-size: .72rem; color: var(--muted); }
.heute-text { flex: 1; min-width: 0; }
.heute-text h2 { margin: 0 0 2px; font-size: 1.35rem; letter-spacing: -.01em; }
.serie { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.serie .flamme { font-size: 1.15rem; }
.frei { font-size: .82rem; color: var(--muted); }
.plan { list-style: none; padding: 0; margin: 14px 0 4px; display: grid; gap: 6px; }
.plan li { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.plan .nr { width: 24px; height: 24px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: .78rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted); }
.plan li.aktiv .nr { background: var(--accent); color: var(--accent-ink); }
.plan li.erledigt { color: var(--muted); }
.plan li.erledigt .nr { background: var(--gruen); color: #fff; }
.gross { width: 100%; padding: 14px 16px; font-size: 1.08rem; margin-top: 12px; }
.wertung-zeile { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wertung-zahl { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.plus { color: var(--gruen); font-weight: 700; }
.minus { color: var(--red); font-weight: 700; }
.kurve { width: 100%; height: 90px; display: block; margin-top: 8px; }
.kurve path.linie { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.kurve path.flaeche { fill: color-mix(in srgb, var(--accent) 14%, transparent); stroke: none; }

/* ---------- Üben ---------- */
.kacheln { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kachel {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 14px; border-radius: 14px; border: 0; background: var(--surface); box-shadow: var(--shadow); min-height: 84px;
}
.kachel b { font-size: 1rem; }
.kachel .gross-icon { font-size: 1.5rem; line-height: 1.2; }
.kachel:disabled { opacity: .55; box-shadow: none; background: var(--surface-2); }
.kachel:not(:disabled):active { transform: scale(.98); }
.motive { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.motiv {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); text-align: left; font-size: .92rem;
}
.motiv-balken { height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.motiv-balken i { display: block; height: 100%; border-radius: 99px; background: var(--muted); }
.motiv.schwach .motiv-balken i { background: var(--red); }
.motiv.stark .motiv-balken i { background: var(--gruen); }
.motiv .klein { color: var(--muted); }
.gruppe-titel { font-size: .8rem; color: var(--muted); margin: 12px 2px 6px; font-weight: 600; }
.bald { position: relative; }
.bald::after { content: attr(data-bald); position: absolute; top: 10px; right: 10px; font-size: .7rem; padding: 2px 7px; border-radius: 99px; background: var(--surface); color: var(--muted); }

/* ---------- Partien ---------- */
.liste { display: grid; gap: 8px; }
.eintrag { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
.eintrag .mitte { flex: 1; min-width: 0; }
.eintrag .titel { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eintrag .unter { font-size: .84rem; color: var(--muted); }
.pille { font-size: .74rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pille.neu { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pille.ok { background: var(--gruen-soft); color: var(--gruen); }
.pille.fehler { background: var(--red-soft); color: var(--red); }
.mini-brett { width: 64px; height: 64px; flex: none; border-radius: 6px; overflow: hidden; }
.fortschritt { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.fortschritt i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ---------- Fortschritt ---------- */
.zahlen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.zahlen b { display: block; font-size: 1.4rem; }
.zahlen span { font-size: .78rem; color: var(--muted); }
.balkenliste { display: grid; gap: 7px; }
.balkenliste .z { display: grid; grid-template-columns: 130px 1fr 44px; gap: 8px; align-items: center; font-size: .88rem; }
.balkenliste .bahn { height: 8px; border-radius: 99px; background: var(--surface-2); position: relative; overflow: hidden; }
.balkenliste .bahn i { position: absolute; top: 0; bottom: 0; border-radius: 99px; }
.balkenliste .bahn::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line); }
.balkenliste .r { text-align: right; color: var(--muted); font-size: .8rem; }
.kalender { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.kalender .wt { font-size: .7rem; color: var(--muted); text-align: center; }
.kalender .t { aspect-ratio: 1; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-size: .72rem; color: var(--muted); }
.kalender .t.teil { background: color-mix(in srgb, var(--accent) 35%, var(--surface-2)); color: var(--text); }
.kalender .t.voll { background: var(--gruen); color: #fff; font-weight: 700; }
.kalender .t.heute { outline: 2px solid var(--accent); outline-offset: 1px; }
.kalender .t.leer { background: transparent; }

/* ---------- Aufgabe (Vollbild) ---------- */
.aufgabe {
  position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); overflow-y: auto;
}
.aufgabe-kopf { display: flex; align-items: center; gap: 8px; padding: 8px 10px 6px; }
.aufgabe-titel { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.aufgabe-titel b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aufgabe-zaehler { font-weight: 700; font-variant-numeric: tabular-nums; padding-right: 6px; }
.aufgabe-zaehler.knapp { color: var(--red); }
.balken { height: 4px; background: var(--surface-2); margin: 0 12px; border-radius: 99px; overflow: hidden; }
.balken i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .5s; }
.balken.fertig i { background: var(--gruen); }
.aufgabe-inhalt { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 0 calc(16px + env(safe-area-inset-bottom)); }
.brett-rahmen { position: relative; width: min(100vw, 560px, calc(100dvh - 300px)); min-width: 280px; }
.brett { width: 100%; aspect-ratio: 1; }
.aufgabe-info { width: min(100%, 560px); padding: 0 14px; }
@media (min-width: 900px) and (min-height: 560px) {
  .aufgabe-inhalt { flex-direction: row; align-items: flex-start; justify-content: center; gap: 24px; padding-top: 16px; }
  .brett-rahmen { width: min(calc(100dvh - 120px), 640px); }
  .aufgabe-info { width: 360px; padding-top: 6px; }
}
.status-zeile { font-size: 1.08rem; font-weight: 700; margin: 4px 0 6px; display: flex; gap: 8px; align-items: center; min-height: 1.5em; }
.status-zeile .farbe { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--muted); flex: none; }
.status-zeile .farbe.w { background: #fff; }
.status-zeile .farbe.b { background: #222; }
.status-zeile.richtig { color: var(--gruen); }
.status-zeile.falsch { color: var(--red); }
.erklaerung { background: var(--surface); border-radius: 14px; padding: 12px 14px; margin-top: 8px; box-shadow: var(--shadow); font-size: .94rem; }
.erklaerung h3 { margin: 0 0 4px; font-size: 1rem; }
.erklaerung p { margin: 4px 0; }
.erklaerung .zuege { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .88rem; background: var(--surface-2); padding: 6px 8px; border-radius: 8px; }
.wertung-aenderung { font-weight: 700; }

/* Zwischenbildschirm über der Aufgabe */
.zwischen { position: absolute; inset: 0; z-index: 5; background: var(--bg); display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.zwischen .card { width: min(100%, 440px); padding: 22px; text-align: center; }
.zwischen h2 { margin: 6px 0; }
.zwischen .gross-icon { font-size: 2.6rem; }
.wahl { display: grid; gap: 8px; margin: 14px 0 4px; text-align: left; }
.wahl button { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-align: left; }
.wahl button b { display: block; }
.wahl button span { font-size: .85rem; color: var(--muted); }

/* ---------- Brettfarben (Feld a8 hell) ---------- */
.brett-rahmen[data-brett="holz"] cg-board, .muster.holz { background-color: #f0d9b5; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2' shape-rendering='crispEdges'%3E%3Cpath fill='%23b58863' d='M1 0h1v1H1zM0 1h1v1H0z'/%3E%3C/svg%3E"); background-size: 25% 25%; }
.brett-rahmen[data-brett="blau"] cg-board, .muster.blau { background-color: #dee3e6; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2' shape-rendering='crispEdges'%3E%3Cpath fill='%238ca2ad' d='M1 0h1v1H1zM0 1h1v1H0z'/%3E%3C/svg%3E"); background-size: 25% 25%; }
.brett-rahmen[data-brett="gruen"] cg-board, .muster.gruen { background-color: #eeeed2; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2' shape-rendering='crispEdges'%3E%3Cpath fill='%23769656' d='M1 0h1v1H1zM0 1h1v1H0z'/%3E%3C/svg%3E"); background-size: 25% 25%; }
.muster { display: block; width: 56px; height: 56px; border-radius: 8px; background-size: 50% 50% !important; }
cg-board square.move-dest { background: radial-gradient(rgba(20, 85, 30, .5) 22%, transparent 0); }
cg-board square.oc.move-dest { background: radial-gradient(transparent 0%, transparent 79%, rgba(20, 85, 0, .3) 80%); }
cg-board square.last-move { background-color: rgba(155, 199, 0, .41); }
cg-board square.selected { background-color: rgba(20, 85, 30, .5); }
cg-board square.check { background: radial-gradient(ellipse at center, rgba(255, 0, 0, 1) 0%, rgba(231, 0, 0, 1) 25%, rgba(169, 0, 0, 0) 89%, rgba(158, 0, 0, 0) 100%); }
.cg-wrap coords { font-size: 10px; font-weight: 700; }
.orientation-white .ranks :nth-child(odd), .orientation-white .files :nth-child(even),
.orientation-black .ranks :nth-child(even), .orientation-black .files :nth-child(odd) { color: rgba(60, 60, 60, .8); }
.orientation-white .ranks :nth-child(even), .orientation-white .files :nth-child(odd),
.orientation-black .ranks :nth-child(odd), .orientation-black .files :nth-child(even) { color: rgba(255, 255, 255, .9); }
.brettwahl { display: flex; gap: 12px; margin: 4px 0 10px; }
.brettwahl label { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); font-size: .85rem; cursor: pointer; }
.brettwahl input { position: absolute; opacity: 0; pointer-events: none; }
.brettwahl input:checked + .muster { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Umwandlung */
.umwandlung { position: absolute; inset: 0; z-index: 20; background: rgb(0 0 0 / .45); display: grid; place-items: center; }
.umwandlung-box { background: var(--surface); border-radius: 14px; padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; max-width: 90%; }
.umwandlung-box p { width: 100%; text-align: center; margin: 0 0 4px; font-weight: 600; }
.umwandlung-box button { width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 4px; }
.umwandlung-box .cg-wrap { width: 100%; height: 100%; }
.umwandlung-box .cg-wrap piece { position: static; display: block; width: 100%; height: 100%; }
.umwandlung-box .abbruch { width: 40px; height: 40px; font-size: 1.1rem; }

/* ---------- Formular / Knöpfe ---------- */
.login { padding-top: 6vh; }
.login form { padding: 24px; display: grid; gap: 12px; text-align: center; }
.login form img { margin: 0 auto; border-radius: 14px; }
.login h2, .login p { margin: 0; }
label { display: grid; gap: 4px; text-align: left; font-size: .9rem; color: var(--muted); }
input[type=email], input[type=password], input[type=text], input[type=time], select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.error { color: var(--red); font-size: .9rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600;
  text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.gefahr { color: var(--red); }
.btn.leise { border-color: transparent; background: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; }
.knoepfe { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.knoepfe .btn.weiter { flex: 1; }

/* ---------- Einstellungen ---------- */
.sheet {
  width: min(560px, 100%); max-height: min(92vh, 900px); margin: auto auto 0; padding: 0 0 calc(20px + env(safe-area-inset-bottom));
  border: 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text); overflow-y: auto;
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet-kopf { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 18px; background: var(--bg); }
.sheet-kopf h2 { margin: 0; font-size: 1.2rem; }
.block { background: var(--surface); margin: 0 12px 12px; padding: 14px; border-radius: 14px; }
.block h3 { margin: 0 0 6px; font-size: 1rem; }
.block p { margin: 4px 0 8px; }
.feld { margin: 8px 0; }
.status { font-weight: 600; }
.zeile { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.zeile select { flex: 1 1 190px; min-width: 190px; }
.zeile input[type=time] { flex: 1; min-width: 96px; max-width: 140px; }
.schalter { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; margin: 8px 0; }
.schalter input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.infos { margin: 0; padding-left: 18px; display: grid; gap: 6px; }

/* ---------- Meldung ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: .92rem;
}
.toast button { border: 0; background: transparent; color: var(--accent-soft); font-weight: 700; padding: 0; }
.leer { text-align: center; padding: 18px 8px; }
