/* ═══════════════════════════════════════════════════════════════════
   Lunara — app design system
   Dark by default, light on request, both driven from one token set.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  /* brand */
  --violet: #8b5cf6;
  --violet-soft: #a78bfa;
  --magenta: #c026d3;
  --rose: #f43f5e;
  --rose-soft: #fb7185;
  --teal: #2dd4bf;
  --teal-deep: #14b8a6;
  --amber: #f59e0b;
  --amber-soft: #fbbf24;
  --sky: #38bdf8;

  /* phase colours — used everywhere the cycle is drawn */
  --c-period: var(--rose);
  --c-fertile: var(--teal);
  --c-ovulation: var(--teal-deep);
  --c-pms: var(--amber);
  --c-follicular: var(--violet-soft);
  --c-luteal: #a78bfa;

  --grad-brand: linear-gradient(135deg, #8b5cf6 0%, #c026d3 55%, #f43f5e 100%);
  --grad-period: linear-gradient(135deg, #fb7185, #e11d48);
  --grad-fertile: linear-gradient(135deg, #5eead4, #0d9488);

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 62px;
  --header-h: 58px;
}

/* dark (default) */
:root,
:root[data-theme='dark'] {
  --bg: #0d0714;
  --bg-2: #150d20;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.075);
  --surface-solid: #1a1226;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f0f8;
  --text-2: #b8afc6;
  --text-3: #857a94;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 3px 14px rgba(0, 0, 0, 0.35);
  --glow: 0 0 42px rgba(139, 92, 246, 0.22);
  --scrim: rgba(6, 3, 11, 0.72);
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #faf7fd;
  --bg-2: #f2ecf9;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-2: rgba(124, 58, 237, 0.06);
  --surface-solid: #ffffff;
  --border: rgba(76, 29, 90, 0.1);
  --border-strong: rgba(76, 29, 90, 0.2);
  --text: #1e1229;
  --text-2: #5c4f6b;
  --text-3: #8b7f99;
  --shadow: 0 12px 40px rgba(76, 29, 90, 0.13);
  --shadow-sm: 0 3px 14px rgba(76, 29, 90, 0.09);
  --glow: 0 0 42px rgba(139, 92, 246, 0.15);
  --scrim: rgba(30, 18, 41, 0.4);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']):not([data-theme='light']) {
    --bg: #faf7fd;
    --bg-2: #f2ecf9;
    --surface: rgba(255, 255, 255, 0.86);
    --surface-2: rgba(124, 58, 237, 0.06);
    --surface-solid: #ffffff;
    --border: rgba(76, 29, 90, 0.1);
    --border-strong: rgba(76, 29, 90, 0.2);
    --text: #1e1229;
    --text-2: #5c4f6b;
    --text-3: #8b7f99;
    --shadow: 0 12px 40px rgba(76, 29, 90, 0.13);
    --shadow-sm: 0 3px 14px rgba(76, 29, 90, 0.09);
    --scrim: rgba(30, 18, 41, 0.4);
    color-scheme: light;
  }
}

/* ── reset ──────────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Ambient wash — the thing that makes it feel like an app, not a form. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 620px at 12% -8%, rgba(139, 92, 246, 0.20), transparent 62%),
    radial-gradient(760px 560px at 96% 4%, rgba(192, 38, 211, 0.15), transparent 60%),
    radial-gradient(900px 700px at 50% 104%, rgba(244, 63, 94, 0.11), transparent 62%);
}

:root[data-theme='light'] body::before {
  background:
    radial-gradient(900px 620px at 12% -8%, rgba(139, 92, 246, 0.16), transparent 62%),
    radial-gradient(760px 560px at 96% 4%, rgba(192, 38, 211, 0.11), transparent 60%),
    radial-gradient(900px 700px at 50% 104%, rgba(244, 63, 94, 0.09), transparent 62%);
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--violet-soft); text-decoration: none; }
ul, ol { list-style: none; }

:focus-visible {
  outline: 2px solid var(--violet-soft);
  outline-offset: 2px;
  border-radius: 6px;
}

::selection { background: rgba(192, 38, 211, 0.35); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── layout shell ───────────────────────────────────────────────── */
#shell { min-height: 100dvh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
}
.app-header .brand img { width: 27px; height: 27px; border-radius: 8px; }
.app-header .spacer { flex: 1; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--text-2);
  transition: background 0.16s, color 0.16s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

main.view {
  padding: 18px 16px calc(var(--nav-h) + var(--safe-bottom) + 28px);
  max-width: 720px;
  margin: 0 auto;
  animation: viewIn 0.32s var(--ease);
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: none; }
}

/* ── bottom navigation (mobile-first) ───────────────────────────── */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(22px) saturate(1.5);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  border-top: 1px solid var(--border);
}

.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--text-3);
  position: relative;
  transition: color 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.active { color: var(--text); }
.tabbar button.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 26px; height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--grad-brand);
}
.tabbar button.active svg { filter: drop-shadow(0 0 9px rgba(192, 38, 211, 0.6)); }
.tabbar button.tab-desktop { display: none; }

/* ── cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.card + .card { margin-top: 14px; }

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 14px;
}
.card-title svg { width: 15px; height: 15px; }

/* ── the hero ring ──────────────────────────────────────────────── */
.hero {
  position: relative;
  display: grid;
  place-items: center;
  padding: 8px 0 20px;
}

.ring-wrap {
  position: relative;
  width: min(310px, 78vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.ring-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.ring-track { stroke: var(--surface-2); }
.ring-seg { transition: stroke-dashoffset 0.9s var(--ease), opacity 0.4s; }
.ring-marker { filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.7)); }

.ring-center {
  position: relative;
  text-align: center;
  z-index: 2;
  padding: 0 34px;
}
.ring-kicker {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-3);
}
.ring-big {
  font-size: clamp(46px, 15vw, 62px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -2.5px;
  margin: 4px 0 2px;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ring-sub { font-size: 13.5px; color: var(--text-2); font-weight: 500; }
.ring-day {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 650;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

/* phase pill under the ring */
.phase-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 650;
  border: 1px solid transparent;
  margin-top: -4px;
}
.phase-pill .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.phase-menstrual { background: rgba(244, 63, 94, 0.14); border-color: rgba(244, 63, 94, 0.35); color: var(--rose-soft); }
.phase-menstrual .dot { background: var(--rose); }
.phase-follicular { background: rgba(167, 139, 250, 0.13); border-color: rgba(167, 139, 250, 0.32); color: var(--violet-soft); }
.phase-follicular .dot { background: var(--violet-soft); }
.phase-fertile, .phase-ovulation { background: rgba(45, 212, 191, 0.13); border-color: rgba(45, 212, 191, 0.34); color: var(--teal); }
.phase-fertile .dot, .phase-ovulation .dot { background: var(--teal); }
.phase-luteal { background: rgba(139, 92, 246, 0.13); border-color: rgba(139, 92, 246, 0.32); color: var(--violet-soft); }
.phase-luteal .dot { background: var(--violet); }
.phase-pms { background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.35); color: var(--amber-soft); }
.phase-pms .dot { background: var(--amber); }
.phase-late { background: rgba(56, 189, 248, 0.13); border-color: rgba(56, 189, 248, 0.32); color: var(--sky); }
.phase-late .dot { background: var(--sky); }

.phase-blurb {
  margin: 14px auto 0;
  max-width: 380px;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-2);
}

/* ── buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 14.5px;
  font-weight: 650;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: transform 0.12s var(--ease), background 0.16s, box-shadow 0.16s, opacity 0.16s;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}
.btn:hover { background: var(--surface); }
.btn:active { transform: scale(0.975); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--grad-brand);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 20px rgba(192, 38, 211, 0.3);
}
.btn-primary:hover { box-shadow: 0 8px 26px rgba(192, 38, 211, 0.42); background: var(--grad-brand); }

.btn-period {
  background: var(--grad-period);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 20px rgba(244, 63, 94, 0.3);
}
.btn-period:hover { background: var(--grad-period); box-shadow: 0 8px 26px rgba(244, 63, 94, 0.42); }

.btn-ghost { background: transparent; }
.btn-danger { color: var(--rose-soft); border-color: rgba(244, 63, 94, 0.3); background: rgba(244, 63, 94, 0.08); }
.btn-sm { padding: 8px 13px; font-size: 13px; border-radius: 11px; }
.btn-lg { padding: 15px 24px; font-size: 15.5px; border-radius: 16px; }

.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* ── prediction strip ───────────────────────────────────────────── */
.predict-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.predict {
  position: relative;
  padding: 14px 14px 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.predict::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent, var(--violet));
}
.predict .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--text-3);
}
.predict .value { font-size: 17px; font-weight: 700; margin-top: 3px; letter-spacing: -0.4px; }
.predict .meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.predict.is-period { --accent: var(--c-period); }
.predict.is-fertile { --accent: var(--c-fertile); }
.predict.is-ovulation { --accent: var(--c-ovulation); }
.predict.is-pms { --accent: var(--c-pms); }

/* ── quick log chips ────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip:active { transform: scale(0.96); }
.chip .emo { font-size: 15px; line-height: 1; }
.chip.on {
  background: rgba(139, 92, 246, 0.18);
  border-color: rgba(139, 92, 246, 0.5);
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.2) inset;
}

.flow-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.flow-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 11px 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  transition: all 0.15s var(--ease);
}
.flow-opt .drops { display: flex; gap: 1px; height: 15px; align-items: center; }
.flow-opt .drops i {
  width: 5px; height: 9px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: currentColor;
  opacity: 0.32;
}
.flow-opt .drops i.f { opacity: 1; }
.flow-opt.on {
  color: var(--rose-soft);
  border-color: rgba(244, 63, 94, 0.5);
  background: rgba(244, 63, 94, 0.13);
}
.flow-opt:active { transform: scale(0.96); }

/* ── calendar ───────────────────────────────────────────────────── */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}
.cal-title { font-size: 18px; font-weight: 700; letter-spacing: -0.4px; }

.cal-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 6px;
}
.cal-dow span {
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-3);
  text-transform: uppercase;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 13px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  border: 1px solid transparent;
  transition: transform 0.12s var(--ease), background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cal-day:active { transform: scale(0.92); }
.cal-day.pad { opacity: 0.2; pointer-events: none; }
.cal-day.future-far { opacity: 0.55; }

.cal-day.period { background: var(--grad-period); color: #fff; border-color: transparent; box-shadow: 0 3px 12px rgba(244, 63, 94, 0.3); }
.cal-day.pred-period {
  color: var(--rose-soft);
  border: 1.5px dashed rgba(244, 63, 94, 0.6);
  background: rgba(244, 63, 94, 0.07);
}
.cal-day.fertile { background: rgba(45, 212, 191, 0.15); color: var(--teal); border-color: rgba(45, 212, 191, 0.28); }
.cal-day.ovulation {
  background: rgba(20, 184, 166, 0.24);
  color: #5eead4;
  border: 1.5px solid var(--teal-deep);
  font-weight: 750;
}
.cal-day.pms { background: rgba(245, 158, 11, 0.12); color: var(--amber-soft); border-color: rgba(245, 158, 11, 0.24); }
.cal-day.today { box-shadow: 0 0 0 2px var(--violet), 0 0 16px rgba(139, 92, 246, 0.45); }
.cal-day.selected { box-shadow: 0 0 0 2px var(--text); }

.cal-day .marks { display: flex; gap: 2px; height: 4px; align-items: center; }
.cal-day .marks i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.cal-day .marks i.note { background: var(--sky); }
.cal-day .marks i.sym { background: var(--violet-soft); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-3); font-weight: 550; }
.legend i { width: 11px; height: 11px; border-radius: 4px; flex: none; }
.legend i.l-period { background: var(--grad-period); }
.legend i.l-pred { border: 1.5px dashed rgba(244, 63, 94, 0.7); }
.legend i.l-fertile { background: rgba(45, 212, 191, 0.5); }
.legend i.l-ov { background: var(--teal-deep); }
.legend i.l-pms { background: rgba(245, 158, 11, 0.5); }

/* ── sheet / modal ──────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  animation: fadeIn 0.22s var(--ease) forwards;
}
@keyframes fadeIn { to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 91;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-solid);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-top: 1px solid var(--border-strong);
  padding: 10px 18px calc(24px + var(--safe-bottom));
  box-shadow: 0 -14px 50px rgba(0, 0, 0, 0.42);
  transform: translateY(100%);
  animation: sheetUp 0.34s var(--ease) forwards;
}
@keyframes sheetUp { to { transform: none; } }

.sheet.closing { animation: sheetDown 0.24s var(--ease) forwards; }
@keyframes sheetDown { to { transform: translateY(100%); } }

.sheet-grip {
  width: 38px; height: 4px;
  border-radius: 3px;
  background: var(--border-strong);
  margin: 0 auto 14px;
}
.sheet h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.4px; margin-bottom: 3px; }
.sheet .sheet-sub { font-size: 13px; color: var(--text-3); margin-bottom: 18px; }

.field { margin-bottom: 15px; }
.field > label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='time'],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--violet);
  background: var(--surface);
}
textarea { resize: vertical; min-height: 82px; line-height: 1.55; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23857a94' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 17px;
  padding-right: 38px;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }

/* slider */
input[type='range'] {
  width: 100%;
  height: 26px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--grad-brand);
  border: 2px solid var(--surface-solid);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
input[type='range']::-moz-range-track { height: 6px; border-radius: 4px; background: var(--surface-2); }
input[type='range']::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--violet);
  border: 2px solid var(--surface-solid);
  cursor: pointer;
}

/* toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .tr-text { min-width: 0; }
.toggle-row .tr-title { font-size: 14.5px; font-weight: 600; }
.toggle-row .tr-desc { font-size: 12.5px; color: var(--text-3); margin-top: 1px; line-height: 1.45; }

.switch { position: relative; width: 48px; height: 29px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.22s var(--ease), border-color 0.22s;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform 0.24s var(--ease), background 0.22s;
}
.switch input:checked + .track { background: var(--grad-brand); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(19px); background: #fff; }

/* ── stats / insights ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
/* Four stats sit as 2×2 rather than an unbalanced 3+1. */
.stat-grid.of-four { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 620px) {
  .stat-grid.of-four { grid-template-columns: repeat(4, 1fr); }
}
.stat {
  padding: 15px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-align: center;
}
.stat .n {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -1px;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat .k {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-top: 3px;
}

/* cycle-length bar chart */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 148px;
  padding-top: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.chart .bar-wrap {
  flex: 1 0 20px;
  min-width: 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
}
.chart .bar {
  width: 100%;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--violet-soft), var(--magenta));
  min-height: 5px;
  transition: height 0.6s var(--ease);
  position: relative;
}
.chart .bar.out { background: linear-gradient(180deg, var(--amber-soft), var(--amber)); }
.chart .bar-n { font-size: 10px; font-weight: 700; color: var(--text-3); }
.chart .bar-x { font-size: 8.5px; color: var(--text-3); opacity: 0.75; white-space: nowrap; }

.avg-line {
  position: relative;
  height: 0;
  border-top: 1px dashed var(--border-strong);
  margin: 0 0 -1px;
}

/* symptom frequency rows */
.freq { display: flex; flex-direction: column; gap: 9px; }
.freq-row { display: grid; grid-template-columns: 108px 1fr 30px; align-items: center; gap: 10px; }
.freq-row .fname { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.freq-row .fbar { height: 8px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.freq-row .fbar i { display: block; height: 100%; border-radius: 5px; background: var(--grad-brand); transition: width 0.7s var(--ease); }
.freq-row .fn { font-size: 11.5px; color: var(--text-3); text-align: right; font-weight: 650; }
.freq-row .fphase { font-size: 10px; }

/* AI cards */
.ai-card {
  padding: 15px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-left: 3px solid var(--violet);
}
.ai-card + .ai-card { margin-top: 9px; }
.ai-card h4 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.ai-card p { font-size: 13.5px; color: var(--text-2); line-height: 1.6; }
.ai-card.tone-positive { border-left-color: var(--teal); }
.ai-card.tone-heads-up { border-left-color: var(--amber); }
.ai-card.tone-care { border-left-color: var(--rose); }

/* ── Luna chat ──────────────────────────────────────────────────── */
.chat-scroll {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 8px;
}
.msg {
  max-width: 84%;
  padding: 12px 15px;
  border-radius: 19px;
  font-size: 14.5px;
  line-height: 1.6;
  animation: msgIn 0.3s var(--ease);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user {
  align-self: flex-end;
  background: var(--grad-brand);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.bot strong { color: var(--text); font-weight: 650; }
.msg.bot ul { margin: 7px 0 0 2px; }
.msg.bot li { padding-left: 15px; position: relative; margin-bottom: 4px; }
.msg.bot li::before { content: '·'; position: absolute; left: 5px; color: var(--violet-soft); font-weight: 700; }

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--violet-soft);
  animation: bounce 1.3s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 60%, 100% { transform: none; opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chat-composer {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  display: flex;
  gap: 9px;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}
.chat-composer textarea {
  min-height: 46px;
  max-height: 130px;
  border-radius: 22px;
  padding: 12px 16px;
  resize: none;
}
.chat-composer .send {
  width: 46px; height: 46px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--grad-brand);
  color: #fff;
  box-shadow: 0 4px 14px rgba(192, 38, 211, 0.35);
  transition: transform 0.14s var(--ease), opacity 0.15s;
}
.chat-composer .send svg { width: 19px; height: 19px; }
.chat-composer .send:active { transform: scale(0.9); }
.chat-composer .send[disabled] { opacity: 0.45; }

.suggest { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.suggest::-webkit-scrollbar { display: none; }
.suggest button {
  flex: none;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}
.suggest button:hover { color: var(--text); border-color: var(--border-strong); }

/* ── auth screens ───────────────────────────────────────────────── */
/* Flex, not grid: a grid column sized `auto` resolves a `width:100%` child
   against its max-content contribution, which lets a long line of body copy
   push the whole card wider than the viewport. */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 20px calc(30px + var(--safe-bottom));
}
.auth-box { width: 100%; max-width: 400px; min-width: 0; }
.auth-logo { display: grid; place-items: center; gap: 14px; margin-bottom: 26px; text-align: center; }
.auth-logo img { width: 74px; height: 74px; border-radius: 22px; box-shadow: var(--glow), var(--shadow); }
.auth-logo h1 { font-size: 27px; font-weight: 800; letter-spacing: -0.9px; }
.auth-logo p { font-size: 14px; color: var(--text-3); }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 15px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.auth-tabs button {
  padding: 10px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text-3);
  transition: all 0.2s var(--ease);
}
.auth-tabs button.on { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow-sm); }

.code-inputs { display: flex; gap: 8px; justify-content: center; }
.code-inputs input {
  width: 46px;
  height: 56px;
  text-align: center;
  font-size: 23px;
  font-weight: 700;
  font-family: var(--mono);
  padding: 0;
  border-radius: 13px;
}

.alert {
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 14px;
  border: 1px solid;
}
.alert-error { background: rgba(244, 63, 94, 0.1); border-color: rgba(244, 63, 94, 0.32); color: var(--rose-soft); }
.alert-ok { background: rgba(45, 212, 191, 0.1); border-color: rgba(45, 212, 191, 0.32); color: var(--teal); }
.alert-info { background: rgba(139, 92, 246, 0.1); border-color: rgba(139, 92, 246, 0.32); color: var(--violet-soft); }

.auth-alt { text-align: center; font-size: 13.5px; color: var(--text-3); margin-top: 18px; }
.auth-alt button { color: var(--violet-soft); font-weight: 600; }

/* ── settings ───────────────────────────────────────────────────── */
.set-group { margin-bottom: 16px; }
.set-group > h3 {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 0 0 9px 4px;
}
.list-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
}
.list-row:last-child { border-bottom: 0; }
.list-row .ico {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--violet-soft);
  flex: none;
}
.list-row .ico svg { width: 17px; height: 17px; }
.list-row .lr-body { flex: 1; min-width: 0; }
.list-row .lr-title { font-size: 14.5px; font-weight: 600; }
.list-row .lr-desc { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.list-row .chev { color: var(--text-3); flex: none; }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.seg button {
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  transition: all 0.18s var(--ease);
}
.seg button.on { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── misc ───────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-3);
}
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: 0.8; }
.empty h3 { font-size: 16.5px; font-weight: 650; color: var(--text-2); margin-bottom: 6px; }
.empty p { font-size: 13.5px; line-height: 1.6; max-width: 300px; margin: 0 auto 18px; }

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  padding: 11px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  font-weight: 550;
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  animation: toastIn 0.3s var(--ease);
  text-align: center;
}
.toast.err { border-color: rgba(244, 63, 94, 0.5); color: var(--rose-soft); }
.toast.ok { border-color: rgba(45, 212, 191, 0.5); color: var(--teal); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.95); } to { opacity: 1; transform: none; } }
.toast.out { animation: toastOut 0.22s var(--ease) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

.spinner {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--violet);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.center { margin: 46px auto; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 12px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mt-lg { margin-top: 24px; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.16), rgba(192, 38, 211, 0.1));
  border: 1px solid rgba(139, 92, 246, 0.3);
  margin-bottom: 14px;
}
.banner svg { width: 20px; height: 20px; flex: none; color: var(--violet-soft); }
.banner .b-text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.5; }
.banner .b-text b { font-weight: 650; }

/* viewing-someone-else strip */
.viewing-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.12);
  border-bottom: 1px solid rgba(56, 189, 248, 0.28);
  color: var(--sky);
}
.viewing-bar button { margin-left: auto; font-size: 12px; font-weight: 650; color: var(--sky); text-decoration: underline; }

/* ── desktop ────────────────────────────────────────────────────── */
@media (min-width: 900px) {
  :root { --nav-h: 0px; }

  #shell.authed {
    display: grid;
    grid-template-columns: 246px 1fr;
    min-height: 100dvh;
  }

  .tabbar {
    position: sticky;
    top: 0;
    left: auto; right: auto; bottom: auto;
    height: 100dvh;
    grid-template-columns: none;
    grid-auto-rows: max-content;
    align-content: start;
    gap: 3px;
    padding: 22px 14px;
    border-top: 0;
    background: color-mix(in srgb, var(--bg) 60%, transparent);
  }
  .tabbar button.tab-desktop { display: flex; }

  /* The divider lives on the content column, which is as tall as the page —
     the sticky sidebar is only ever one viewport high. */
  .app-main { border-left: 1px solid var(--border); min-width: 0; }
  .tabbar::before {
    content: '';
    display: block;
    height: 46px;
    margin: 0 0 16px 8px;
    background: url('/assets/logo.svg') left center / 34px 34px no-repeat;
  }
  .tabbar button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 13px;
    padding: 11px 14px;
    border-radius: 13px;
    font-size: 14.5px;
    font-weight: 600;
  }
  .tabbar button:hover { background: var(--surface-2); color: var(--text); }
  .tabbar button.active { background: var(--surface-2); }
  .tabbar button.active::before {
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 3px; height: 22px;
    border-radius: 0 4px 4px 0;
  }

  .app-header { padding-left: 26px; padding-right: 26px; }
  .app-header .brand { display: none; }
  main.view { padding: 28px 26px 60px; max-width: 780px; }

  .sheet {
    left: 50%;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.96);
    width: min(560px, 92vw);
    max-height: 86dvh;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-strong);
    animation: modalIn 0.26s var(--ease) forwards;
    padding-bottom: 24px;
  }
  @keyframes modalIn { to { transform: translate(-50%, -50%) scale(1); } }
  .sheet.closing { animation: modalOut 0.2s var(--ease) forwards; }
  @keyframes modalOut { to { opacity: 0; transform: translate(-50%, -50%) scale(0.96); } }
  .sheet-grip { display: none; }

  .toast-host { bottom: 26px; }
  .chat-composer { bottom: 0; }
}

@media (min-width: 620px) {
  .hero .ring-wrap { width: 330px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
