:root {
  /* light-dark() zieht die Variante aus color-scheme — ein Block statt zwei. */
  color-scheme: light dark;

  /* Warmes Papier statt Weiß — Pastell auf Weiß wirkt kalt und verliert Kontrast. */
  --paper: light-dark(#fbf6f2, #211a1d);
  --raised: light-dark(#fffcfa, #2b2226);
  --ink: light-dark(#3a2b30, #f2e7e6);        /* ~11:1 auf --paper */
  --ink-soft: light-dark(#7d6a70, #b39ea6);   /* ~4.6:1 — AA für Fließtext */
  --line: light-dark(#ebdfd9, #3b3035);

  /* Phasen: gedeckt, diskret. Kein Blutrot — die App ist auch mal in der Bahn offen. */
  --period: light-dark(#d99aa2, #b8737d);
  --period-ink: light-dark(#8a4650, #ffe6e9);
  --predicted: light-dark(#e9c9cd, #4a373d);
  --fertile: light-dark(#b9cfc0, #55705f);
  --fertile-ink: light-dark(#4e6b58, #e2f0e7);
  --accent: light-dark(#a8869b, #c4a4b8);

  --r: 18px;
  --shadow: 0 1px 2px rgba(58, 43, 48, .05), 0 8px 24px -12px rgba(58, 43, 48, .18);
}

/* Manueller Umschalter schlägt die Systemeinstellung. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.55 ui-rounded, 'SF Pro Rounded', -apple-system, 'Segoe UI', system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 460px; margin: 0 auto; padding: 8px 20px; }

/* --- Kopf --- */
.head { padding: 24px 4px 20px; }
h1 { font-size: 15px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.lead { margin-top: 14px; font-size: 26px; line-height: 1.3; letter-spacing: -.01em; }
.lead strong { font-weight: 600; }
.pred { margin-top: 10px; color: var(--ink-soft); }
.pred strong { color: var(--ink); font-weight: 600; }
.pred small { font-size: 14px; }

/* --- Kalender --- */
.cal { background: var(--raised); border-radius: var(--r); padding: 14px 12px 10px; box-shadow: var(--shadow); }
.cal-nav { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 10px; }
.cal-nav strong { font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.weekdays { color: var(--ink-soft); font-size: 12px; text-align: center; padding-bottom: 6px; }

.cell {
  position: relative; aspect-ratio: 1; border: 0; border-radius: 12px;
  background: transparent; color: inherit; font: inherit; font-size: 15px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  cursor: pointer; transition: background .15s, transform .1s;
}
.cell:active { transform: scale(.92); }
.cell[data-today] .num { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.cell.period { background: var(--period); color: var(--period-ink); font-weight: 600; }
.cell.predicted { background: var(--predicted); }
.cell.fertile { background: var(--fertile); color: var(--fertile-ink); }
.dots { font-size: 9px; line-height: 1; letter-spacing: 1px; }
.dots.note { color: var(--accent); font-size: 16px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 14px 4px 4px; font-size: 12px; color: var(--ink-soft); }
.legend span { display: flex; align-items: center; gap: 5px; }
.sw { width: 11px; height: 11px; border-radius: 4px; display: inline-block; }
.sw.period { background: var(--period); } .sw.predicted { background: var(--predicted); } .sw.fertile { background: var(--fertile); }

/* --- Sheet --- */
.scrim { position: fixed; inset: 0; background: rgba(58, 43, 48, .3); backdrop-filter: blur(2px); animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  max-width: 460px; margin: 0 auto;
  background: var(--raised); border-radius: 26px 26px 0 0;
  padding: 10px 22px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px -12px rgba(58, 43, 48, .3);
  animation: up .28s cubic-bezier(.2, .9, .3, 1);
}
.handle { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 21px; font-weight: 600; margin-bottom: 18px; }
.sheet label { display: block; font-size: 13px; color: var(--ink-soft); margin: 16px 0 8px; }

.segs { display: flex; gap: 5px; background: var(--paper); padding: 4px; border-radius: 13px; }
.seg { flex: 1; border: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: 14px; padding: 9px 0; border-radius: 10px; cursor: pointer; }
.seg.on { background: var(--period); color: var(--period-ink); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--ink-soft); font: inherit; font-size: 14px; padding: 7px 13px; border-radius: 999px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--raised); }

textarea, input[type="url"] { width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 13px; padding: 11px 13px; font: inherit; font-size: 15px; color: inherit; resize: none; }
textarea:focus-visible, input:focus-visible, .cell:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card label { display: block; font-size: 13px; color: var(--ink-soft); margin: 14px 0 7px; }
.check { display: flex !important; gap: 10px; align-items: flex-start; margin-top: 14px !important; line-height: 1.45; }
.check input { accent-color: var(--accent); margin-top: 3px; flex: none; width: 17px; height: 17px; }
.ok { color: var(--fertile-ink); }
.err { color: var(--period-ink); }

/* --- Buttons & Karten --- */
button { cursor: pointer; }
.primary { width: 100%; margin-top: 22px; border: 0; border-radius: 14px; background: var(--ink); color: var(--paper); font: inherit; font-weight: 600; padding: 14px; }
.primary:disabled { opacity: .35; cursor: not-allowed; }
.ghost { border: 0; background: transparent; color: var(--ink-soft); font-size: 24px; line-height: 1; padding: 4px 12px; border-radius: 10px; }

.stack { display: grid; gap: 14px; }
.card { background: var(--raised); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.card p { font-size: 14px; color: var(--ink-soft); }
.card .primary { margin-top: 16px; }
dl div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
dl div:last-child { border: 0; }
dt { color: var(--ink-soft); }
dd { font-weight: 600; }
.row { display: flex; gap: 8px; margin-top: 14px; }
.row button { flex: 1; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; font-size: 14px; padding: 10px; border-radius: 12px; }
.row .danger { color: var(--period-ink); border-color: var(--period); }
.fineprint { font-size: 12px; line-height: 1.6; color: var(--ink-soft); padding: 4px 6px; }
code { font-size: .9em; background: var(--paper); padding: 1px 5px; border-radius: 5px; }

/* --- Tabs --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1;
  display: flex; justify-content: center; gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.tabs button { border: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: 14px; padding: 10px 26px; border-radius: 12px; }
.tabs .on { background: var(--raised); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
