:root {
  color-scheme: light dark;
  --bg: #fbf6f3;
  --card: #ffffff;
  --ink: #2b2124;
  --muted: #7d6e72;
  --line: #eee3df;
  --rose: #d9536f;
  --rose-ink: #ffffff;
  --rose-soft: #f8dbe1;
  --rose-1: #f3b8c4;
  --rose-2: #ea95a7;
  --rose-3: #d9536f;
  --rose-4: #c23d5b;
  --rose-5: #9f2744;
  --pred: #e58ea0;
  --low: #cfe6dc;
  --low-ink: #3f7a66;
  --pain: #8f6fc9;
  --warn-bg: #fff4e5;
  --warn-ink: #7a4b00;
  --shadow: 0 6px 24px rgba(80, 40, 50, 0.08);
  --radius: 20px;
  --tab-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1517;
    --card: #2a2023;
    --ink: #f6eef0;
    --muted: #b6a4a9;
    --line: #3c2f33;
    --rose: #ee7189;
    --rose-soft: #4a2a33;
    --rose-1: #6e3646;
    --rose-2: #8f4157;
    --rose-3: #c4506b;
    --rose-4: #dc6982;
    --rose-5: #f08aa0;
    --pred: #c86b80;
    --low: #23443a;
    --low-ink: #9fd6c2;
    --pain: #b39ae6;
    --warn-bg: #3a2c16;
    --warn-ink: #f3cf8f;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; }
.app-shell main {
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
}
.page-title { font-size: 1.9rem; font-weight: 750; letter-spacing: -0.02em; margin: 8px 4px 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.12rem; margin-bottom: 6px; }
.card h3 { font-size: 0.95rem; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
.lead { color: var(--muted); line-height: 1.45; margin: 4px 0 14px; }
.small { color: var(--muted); font-size: 0.88rem; line-height: 1.45; margin: 6px 0; }
.meta { color: var(--muted); font-size: 0.88rem; margin: 10px 0 0; min-height: 1em; }
.center { text-align: center; }
.note { background: var(--rose-soft); border-radius: 14px; padding: 12px 14px; font-size: 0.92rem; margin: 0 0 12px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; line-height: 1.45; }
.disclaimer { color: var(--muted); font-size: 0.78rem; margin: 12px 0 0; }

/* buttons */
.btn-primary, .btn-secondary, .btn-danger, .btn-danger-soft {
  display: block; width: 100%; min-height: 50px; border-radius: 14px; border: 0;
  font-size: 1.02rem; font-weight: 600; padding: 12px 16px; text-align: center;
}
.btn-primary { background: var(--rose); color: var(--rose-ink); }
.btn-primary:disabled { opacity: 0.5; }
.btn-secondary { background: var(--rose-soft); color: var(--ink); }
.btn-danger { background: #c2334f; color: #fff; }
.btn-danger-soft { background: transparent; color: #c2334f; border: 1.5px solid currentColor; }
@media (prefers-color-scheme: dark) { .btn-danger-soft { color: #ff8aa0; } }
.btn-ghost { background: none; border: 0; color: var(--rose); font-weight: 600; padding: 14px; margin-top: 6px; }
.btn-col { display: grid; gap: 10px; }
.file-btn { display: flex; align-items: center; justify-content: center; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--card);
  font-size: 1.8rem; line-height: 1; box-shadow: var(--shadow); color: var(--rose);
}
.info-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--muted); background: transparent;
  color: var(--muted); font-weight: 700; font-style: italic; font-family: Georgia, serif; flex: none; padding: 0;
}

/* calendar */
.month-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.month-title { background: none; border: 0; font-size: 1.45rem; font-weight: 750; letter-spacing: -0.01em; padding: 8px; }
.calendar { background: var(--card); border-radius: var(--radius); padding: 10px 8px 12px; box-shadow: var(--shadow); touch-action: pan-y; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 6px; }
.wd { text-align: center; font-size: 0.75rem; color: var(--muted); font-weight: 600; padding: 4px 0 6px; }
.day {
  position: relative; height: 46px; border: 0; background: transparent; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.02rem; font-variant-numeric: tabular-nums;
}
.day.empty { pointer-events: none; }
.day .n { position: relative; z-index: 1; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.day.future .n { color: var(--muted); }
.day.today .n { box-shadow: 0 0 0 2px var(--ink); font-weight: 700; }
.day.period { background: var(--rose-2); color: #fff; }
.day.period .n { color: #fff; font-weight: 650; }
.day.period.flow-1 { background: var(--rose-1); }
.day.period.flow-2 { background: var(--rose-2); }
.day.period.flow-3 { background: var(--rose-3); }
.day.period.flow-4 { background: var(--rose-4); }
.day.period.flow-5 { background: var(--rose-5); }
.day.period.today .n { box-shadow: 0 0 0 2px #fff; }
.day.p-start, .day.pr-start, .day.lr-start { border-top-left-radius: 23px; border-bottom-left-radius: 23px; }
.day.p-end, .day.pr-end, .day.lr-end { border-top-right-radius: 23px; border-bottom-right-radius: 23px; }
.day.p-open { border-top-right-radius: 8px; border-bottom-right-radius: 8px; background-image: linear-gradient(90deg, transparent 60%, rgba(255,255,255,0.35)); }
.day.pred { border-top: 2px dashed var(--pred); border-bottom: 2px dashed var(--pred); background: color-mix(in srgb, var(--rose-soft) 55%, transparent); }
.day.pred.pr-start { border-left: 2px dashed var(--pred); }
.day.pred.pr-end { border-right: 2px dashed var(--pred); }
.day.low { background: var(--low); }
.day.low .n { color: var(--low-ink); }
.day .mark { position: absolute; bottom: 3px; left: 50%; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--pain); z-index: 2; }
.day.period .mark { background: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 0.82rem; color: var(--muted); margin: 12px 6px 0; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .info-btn { margin-left: auto; }
.legend .info-btn::after { content: ""; position: absolute; inset: -8px; }
.info-btn { position: relative; }
.legend .muted { opacity: 0.45; }
.sw { display: inline-block; width: 16px; height: 12px; border-radius: 6px; vertical-align: middle; }
.sw-period { background: var(--rose-3); }
.sw-pred { border: 2px dashed var(--pred); background: var(--rose-soft); }
.sw-low { background: var(--low); border: 1px solid var(--low-ink); }
.sw-flow { background: var(--rose-3); }
.sw-pain { background: var(--pain); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 6px 0; }

/* last period card */
.last-card { padding: 20px; border: 2px solid var(--rose-soft); }
.lc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lc-kicker { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.74rem; font-weight: 700; color: var(--rose); }
.lc-big { font-size: 1.7rem; font-weight: 760; letter-spacing: -0.02em; margin: 6px 0 4px; }
.lc-mid { font-size: 1.25rem; font-weight: 700; margin: 4px 0 2px; }
.lc-facts { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); }
.lc-facts strong { color: var(--ink); font-size: 1.1rem; }
.lc-next { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.lc-low { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 12px; border-radius: 14px; background: color-mix(in srgb, var(--low) 60%, transparent); }
.lc-low > div { flex: 1; }
.lc-low .sw { width: 14px; height: 32px; }
.pill { border-radius: 999px; padding: 3px 10px; font-size: 0.78rem; font-weight: 700; }
.pill-open { background: var(--rose); color: #fff; }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 10, 12, 0.38); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 24px 24px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(30px); transition: transform 0.2s ease; overscroll-behavior: contain;
}
.sheet.open { transform: none; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-size: 1.25rem; }
.sheet-status { color: var(--rose); font-weight: 600; margin: 4px 0 14px; font-size: 0.92rem; }
.sheet-actions { display: grid; gap: 8px; }
.details { margin-top: 6px; }
.field { display: block; background: var(--card); border-radius: 16px; padding: 14px; margin-top: 12px; }
.field-head { display: flex; justify-content: space-between; font-weight: 650; margin-bottom: 10px; }
.field-val { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.meter { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.lvl {
  height: 48px; border-radius: 12px; border: 0; background: var(--line); color: var(--muted);
  font-weight: 700; font-size: 1rem; transition: transform 0.08s;
}
.lvl:active { transform: scale(0.95); }
.meter-flow .lvl.on.lvl-1 { background: var(--rose-1); color: #fff; }
.meter-flow .lvl.on.lvl-2 { background: var(--rose-2); color: #fff; }
.meter-flow .lvl.on.lvl-3 { background: var(--rose-3); color: #fff; }
.meter-flow .lvl.on.lvl-4 { background: var(--rose-4); color: #fff; }
.meter-flow .lvl.on.lvl-5 { background: var(--rose-5); color: #fff; }
.meter-pain .lvl.on { color: #fff; }
.meter-pain .lvl.on.lvl-1 { background: color-mix(in srgb, var(--pain) 35%, var(--line)); }
.meter-pain .lvl.on.lvl-2 { background: color-mix(in srgb, var(--pain) 55%, var(--line)); }
.meter-pain .lvl.on.lvl-3 { background: color-mix(in srgb, var(--pain) 75%, var(--line)); }
.meter-pain .lvl.on.lvl-4 { background: var(--pain); }
.meter-pain .lvl.on.lvl-5 { background: color-mix(in srgb, var(--pain) 75%, #2a1050); }
.lvl.sel { outline: 3px solid var(--ink); outline-offset: 1px; }
.meter-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: transparent; border-radius: 999px; padding: 9px 14px; min-height: 42px;
  font-size: 0.92rem; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--rose); border-color: var(--rose); color: #fff; }
.chip.static { min-height: 0; padding: 6px 12px; }
.chip .emo { font-size: 1.15rem; }
textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit;
  font-size: 16px; background: var(--bg); color: var(--ink); resize: vertical;
}
.sheet-foot { position: sticky; bottom: 0; padding-top: 14px; background: linear-gradient(transparent, var(--bg) 30%); }

/* analysis */
.reg { border-left: 6px solid var(--rose); }
.reg-sehr { border-left-color: #4f9d7f; }
.reg-leicht { border-left-color: #e0a43a; }
.reg-stark { border-left-color: #c2334f; }
.reg-label { font-size: 1.6rem; font-weight: 760; margin: 6px 0 2px; }
.rule summary { color: var(--rose); font-size: 0.88rem; font-weight: 600; margin-top: 8px; cursor: pointer; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.stat .v { font-size: 1.5rem; font-weight: 760; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 0.8rem; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; overflow: visible; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-axis { fill: var(--muted); font-size: 10px; }
.c-band { fill: var(--low); opacity: 0.6; }
.c-band-label { fill: var(--low-ink); font-size: 9.5px; }
.c-avg { stroke: var(--rose); stroke-width: 1.5; stroke-dasharray: 5 4; }
.c-avg-label { fill: var(--rose); font-size: 10px; font-weight: 700; }
.c-line { fill: none; stroke: var(--rose-2); stroke-width: 2.5; stroke-linejoin: round; }
.c-dot { fill: var(--rose); stroke: var(--card); stroke-width: 2; }
.c-dot.out { fill: #e0a43a; }
.c-val { fill: var(--ink); font-size: 10px; font-weight: 600; }
.c-bar { fill: var(--rose-3); }
.c-flow { fill: var(--rose-3); }
.c-pain { fill: var(--pain); }
.freq { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.freq li { display: grid; grid-template-columns: 9.5em 1fr 2.5em; gap: 10px; align-items: center; font-size: 0.9rem; }
.freq .cnt { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
progress { width: 100%; height: 10px; appearance: none; -webkit-appearance: none; border: 0; border-radius: 5px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 5px; }
progress::-webkit-progress-value { background: var(--pain); border-radius: 5px; }
progress::-moz-progress-bar { background: var(--pain); }
.plist { list-style: none; margin: 0; padding: 0; }
.pl-item { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 2px; display: flex; flex-direction: column; gap: 2px; }
.plist li:last-child .pl-item { border-bottom: 0; }
.pl-date { font-weight: 650; }
.pl-meta { font-size: 0.85rem; color: var(--muted); }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line);
}
.tab { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.78rem; color: var(--muted); min-height: 52px; font-weight: 600; }
.tab .ti { font-size: 1.35rem; line-height: 1.2; }
.tab.active { color: var(--rose); }

/* modal + toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 10, 12, 0.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--card); border-radius: 22px; padding: 22px; max-width: 420px; width: 100%; max-height: 86vh; overflow-y: auto; }
.modal-card h2 { font-size: 1.2rem; margin-bottom: 10px; }
#modal-body { color: var(--ink); line-height: 1.5; margin-bottom: 18px; }
#modal-body p { margin: 0 0 10px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60; font-weight: 600; font-size: 0.92rem;
}

/* lock screen */
.lock-screen { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; }
.lock-card { width: 100%; max-width: 360px; text-align: center; }
.lock-card .logo { border-radius: 16px; margin-bottom: 14px; }
.lock-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.lock-field { display: block; text-align: left; margin: 14px 0; }
.lock-field span { display: block; font-weight: 600; margin-bottom: 6px; color: var(--muted); font-size: 0.9rem; }
.lock-field input {
  display: block; width: 100%; font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; padding: 12px;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
}
.lock-field input:focus { outline: none; border-color: var(--rose); }
.pin-input { -webkit-text-security: disc; text-security: disc; }
.pin-input.reveal { -webkit-text-security: none; text-security: none; }
.pin-show { display: flex; gap: 0.5rem; align-items: center; font-size: 0.92rem; margin: 4px 0 8px; color: var(--muted); }
.pin-show input { width: 20px; height: 20px; accent-color: var(--rose); }
.lock-error { color: #c2334f; min-height: 1.3em; font-size: 0.92rem; margin: 6px 0; }
@media (prefers-color-scheme: dark) { .lock-error { color: #ff8aa0; } }
#lock-form .btn-secondary { margin-top: 10px; }
