:root {
  color-scheme: light dark;
  --bg: #f6f4fb;
  --surface: #ffffff;
  --surface-soft: #f0edf8;
  --text: #1e1a28;
  --muted: #706a7d;
  --border: #e6e0ef;
  --accent: #7157e8;
  --accent-strong: #5a3fd3;
  --accent-soft: #e8e1ff;
  --danger: #b93850;
  --shadow: 0 14px 40px rgba(48, 35, 85, .10);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121016;
    --surface: #1d1a23;
    --surface-soft: #292430;
    --text: #f5f0fb;
    --muted: #afa8b8;
    --border: #37313e;
    --accent: #9a82ff;
    --accent-strong: #b29fff;
    --accent-soft: #332956;
    --danger: #ff8ea1;
    --shadow: 0 16px 48px rgba(0, 0, 0, .32);
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.app-frame { width: 100%; max-width: 620px; margin: 0 auto; min-height: 100vh; position: relative; }
.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 10px; }
.eyebrow { margin: 0 0 4px; color: var(--accent-strong); font-size: .76rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.topbar-name { margin: 0; font-size: 1.05rem; font-weight: 750; }
.main-content { padding: 10px 18px calc(104px + var(--safe-bottom)); }
.stack { display: grid; gap: 16px; }
.home-stack { gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(30, 22, 46, .035); }

h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.75rem, 8vw, 2.35rem); line-height: 1.05; letter-spacing: -.045em; margin: 0; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 0; }
p { line-height: 1.5; }
.muted { color: var(--muted); }

.icon-button { width: 46px; height: 46px; border-radius: 16px; border: 0; background: var(--accent); color: white; display: grid; place-items: center; cursor: pointer; }
.icon-button svg { width: 23px; height: 23px; }
.icon-button.quiet { background: var(--surface-soft); color: var(--text); }
.icon-button:focus-visible, .button:focus-visible, .choice:focus-visible, .segmented button:focus-visible, .symptom-shortcut:focus-visible, .nav-item:focus-visible, .calendar-day:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.button { min-height: 50px; padding: 0 18px; border-radius: 16px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; font-weight: 800; cursor: pointer; }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-strong); }
.button.secondary { background: var(--surface-soft); border-color: var(--border); color: var(--text); }
.button.full { width: 100%; }
.button.grow { flex: 1; }
.danger-text { color: var(--danger) !important; }
.text-button { border: 0; background: transparent; color: var(--accent-strong); font-weight: 800; padding: 10px 0 10px 14px; cursor: pointer; }

.bottom-nav { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: 0; width: min(100%, 620px); height: calc(76px + var(--safe-bottom)); padding: 7px 10px var(--safe-bottom); display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--surface) 94%, transparent); border-top: 1px solid var(--border); backdrop-filter: blur(18px); }
.nav-item { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 14px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 750; }
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent-strong); background: var(--accent-soft); }

.prediction-card { position: relative; overflow: hidden; background: linear-gradient(145deg, #6243dc, #8970f4); color: white; border-radius: 28px; padding: 22px; box-shadow: var(--shadow); }
.prediction-card::after { content: ""; position: absolute; width: 210px; height: 210px; border-radius: 50%; background: rgba(255,255,255,.08); top: -115px; right: -70px; }
.prediction-topline { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: rgba(255,255,255,.86); font-size: .9rem; font-weight: 750; }
.confidence-pill { padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.16); font-size: .72rem; }
.prediction-date { font-size: clamp(2.6rem, 14vw, 4.2rem); line-height: .96; letter-spacing: -.065em; font-weight: 860; margin: 20px 0 7px; }
.prediction-countdown { margin: 0; font-size: 1.05rem; font-weight: 750; }
.prediction-range { color: rgba(255,255,255,.8); font-size: .88rem; margin: 12px 0 18px; }
.timeline { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; padding: 13px 8px; background: rgba(20,10,65,.16); border-radius: 18px; }
.timeline-day { min-width: 0; text-align: center; display: grid; justify-items: center; gap: 5px; font-size: .69rem; color: rgba(255,255,255,.7); }
.timeline-number { font-weight: 750; }
.timeline-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.22); transform: scale(calc(1 + var(--p, 0))); }
.timeline-day.peak { color: white; }
.timeline-day.peak .timeline-dot { width: 12px; height: 12px; background: white; box-shadow: 0 0 0 5px rgba(255,255,255,.16); }
.timeline-day.today .timeline-number { text-decoration: underline; text-underline-offset: 4px; }
.probability-1 { --p: .2; background: rgba(255,255,255,.35); }
.probability-2 { --p: .4; background: rgba(255,255,255,.5); }
.probability-3, .probability-4, .probability-5, .probability-6, .probability-7, .probability-8, .probability-9, .probability-10 { --p: .65; background: rgba(255,255,255,.78); }
.prediction-why { margin-top: 14px; font-size: .82rem; color: rgba(255,255,255,.84); }
.prediction-why summary { cursor: pointer; font-weight: 800; }
.prediction-why p { margin: 8px 0 0; }
.cycle-strip { display: flex; justify-content: space-between; align-items: center; padding: 0 5px; color: var(--muted); font-size: .9rem; }
.cycle-strip strong { color: var(--text); }

.empty-forecast { padding: 26px; text-align: center; }
.empty-forecast h1 { margin: 7px 0 10px; }
.empty-forecast p:not(.eyebrow) { color: var(--muted); margin: 0 auto 20px; max-width: 34ch; }
.empty-icon { width: 58px; height: 58px; border-radius: 20px; display: grid; place-items: center; margin: 0 auto 16px; background: var(--accent-soft); color: var(--accent-strong); font-size: 1.8rem; font-weight: 900; }

.today-card { padding: 19px; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 15px; }
.saved-badge { color: var(--accent-strong); background: var(--accent-soft); border-radius: 999px; padding: 6px 10px; font-size: .72rem; font-weight: 800; }
.today-summary { padding: 14px; border-radius: 16px; background: var(--surface-soft); margin-bottom: 12px; }
.today-summary p { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.insight-card { padding: 16px; display: flex; gap: 13px; align-items: center; }
.insight-card p:last-child { margin: 0; }
.mini-icon { width: 42px; height: 42px; flex: 0 0 auto; border-radius: 14px; display: grid; place-items: center; color: var(--accent-strong); background: var(--accent-soft); font-size: 1.2rem; }
.planner-promo { padding: 18px; display: flex; align-items: center; justify-content: space-between; text-decoration: none; }
.planner-promo > span { font-size: 1.7rem; color: var(--accent-strong); }

.page-heading { padding: 6px 4px 4px; }
.page-heading > p:last-child { margin: 9px 0 0; color: var(--muted); max-width: 40ch; }
.month-heading { display: grid; grid-template-columns: 46px 1fr 46px; align-items: center; text-align: center; }
.month-heading .icon-button { text-decoration: none; font-size: 2rem; }

.calendar-card { padding: 14px; }
.weekday-row, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekday-row { color: var(--muted); font-size: .7rem; font-weight: 850; text-align: center; padding-bottom: 7px; }
.calendar-day { position: relative; min-width: 0; aspect-ratio: 1/1.04; border: 0; border-radius: 13px; background: transparent; display: grid; place-items: center; align-content: center; gap: 4px; cursor: pointer; color: var(--text); }
.calendar-day:disabled { cursor: default; }
.calendar-day.outside { color: color-mix(in srgb, var(--muted) 48%, transparent); }
.calendar-day.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.calendar-day.has-flow { background: var(--accent-soft); font-weight: 850; }
.calendar-day.flow-medium, .calendar-day.flow-heavy { background: color-mix(in srgb, var(--accent) 25%, var(--surface)); }
.day-markers { height: 6px; display: flex; gap: 3px; }
.recorded-marker, .predicted-marker { display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
.recorded-marker { background: var(--accent); }
.predicted-marker { border: 1.5px solid var(--accent); background: transparent; }
.calendar-help { margin: -5px 4px 0; color: var(--muted); font-size: .82rem; text-align: center; }
.calendar-legend { display: flex; gap: 18px; justify-content: center; color: var(--muted); font-size: .75rem; }
.calendar-legend span { display: flex; align-items: center; gap: 6px; }

.planner-form { padding: 18px; display: grid; gap: 16px; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-soft); border-radius: 14px; padding: 4px; }
.mode-switch button { min-height: 42px; border: 0; background: transparent; border-radius: 11px; font-weight: 800; cursor: pointer; }
.mode-switch button.selected { background: var(--surface); color: var(--accent-strong); box-shadow: 0 2px 8px rgba(0,0,0,.07); }
label { display: grid; gap: 7px; font-weight: 750; font-size: .88rem; }
input, textarea { width: 100%; min-height: 50px; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; background: var(--surface); color: var(--text); }
textarea { resize: vertical; }
.planner-result { padding: 20px; display: grid; grid-template-columns: 92px 1fr; gap: 17px; align-items: center; }
.result-ring { --risk: 0deg; width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) var(--risk), var(--surface-soft) 0); position: relative; }
.result-ring::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--surface); }
.result-ring strong { position: relative; z-index: 1; font-size: 1.2rem; }
.planner-result h2 { font-size: 1.45rem; margin: 3px 0; }
.planner-result p { margin: 4px 0; color: var(--muted); font-size: .88rem; }
.medium-risk { font-weight: 750; color: var(--text) !important; }
.privacy-note { display: flex; align-items: flex-start; gap: 10px; color: var(--muted); font-size: .78rem; padding: 4px 9px; }
.privacy-note svg { width: 22px; height: 22px; flex: 0 0 auto; color: var(--accent-strong); }
.privacy-note p { margin: 0; }

.profile-card { padding: 18px; display: flex; align-items: center; gap: 13px; }
.avatar { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); font-size: 1.25rem; font-weight: 900; }
.profile-card p { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.settings-section { overflow: hidden; }
.section-heading { padding: 17px 18px 8px; }
.settings-row { width: 100%; min-height: 68px; padding: 12px 18px; border: 0; border-top: 1px solid var(--border); background: transparent; display: flex; justify-content: space-between; align-items: center; gap: 16px; text-decoration: none; text-align: left; cursor: pointer; }
.settings-row span:first-child { display: grid; gap: 3px; }
.settings-row small { color: var(--muted); font-size: .76rem; font-weight: 500; }
.settings-row em { font-style: normal; font-size: .65rem; color: var(--accent-strong); background: var(--accent-soft); border-radius: 999px; padding: 3px 6px; }
.button-row { color: inherit; }
.version-label { text-align: center; color: var(--muted); font-size: .72rem; }

.login-screen { min-height: calc(100vh - 30px); padding: 42px 4px; display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.brand-mark { width: 70px; height: 70px; border-radius: 23px; background: var(--accent); color: white; display: grid; place-items: center; box-shadow: var(--shadow); }
.brand-mark svg { width: 45px; height: 45px; }
.login-copy h1 { margin: 5px 0 9px; }
.login-copy p:last-child { color: var(--muted); margin: 0; }
.login-form { padding: 20px; display: grid; gap: 15px; }
.check-row { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--muted); }
.check-row input { width: 20px; min-height: 20px; accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: .82rem; margin: 0; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(12, 8, 20, .55); backdrop-filter: blur(3px); }
.entry-sheet { position: fixed; z-index: 60; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 620px); max-height: 94vh; overflow: auto; overscroll-behavior: contain; background: var(--surface); border-radius: 28px 28px 0 0; box-shadow: 0 -20px 70px rgba(0,0,0,.25); padding: 8px 18px calc(18px + var(--safe-bottom)); }
.entry-sheet::before { content: ""; display: block; width: 42px; height: 5px; border-radius: 5px; margin: 3px auto 9px; background: var(--border); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 12px; }
.sheet-header h2 { font-size: 1.45rem; }
.field-group { border: 0; padding: 0; margin: 0 0 19px; }
.field-group legend, .field-group > h3 { font-size: .88rem; font-weight: 850; margin-bottom: 9px; }
.choice-grid { display: grid; gap: 7px; }
.flow-grid { grid-template-columns: repeat(3, 1fr); }
.illness-grid { grid-template-columns: repeat(2, 1fr); }
.choice { min-height: 46px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); font-weight: 750; cursor: pointer; }
.choice.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.toggle-card { grid-template-columns: auto 1fr; display: grid; align-items: center; gap: 12px; padding: 13px; margin: -5px 0 19px; border-radius: 15px; background: var(--surface-soft); cursor: pointer; }
.toggle-card input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 46px; height: 28px; border-radius: 99px; padding: 3px; background: color-mix(in srgb, var(--muted) 35%, var(--surface)); transition: .2s; }
.toggle-track span { display: block; width: 22px; height: 22px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: .2s; }
.toggle-card input:checked + .toggle-track { background: var(--accent); }
.toggle-card input:checked + .toggle-track span { transform: translateX(18px); }
.toggle-card small { display: block; color: var(--muted); font-weight: 500; margin-top: 2px; }
.field-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 9px; }
.field-heading h3 { font-size: .88rem; font-weight: 850; }
.field-heading > span { color: var(--muted); font-size: .7rem; font-weight: 700; }
.symptom-shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.symptom-shortcut { min-width: 0; min-height: 88px; padding: 10px 4px 8px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface-soft); color: var(--muted); display: grid; justify-items: center; align-content: center; gap: 5px; cursor: pointer; }
.symptom-shortcut svg { width: 25px; height: 25px; }
.symptom-shortcut .symptom-label { max-width: 100%; font-size: .67rem; line-height: 1.1; font-weight: 800; text-align: center; }
.symptom-shortcut small { max-width: 100%; color: var(--muted); font-size: .62rem; line-height: 1.1; font-weight: 650; text-align: center; }
.symptom-shortcut.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.symptom-shortcut.active small { color: var(--accent-strong); font-weight: 850; }
.symptom-shortcut[data-level="severe"], .symptom-shortcut[data-level="fever"] { box-shadow: inset 0 0 0 1px var(--accent); }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface-soft); padding: 4px; border-radius: 13px; }
.segmented button { min-width: 0; min-height: 39px; padding: 0 4px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: .72rem; font-weight: 750; cursor: pointer; }
.segmented button.selected { background: var(--surface); color: var(--accent-strong); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.optional-details { margin: 0 0 18px; }
.optional-details summary { cursor: pointer; color: var(--accent-strong); font-size: .85rem; font-weight: 800; margin-bottom: 9px; }
.symptom-picker-backdrop { position: fixed; inset: 0; z-index: 65; background: rgba(12, 8, 20, .42); backdrop-filter: blur(2px); }
.symptom-picker { position: fixed; z-index: 70; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 620px); background: var(--surface); border-radius: 25px 25px 0 0; box-shadow: 0 -20px 70px rgba(0,0,0,.26); padding: 11px 18px calc(20px + var(--safe-bottom)); }
.symptom-picker::before { content: ""; display: block; width: 42px; height: 5px; border-radius: 5px; margin: 0 auto 9px; background: var(--border); }
.sheet-header.compact { padding-bottom: 15px; }
.symptom-levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.symptom-levels .choice { min-height: 50px; }
.symptom-levels .clear-choice { grid-column: 1 / -1; min-height: 44px; background: transparent; color: var(--danger); }
.symptom-levels .choice:disabled { cursor: default; opacity: .45; }
.sheet-actions { position: sticky; bottom: calc(-18px - var(--safe-bottom)); display: flex; gap: 9px; padding: 12px 0 calc(18px + var(--safe-bottom)); background: linear-gradient(transparent, var(--surface) 18%); }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(91px + var(--safe-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 14px; box-shadow: var(--shadow); font-size: .84rem; font-weight: 750; }
.offline-screen { min-height: 100vh; padding: 30px; display: grid; place-content: center; text-align: center; }
.offline-screen .brand-mark { margin: 0 auto 18px; }

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app-frame { min-height: calc(100vh - 36px); border: 1px solid var(--border); border-radius: 32px; overflow: hidden; background: var(--bg); box-shadow: var(--shadow); }
  .bottom-nav { bottom: 18px; border-radius: 0 0 32px 32px; border: 1px solid var(--border); border-top: 1px solid var(--border); }
  .entry-sheet { bottom: 18px; border-radius: 28px; max-height: calc(100vh - 36px); }
  .symptom-picker { bottom: 18px; border-radius: 25px; }
}

@media (prefers-reduced-motion: no-preference) {
  .entry-sheet:not([hidden]), .symptom-picker:not([hidden]) { animation: sheet-in .22s ease-out; }
  .sheet-backdrop:not([hidden]), .symptom-picker-backdrop:not([hidden]) { animation: fade-in .18s ease-out; }
  @keyframes sheet-in { from { transform: translate(-50%, 22px); opacity: .7; } }
  @keyframes fade-in { from { opacity: 0; } }
}
