:root {
  --bg: #f7f1ee;
  --card: #ffffff;
  --text: #2b2326;
  --muted: #7a6e72;
  --line: #eadfdb;
  --accent: #b5476b;
  --phase-mens: #d9576f;
  --phase-follikel: #5fa88a;
  --phase-aggl: #e0a43c;
  --phase-luteal: #7f74c9;
  --phase-pms: #4f86c6;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1719;
    --card: #262023;
    --text: #f3ecee;
    --muted: #a99ca1;
    --line: #3a3135;
    --accent: #e57a9a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + var(--safe-b));
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 8px;
}
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -0.5px; }
main { padding: 0 16px 16px; max-width: 640px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card h2 { margin: 0 0 6px; font-size: 19px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.phase-hero {
  color: #fff;
  background: var(--phase-color, var(--accent));
  border-radius: var(--radius);
  padding: 20px;
  margin: 8px 0 12px;
}
.phase-hero .day { font-size: 15px; opacity: .9; }
.phase-hero .name { font-size: 28px; font-weight: 700; margin: 2px 0 8px; }
.phase-hero p { margin: 0; opacity: .95; }
.phase-hero .next { margin-top: 12px; font-weight: 600; }

.ring { display: flex; gap: 3px; margin-top: 14px; }
.ring span { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.35); }
.ring span.on { background: #fff; }

.tip { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.tip:first-of-type { border-top: 0; }
.tip .icon { font-size: 24px; line-height: 1; padding-top: 2px; }
.tip .cat { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.tip p { margin: 2px 0 0; }
.tip details { margin-top: 6px; font-size: 14px; color: var(--muted); }
.tip summary { cursor: pointer; color: var(--accent); font-weight: 500; list-style: none; }
.tip summary::-webkit-details-marker { display: none; }
.tip details a { color: var(--accent); word-break: break-word; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; margin-right: 6px; }
.badge.starkt { background: #d9f0e4; color: #1f6b47; }
.badge.måttligt { background: #fbecd0; color: #8a5a07; }
.badge.begränsat { background: #ece8e9; color: #6a5f63; }
.badge.inget { background: #f6dede; color: #8e2b2b; }
.helped { background: var(--bg); color: var(--text); border: 1px solid var(--line); padding: 6px 12px; font-size: 14px; border-radius: 99px; margin-top: 8px; }
.helped.on { background: var(--phase-follikel); border-color: var(--phase-follikel); color: #fff; }
.food { display: grid; grid-template-columns: 1fr; padding: 8px 0; border-top: 1px solid var(--line); }
.food:first-of-type { border-top: 0; }
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.seg button { background: var(--card); color: var(--text); padding: 8px 12px; font-size: 14px; white-space: nowrap; border: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

button, .btn {
  font: inherit; border: 0; cursor: pointer;
  border-radius: 12px; padding: 12px 16px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn.secondary { background: var(--line); color: var(--text); }
.btn.danger { background: transparent; color: #c0392b; border: 1px solid #c0392b; }
.btn.block { display: block; width: 100%; margin-top: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=date], input[type=number], textarea, select {
  font: inherit; width: 100%; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }

/* Kalender */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head button { background: var(--line); color: var(--text); padding: 8px 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.cal-grid .dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.cal-day {
  aspect-ratio: 1; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 15px; background: transparent; color: var(--text); padding: 0; font-weight: 500;
  position: relative;
}
.cal-day.other { visibility: hidden; }
.cal-day.today { outline: 2px solid var(--text); outline-offset: -2px; }
.cal-day.bleed { background: var(--phase-mens); color: #fff; }
.cal-day.pred-mens { border: 2px dashed var(--phase-mens); }
.cal-day .dot { width: 5px; height: 5px; border-radius: 50%; position: absolute; bottom: 5px; }
.cal-day.has-log::after { content: ""; position: absolute; top: 5px; right: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 99px; font-weight: 500; font-size: 15px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.scale { display: flex; gap: 6px; }
.scale button { flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--line); padding: 10px 0; font-size: 20px; }
.scale button.on { background: var(--accent); border-color: var(--accent); }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--card); border-radius: 22px 22px 0 0;
  max-height: 88vh; overflow-y: auto;
  padding: 10px 16px calc(20px + var(--safe-b));
  max-width: 640px; margin: 0 auto;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  flex: 1; background: none; color: var(--muted); border-radius: 0;
  padding: 8px 0 10px; font-size: 11px; font-weight: 500;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar button span { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); }
.tabbar button.active span { filter: none; opacity: 1; }

.pattern { padding: 8px 0; border-top: 1px solid var(--line); }
.pattern:first-of-type { border-top: 0; }
ul.plain { padding-left: 20px; margin: 6px 0; }
ul.plain li { margin: 4px 0; }
.sources li { font-size: 13px; color: var(--muted); }
.sources a { color: var(--accent); word-break: break-word; }
.disclaimer { font-size: 13px; color: var(--muted); text-align: center; margin: 18px 8px 4px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-b)); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; z-index: 30; font-size: 15px;
}
.cal-day.pred-window { border: 2px dotted color-mix(in srgb, var(--phase-mens) 60%, transparent); }
