:root {
  color-scheme: light dark;
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --text: #1C1C1E;
  --muted: #6C6C70;
  --line: rgba(60, 60, 67, 0.2);
  --accent: #2F6B4F;
  --accent-ink: #FFFFFF;
  --red: #D9534F;
  --green: #4C9A5B;
  --yellow: #F2CC4B;
  --white: #FFFFFF;
  --white-line: #BBBBBB;
  --ok: #2F6B4F;      --ok-bg: #E6F0EA;
  --avoid: #A0522D;   --avoid-bg: #F7EAE2;
  --fertile: #2B6CB0; --fertile-bg: #E4EEF8;
  --neutral: #55555A; --neutral-bg: #EBEBE7;
  --warn: #A0522D;
  --tabbar-h: 52px;
  --font: -apple-system, system-ui, Roboto, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1C1C1E;
    --text: #F2F2F7;
    --muted: #9A9AA0;
    --line: rgba(235, 235, 245, 0.2);
    --accent: #5FA583;
    --accent-ink: #0B1A12;
    --white-line: #6A6A6A;
    --ok: #7CC29E;      --ok-bg: #1B2B23;
    --avoid: #E0936B;   --avoid-bg: #33241C;
    --fertile: #7DB0E8; --fertile-bg: #18273A;
    --neutral: #B5B5BA; --neutral-bg: #262628;
    --warn: #E0936B;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }
#view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 16px) 24px calc(env(safe-area-inset-left) + 16px);
  outline: none;
  -webkit-overflow-scrolling: touch;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.hidden { display: none !important; }

/* Tab bar */
#tabs {
  display: flex;
  background: var(--surface);
  border-top: 0.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
#tabs button {
  flex: 1;
  min-height: var(--tabbar-h);
  font-size: 14px;
  color: var(--muted);
  border-top: 2px solid transparent;
  margin-top: -0.5px;
}
#tabs button[aria-current="page"] { color: var(--accent); border-top-color: var(--accent); font-weight: 600; }

/* Headings and groups */
h1 { font-size: 28px; line-height: 1.15; margin: 4px 0 14px; font-weight: 700; letter-spacing: -0.2px; }
h2.label {
  font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); margin: 22px 4px 6px;
}
.group {
  background: var(--surface);
  border-top: 0.5px solid var(--line);
  border-bottom: 0.5px solid var(--line);
  margin: 0 -16px;
  padding: 0 16px;
}
.row { padding: 10px 0; border-top: 0.5px solid var(--line); }
.row:first-child { border-top: 0; }
.row > .cap { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.row.inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 4px 0; }
.hint.warn { color: var(--warn); }

/* Segmented control */
.seg { display: flex; border: 1px solid var(--accent); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1 1 0;
  min-height: 44px;
  padding: 6px 4px;
  font-size: 15px;
  line-height: 1.2;
  color: var(--accent);
  border-left: 1px solid var(--accent);
  text-align: center;
}
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.small button { font-size: 14px; padding: 6px 2px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--accent); color: var(--accent); font-weight: 500; font-size: 16px;
  text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn[disabled] { opacity: 0.5; }
.btn.block { display: flex; width: 100%; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
.btns .btn { flex: 1 1 140px; }
input[type="text"], input[type="date"], textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  appearance: none; -webkit-appearance: none;
}
input[type="date"] { min-width: 0; }
textarea { resize: vertical; min-height: 76px; line-height: 1.35; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.fields2 { display: flex; gap: 10px; }
.fields2 > label { flex: 1; min-width: 0; }
.fields2 .cap { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* Switch */
.switch {
  position: relative; width: 51px; height: 31px; border-radius: 16px; flex: none;
  background: var(--line); transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 0.5px 1.5px rgba(0,0,0,.3);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch-hit { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: flex-end; }

/* Stamps: flat squares */
.stamp {
  --s: 36px;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--s); height: var(--s); flex: none;
  color: #000; font-weight: 800; font-size: calc(var(--s) * 0.58); line-height: 1;
  font-family: var(--font);
  border: 1px solid transparent;
}
.stamp.red { background: var(--red); }
.stamp.green { background: var(--green); }
.stamp.yellow { background: var(--yellow); }
.stamp.white { background: var(--white); border-color: var(--white-line); }
.stamp.empty { background: transparent; border: 1px dashed var(--line); }
.stamp.sm { --s: 26px; }
.stamp.lg { --s: 48px; }
.stamp .g { display: block; transform: translateY(-0.02em); }
.stamp .n {
  font-size: 0.5em; font-weight: 800; align-self: flex-end; margin-bottom: 14%; margin-left: 1px; line-height: 1;
}
.stamp .x {
  position: absolute; left: 0; right: 0; bottom: 3%; text-align: center;
  font-size: 0.4em; font-weight: 800; line-height: 1;
}
.stamp svg { width: 62%; height: 62%; fill: #000; }
.stamp.sm .n { margin-bottom: 8%; }
.stamp.bleed .g { font-size: 1.3em; }
.stamp.peak .g { transform: translateY(-0.14em); }

/* Today */
.datebar { display: flex; align-items: center; gap: 4px; margin-bottom: 14px; }
.datebar .nav { width: 44px; height: 44px; font-size: 28px; line-height: 1; color: var(--accent); border-radius: 8px; flex: none; }
.datebar .nav[disabled] { color: var(--line); }
.datebar .when { position: relative; flex: 1; min-width: 0; text-align: center; padding: 2px 0; }
.datebar .when .d { font-size: 20px; font-weight: 700; display: block; }
.datebar .when .s { font-size: 13px; color: var(--muted); display: block; }
.datebar .when input[type="date"] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; cursor: pointer;
}
.banner { border-left: 4px solid var(--neutral); background: var(--neutral-bg); padding: 12px 14px; border-radius: 0 8px 8px 0; }
.banner .h { font-size: 19px; font-weight: 700; margin: 0 0 2px; }
.banner .t { font-size: 15px; margin: 0; }
.banner.ok { border-color: var(--ok); background: var(--ok-bg); }
.banner.ok .h { color: var(--ok); }
.banner.avoid { border-color: var(--avoid); background: var(--avoid-bg); }
.banner.avoid .h { color: var(--avoid); }
.banner.fertile { border-color: var(--fertile); background: var(--fertile-bg); }
.banner.fertile .h { color: var(--fertile); }
.banner.neutral .h { color: var(--neutral); }

details.disc { margin-top: 18px; }
details.disc summary {
  min-height: 44px; display: flex; align-items: center; color: var(--accent); cursor: pointer; list-style: none; font-size: 15px;
}
details.disc summary::-webkit-details-marker { display: none; }
details.disc summary::before { content: "\203A"; display: inline-block; margin-right: 8px; transition: transform .15s; font-size: 20px; }
details.disc[open] summary::before { transform: rotate(90deg); }

/* Chart */
.cycle { margin: 0 -16px 22px; }
.cycle .hd { padding: 0 20px 6px; font-size: 14px; color: var(--muted); }
.cycle .hd b { color: var(--text); font-weight: 600; }
.cycle .flags { padding: 0 20px 6px; font-size: 13px; color: var(--warn); }
.strip {
  display: flex; overflow-x: auto; padding: 8px 16px 8px; background: var(--surface);
  border-top: 0.5px solid var(--line); border-bottom: 0.5px solid var(--line);
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }
.cell {
  flex: none; width: 44px; min-height: 44px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 0;
  font-size: 10px; color: var(--muted);
}
.cell .cd { height: 13px; line-height: 13px; }
.cell .mark { height: 15px; line-height: 15px; font-size: 12px; color: var(--text); white-space: nowrap; }
.cell .dt { line-height: 12px; white-space: nowrap; }
.cell .love { height: 12px; line-height: 12px; font-size: 11px; color: var(--red); }
.cell.today .dt, .cell.today .cd { color: var(--accent); font-weight: 700; }

/* Calendar */
.monthbar { display: flex; align-items: center; margin-bottom: 8px; }
.monthbar .nav { width: 44px; height: 44px; font-size: 28px; line-height: 1; color: var(--accent); }
.monthbar .title { flex: 1; text-align: center; font-size: 18px; font-weight: 700; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal .day {
  min-height: 56px; padding: 3px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 12px; color: var(--text); background: var(--surface); border: 1px solid transparent; border-radius: 4px;
}
.cal .day.blank { background: transparent; }
.cal .day.future { color: var(--muted); }
.cal .day.today .n { color: var(--accent); font-weight: 700; }
.cal .day.today { border-color: var(--accent); }
.cal .day.est-peak { border: 1px dashed var(--fertile); }
.cal .day.est-period { border: 1px dashed var(--red); }
.legend { font-size: 13px; color: var(--muted); margin-top: 14px; display: grid; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 14px; border: 1px dashed; vertical-align: -2px; margin-right: 6px; }
.legend i.p { border-color: var(--fertile); }
.legend i.m { border-color: var(--red); }

/* Settings */
.status { font-size: 14px; margin: 10px 4px 0; color: var(--muted); min-height: 20px; }
.status.err { color: var(--warn); }
.about { font-size: 14px; color: var(--muted); margin: 26px 4px 8px; text-align: center; }
.empty-note { color: var(--muted); font-size: 15px; padding: 16px 4px; }
input[type="file"] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
