:root {
  --bg: #fbf7f0; --surface: #ffffff; --surface-2: #f3eee5; --text: #1d1a16; --muted: #6f675c; --border: #e8e0d2;
  --brand: #7c3aed; --brand-ink: #ffffff; --brand-soft: #ede4ff;
  --fart: #15803d; --fart-soft: #dcfce7; --burp: #0369a1; --burp-soft: #e0f2fe;
  --danger: #dc2626; --danger-soft: #fee2e2; --warn: #b45309; --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgb(40 30 10 / 6%), 0 6px 24px rgb(40 30 10 / 7%);
  --radius: 20px; --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110; --surface: #1c1a18; --surface-2: #272421; --text: #f5f1ea; --muted: #a69d90; --border: #35312c;
    --brand: #a78bfa; --brand-ink: #1a1033; --brand-soft: #2c2145;
    --fart: #4ade80; --fart-soft: #143221; --burp: #38bdf8; --burp-soft: #0b2a3b;
    --danger: #f87171; --danger-soft: #3b1515; --warn: #fbbf24; --warn-soft: #3a2a0b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 28px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.15; }
h1 { font-size: 1.75rem; font-weight: 850; }
h2 { font-size: 1.15rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 750; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: grid; gap: 14px; }
.stack.tight { gap: 8px; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.boot { display: grid; place-items: center; min-height: 100vh; font-size: 64px; animation: puff 1.2s ease-in-out infinite; }
.noscript { padding: 24px; text-align: center; }
@keyframes puff { 50% { transform: scale(1.15) translateX(6px); opacity: 0.7; } }

/* Layout */
.app { min-height: 100vh; }
.page { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 18px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); display: grid; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.soft { box-shadow: none; background: var(--surface-2); }
.card.warn { background: var(--warn-soft); border-color: transparent; }
.card.brand { background: linear-gradient(135deg, var(--brand), #db2777); color: #fff; border: 0; }
.card.brand .muted { color: rgb(255 255 255 / 80%); }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

/* Bottom nav */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.nav a { display: grid; place-items: center; align-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 0.72rem; font-weight: 650; }
.nav a .ico { font-size: 1.35rem; line-height: 1; filter: grayscale(1); opacity: 0.75; transition: transform 0.15s; }
.nav a[aria-current="page"] { color: var(--text); }
.nav a[aria-current="page"] .ico { filter: none; opacity: 1; transform: translateY(-2px) scale(1.1); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; text-decoration: none; color: var(--text);
  transition: transform 0.08s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 0.88rem; }
.btn.icon { width: 40px; min-height: 40px; padding: 0; }
.btn.white { background: #fff; color: #3b0764; border: 0; }

.log-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-log {
  display: grid; justify-items: center; gap: 4px; padding: 18px 10px; border-radius: 24px; border: 0; font-weight: 800; font-size: 1.05rem;
  box-shadow: var(--shadow); transition: transform 0.1s;
}
.big-log .emoji { font-size: 2.6rem; line-height: 1; }
.big-log:active { transform: scale(0.96); }
.big-log.fart { background: var(--fart-soft); color: var(--fart); }
.big-log.burp { background: var(--burp-soft); color: var(--burp); }

/* Counters */
.counters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.counter { display: grid; gap: 8px; justify-items: center; text-align: center; position: relative; }
.counter .ring { width: 116px; height: 116px; position: relative; }
.counter .ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.counter .ring .track { stroke: var(--surface-2); }
.counter .ring .bar { transition: stroke-dashoffset 0.6s cubic-bezier(.2,.8,.2,1); }
.counter.fart .ring .bar { stroke: var(--fart); }
.counter.burp .ring .bar { stroke: var(--burp); }
.counter .ring .num { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; }
.counter .ring .num b { font-size: 2.1rem; font-weight: 850; line-height: 1; }
.counter .ring .num span { font-size: 0.75rem; color: var(--muted); font-weight: 650; }
.counter .quick { position: absolute; top: 8px; right: 8px; z-index: 2; }
.status { font-size: 0.82rem; font-weight: 650; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.pill.fire { background: var(--warn-soft); color: var(--warn); }
.pill.star { background: var(--brand-soft); color: var(--brand); }

/* Timeline */
.timeline { display: grid; gap: 2px; }
.entry { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 10px 6px; border-radius: 14px; background: none; border: 0; text-align: left; width: 100%; }
.entry:hover { background: var(--surface-2); }
.entry .badge { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 1.4rem; }
.entry .badge.fart { background: var(--fart-soft); }
.entry .badge.burp { background: var(--burp-soft); }
.entry .meta { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .when { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 22px 10px; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty .big { font-size: 2.6rem; }

/* Segmented control & chips */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; border-radius: 999px; min-height: 38px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 0.88rem; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale button { border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 8px 2px; display: grid; justify-items: center; gap: 2px; font-size: 0.7rem; font-weight: 650; color: var(--muted); }
.scale button .e { font-size: 1.5rem; }
.scale button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.scale.four { grid-template-columns: repeat(4, 1fr); }
.card.gut { border-left: 5px solid var(--brand); }

/* Forms */
label.field { display: grid; gap: 6px; font-weight: 700; font-size: 0.9rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); font-weight: 500;
}
textarea.input { min-height: 72px; resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.9rem; text-align: left; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--border); position: relative; transition: background 0.2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgb(0 0 0 / 30%); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:disabled { opacity: 0.5; }
.type-desc { font-size: 0.86rem; color: var(--muted); }
.health-note { font-size: 0.84rem; background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 12px; }
details.triggers summary { cursor: pointer; }
details.triggers > .chips { margin-top: 10px; }
.error { color: var(--danger); font-size: 0.88rem; font-weight: 600; }

/* Sheet / dialog */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 45%); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s ease-out; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px); animation: rise 0.22s cubic-bezier(.2,.8,.2,1); overscroll-behavior: contain;
}
.sheet .grabber { width: 42px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-foot { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--bg); padding: 12px 0 4px; margin-top: 8px; display: grid; gap: 8px; }
@media (min-width: 600px) { .backdrop { align-items: center; } .sheet { border-radius: 26px; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Toast */
.toasts { position: fixed; z-index: 60; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 12px); display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 0.92rem; box-shadow: var(--shadow); animation: drop 0.2s ease-out; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }
@keyframes drop { from { transform: translateY(-12px); opacity: 0; } }

/* Recorder & player */
.recorder { display: grid; gap: 10px; padding: 14px; border-radius: 18px; background: var(--surface-2); }
.rec-live { display: flex; align-items: center; gap: 12px; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; flex: none; }
@keyframes blink { 50% { opacity: 0.3; } }
.meter { flex: 1; height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--fart), var(--warn), var(--danger)); transition: width 0.06s linear; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; }
.player { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; }
.play { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 1rem; display: grid; place-items: center; }
.wave { display: flex; align-items: center; gap: 2px; height: 38px; }
.wave i { flex: 1; min-height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--brand) 30%, var(--border)); transition: background 0.1s; }
.wave i.on { background: var(--brand); }
.dur { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Community */
.post { display: grid; gap: 12px; }
.post-head { display: flex; align-items: center; gap: 10px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; }
.post-head .who { font-weight: 800; }
.post-head .what { font-size: 0.85rem; color: var(--muted); }
.reactions { display: flex; gap: 6px; flex-wrap: wrap; }
.react { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 0.95rem; display: inline-flex; gap: 6px; align-items: center; font-weight: 700; }
.react span { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.react[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.react[aria-pressed="true"] span { color: var(--brand); }
.featured { border: 2px solid var(--warn); }
.featured-label { font-weight: 850; color: var(--warn); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; }
.menu { display: grid; gap: 6px; }
.menu button { text-align: left; }

/* Insights */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--surface-2); border-radius: 16px; padding: 12px 10px; display: grid; gap: 2px; }
.tile b { font-size: 1.35rem; font-weight: 850; font-variant-numeric: tabular-nums; }
.tile span { font-size: 0.74rem; color: var(--muted); font-weight: 650; }
.chart { width: 100%; height: auto; display: block; }
.chart .f { fill: var(--fart); }
.chart .b { fill: var(--burp); }
.chart .h { fill: var(--brand); }
.chart .p { fill: var(--danger); }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); font-weight: 650; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .lf { background: var(--fart); } .legend .lb { background: var(--burp); }
.legend .lh { background: var(--brand); } .legend .lp { background: var(--danger); }
.warn-text { color: var(--warn); font-weight: 700; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.bar-mini { height: 8px; border-radius: 999px; background: var(--brand); min-width: 4px; }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.badge-item { display: grid; justify-items: center; gap: 4px; text-align: center; font-size: 0.72rem; font-weight: 700; padding: 10px 4px; border-radius: 16px; background: var(--surface-2); }
.badge-item .e { font-size: 1.7rem; }
.badge-item.locked { opacity: 0.35; filter: grayscale(1); }
.lock { position: relative; }
.lock-overlay { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 8px; text-align: center; padding: 16px;
  background: color-mix(in srgb, var(--surface) 75%, transparent); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); border-radius: var(--radius); }

/* Welcome */
.welcome { min-height: 100vh; display: grid; align-content: center; gap: 22px; max-width: 440px; margin: 0 auto; padding: 32px 16px calc(32px + env(safe-area-inset-bottom)); text-align: center; }
.logo { font-size: 72px; line-height: 1; animation: puff 2.4s ease-in-out infinite; }
.welcome h1 { font-size: 2.3rem; }
.features { display: grid; gap: 10px; text-align: left; }
.features div { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; font-weight: 600; }
.features span { font-size: 1.5rem; }
details.card summary { cursor: pointer; font-weight: 800; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "＋"; color: var(--muted); }
details.card[open] summary::after { content: "－"; }
details.card[open] summary { margin-bottom: 12px; }
ul.flags { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.code-box { font: 700 1.25rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.05em; text-align: center; padding: 14px; border-radius: 14px; background: var(--surface-2); user-select: all; word-break: break-all; }

/* Legal / report pages */
.doc { max-width: 720px; margin: 0 auto; padding: 32px 18px 64px; display: grid; gap: 14px; }
.doc h1 { font-size: 2rem; }
.doc h2 { margin-top: 12px; }
.doc ul { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.report table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.report th, .report td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f5f5f5; --text: #000; --muted: #444; --border: #ccc; --shadow: none; }
  .no-print { display: none !important; }
  .card { break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.player-wrap { padding: 0 6px 10px 62px; }
