:root {
  /* calming, warm "paper" palette */
  --bg: #f4f1ea;
  --bg-2: #ece7dd;
  --card: #ffffff;
  --ink: #2a2a2f;
  --ink-soft: #55535c;
  --muted: #9b958a;
  --line: #ebe6dd;

  --brand: #3a9d92;       /* sage teal */
  --ot: #5b8def;          /* soft blue */
  --speech: #9b87e0;      /* soft violet */
  --aba: #ee9f54;         /* warm amber */

  --green: #46b07e;
  --red: #e8766c;
  --amber: #f0a45b;
  --grey: #c7c1b6;

  --shadow: 0 1px 2px rgba(40,35,25,.04), 0 6px 18px rgba(40,35,25,.05);
  --radius: 20px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 60px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141417;
    --bg-2: #1c1c20;
    --card: #1f1f24;
    --ink: #f1efe9;
    --ink-soft: #c9c6bf;
    --muted: #8a867e;
    --line: #2c2c32;
    --brand: #4cbcae;
    --green: #4fbc89;
    --red: #ee8278;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
#app { min-height: 100vh; }

/* helper: soft tint from an accent color */
.tint-OT { --accent: var(--ot); }
.tint-Speech { --accent: var(--speech); }
.tint-ABA { --accent: var(--aba); }

/* ---------- iOS large-title header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(var(--safe-top) + 18px) 20px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}
.topbar h1 { font-size: 30px; font-weight: 800; margin: 0; letter-spacing: -0.02em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--brand); color: #fff; font-size: 24px; line-height: 1;
  cursor: pointer; box-shadow: var(--shadow); flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; padding-bottom: 2px;
}
.icon-btn:active { transform: scale(0.9); }

/* ---------- Main view ---------- */
#view {
  padding: 8px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
  max-width: 720px; margin: 0 auto;
}
.section-title {
  font-size: 13px; font-weight: 700; letter-spacing: .04em; color: var(--muted);
  margin: 22px 6px 10px; text-transform: uppercase;
}
.greeting { color: var(--muted); font-size: 15px; margin: 0 6px 4px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- header actions + inline icons ---------- */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.ghost { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--ink); }
.ic { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; margin-right: 7px; color: inherit; }
.ic svg { width: 100%; height: 100%; display: block; }

/* ---------- track section header ---------- */
.track-head {
  display: flex; align-items: center; gap: 9px;
  font-size: 16px; font-weight: 800; letter-spacing: -0.01em;
  margin: 6px 4px 12px; color: var(--ink);
}
.track-head .ic { width: 22px; height: 22px; vertical-align: middle; margin: 0; color: var(--brand); }
.card h2 .ic, .section-title .ic { color: var(--brand); }

/* ---------- "as of today" headline ---------- */
.todate {
  margin-top: 10px; font-size: 13px; color: var(--ink-soft);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  padding: 9px 11px; border-radius: 11px; line-height: 1.35;
}
.todate strong { color: var(--ink); font-weight: 800; }

/* ---------- stepper ---------- */
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: 0 0 auto; }
.stepper button {
  width: 42px; height: 42px; border: none; background: var(--bg-2); color: var(--ink);
  font-size: 22px; font-weight: 700; cursor: pointer; line-height: 1;
}
.stepper button:active { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.stepper .stepper-n { min-width: 46px; text-align: center; font-weight: 800; font-size: 18px; }

/* ---------- per-plan breakdown bar ---------- */
.statbar { display: flex; height: 16px; border-radius: 999px; overflow: hidden; background: var(--bg-2); margin: 12px 0 14px; }
.statbar span { display: block; transition: flex .3s; }

/* ---------- settings ---------- */
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.switch {
  position: relative; width: 50px; height: 30px; flex: 0 0 auto; cursor: pointer;
  appearance: none; -webkit-appearance: none; background: var(--line); border: none; border-radius: 999px;
  transition: background .2s;
}
.switch:checked { background: var(--green); }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch:checked::after { transform: translateX(20px); }

/* ---------- Donut / ring ---------- */
.donut { position: relative; display: inline-grid; place-items: center; }
.donut-center {
  position: absolute; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.donut-center .big { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.donut-center .lbl { font-size: 11px; color: var(--muted); margin-top: 3px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 4px; }
.legend span { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.stat-flex { display: flex; align-items: center; gap: 18px; }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow);
}
.tile .num { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.tile .cap { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.flame .num { color: var(--amber); }

/* ---------- Streak banner ---------- */
.streak {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--amber) 22%, var(--card)), var(--card));
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.streak .flame-ico { font-size: 34px; }
.streak .n { font-size: 24px; font-weight: 800; }
.streak .t { font-size: 13px; color: var(--ink-soft); }

/* ---------- Heatmap ---------- */
.heatmap {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 4px; overflow-x: auto; padding-bottom: 2px;
}
.hm-cell {
  width: 13px; height: 13px; border-radius: 4px; display: block;
  background: color-mix(in srgb, var(--muted) 16%, transparent);
}
.hm-legend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 8px; font-size: 11px; color: var(--muted); }
.hm-legend i { width: 12px; height: 12px; border-radius: 4px; }

/* ---------- Plan cards (with ring) ---------- */
.plan-card {
  display: flex; align-items: center; gap: 16px; cursor: pointer;
  border-left: 4px solid var(--accent, var(--brand));
}
.plan-card .ring-wrap { flex: 0 0 auto; }
.plan-card .info { flex: 1; min-width: 0; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px; margin-bottom: 6px;
  color: var(--accent, var(--brand));
  background: color-mix(in srgb, var(--accent, var(--brand)) 16%, transparent);
}
.plan-card .info h2 { font-size: 16px; }
.plan-card .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.plan-card .counts { font-size: 13px; color: var(--ink-soft); margin-top: 8px; display: flex; gap: 12px; }
.plan-card .chev { color: var(--muted); font-size: 22px; flex: 0 0 auto; }

/* ---------- Timeline (program detail) ---------- */
.timeline { position: relative; margin: 8px 0 4px; padding-left: 6px; }
.timeline::before {
  content: ""; position: absolute; left: 16px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px;
  background: linear-gradient(var(--ot), var(--speech), var(--aba), var(--green));
  opacity: .35;
}
.tl-item { position: relative; display: flex; gap: 14px; padding: 0 0 12px 0; }
.tl-node {
  position: relative; z-index: 1; flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--grey);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800;
  color: var(--muted); box-shadow: 0 0 0 4px var(--bg);
}
.tl-item.attended .tl-node { border-color: var(--green); color: var(--green); }
.tl-item.missed .tl-node { border-color: var(--red); color: var(--red); }
.tl-card {
  flex: 1; background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
  cursor: pointer;
}
.tl-card .tl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tl-card .tl-num { font-weight: 700; font-size: 15px; }
.tl-card .tl-date { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tl-card .tl-notes { color: var(--ink-soft); font-size: 13px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-card .tl-docs { font-size: 12px; color: var(--brand); margin-top: 6px; }

/* ---------- Status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.pill.yes { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.pill.no { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.pill.none { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 14px; padding: 14px 16px;
  font-size: 15px; font-weight: 700; cursor: pointer; width: 100%;
  background: var(--brand); color: #fff;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--ink); }
.btn.danger { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.btn.small { width: auto; padding: 9px 14px; font-size: 13px; border-radius: 12px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 14px; font-size: 14px; font-weight: 600; }
label.field span { display: block; margin-bottom: 7px; }
input, select, textarea {
  width: 100%; padding: 13px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--ink); font-size: 16px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); border-color: var(--brand); }
textarea { min-height: 84px; resize: vertical; }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 13px; border-radius: 13px; border: 1.5px solid var(--line);
  background: var(--bg-2); color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer;
  transition: all .12s;
}
.seg button.on-brand { background: var(--brand); color: #fff; border-color: var(--brand); }
.seg button.on-OT { background: var(--ot); color: #fff; border-color: var(--ot); }
.seg button.on-Speech { background: var(--speech); color: #fff; border-color: var(--speech); }
.seg button.on-ABA { background: var(--aba); color: #fff; border-color: var(--aba); }
.seg button.on-green { background: var(--green); color: #fff; border-color: var(--green); }
.seg button.on-red { background: var(--red); color: #fff; border-color: var(--red); }

/* ---------- Daily checklist ---------- */
.check-item { display: flex; align-items: center; gap: 13px; padding: 14px 2px; border-bottom: 1px solid var(--line); }
.check-item:last-child { border-bottom: none; }
.check-box {
  width: 27px; height: 27px; border-radius: 9px; border: 2px solid var(--line);
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center; font-size: 16px; color: #fff;
  transition: all .15s;
}
.check-item.done .check-box { background: var(--green); border-color: var(--green); transform: scale(1.05); }
.check-item.done .check-text { text-decoration: line-through; color: var(--muted); }
.check-text { flex: 1; font-size: 15px; }
.check-cat { font-size: 10.5px; font-weight: 800; padding: 3px 9px; border-radius: 999px; color: #fff; }

/* ---------- Resources ---------- */
.res-item { display: block; text-decoration: none; color: inherit; }
.res-item h3 { margin: 0 0 4px; font-size: 15px; }
.res-item p { margin: 0; color: var(--muted); font-size: 13px; }
.res-item .host { color: var(--brand); font-size: 12px; font-weight: 700; margin-top: 8px; display: inline-block; }

/* ---------- Documents ---------- */
.doc-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc-row .doc-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Empty state ---------- */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 50px; margin-bottom: 12px; }
.empty p { margin: 0 0 18px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--tabbar-h) + 8px + var(--safe-bottom));
  padding: 6px 6px var(--safe-bottom);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 0; -webkit-tap-highlight-color: transparent;
}
.tab .tab-ico {
  display: flex; align-items: center; justify-content: center;
  width: 60px; height: 30px; border-radius: 999px; position: relative;
  transition: background .22s ease, transform .22s cubic-bezier(.2,.8,.2,1);
}
.tab .tab-ico svg {
  width: 24px; height: 24px; display: block;
  transition: stroke-width .2s ease, transform .22s cubic-bezier(.2,.8,.2,1);
}
.tab .tab-lbl { font-size: 11px; font-weight: 600; letter-spacing: .01em; transition: color .2s, font-weight .2s; }

/* press feedback */
.tab:active .tab-ico { transform: scale(.88); }

/* active state: tinted pill + accent color + slightly bolder stroke */
.tab.active { color: var(--brand); }
.tab.active .tab-ico { background: color-mix(in srgb, var(--brand) 15%, transparent); }
.tab.active .tab-ico svg { stroke-width: 2.3; transform: translateY(-0.5px); }
.tab.active .tab-lbl { font-weight: 700; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20,18,14,.42); display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--bg); width: 100%; max-width: 560px;
  border-radius: 24px 24px 0 0; padding: 18px 18px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto; animation: slideup .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h2 { margin: 0 0 4px; font-size: 21px; font-weight: 800; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.modal-handle { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 0 auto 16px; }
@media (min-width: 600px) { .modal-overlay { align-items: center; } .modal { border-radius: 24px; } }
