/* Sage mini-apps, in Apple's style: content first, UI recedes. Hierarchy from size, weight, spacing
   and grouping; no borders or drop shadows; one accent; pill buttons; glass only on the floating
   action bar. Runs inside the iMessage sheet, so the type scale is sized for a phone. */
:root {
  --ink: #1d1d1f;
  --ink-2: rgb(29 29 31 / 0.6);   /* secondary text: the ink at lower opacity, not a new gray */
  --ink-3: rgb(29 29 31 / 0.4);
  --page: #ffffff;
  --tile: #f5f5f7;                /* grouped content on the white page */
  --accent: #0071e3;              /* primary buttons */
  --link: #0066cc;                /* links */
  --accent-tint: rgb(0 113 227 / 0.1);
  --fill: rgb(29 29 31 / 0.08);   /* tracks, unselected marks */
  --alert-ink: #b3261e;           /* reserved for "call 911": safety outranks the one-accent rule */
  --alert-tint: rgb(179 38 30 / 0.08);
  --radius: 22px;
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f5f5f7; --ink-2: rgb(245 245 247 / 0.62); --ink-3: rgb(245 245 247 / 0.4);
    --page: #000000; --tile: #1c1c1e; --link: #2997ff; --accent-tint: rgb(41 151 255 / 0.16); --fill: rgb(245 245 247 / 0.12);
    --alert-ink: #ff6961; --alert-tint: rgb(255 105 97 / 0.14);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100svh; background: var(--page); color: var(--ink); font: 400 17px/1.47 var(--font); -webkit-font-smoothing: antialiased; }
main { max-width: 600px; margin: 0 auto; padding: 28px 20px calc(132px + env(safe-area-inset-bottom)); }
h1 { font-size: 34px; line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; margin: 2px 0 10px; }
h2 { font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: -0.015em; margin: 0 0 8px; }
h3 { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
p { margin: 0 0 12px; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-2); }
.small { font-size: 15px; }
.tiny { font-size: 13px; color: var(--ink-3); }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Header: a small eyebrow above a big headline. */
.header { padding: 4px 0 14px; }
.chip, .eyebrow { display: block; font-size: 15px; font-weight: 600; color: var(--ink-2); letter-spacing: -0.005em; margin-bottom: 4px; }
.display { font-size: 48px; line-height: 1.04; font-weight: 600; letter-spacing: -0.025em; margin: 2px 0 8px; }
.lede { font-size: 19px; line-height: 1.4; color: var(--ink-2); margin: 0 0 8px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; font-size: 17px; color: var(--link); background: none; border: 0; padding: 0; cursor: pointer; }

/* Tiles: grouped content, no borders or shadows. */
.card { background: var(--tile); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 12px; }
.section-gap { margin-top: 44px; }
.bento { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.bento .tile { background: var(--tile); border-radius: var(--radius); padding: 18px; min-height: 124px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.bento .tile.wide { grid-column: span 2; }
.bento .stat { font-size: 40px; line-height: 1; font-weight: 600; letter-spacing: -0.03em; }
.bento .stat small { font-size: 19px; font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.bento .claim { font-size: 15px; color: var(--ink-2); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fact { background: var(--tile); border-radius: 18px; padding: 16px; }
.fact b { display: block; font-size: 19px; font-weight: 600; }
.fact span { font-size: 15px; color: var(--ink-2); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 14px; padding: 10px 0; }
.timeline .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 8px; flex: none; }
details { padding: 14px 0; }
details + details { box-shadow: 0 -1px 0 var(--fill); }
summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--link); font-weight: 400; font-size: 22px; line-height: 1; }
details[open] summary::after { content: "–"; }
details p { margin-top: 8px; color: var(--ink-2); }

/* Grouped list rows (Settings style): separation by spacing and a hairline inset, not borders. */
.list { background: var(--tile); border-radius: var(--radius); padding: 4px 18px; }
.list-row { display: flex; align-items: center; gap: 14px; min-height: 60px; padding: 10px 0; }
.list-row + .list-row { box-shadow: 0 -1px 0 var(--fill); }
.list-row .title { font-weight: 600; }
.list-row .sub { font-size: 15px; color: var(--ink-2); }
.list-row .end { margin-left: auto; font-size: 15px; color: var(--ink-2); white-space: nowrap; }
.status-dot { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--fill); color: var(--page); }
.status-dot.done { background: var(--accent); }
.status-dot.done::after { content: ""; width: 10px; height: 6px; border: solid currentColor; border-width: 0 0 2.5px 2.5px; transform: rotate(-45deg) translate(1px, -1px); }
.status-dot.due { background: var(--accent-tint); box-shadow: inset 0 0 0 2px var(--accent); }
.status-dot.missed { background: var(--fill); }

/* Buttons: pills, solid accent for the one primary action, links for the rest. */
button { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 52px;
  padding: 14px 22px; border-radius: 980px; border: 0; background: var(--accent); color: #fff;
  font-weight: 500; font-size: 17px; letter-spacing: -0.01em; cursor: pointer; text-decoration: none;
  transition: transform 0.4s var(--spring), opacity 0.2s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.35; cursor: default; transform: none; }
.btn.secondary { background: var(--accent-tint); color: var(--link); }
.btn.ghost { background: transparent; color: var(--link); min-height: 44px; font-weight: 400; }
.btn.alert { background: var(--alert-ink); color: #fff; }
.btn .icon { width: 22px; height: 22px; }

/* The floating action bar: Liquid Glass (a floating control, never on content). */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 0 12px calc(12px + env(safe-area-inset-bottom)); pointer-events: none; }
.actionbar .inner {
  pointer-events: auto; max-width: 576px; margin: 0 auto; display: flex; gap: 8px; padding: 8px; border-radius: 34px;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.5), rgb(255 255 255 / 0.12) 55%, rgb(255 255 255 / 0.2)),
    rgb(255 255 255 / 0.55);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.9), inset 0 0 0 0.5px rgb(255 255 255 / 0.35);
}
@media (prefers-color-scheme: dark) {
  .actionbar .inner {
    background: linear-gradient(180deg, rgb(255 255 255 / 0.14), rgb(255 255 255 / 0.04) 55%, rgb(255 255 255 / 0.06)), rgb(30 30 32 / 0.55);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.22);
  }
}
.actionbar .btn { min-height: 50px; }
.actionbar .btn.back { width: auto; flex: 0 0 auto; padding: 14px 20px; background: transparent; color: var(--link); }

/* Progress */
pa-progress { display: block; height: 4px; border-radius: 99px; background: var(--fill); overflow: hidden; margin: 8px 0 22px; }
pa-progress .bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.6s var(--spring); }

/* Choices: tiles that fill with a tint when chosen. */
pa-options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; padding: 14px 18px; text-align: left;
  background: var(--tile); border: 0; border-radius: 18px; cursor: pointer; font-size: 17px;
  transition: background 0.3s var(--spring), transform 0.4s var(--spring);
}
.option:active { transform: scale(0.98); }
.option .mark { width: 24px; height: 24px; border-radius: 50%; background: var(--fill); flex: none; display: grid; place-items: center; transition: background 0.3s var(--spring); }
.option[data-multi] .mark { border-radius: 7px; }
.option[aria-pressed="true"] { background: var(--accent-tint); color: var(--ink); }
.option[aria-pressed="true"] .mark { background: var(--accent); }
.option[aria-pressed="true"] .mark::after { content: ""; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2.5px 2.5px; transform: rotate(-45deg) translate(1px, -1px); }
pa-yes-no { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
pa-yes-no .option { justify-content: center; font-weight: 600; min-height: 76px; font-size: 21px; }
pa-yes-no .option .mark { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-toggle { min-height: 44px; padding: 0 18px; border-radius: 980px; border: 0; background: var(--tile); font-size: 16px; cursor: pointer; transition: background 0.3s var(--spring); }
.chip-toggle[aria-pressed="true"] { background: var(--accent); color: #fff; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--tile); border-radius: 14px; padding: 3px; gap: 3px; margin-bottom: 16px; }
.segmented button { border: 0; background: transparent; padding: 10px 6px; min-height: 44px; border-radius: 11px; font-weight: 500; font-size: 15px; cursor: pointer; transition: background 0.3s var(--spring); }
.segmented button[aria-pressed="true"] { background: var(--page); font-weight: 600; }
.segmented button small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-2); }

/* Controls sitting on a gray tile switch to the page color so they still read as controls. */
.card .option, .card pa-number input, .card pa-number .step, .card .text-input, .card .chip-toggle:not([aria-pressed="true"]) { background: var(--page); }
.card .option[aria-pressed="true"] { background: var(--accent-tint); }

/* Number and scale */
pa-number { display: flex; align-items: flex-start; gap: 10px; }
pa-number .grow { min-width: 0; }
pa-number input {
  display: block; width: 100%; min-width: 0; height: 76px; font-size: 40px; font-weight: 600; letter-spacing: -0.02em; text-align: center; border-radius: 18px;
  border: 0; background: var(--tile); color: var(--ink); font-family: var(--font);
}
pa-number input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
pa-number .step { width: 56px; height: 56px; margin-top: 10px; border-radius: 50%; border: 0; background: var(--tile); color: var(--link); font-size: 28px; cursor: pointer; flex: none; }
pa-number .unit { display: block; text-align: center; color: var(--ink-2); margin-top: 6px; font-size: 15px; }
pa-scale { display: block; }
pa-scale .value { font-size: 64px; font-weight: 600; letter-spacing: -0.03em; text-align: center; line-height: 1; }
pa-scale .label { text-align: center; color: var(--ink-2); margin: 6px 0 14px; min-height: 1.5em; }
pa-scale input[type="range"] { width: 100%; accent-color: var(--accent); height: 36px; }
pa-scale .ends { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-3); }
.text-input {
  width: 100%; height: 56px; padding: 0 18px; font-size: 17px; border-radius: 14px; border: 0;
  background: var(--tile); color: var(--ink); font-family: var(--font);
}
.text-input:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* Slots */
pa-slots { display: block; }
.days { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 0 -20px 16px; padding-left: 20px; padding-right: 20px; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.day { flex: none; width: 64px; padding: 10px 0; border-radius: 18px; border: 0; background: var(--tile); text-align: center; cursor: pointer; transition: background 0.3s var(--spring); }
.day small { display: block; font-size: 12px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; }
.day b { display: block; font-size: 22px; font-weight: 600; }
.day[aria-pressed="true"] { background: var(--accent); color: #fff; }
.day[aria-pressed="true"] small { color: rgb(255 255 255 / 0.8); }
.times { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.time { min-height: 50px; border-radius: 980px; border: 0; background: var(--tile); font-weight: 500; cursor: pointer; transition: background 0.3s var(--spring); }
.time[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* Verify (Face ID) */
pa-verify { display: block; }
.faceid { width: 64px; height: 64px; margin: 4px auto 14px; display: block; color: var(--accent); }
.notice { display: flex; gap: 10px; padding: 14px 16px; border-radius: 16px; background: var(--tile); color: var(--ink); font-size: 15px; text-align: left; }
.notice.alert { background: var(--alert-tint); color: var(--alert-ink); flex-direction: column; gap: 10px; margin: 16px 0; }
.notice.alert b { font-size: 17px; }
.error { color: var(--alert-ink); font-size: 15px; margin-top: 8px; min-height: 1.2em; }

/* Consent */
.section { padding: 18px 0; }
.section + .section { box-shadow: 0 -1px 0 var(--fill); }
.section:first-child { padding-top: 4px; }
.keypoint { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.ack { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 8px; font-weight: 500; color: var(--link); cursor: pointer; }
.ack input, .agree input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.agree { display: flex; gap: 12px; align-items: flex-start; padding: 14px 0; cursor: pointer; }
.agree + .agree { box-shadow: 0 -1px 0 var(--fill); }
.feedback { font-size: 15px; margin-top: 8px; font-weight: 500; }
.feedback.good { color: var(--ink-2); }
.feedback.bad { color: var(--alert-ink); }

/* Results */
.result { text-align: center; padding: 32px 4px 8px; }
.result .badge { width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 18px; background: var(--accent); color: #fff; }
.result .badge.warn, .result .badge.neutral { background: var(--tile); color: var(--ink); }
.result .badge svg { width: 38px; height: 38px; }
.result h2 { font-size: 34px; letter-spacing: -0.02em; }
@keyframes pop { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.result .badge { animation: pop 0.7s var(--spring) both; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 15px; text-align: left; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

/* Study progress, streak and trends */
.ring { display: block; width: 132px; height: 132px; margin: 4px auto 0; }
.ring .track { stroke: var(--fill); }
.ring .fill { stroke: var(--accent); transition: stroke-dashoffset 1s var(--spring); }
.ring .ring-big { font: 600 34px var(--font); letter-spacing: -0.02em; fill: var(--ink); }
.ring .ring-small { font: 400 12px var(--font); fill: var(--ink-2); }
.streak { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; text-align: center; }
.streak span { font-size: 13px; color: var(--ink-2); }
.streak i { display: grid; place-items: center; width: 34px; height: 34px; margin: 6px auto 0; border-radius: 50%; background: var(--fill); font-style: normal; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.streak i.done { background: var(--accent); color: #fff; }
.streak i.today { box-shadow: inset 0 0 0 2px var(--accent); background: transparent; color: var(--link); }
.trend { display: grid; gap: 6px; }
.trend .head { display: flex; justify-content: space-between; align-items: baseline; }
.trend .now { font-size: 34px; font-weight: 600; letter-spacing: -0.02em; }
.trend .now small { font-size: 15px; font-weight: 400; color: var(--ink-2); }
.trend svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend polyline { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.trend circle { fill: var(--accent); }
.trend + .trend { margin-top: 18px; }

/* Motion: fade and rise into view on a spring. */
.skeleton { height: 18px; border-radius: 9px; background: linear-gradient(90deg, var(--tile), var(--fill), var(--tile)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 12px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.fade-in > * { animation: rise 0.7s var(--spring) both; }
.fade-in > *:nth-child(2) { animation-delay: 0.05s; }
.fade-in > *:nth-child(3) { animation-delay: 0.1s; }
.fade-in > *:nth-child(4) { animation-delay: 0.15s; }
.fade-in > *:nth-child(5) { animation-delay: 0.2s; }
.fade-in > *:nth-child(n + 6) { animation-delay: 0.25s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
