:root {
  --green: #085041;
  --green-d: #063c30;
  --green-l: #0a6651;
  --bg: #f5f7f4;
  --card: #ffffff;
  --text: #1b231f;
  --muted: #5c665f;
  --accent: #b3402e;       /* outcomes */
  --accent-bg: #fbeeea;
  --line: #e1e6e0;
  --radius: 16px;
  --tap: 64px;
  --maxw: 560px;
  font-size: 18px;
}
[data-theme="dark"] {
  --bg: #0e1411;
  --card: #182019;
  --text: #eef2ee;
  --muted: #9aa69e;
  --accent: #e07a64;
  --accent-bg: #2a1c18;
  --line: #26312b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  overscroll-behavior-y: contain;
}
#app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px calc(86px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
button { font-family: inherit; font-size: 1rem; color: inherit; cursor: pointer; }

/* Header */
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg);
  padding: 14px 2px 10px;
  border-bottom: 1px solid var(--line);
}
.appbar h1 { font-size: 1.25rem; margin: 0; letter-spacing: .2px; }
.appbar .date { color: var(--muted); font-size: .95rem; margin-left: auto; margin-right: 10px; }
.iconbtn {
  border: none; background: transparent; font-size: 1.5rem;
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
}
.iconbtn:active { background: var(--line); }

/* Section headings */
.section-title {
  font-size: .8rem; font-weight: 700; letter-spacing: .8px;
  color: var(--muted); text-transform: uppercase;
  margin: 22px 4px 10px;
}

/* Tile grid */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  border: 1px solid var(--line); background: var(--card);
  border-radius: var(--radius); min-height: var(--tap);
  padding: 14px 12px; text-align: left;
  display: flex; align-items: center; gap: 12px;
  transition: transform .06s ease;
}
.tile:active { transform: scale(.97); }
.tile .emoji { font-size: 1.7rem; line-height: 1; }
.tile .label { font-size: 1.05rem; font-weight: 600; }
.tile.wide { grid-column: 1 / -1; justify-content: center; }
.tile.outcome { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-bg); }
.tile.outcome .label { color: var(--accent); }
.tile.more { justify-content: center; color: var(--muted); border-style: dashed; }

/* Today / history list */
.daygroup h3 { font-size: .95rem; color: var(--muted); margin: 20px 4px 8px; }
.entry {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  width: 100%; text-align: left;
}
.entry .t { font-variant-numeric: tabular-nums; color: var(--muted); width: 72px; font-size: .9rem; flex: none; }
.entry .e { font-size: 1.3rem; flex: none; }
.entry .lbl { font-weight: 600; }
.entry .meta { color: var(--muted); font-size: .85rem; }
.entry.outcome { border-left: 4px solid var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* Bottom nav */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.nav button {
  border: none; background: transparent; flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.nav button .ni { font-size: 1.35rem; }
.nav button.active { color: var(--green); }
[data-theme="dark"] .nav button.active { color: var(--green-l); }

/* Onboarding */
.onb { padding-top: 40px; }
.onb h1 { font-size: 1.6rem; margin: 0 4px 6px; }
.onb p.sub { color: var(--muted); margin: 0 4px 24px; }
.choice {
  width: 100%; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px; margin-bottom: 14px; display: flex; gap: 14px; align-items: center;
}
.choice .emoji { font-size: 2rem; }
.choice .ct strong { font-size: 1.15rem; display: block; }
.choice .ct span { color: var(--muted); font-size: .9rem; }
.choice:active { transform: scale(.98); }
.choice.add { border-style: dashed; color: var(--muted); }
.choice.add .ct strong { font-weight: 700; }
.choice.removing { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-bg); }
.choice.removing .ct strong, .choice.removing .emoji { color: var(--accent); }

/* Home big buttons */
.bigbtns { display: flex; flex-direction: column; gap: 14px; margin: 18px 0 6px; }
.bigbtn {
  display: flex; align-items: center; gap: 18px; width: 100%; min-height: 104px;
  border: none; border-radius: 22px; padding: 0 24px; color: #fff; text-align: left;
  transition: transform .06s ease;
}
.bigbtn:active { transform: scale(.98); }
.bigbtn .be { font-size: 2.6rem; line-height: 1; }
.bigbtn .bt { display: flex; flex-direction: column; }
.bigbtn .bt strong { font-size: 1.6rem; font-weight: 800; line-height: 1.15; }
.bigbtn .bt span { font-size: .95rem; opacity: .92; }
.bigbtn.input { background: var(--green); }
.bigbtn.symptom { background: var(--accent); }

/* Drill-down list */
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.stack .choice { padding: 16px; min-height: 68px; }

/* Modal / sheet */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.sheet {
  background: var(--card); width: 100%; max-width: var(--maxw);
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: rise .18s ease; max-height: 88vh; overflow-y: auto;
}
.search {
  width: 100%; font-size: 1.05rem; padding: 13px 14px; box-sizing: border-box;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text);
  position: sticky; top: -2px; z-index: 1; margin-bottom: 6px;
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 16px; font-size: 1.3rem; display: flex; align-items: center; gap: 10px; }
.sheet .field-label { font-size: .85rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 16px 2px 8px; }
.opts { display: flex; gap: 10px; flex-wrap: wrap; }
.opt {
  flex: 1; min-width: 90px; min-height: 56px; border: 1.5px solid var(--line);
  background: var(--bg); border-radius: 14px; font-size: 1.05rem; font-weight: 600;
}
.opt.sel { border-color: var(--green); background: color-mix(in srgb, var(--green) 12%, var(--card)); color: var(--green); }
[data-theme="dark"] .opt.sel { color: var(--green-l); }
.bristol { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bristol .opt { min-width: 0; flex-direction: column; display: flex; align-items: center; justify-content: center; padding: 6px; }
.bristol .opt b { font-size: 1.1rem; }
.bristol .opt small { font-size: .62rem; color: var(--muted); line-height: 1.1; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale .opt { min-width: 0; min-height: 50px; }
.timerow { display: flex; align-items: center; gap: 12px; }
.timerow .now { flex: 1; text-align: center; font-size: 1.15rem; font-weight: 700; }
.roundbtn { width: 54px; height: 54px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--bg); font-size: 1.6rem; }
.sheet textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px;
  font-size: 1rem; min-height: 64px; background: var(--bg); color: var(--text); resize: vertical;
}
.note-wrap { position: relative; }
.mic { position: absolute; right: 8px; bottom: 8px; width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--green); color: #fff; font-size: 1.2rem; }
.mic.live { background: var(--accent); }
.sheet-actions { display: flex; gap: 12px; margin-top: 22px; }
.btn { flex: 1; min-height: 56px; border-radius: 14px; font-size: 1.1rem; font-weight: 700; border: 1.5px solid var(--line); background: var(--bg); }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

/* Settings */
.set-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: none; }
.set-row .rl { font-weight: 600; }
.set-row .rs { color: var(--muted); font-size: .85rem; }
.set-row input[type=text], .set-row input[type=password], .set-row select {
  font-size: 1rem; padding: 10px; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%;
}
.set-full { padding: 16px; }
.switch { width: 54px; height: 32px; border-radius: 16px; border: none; background: var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on { background: var(--green); }
.switch.on::after { left: 25px; }
.linkbtn { background: transparent; border: none; color: var(--green); font-weight: 700; font-size: 1rem; padding: 6px 0; }
[data-theme="dark"] .linkbtn { color: var(--green-l); }
.set-row.tap { width: 100%; background: none; border: none; border-bottom: 1px solid var(--line); text-align: left; text-decoration: none; color: inherit; font: inherit; cursor: pointer; }
.set-group .set-row.tap:last-child { border-bottom: none; }
.set-row.tap:active { background: var(--bg); }
.set-row.tap span[aria-hidden] { color: var(--muted); font-size: 1.2rem; }

/* Insights cards */
.card { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.card-h { display: flex; align-items: center; gap: 10px; }
.card-h .ci { font-size: 1.4rem; }
.card-h strong { font-size: 1.08rem; }
.card-h .ratio { margin-left: auto; color: var(--green); font-weight: 800; white-space: nowrap; }
[data-theme="dark"] .card-h .ratio { color: var(--green-l); }
.card-b { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.ai-out { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-top: 12px; line-height: 1.5; }
.help p { margin: 6px 2px 12px; }

/* Prominent AI box on the Analyse tab */
.aibox { background: var(--green); color: #fff; border-radius: 20px; padding: 20px 18px; margin: 16px 0 10px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.aibox-h { margin: 0 0 6px; font-size: 1.35rem; }
.aibox-sub { margin: 0 0 12px; opacity: .95; font-size: .96rem; line-height: 1.4; }
.aisteps { margin: 0 0 14px; padding-left: 22px; font-size: .96rem; }
.aisteps li { margin: 3px 0; }
.aibox .btn.primary { background: #fff; color: var(--green); border-color: #fff; width: 100%; }
.ailinks { display: flex; gap: 8px; margin-top: 12px; }
.ailink { flex: 1; text-align: center; padding: 12px 6px; border-radius: 12px; background: rgba(255,255,255,.16); color: #fff; text-decoration: none; font-weight: 700; border: 1px solid rgba(255,255,255,.45); }
.ailink:active { background: rgba(255,255,255,.3); }
.aibox .muted-note { color: rgba(255,255,255,.85); margin: 10px 0 0; }
.patt-h { font-weight: 700; margin: 16px 4px 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(94px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--green-d); color: #fff; border-radius: 14px;
  padding: 12px 16px; display: flex; align-items: center; gap: 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 92%;
}
.toast[hidden] { display: none; }
.toast button { background: transparent; border: none; color: #ffe; font-weight: 800; text-decoration: underline; }
.muted-note { color: var(--muted); font-size: .85rem; margin: 8px 4px; }
