/* ---------- Colors ---------- */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1e407c;        /* Penn State Beaver Blue */
  --accent-text: #ffffff;
  --accent-soft: #e6edf7;
  --hero-1: #2b5aa8;
  --hero-2: #1e407c;
  --hero-3: #001e44;        /* Nittany Navy */
  --hot: #dc2626;
  --hot-soft: #fef2f2;
  --test: #b45309;
  --test-soft: #fef3c7;
  --ok: #059669;
  --ok-soft: #e7f6ef;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 14px -4px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 14px 30px -14px rgba(15, 23, 42, 0.35);
  --round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
:root[data-theme="midnight"] { --accent: #4338ca; --accent-soft: #eef2ff; --hero-1: #4f46e5; --hero-2: #312e81; --hero-3: #0b0b14; }
:root[data-theme="sunset"]   { --accent: #c2410c; --accent-soft: #fff1e6; --hero-1: #f97316; --hero-2: #db2777; --hero-3: #6d28d9; }
:root[data-theme="forest"]   { --accent: #15803d; --accent-soft: #e7f6ec; --hero-1: #22c55e; --hero-2: #15803d; --hero-3: #064e3b; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2c2c2e;
    --accent: #8fb3ea;
    --accent-text: #001e44;
    --accent-soft: #0f2340;
    --hot: #f87171;
    --hot-soft: #3b0d0d;
    --test: #fbbf24;
    --test-soft: #3a2a05;
    --ok: #34d399;
    --ok-soft: #062e22;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
    --shadow-lg: 0 14px 30px -14px rgba(0, 0, 0, 0.8);
  }
  :root[data-theme="midnight"] { --accent: #a5b4fc; --accent-text: #1e1b4b; --accent-soft: #1e1b4b; }
  :root[data-theme="sunset"]   { --accent: #fdba74; --accent-text: #431407; --accent-soft: #3b1a0a; }
  :root[data-theme="forest"]   { --accent: #86efac; --accent-text: #052e16; --accent-soft: #0b2a17; }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { overscroll-behavior-y: none; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
button, input, textarea { font: inherit; color: inherit; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.mini { width: 14px; height: 14px; vertical-align: -2px; stroke-width: 2.2; }

/* ---------- Launch screen ---------- */
#splash {
  position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: linear-gradient(160deg, var(--hero-1), var(--hero-3));
  color: #fff; font-family: var(--round); font-size: 26px; letter-spacing: -0.01em;
  transition: opacity 0.45s ease, transform 0.45s ease;
}
#splash img { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.5); animation: splash-pop 0.6s cubic-bezier(.2, 1.4, .4, 1); }
#splash.hide { opacity: 0; transform: scale(1.06); pointer-events: none; }
@keyframes splash-pop { from { transform: scale(0.7); opacity: 0; } }

/* ---------- Photo backdrop behind the Today header ---------- */
#backdrop {
  position: absolute; top: 0; left: 0; right: 0; height: 330px; z-index: 0; pointer-events: none;
  opacity: 0; transition: opacity 0.5s;
  background: radial-gradient(120% 90% at 15% 0%, color-mix(in srgb, var(--hero-1) 38%, transparent), transparent 70%),
              radial-gradient(90% 80% at 95% 10%, color-mix(in srgb, var(--hero-3) 26%, transparent), transparent 70%);
  -webkit-mask-image: linear-gradient(#000 45%, transparent);
  mask-image: linear-gradient(#000 45%, transparent);
}
#backdrop.photo { background-size: cover; background-position: center; filter: blur(26px) saturate(1.4); transform: scale(1.25); }
#backdrop.show { opacity: 0.55; }
#backdrop.photo.show { opacity: 0.6; }
@media (prefers-color-scheme: dark) { #backdrop.show { opacity: 0.45; } }

/* ---------- Pull to refresh ---------- */
#ptr {
  position: fixed; top: calc(env(safe-area-inset-top) + 4px); left: 50%; z-index: 30;
  transform: translate(-50%, -60px); opacity: 0; transition: transform 0.3s, opacity 0.3s; pointer-events: none;
}
#ptr img { width: 38px; height: 38px; border-radius: 11px; display: block; box-shadow: var(--shadow-lg); }
#ptr.armed img { outline: 3px solid var(--accent); outline-offset: 2px; }
#ptr.spinning { opacity: 1 !important; }
#ptr.spinning img { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Header + search ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 10px;
  background: transparent; transition: background 0.25s, box-shadow 0.25s;
}
body.scrolled .top {
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(1.8) blur(18px); backdrop-filter: saturate(1.8) blur(18px);
  box-shadow: 0 1px 0 var(--line);
}
.top-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
h1 {
  font-family: var(--round); font-size: 32px; font-weight: 800; margin: 0 0 10px; letter-spacing: -0.02em; line-height: 1.1; white-space: pre-line;
}
.eyebrow {
  margin: 6px 0 2px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent); min-height: 1em;
}
.round-btn {
  width: 40px; height: 40px; margin-bottom: 10px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); color: var(--muted); cursor: pointer;
}
.top-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.top-actions .round-btn { margin-bottom: 0; }
.update-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 14px; cursor: pointer;
  box-shadow: 0 6px 16px -6px var(--accent); animation: pop 0.35s ease-out, glow 2s ease-in-out 0.4s infinite;
}
.update-btn[hidden] { display: none; }
.update-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes glow { 50% { box-shadow: 0 0 0 6px var(--accent-soft); } }
.round-btn svg, .tabs svg, #assistant-fab svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.search input {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 0;
  background: color-mix(in srgb, var(--card) 88%, transparent); box-shadow: var(--shadow); font-size: 16px; outline: none;
}
.search input:focus { box-shadow: 0 0 0 2px var(--accent); }

main { position: relative; z-index: 1; padding: 4px 16px 16px; max-width: 640px; margin: 0 auto; }

/* Cards rise in one after another when you switch tabs. */
#view.enter > *, #view.enter .list > li { animation: rise 0.42s cubic-bezier(.2, .8, .2, 1) both; }
#view.enter > :nth-child(2) { animation-delay: 40ms; }
#view.enter > :nth-child(3) { animation-delay: 80ms; }
#view.enter > :nth-child(4) { animation-delay: 120ms; }
#view.enter > :nth-child(5) { animation-delay: 160ms; }
#view.enter > :nth-child(n+6) { animation-delay: 200ms; }
#view.enter .list > li:nth-child(2) { animation-delay: 220ms; }
#view.enter .list > li:nth-child(3) { animation-delay: 250ms; }
#view.enter .list > li:nth-child(n+4) { animation-delay: 280ms; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Bottom tabs (frosted) ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--card) 72%, transparent);
  -webkit-backdrop-filter: saturate(1.8) blur(20px); backdrop-filter: saturate(1.8) blur(20px);
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  position: relative; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 5px 0 4px; cursor: pointer; border-radius: 14px;
}
.tabs button::before {
  content: ''; position: absolute; inset: 1px 10px; border-radius: 14px; background: var(--accent-soft);
  opacity: 0; transform: scale(0.7); transition: opacity 0.25s, transform 0.3s cubic-bezier(.2, 1.4, .4, 1); z-index: -1;
}
.tabs svg { width: 24px; height: 24px; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active::before { opacity: 1; transform: scale(1); }
.tabs button.active svg { stroke-width: 2.2; }
.tabs button.bounce svg { animation: bounce 0.4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes bounce { 40% { transform: scale(0.82); } 100% { transform: scale(1); } }

/* ---------- Assistant button ---------- */
#assistant-fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; color: #fff;
  background: linear-gradient(140deg, var(--hero-1), var(--hero-3));
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--hero-2) 80%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.2s;
}
#assistant-fab:active { transform: scale(0.92); }
#assistant-fab svg { width: 24px; height: 24px; stroke-width: 2; }

/* ---------- Sections and lists ---------- */
.section { font-family: var(--round); font-size: 20px; font-weight: 700; margin: 24px 0 8px; letter-spacing: -0.01em; }
.day { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 18px 4px 6px; scroll-margin-top: 150px; border-radius: 8px; }
.section { scroll-margin-top: 150px; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 30% { background: var(--accent-soft); color: var(--accent); } }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 12px;
  background: color-mix(in srgb, var(--c, var(--accent)) 5%, var(--card));
  border-radius: 18px; padding: 13px 13px 13px 15px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
/* A colored stripe for the class on the left edge. */
.card::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--c, transparent); }
.card.urgent { box-shadow: var(--shadow), inset 0 0 0 1.5px var(--hot); }
.card.big { padding: 16px 14px 16px 17px; }
.card.big .card-title { font-size: 17px; }
.course { color: var(--c, var(--muted)); font-weight: 600; }
.course .ic { margin-right: 3px; }
.card.done .card-title { text-decoration: line-through; color: var(--muted); }
.card-body { flex: 1; min-width: 0; cursor: pointer; }
.card-title { font-weight: 600; overflow-wrap: anywhere; }
.card-meta { font-size: 14px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.emblem {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: color-mix(in srgb, var(--c, var(--accent)) 15%, var(--card)); color: var(--c, var(--accent));
}
.check {
  width: 28px; height: 28px; flex: none; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--c, var(--line)) 45%, var(--line));
  background: none; color: #fff; cursor: pointer; padding: 0; display: grid; place-items: center;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.check .ic { width: 16px; height: 16px; stroke-width: 3; opacity: 0; transform: scale(0.4); transition: opacity 0.2s, transform 0.3s cubic-bezier(.2, 1.6, .4, 1); }
.done .check, .completing .check { background: var(--ok); border-color: var(--ok); }
.done .check .ic, .completing .check .ic { opacity: 1; transform: none; }
.completing .check { animation: check-pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes check-pop { 50% { transform: scale(1.3); } }
.completing .card-title { text-decoration: line-through; color: var(--muted); }
li.completing { animation: slide-away 0.42s 0.12s ease-in forwards; }
@keyframes slide-away { to { opacity: 0; transform: translateX(40px); max-height: 0; margin-bottom: -10px; } }

.pill {
  flex: none; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.pill.calm { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--test-soft); color: var(--test); }
.pill.hot { background: var(--hot-soft); color: var(--hot); }
.tag {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 6px; vertical-align: 2px; margin-right: 5px;
  background: var(--test-soft); color: var(--test);
}
.tag.quiz { background: var(--accent-soft); color: var(--accent); }

/* ---------- Swipe actions ---------- */
li.swipe { position: relative; list-style: none; border-radius: 18px; }
li.swipe .card { transition: transform 0.3s cubic-bezier(.2, .8, .2, 1); z-index: 1; touch-action: pan-y; }
.swipe-bg {
  position: absolute; inset: 0; border-radius: 18px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; font-weight: 700; color: #fff; overflow: hidden;
}
.swipe-bg span { display: flex; align-items: center; gap: 6px; opacity: 0.55; transition: opacity 0.15s, transform 0.2s; }
.swipe-bg .ic { stroke-width: 2.6; }
li.swipe[data-dir="right"] .swipe-bg { background: var(--ok); }
li.swipe[data-dir="left"] .swipe-bg { background: #6366f1; justify-content: flex-end; }
li.swipe[data-dir="right"] .sb-snooze, li.swipe[data-dir="left"] .sb-done { display: none; }
li.swipe.armed .swipe-bg span { opacity: 1; transform: scale(1.12); }
li.swipe:not([data-dir]) .swipe-bg { display: none; }

/* ---------- "Next up" card ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 18px; margin-top: 6px; cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  color: #fff; background: linear-gradient(135deg, var(--hero-1) 0%, var(--hero-2) 50%, var(--hero-3) 100%);
  box-shadow: 0 16px 30px -16px color-mix(in srgb, var(--hero-3) 85%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.hero::after {
  content: ''; position: absolute; right: -50px; top: -60px; width: 190px; height: 190px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08); pointer-events: none;
}
.hero.warn { background: linear-gradient(135deg, #f59e0b 0%, #d97706 45%, #92400e 100%); }
.hero.hot { background: linear-gradient(135deg, #f43f5e 0%, #dc2626 45%, #7f1d1d 100%); }
.hero-text { flex: 1; min-width: 0; position: relative; z-index: 1; }
.hero .label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }
.hero .title { font-family: var(--round); font-size: 21px; font-weight: 700; margin: 6px 0 3px; line-height: 1.25; overflow-wrap: anywhere; }
.hero .meta { font-size: 14px; opacity: 0.85; }
.hero .tag { background: rgba(255, 255, 255, 0.22); color: #fff; }
.hero-ring { position: relative; flex: none; width: 92px; height: 92px; z-index: 1; }
.hero-ring .ring { display: block; }
.ring-arc { animation: ring-in 1s cubic-bezier(.2, .8, .2, 1); }
@keyframes ring-in { from { stroke-dashoffset: var(--len); } }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1; }
.ring-center b { font-family: var(--round); font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ring-center span { font-size: 11px; font-weight: 600; opacity: 0.85; margin-top: 3px; }
.hero.calm { background: linear-gradient(135deg, #34d399 0%, #059669 45%, #064e3b 100%); min-height: 150px; align-items: flex-end; cursor: default; }
.hero .grass { position: absolute; right: 0; bottom: 0; width: 240px; height: auto; pointer-events: none; }
.hero.calm .hero-text { max-width: 70%; }

/* ---------- Streak ---------- */
.streak {
  display: inline-flex; align-items: center; gap: 7px; margin: 4px 0 8px; padding: 7px 13px 7px 10px; border-radius: 999px; border: 0;
  background: color-mix(in srgb, #f97316 14%, var(--card)); color: var(--text); font-size: 14px; box-shadow: var(--shadow);
}
.streak .ic { color: #f97316; fill: color-mix(in srgb, #f97316 35%, transparent); }
.streak.late { background: var(--hot-soft); cursor: pointer; }
.streak.late .ic { color: var(--hot); fill: none; }

/* ---------- Week strip with daily load bars ---------- */
.week { margin-top: 14px; background: color-mix(in srgb, var(--card) 92%, transparent); border-radius: 20px; padding: 12px 8px 10px; box-shadow: var(--shadow); }
.week-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.wday {
  border: 0; background: none; padding: 4px 0; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; border-radius: 14px;
}
.wday:active { background: var(--accent-soft); }
.wday .wd { font-size: 11px; font-weight: 700; color: var(--muted); }
.wday .dn {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--round); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.wday.today .dn { background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 10px -4px var(--accent); }
.wday.free .dn { color: var(--muted); }
.wday .bar { height: 34px; width: 14px; display: flex; flex-direction: column-reverse; gap: 2px; align-items: stretch; }
.wday .bar i { display: block; border-radius: 3px; }
.wday .bar:empty::after { content: ''; display: block; height: 3px; border-radius: 3px; background: var(--line); }
.week-note { margin: 6px 8px 0; font-size: 13px; color: var(--muted); text-align: center; }
.week-note b { color: var(--text); }

/* ---------- Today stat tiles (widget style) ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat {
  position: relative; text-align: left; border: 0; border-radius: 22px; padding: 14px 12px 12px; cursor: pointer; min-height: 104px;
  background: color-mix(in srgb, var(--sc) 13%, var(--card)); box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: flex-end;
}
.stat-ic {
  position: absolute; top: 11px; left: 11px; width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--sc) 22%, var(--card)); color: var(--sc);
}
.stat-ic .ic { width: 17px; height: 17px; }
.stat .n { font-family: var(--round); font-size: 32px; font-weight: 800; display: block; letter-spacing: -0.02em; color: var(--sc, var(--text)); line-height: 1; margin-top: 30px; }
.stat .l { font-size: 12.5px; font-weight: 600; color: var(--muted); line-height: 1.2; display: block; margin-top: 4px; }

/* ---------- Later (compact) ---------- */
details.later { margin-top: 22px; background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 4px 14px; }
details.later summary { cursor: pointer; padding: 10px 0; font-family: var(--round); font-weight: 700; font-size: 17px; list-style: none; display: flex; align-items: center; gap: 8px; }
details.later summary::-webkit-details-marker { display: none; }
details.later summary::after { content: '›'; margin-left: auto; color: var(--muted); font-size: 22px; transition: transform 0.2s; }
details.later[open] summary::after { transform: rotate(90deg); }
.count { font-size: 12px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; }
.compact { list-style: none; margin: 0 0 8px; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; font-size: 15px; }
.row-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.row-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-date { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 22px 8px 0; }
.link-btn { display: block; margin: 14px auto 0; border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 14px; cursor: pointer; }

/* ---------- Grades ---------- */
.grade-ring { position: relative; width: 50px; height: 50px; flex: none; }
.grade-ring .ring { display: block; }
.grade { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--round); font-size: 16px; font-weight: 800; color: var(--muted); }
.grade.g-a { color: var(--ok); }
.grade.g-b { color: var(--accent); }
.grade.g-c { color: var(--test); }
.grade.g-low { color: var(--hot); }
.bell {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.bell .ic { width: 18px; height: 18px; }
.bell.off { background: var(--bg); color: var(--muted); box-shadow: 0 0 0 1px var(--line); }
details.howto { margin-top: 12px; font-size: 15px; }
details.howto summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.howto ol { padding-left: 20px; margin: 8px 0; }
details.howto li { margin: 4px 0; }

/* ---------- Buttons, chips, forms ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 11px 16px; background: var(--card); color: var(--text);
  box-shadow: var(--shadow); font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: transform 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 14px -8px var(--accent); }
.btn.danger { color: var(--hot); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.5; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; }
.row-actions .btn.primary { flex: 1; }
.icon-btn:focus:not(:focus-visible) { outline: none; }
.icon-btn { border: 0; background: none; padding: 6px; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; border-radius: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }
.chip {
  border: 0; border-radius: 999px; padding: 7px 14px; background: var(--card); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 4px; }
.toolbar .section { margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--hot); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.banner {
  background: var(--accent-soft); border-radius: 16px; padding: 12px 14px; margin: 8px 0;
  display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 15px;
}
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.add-row input { flex: 1; min-width: 0; }
input:not([type=search]):not([type=file]), textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-top: 12px; }
label input, label textarea { margin-top: 4px; color: var(--text); font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details.past { margin-top: 20px; }
details.past summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 8px; }

/* Theme picker */
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swatch {
  display: flex; align-items: center; gap: 10px; border: 0; border-radius: 14px; padding: 10px; cursor: pointer; text-align: left;
  background: var(--bg); font-weight: 600; font-size: 14px;
}
.swatch .sw { width: 28px; height: 28px; border-radius: 9px; background: linear-gradient(135deg, var(--sw1), var(--sw2)); flex: none; }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Photos ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.tile {
  position: relative; border: 0; padding: 0; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--line); cursor: pointer;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 12px; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,0.65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preview { width: 100%; max-height: 55vh; object-fit: contain; border-radius: 12px; background: var(--bg); }

/* ---------- Bottom sheet ---------- */
dialog#sheet {
  border: 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  margin: auto auto 0; border-radius: 24px 24px 0 0;
  background: var(--card); color: var(--text);
}
dialog#sheet[open] { animation: sheet-up 0.32s cubic-bezier(.2, .9, .3, 1); }
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0.4; } }
dialog#sheet::backdrop { background: rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 6px; font-family: var(--round); font-size: 22px; overflow-wrap: anywhere; }
dialog h3 { margin: 18px 0 6px; font-size: 16px; }
.sheet-course { color: var(--c); font-weight: 600; }
.notes { white-space: pre-wrap; background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 15px; overflow-wrap: anywhere; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.sheet-actions .danger { margin-right: auto; }
.late-sheet .list { margin-top: 10px; }

/* ---------- Voice assistant ---------- */
dialog#sheet.voice-sheet { height: 88vh; display: flex; flex-direction: column; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.voice { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.voice-head { display: flex; align-items: center; justify-content: space-between; }
.voice-head h2 { display: flex; align-items: center; gap: 8px; margin: 0; }
.voice-head h2 .ic { color: var(--accent); }
.chat { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px 2px; }
.chat-hello { color: var(--muted); text-align: center; margin: 18px 12px 12px; }
.suggest { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.suggest .chip { white-space: normal; text-align: center; font-weight: 500; }
.bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 20px; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere;
  animation: rise 0.25s ease-out;
}
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 6px; }
.bubble.error { color: var(--hot); }
.acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.act { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; padding: 4px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.typing { display: flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: dots 1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dots { 50% { opacity: 0.25; transform: translateY(-3px); } }
.orb-wrap { display: flex; flex-direction: column; align-items: center; padding: 6px 0 4px; }
.orb {
  position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; cursor: pointer; color: #fff; padding: 0;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--hero-1) 60%, #fff), var(--hero-1) 45%, var(--hero-3));
  box-shadow: 0 12px 30px -10px var(--hero-2), inset 0 2px 6px rgba(255, 255, 255, 0.35);
  transition: transform 0.25s;
}
.orb::before, .orb::after {
  content: ''; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--hero-1); opacity: 0; pointer-events: none;
}
.orb-core { display: grid; place-items: center; width: 100%; height: 100%; }
.orb .ic { width: 30px; height: 30px; stroke-width: 2; }
.orb[data-mode="listening"] { transform: scale(1.08); }
.orb[data-mode="listening"]::before { animation: ripple 1.4s ease-out infinite; }
.orb[data-mode="listening"]::after { animation: ripple 1.4s ease-out 0.7s infinite; }
.orb[data-mode="thinking"] { animation: breathe 1.2s ease-in-out infinite; }
.orb[data-mode="thinking"] .ic { opacity: 0.4; }
.orb[data-mode="speaking"] { animation: talk 0.5s ease-in-out infinite alternate; }
@keyframes ripple { from { opacity: 0.7; transform: scale(0.9); } to { opacity: 0; transform: scale(1.45); } }
@keyframes breathe { 50% { transform: scale(0.92); filter: hue-rotate(25deg); } }
@keyframes talk { from { transform: scale(1); } to { transform: scale(1.1); } }
.voice-status { margin: 10px 0 4px; min-height: 1.3em; font-size: 14px; color: var(--muted); text-align: center; max-width: 90%; }
.ask-row { margin-top: 6px; }
.ask-row .btn { padding: 0 14px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(146px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 15px;
  display: flex; align-items: center; gap: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.25s cubic-bezier(.2, 1.4, .4, 1);
  max-width: calc(100% - 32px); width: max-content; z-index: 20; box-shadow: var(--shadow-lg);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.show.has-action { pointer-events: auto; }
#toast button { border: 0; background: none; color: var(--accent-soft); font-weight: 700; cursor: pointer; padding: 2px 0; }

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* "Make an appointment" voice button on Today */
.voice-cta {
  width: 100%; margin-top: 12px; border: 0; cursor: pointer; text-align: left; color: var(--text);
  display: flex; align-items: center; gap: 14px; padding: 12px 16px 12px 12px; border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 9%, var(--card)); box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.voice-cta:active { transform: scale(0.98); }
.voice-cta-ic {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff;
  background: linear-gradient(140deg, var(--hero-1), var(--hero-3));
  box-shadow: 0 6px 14px -6px var(--hero-2);
  animation: cta-pulse 2.6s ease-in-out infinite;
}
.voice-cta-ic .ic { width: 22px; height: 22px; stroke-width: 2; }
.voice-cta-text { display: flex; flex-direction: column; min-width: 0; }
.voice-cta-text b { font-family: var(--round); font-size: 17px; }
.voice-cta-text small { color: var(--muted); font-size: 13px; margin-top: 1px; }
@keyframes cta-pulse { 0%, 70%, 100% { box-shadow: 0 6px 14px -6px var(--hero-2), 0 0 0 0 color-mix(in srgb, var(--hero-1) 40%, transparent); }
  35% { box-shadow: 0 6px 14px -6px var(--hero-2), 0 0 0 8px transparent; } }

/* ---------- Welcome / log in / create account (shown until someone signs in) ---------- */
#gate {
  position: fixed; inset: 0; z-index: 90; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
}
#gate[hidden] { display: none; }
body.gated { overflow: hidden; }
.gate-inner { max-width: 400px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.gate-welcome {
  position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(160deg, var(--hero-1), var(--hero-3)); color: #fff;
  padding: calc(env(safe-area-inset-top) + 64px) 24px calc(env(safe-area-inset-bottom) + 28px);
}
.gate-brand { text-align: center; }
.gate-brand img { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.5); }
.gate-brand h1 { font-family: var(--round); font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin: 18px 0 8px; }
.gate-brand p { margin: 0 auto; max-width: 300px; opacity: 0.85; font-size: 17px; }
.gate-buttons { width: 100%; max-width: 400px; margin: 0 auto; }
.gate-welcome .btn { width: 100%; padding: 15px; font-size: 17px; font-weight: 700; margin-top: 12px; }
.gate-welcome .btn.primary { background: #fff; color: var(--hero-3); box-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.6); }
.gate-welcome .btn.ghost { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: none; }
.gate-back { background: none; border: 0; color: var(--accent); font-size: 17px; padding: 6px 0; cursor: pointer; align-self: flex-start; }
.gate-title { font-family: var(--round); font-size: 32px; font-weight: 800; letter-spacing: -0.02em; margin: 18px 0 4px; }
.gate-sub { color: var(--muted); margin: 0 0 8px; }
.gate-form .btn.primary { width: 100%; padding: 14px; font-size: 17px; font-weight: 700; margin-top: 22px; }
.gate-error { color: var(--hot); font-size: 14px; margin: 12px 0 0; min-height: 1.2em; }
.gate-hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.gate-switch { margin-top: auto; padding-top: 28px; text-align: center; font-size: 13px; color: var(--muted); }
.gate-switch button { background: none; border: 0; padding: 4px; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.gate-forgot { display: block; margin: 8px 0 0 auto; background: none; border: 0; padding: 4px 0; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; }
