/* Lilac: soft UI. Lora for display, Nunito for text, Noto SC for Chinese.
 *
 * Colour themes: <html data-theme="lilac|rose|peach|mint|ocean" data-scheme="light|dark">,
 * set by js/theme.js. Each theme defines the same set of variables for light and dark.
 * Period colours (--rose…) stay the same in every theme so their meaning never changes.
 * Text contrast for every theme was checked: 4.5:1 or better for body text and buttons. */
:root {
  /* Shared, light */
  --card: rgba(255, 255, 255, 0.78);
  --card-solid: #FFFFFF;
  --card-edge: rgba(255, 255, 255, 0.9);
  --on-violet: #FFFFFF;
  --rose: #D9578A;         /* period, warnings */
  --rose-deep: #B23A68;
  --rose-soft: #FDE3EE;
  --on-rose: #FFFFFF;
  --period-a: #E46E9A;
  --period-b: #B23A68;
  --shadow: 0 1px 2px rgba(20, 16, 40, 0.04), 0 12px 32px -14px rgba(20, 16, 40, 0.18);
  --shadow-lift: 0 2px 4px rgba(20, 16, 40, 0.05), 0 18px 40px -16px rgba(20, 16, 40, 0.26);
  --grad-period: linear-gradient(135deg, var(--period-a) 0%, var(--period-b) 100%);
  --grad-cycle: linear-gradient(135deg, var(--cycle-a) 0%, var(--cycle-b) 55%, var(--cycle-c) 100%);

  /* Lilac theme, light (default) */
  --bg: #F6F0FF;
  --bg-lilac: #E6DAFF;     /* the three background glows */
  --bg-blush: #FFE4EF;
  --bg-peach: #FFEFE6;
  --line: #EADFF7;
  --lilac: #D8C8F4;        /* theme tint */
  --lilac-soft: #F1EAFC;
  --violet: #6B4BBE;       /* theme accent: actions, focus, today */
  --violet-deep: #52369A;
  --plum: #2A1840;         /* ink */
  --plum-muted: #6A5B82;
  --cycle-a: #9A7CE6;      /* dial ring + history bars */
  --cycle-b: #C07ACB;
  --cycle-c: #EE8FB2;
  --grad-button: linear-gradient(135deg, #6B4BBE 0%, #8E3F8F 100%);

  --display: "Lora", "Noto Serif SC", Georgia, serif;
  --body: "Nunito", "Noto Sans SC", system-ui, sans-serif;

  --r-lg: 28px;
  --r-md: 20px;
  --r-sm: 14px;
  --gutter: clamp(16px, 4vw, 40px);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

/* Shared, dark + Lilac theme, dark */
:root[data-scheme="dark"] {
  --card-edge: rgba(255, 255, 255, 0.06);
  --on-violet: #1B1326;
  --rose: #F08DB2;
  --rose-deep: #F6A9C6;
  --rose-soft: #4A2236;
  --on-rose: #1B1326;
  --period-a: #F6A9C6;
  --period-b: #E07AA2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -14px rgba(0, 0, 0, 0.6);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.3), 0 18px 40px -16px rgba(0, 0, 0, 0.7);

  --bg: #16101F;
  --bg-lilac: #2A1D48;
  --bg-blush: #3A1830;
  --bg-peach: #2A1A1F;
  --card: rgba(36, 27, 50, 0.78);
  --card-solid: #241B32;
  --line: #3A2E4E;
  --lilac: #4C3D6E;
  --lilac-soft: #2D2342;
  --violet: #C2AEF5;
  --violet-deep: #DCD0FA;
  --plum: #F3EDFB;
  --plum-muted: #B9ACCD;
  --grad-button: linear-gradient(135deg, #C2AEF5 0%, #F0A8C8 100%);
  color-scheme: dark;
}

/* Rose */
:root[data-theme="rose"] {
  --bg: #FFF1F4; --bg-lilac: #FFD9E3; --bg-blush: #F3E1FF; --bg-peach: #FFE9D9;
  --line: #F6DCE4; --lilac: #F7C9D6; --lilac-soft: #FDECF1;
  --violet: #B8336A; --violet-deep: #8F2452;
  --plum: #3A1626; --plum-muted: #7A5363;
  --cycle-a: #F6B3C8; --cycle-b: #E9789E; --cycle-c: #C9457D;
  --grad-button: linear-gradient(135deg, #B8336A 0%, #8F2452 100%);
}
:root[data-theme="rose"][data-scheme="dark"] {
  --bg: #1E1015; --bg-lilac: #3E1A28; --bg-blush: #2E1838; --bg-peach: #33201A;
  --card: rgba(46, 26, 34, 0.78); --card-solid: #2E1A22;
  --line: #4A2E39; --lilac: #6A3A4D; --lilac-soft: #3A2129;
  --violet: #F4A3BF; --violet-deep: #F9C4D6;
  --plum: #FBEFF3; --plum-muted: #CFB1BC;
  --grad-button: linear-gradient(135deg, #F4A3BF 0%, #F7C0A8 100%);
}

/* Peach */
:root[data-theme="peach"] {
  --bg: #FFF5EE; --bg-lilac: #FFE0CC; --bg-blush: #FFE8EF; --bg-peach: #FFF1D6;
  --line: #F5E0D2; --lilac: #F8D4BE; --lilac-soft: #FDEDE3;
  --violet: #A84B22; --violet-deep: #8A3D1C;
  --plum: #3B2016; --plum-muted: #76574A;
  --cycle-a: #F8C29E; --cycle-b: #F29A86; --cycle-c: #E57C9C;
  --grad-button: linear-gradient(135deg, #A84B22 0%, #9A3F55 100%);
}
:root[data-theme="peach"][data-scheme="dark"] {
  --bg: #1E140F; --bg-lilac: #3A2416; --bg-blush: #35191F; --bg-peach: #33280F;
  --card: rgba(45, 33, 26, 0.78); --card-solid: #2D211A;
  --line: #483429; --lilac: #6A4A38; --lilac-soft: #38291F;
  --violet: #F6B894; --violet-deep: #FAD2BA;
  --plum: #FBF1EA; --plum-muted: #CDB6A8;
  --grad-button: linear-gradient(135deg, #F6B894 0%, #F3A7B8 100%);
}

/* Mint */
:root[data-theme="mint"] {
  --bg: #EFFAF5; --bg-lilac: #D3F2E4; --bg-blush: #E3F4FF; --bg-peach: #FFF0E8;
  --line: #D6EEE3; --lilac: #BFE8D6; --lilac-soft: #E4F6EE;
  --violet: #1F7A5C; --violet-deep: #165B44;
  --plum: #14322A; --plum-muted: #4F6E63;
  --cycle-a: #8FDDBB; --cycle-b: #5CBFA6; --cycle-c: #4AA3B8;
  --grad-button: linear-gradient(135deg, #1F7A5C 0%, #2A6E80 100%);
}
:root[data-theme="mint"][data-scheme="dark"] {
  --bg: #0E1A16; --bg-lilac: #163A2C; --bg-blush: #15283A; --bg-peach: #2E2219;
  --card: rgba(24, 42, 36, 0.78); --card-solid: #182A24;
  --line: #2A4239; --lilac: #2F5C4C; --lilac-soft: #1E342C;
  --violet: #86DDB9; --violet-deep: #B2EBD3;
  --plum: #EAF7F1; --plum-muted: #A6C7BA;
  --grad-button: linear-gradient(135deg, #86DDB9 0%, #8CCFE0 100%);
}

/* Ocean */
:root[data-theme="ocean"] {
  --bg: #EEF5FF; --bg-lilac: #D6E6FF; --bg-blush: #DFF5F7; --bg-peach: #EDE4FF;
  --line: #D7E3F5; --lilac: #C3D8F5; --lilac-soft: #E6EFFC;
  --violet: #2F5FB3; --violet-deep: #224A8E;
  --plum: #172440; --plum-muted: #55617E;
  --cycle-a: #9CC0F3; --cycle-b: #7A9BE6; --cycle-c: #9B87E0;
  --grad-button: linear-gradient(135deg, #2F5FB3 0%, #4B4BAF 100%);
}
:root[data-theme="ocean"][data-scheme="dark"] {
  --bg: #0E1420; --bg-lilac: #17284A; --bg-blush: #13303A; --bg-peach: #251C44;
  --card: rgba(24, 34, 54, 0.78); --card-solid: #182236;
  --line: #2A3756; --lilac: #34507A; --lilac-soft: #1E2A44;
  --violet: #9EC0F5; --violet-deep: #C3D8FA;
  --plum: #EDF2FB; --plum-muted: #A9B6CF;
  --grad-button: linear-gradient(135deg, #9EC0F5 0%, #B7A8F0 100%);
}

/* Smooth colour change when switching themes (skipped on first load and for reduced motion). */
:root.theme-anim, :root.theme-anim * {
  transition: background-color 0.35s var(--ease), color 0.35s var(--ease), border-color 0.35s var(--ease) !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--plum);
  font: 400 1rem/1.6 var(--body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 { font-family: var(--display); margin: 0; font-weight: 600; }
p { margin: 0; }
button { font-family: inherit; }

:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; border-radius: 10px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip {
  position: absolute; left: 16px; top: -60px; z-index: 20;
  background: var(--violet); color: var(--on-violet);
  padding: 10px 16px; border-radius: 12px;
}
.skip:focus { top: 12px; }

.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-xs { width: 13px; height: 13px; }

/* ---------- Background aura: three soft blobs that drift slowly ---------- */
.aura { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.aura span {
  position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.85;
  animation: drift 28s ease-in-out infinite alternate;
}
.aura span:nth-child(1) { width: 55vmax; height: 55vmax; left: -15vmax; top: -20vmax; background: var(--bg-lilac); }
.aura span:nth-child(2) { width: 45vmax; height: 45vmax; right: -15vmax; top: 5vmax; background: var(--bg-blush); animation-duration: 34s; }
.aura span:nth-child(3) { width: 40vmax; height: 40vmax; left: 20vmax; bottom: -25vmax; background: var(--bg-peach); animation-duration: 40s; }
@keyframes drift { to { transform: translate(4vmax, 3vmax) scale(1.06); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 22px;
  border-radius: 999px; border: 1.5px solid transparent;
  font: 700 0.95rem/1 var(--body);
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.2s, border-color 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--grad-button); color: var(--on-violet); box-shadow: var(--shadow); }
.btn-primary:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.btn-quiet { background: var(--card); color: var(--plum); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--violet); }
.btn-danger { color: var(--rose-deep); }

.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--plum);
  font: 400 1.5rem/1 var(--body); cursor: pointer;
  transition: background-color 0.2s;
}
.icon-btn:hover { background: var(--lilac-soft); }

.soft-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px 0 14px;
  border: 0; border-radius: 999px;
  background: var(--lilac-soft); color: var(--violet);
  font: 700 0.92rem/1.2 var(--body); cursor: pointer;
  transition: background-color 0.2s, transform 0.2s var(--ease);
}
.soft-btn:hover { background: var(--lilac); }
.soft-btn:active { transform: scale(0.97); }

.link-btn {
  border: 0; background: none; padding: 8px 0; min-height: 36px;
  color: var(--violet); font: 600 0.92rem/1.3 var(--body);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
  justify-self: start;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--card-edge);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 28px);
}
.panel-title { font-size: 1.35rem; margin-bottom: 16px; }

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1140px; margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) var(--gutter) 8px;
}
.wordmark { display: flex; align-items: center; gap: 8px; min-width: 0; }
.wordmark-mark { width: 26px; height: 26px; fill: var(--rose); stroke: none; }
.wordmark-name { font: italic 600 1.7rem/1 var(--display); color: var(--violet); letter-spacing: -0.01em; }
.wordmark-note {
  margin-left: 6px; padding: 5px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--card-edge);
  font-size: 0.75rem; font-weight: 600; color: var(--plum-muted); white-space: nowrap;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.lang-btn {
  min-height: 44px; padding: 0 14px; white-space: nowrap;
  border: 0; border-radius: 999px; background: transparent;
  color: var(--violet); font: 700 0.9rem/1 var(--body); cursor: pointer;
}
.lang-btn:hover { background: var(--lilac-soft); }
.sync-chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--card-edge); border-radius: 999px;
  background: var(--card); color: var(--plum);
  font: 700 0.85rem/1 var(--body); cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow);
}
.sync-chip::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--plum-muted); opacity: 0.45;
}
.sync-chip[data-state="synced"]::before, .sync-chip[data-state="idle"]::before { background: #3FAF7F; opacity: 1; }
.sync-chip[data-state="syncing"]::before { background: var(--violet); opacity: 1; animation: pulse 1s ease-in-out infinite alternate; }
.sync-chip[data-state="error"]::before { background: var(--rose); opacity: 1; }
@keyframes pulse { to { opacity: 0.25; } }

main { max-width: 1140px; margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 440px);
  grid-template-areas: "copy dial" "checkin dial";
  column-gap: clamp(24px, 5vw, 64px);
  row-gap: 24px;
  align-items: center;
  padding: clamp(16px, 4vw, 40px) 0 clamp(24px, 4vw, 40px);
}
.hero-copy { grid-area: copy; display: grid; gap: 14px; align-self: end; }
.dial-wrap { grid-area: dial; position: relative; }
.checkin { grid-area: checkin; align-self: start; }

.greeting {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; color: var(--violet); font-size: 1rem;
}
.greeting .ic { width: 18px; height: 18px; fill: var(--rose); stroke: none; }
.status { display: grid; gap: 12px; justify-items: start; }
.eyebrow {
  font-size: 0.82rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--rose-deep);
}
.headline {
  font-size: clamp(2.3rem, 5.6vw, 4rem);
  font-weight: 600; line-height: 1.04; letter-spacing: -0.02em;
}
.headline em { font-style: italic; color: var(--violet); }
.lede { font-size: 1.1rem; color: var(--plum); max-width: 32rem; }
.basis { font-size: 0.95rem; color: var(--plum-muted); }
.remind { margin-top: 4px; }

/* ---------- Dial ---------- */
.dial { width: 100%; height: auto; display: block; overflow: visible; }
.dial-face-edge { fill: none; stroke: var(--card-edge); stroke-width: 1.5; }
.dial-track { fill: none; stroke: var(--lilac-soft); stroke-width: 20; }
.dial-arc { fill: none; stroke-width: 20; stroke-linecap: round; }
.dial-arc.window { stroke: var(--rose); opacity: 0.28; }
.dial-arc.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.4s var(--ease) 0.15s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.dial-dot { fill: var(--card-solid); opacity: 0.85; }
.dial-pearl { fill: var(--card-solid); stroke: var(--violet); stroke-width: 4; }
.dial-pearl-core { fill: var(--violet); }
.dial-halo { fill: var(--violet); opacity: 0.18; transform-box: fill-box; transform-origin: center; animation: halo 2.6s ease-in-out infinite; }
@keyframes halo { 0%, 100% { transform: scale(1); opacity: 0.18; } 50% { transform: scale(1.45); opacity: 0.05; } }
.dial-phase { font: 800 12px var(--body); letter-spacing: 0.16em; text-transform: uppercase; fill: var(--rose-deep); }
.dial-day { font: 600 92px var(--display); fill: var(--plum); }
.dial-sub { font: 600 15px var(--body); fill: var(--plum-muted); }
.dial-empty-ic { fill: var(--rose); stroke: none; }

/* ---------- Check-in ---------- */
.checkin { display: grid; gap: 16px; }
.checkin-head { display: grid; gap: 2px; }
.checkin-head h2 { font-size: 1.35rem; }
.checkin-sub { color: var(--plum-muted); font-size: 0.95rem; }
.flow-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.flow-btn {
  display: grid; justify-items: center; align-content: center; gap: 6px;
  padding: 12px 4px 10px; min-height: 76px;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--card-solid); color: var(--plum);
  font: 700 0.82rem/1.15 var(--body); cursor: pointer;
  transition: transform 0.2s var(--ease), border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.flow-btn:hover { border-color: var(--rose); transform: translateY(-2px); box-shadow: var(--shadow); }
.flow-btn:active { transform: scale(0.95); }
.flow-ic { display: inline-flex; align-items: center; justify-content: center; gap: 1px; height: 22px; color: var(--rose); }
.flow-ic .ic { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.flow-ic .ic-xs { width: 10px; height: 10px; }
.flow-btn[data-flow="none"] .flow-ic { color: var(--plum-muted); }
.flow-btn[data-flow="none"] .flow-ic .ic { fill: none; stroke: currentColor; width: 20px; height: 20px; }
.flow-btn[aria-pressed="true"] {
  background: var(--grad-period); border-color: transparent; color: var(--on-rose);
  box-shadow: var(--shadow-lift);
}
.flow-btn[aria-pressed="true"] .flow-ic { color: var(--on-rose); }
.flow-btn[data-flow="none"][aria-pressed="true"] { background: var(--grad-button); color: var(--on-violet); }
.flow-btn[data-flow="none"][aria-pressed="true"] .flow-ic { color: var(--on-violet); }
.checkin .soft-btn { justify-self: start; }

/* ---------- Stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px;
  margin-bottom: 24px;
}
.stat { display: grid; gap: 4px; align-content: start; padding: 18px 20px; }
.stat-ic {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; background: var(--lilac-soft); color: var(--violet);
  margin-bottom: 6px;
}
.stat:nth-child(2) .stat-ic { background: var(--rose-soft); color: var(--rose-deep); }
.stat-value { font: 600 1.9rem/1.1 var(--display); }
.stat-value small { font: 700 0.9rem var(--body); color: var(--plum-muted); margin-left: 4px; }
.stat-label { font-size: 0.88rem; color: var(--plum-muted); font-weight: 700; }

/* ---------- Grid ---------- */
.grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; align-items: start; }

/* ---------- Calendar ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.month-label { font: 600 1.35rem/1 var(--display); }
.weekdays, .week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekdays span { text-align: center; font-size: 0.75rem; font-weight: 800; color: var(--plum-muted); padding: 6px 0; }
.days { display: grid; gap: 4px; }
.day {
  position: relative; aspect-ratio: 1; min-height: 40px;
  border: 0; border-radius: 50%; background: transparent; color: var(--plum);
  font: 700 0.95rem/1 var(--body); cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.2s var(--ease), background-color 0.2s;
}
.day:hover:not(:disabled) { background: var(--lilac-soft); transform: scale(1.06); }
.day:disabled { cursor: default; }
.day.is-outside .num { opacity: 0.5; }
.day:disabled .num { opacity: 0.62; }
.day.is-period { background: var(--grad-period); color: var(--on-rose); }
.day.is-period:hover:not(:disabled) { background: var(--grad-period); }
.day.flow-light, .day.flow-gap { background: var(--rose-soft); color: var(--rose-deep); }
.day.flow-light:hover:not(:disabled), .day.flow-gap:hover:not(:disabled) { background: var(--rose-soft); }
.day.is-spotting::after {
  content: ""; position: absolute; bottom: 16%;
  width: 6px; height: 6px; border-radius: 50%; background: var(--rose);
}
.day.is-predicted { box-shadow: inset 0 0 0 2px var(--rose); background: color-mix(in srgb, var(--rose-soft) 60%, transparent); }
.day.is-predicted .num { opacity: 1; }
.day.is-today { box-shadow: inset 0 0 0 2.5px var(--violet); }
.day.is-today.is-period { box-shadow: inset 0 0 0 2.5px var(--violet), inset 0 0 0 5px var(--card-solid); }
.day .mark { position: absolute; top: 12%; right: 16%; width: 6px; height: 6px; border-radius: 50%; background: var(--violet); }
.day.is-period .mark { background: var(--on-rose); }

.legend { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 0.85rem; color: var(--plum-muted); font-weight: 600; }
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.key { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.key-period { background: var(--grad-period); }
.key-predicted { box-shadow: inset 0 0 0 2px var(--rose); background: var(--rose-soft); }
.key-spotting { width: 6px; height: 6px; margin: 0 4px; background: var(--rose); }
.key-today { box-shadow: inset 0 0 0 2.5px var(--violet); }
.hint { margin-top: 10px; font-size: 0.85rem; color: var(--plum-muted); }

/* ---------- Guidance ---------- */
.guidance { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.guide {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; align-items: start;
  padding: 16px 18px; border-radius: var(--r-md);
  background: var(--lilac-soft);
}
.guide > :not(.guide-ic) { grid-column: 2; }
.guide-ic {
  grid-column: 1; grid-row: 1 / span 4; width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; background: var(--card-solid); color: var(--violet);
}
.guide h3 { font-size: 1.05rem; line-height: 1.35; }
.guide p { font-size: 0.95rem; }
.guide-flag { background: var(--rose-soft); }
.guide-flag .guide-ic { color: var(--rose-deep); }
.guide-tag { font-size: 0.72rem !important; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--rose-deep); }
.source { justify-self: start; font-size: 0.8rem; font-weight: 700; color: var(--violet); text-underline-offset: 3px; }

/* ---------- History ---------- */
.history-panel { margin-top: 24px; }
.history-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 24px; margin-bottom: 8px; }
.history-head .panel-title { margin-bottom: 0; }
.history-key { display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--plum-muted); }
.band-swatch { width: 22px; height: 10px; border-radius: 4px; background: var(--lilac); }
.history { list-style: none; margin: 0; padding: 0; }
.cycle-row {
  display: grid; grid-template-columns: 9rem 5.5rem 1fr 8rem; align-items: center; gap: 16px;
  padding: 14px 0; border-top: 1px solid var(--line);
}
.cycle-row:first-child { border-top: 0; }
.cycle-date, .cycle-bleed { font-size: 0.88rem; color: var(--plum-muted); font-weight: 600; }
.cycle-len { font: 600 1.1rem/1 var(--display); }
.cycle-len.is-out { color: var(--rose-deep); }
.bar { position: relative; height: 14px; border-radius: 999px; background: var(--lilac-soft); overflow: hidden; }
.bar-band { position: absolute; top: 0; bottom: 0; background: var(--lilac); }
.bar-fill { position: absolute; left: 0; top: 3px; bottom: 3px; border-radius: 999px; background: var(--grad-cycle); }
.bar-bleed { position: absolute; left: 0; top: 3px; bottom: 3px; border-radius: 999px; background: var(--grad-period); }
.history-empty { color: var(--plum-muted); padding: 8px 0; }

/* ---------- Footer ---------- */
.foot { max-width: 1140px; margin: 40px auto 0; padding: 24px var(--gutter) calc(48px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }
.disclaimer { font-size: 0.9rem; color: var(--plum-muted); max-width: 46rem; }
.data-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.data-controls label.btn:focus-within { outline: 3px solid var(--violet); outline-offset: 2px; }

/* ---------- Toast + petals ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 999px;
  background: var(--plum); color: var(--bg);
  font-weight: 700; font-size: 0.95rem; box-shadow: var(--shadow-lift);
  transition: opacity 0.25s var(--ease), transform 0.35s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .ic { width: 18px; height: 18px; fill: var(--rose); stroke: none; }
.petals { position: fixed; inset: 0; pointer-events: none; z-index: 25; }
.petal {
  position: absolute; width: 12px; height: 16px;
  border-radius: 80% 0 80% 0; background: var(--grad-period);
  animation: petal 0.9s var(--ease) forwards;
}
.petal:nth-child(3n) { background: var(--grad-cycle); }
@keyframes petal {
  from { transform: translate(0, 0) rotate(0) scale(0.6); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(1); opacity: 0; }
}

/* ---------- Dialogs (bottom sheet on phones) ---------- */
.sheet {
  width: min(540px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  border: 0; border-radius: var(--r-lg); padding: 0;
  background: var(--card-solid); color: var(--plum);
  box-shadow: 0 24px 48px -16px rgba(0, 0, 0, 0.28);
}
.sheet[open] { animation: sheet-in 0.35s var(--ease); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px) scale(0.98); } }
.sheet::backdrop { background: rgba(42, 24, 64, 0.32); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.day-dialog form { padding: 20px 24px 24px; display: grid; gap: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-size: 1.4rem; }

fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--plum-muted); margin-bottom: 10px; }
.choices, .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.choices legend, .chips legend { width: 100%; }
.choices label, .chips label { position: relative; }
.choices input, .chips input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choices span, .chips span {
  display: inline-flex; align-items: center; min-height: 42px; padding: 0 16px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--card-solid);
  font-size: 0.92rem; font-weight: 600;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.choices input:checked + span { background: var(--grad-button); border-color: transparent; color: var(--on-violet); }
.flow-choices input:checked + span { background: var(--grad-period); color: var(--on-rose); }
.flow-choices input[value="none"]:checked + span { background: var(--plum-muted); color: var(--card-solid); }
.chips input:checked + span { background: var(--lilac); border-color: var(--lilac); color: var(--plum); }
.choices input:focus-visible + span, .chips input:focus-visible + span { outline: 3px solid var(--violet); outline-offset: 2px; }
.checks { display: grid; gap: 10px; }
.checks label { display: flex; gap: 10px; align-items: center; font-size: 0.95rem; }
.checks input { width: 20px; height: 20px; accent-color: var(--violet); }
.note { display: grid; gap: 8px; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--plum-muted); }
.note textarea, .field input {
  font: 400 1rem/1.4 var(--body); text-transform: none; letter-spacing: 0;
  color: var(--plum); background: var(--lilac-soft);
  border: 1.5px solid transparent; border-radius: var(--r-sm);
  padding: 12px 14px; resize: vertical;
}
.note textarea:focus-visible, .field input:focus-visible { border-color: var(--violet); outline: none; }
.dialog-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Sync dialog ---------- */
.sync-dialog > .dialog-head { padding: 18px 16px 0 24px; }
.sync-dialog > .dialog-head form { padding: 0; display: block; }
.sync-body { padding: 14px 24px 24px; display: grid; gap: 14px; }
.sync-dialog .sync-form { display: grid; gap: 14px; padding: 0; }
.muted { color: var(--plum-muted); }
.field { display: grid; gap: 6px; font-size: 0.82rem; font-weight: 800; color: var(--plum-muted); }
.field input { min-height: 46px; }
.field-help { font-weight: 500; font-size: 0.85rem; }
.sync-error { color: var(--rose-deep); font-size: 0.92rem; font-weight: 600; }
.sync-error:empty { display: none; }
.sync-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sync-actions > :only-child { margin-left: auto; }
.sync-actions > .btn-quiet:only-child { margin-left: 0; }

/* ---------- Appearance dialog ---------- */
.theme-btn { color: var(--violet); }
.theme-dialog form { padding: 20px 24px 24px; display: grid; gap: 20px; }
.swatches { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.swatches legend { grid-column: 1 / -1; }
.swatches label {
  position: relative; display: grid; justify-items: center; gap: 8px;
  padding: 12px 4px 10px; border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--card-solid);
  font-size: 0.85rem; font-weight: 700; cursor: pointer;
  transition: border-color 0.2s, transform 0.2s var(--ease);
}
.swatches label:hover { transform: translateY(-2px); }
.swatches input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatches label:has(input:checked) { border-color: var(--violet); box-shadow: 0 0 0 2px var(--violet) inset; }
.swatches label:has(input:focus-visible) { outline: 3px solid var(--violet); outline-offset: 2px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06); }
.sw-lilac { background: conic-gradient(from 200deg, #6B4BBE, #C07ACB, #EE8FB2, #E6DAFF, #6B4BBE); }
.sw-rose  { background: conic-gradient(from 200deg, #B8336A, #E9789E, #F6B3C8, #FFE9D9, #B8336A); }
.sw-peach { background: conic-gradient(from 200deg, #A84B22, #F29A86, #F8C29E, #FFF1D6, #A84B22); }
.sw-mint  { background: conic-gradient(from 200deg, #1F7A5C, #5CBFA6, #8FDDBB, #E3F4FF, #1F7A5C); }
.sw-ocean { background: conic-gradient(from 200deg, #2F5FB3, #7A9BE6, #9CC0F3, #EDE4FF, #2F5FB3); }
.theme-note { font-size: 0.9rem; }
@media (max-width: 420px) {
  .swatches { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Chinese ---------- */
:lang(zh) body { line-height: 1.75; }
:lang(zh) .headline { line-height: 1.25; letter-spacing: 0; font-weight: 700; }
:lang(zh) .eyebrow, :lang(zh) .guide-tag, :lang(zh) legend, :lang(zh) .note, :lang(zh) .dial-phase { letter-spacing: 0.06em; }
:lang(zh) .dial-phase { font-size: 14px; }
:lang(zh) .dial-sub { font-size: 16px; }

/* ---------- Load-in ---------- */
.rise { animation: rise 0.7s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; grid-template-areas: "copy" "dial" "checkin"; }
  .dial-wrap { width: min(340px, 86vw); justify-self: center; }
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cycle-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .cycle-row .bar, .cycle-bleed { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .wordmark-note { display: none; }
  .checkin { padding: 18px 16px; }
  /* Buttons size to their labels so longer ones ("Spotting", "点滴出血") keep their padding. */
  .flow-picker { grid-template-columns: repeat(5, auto); justify-content: space-between; gap: 4px; }
  .flow-btn { font-size: 0.72rem; min-height: 70px; min-width: 52px; padding: 10px 8px 8px; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 1.6rem; }
  .sheet {
    width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: 92dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}
@media (max-width: 360px) {
  /* Smallest phones: two rows so no label is squeezed. */
  .flow-picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .flow-btn { flex: 0 0 calc((100% - 12px) / 3); }
}
@media (max-width: 380px) {
  .day { min-height: 34px; font-size: 0.85rem; }
  /* Narrow phones: keep the header on one line. */
  .top { gap: 6px; }
  .wordmark { gap: 5px; }
  .wordmark-name { font-size: 1.4rem; }
  .wordmark-mark { width: 20px; height: 20px; }
  .top-actions { gap: 2px; }
  .theme-btn { width: 40px; }
  .lang-btn { padding: 0 8px; }
  .sync-chip { padding: 0 11px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .dial-arc.draw { stroke-dashoffset: 0; }
}
