:root {
  --ink: #1B2A47;
  --ink-2: #4A5878;
  --ink-3: #7D88A1;
  --paper: #F3F6FA;
  --card: #FFFFFF;
  --line: #DCE3EE;
  --given: #2E8B67;
  --given-soft: #E3F3EC;
  --due: #E39A2D;
  --due-soft: #FDF1DD;
  --late: #CF4436;
  --late-soft: #FBE7E5;
  --psm: #6B4FB5;
  --psm-soft: #EEE9FA;
  --track: #E3E8F1;

  --display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --text: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E8EDF6;
    --ink-2: #B3BDD0;
    --ink-3: #7F8BA3;
    --paper: #0F1729;
    --card: #18223A;
    --line: #26324D;
    --given: #4CB98E;
    --given-soft: #173A30;
    --due: #F0B04F;
    --due-soft: #3B2E17;
    --late: #EE6A5C;
    --late-soft: #3D1F1E;
    --psm: #9E86E6;
    --psm-soft: #2A2348;
    --track: #26324D;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--psm); outline-offset: 2px; border-radius: 6px; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.015em; margin: 0; }

/* ---------- layout ---------- */

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0 8px;
}

.top-date { margin: 0; color: var(--ink-3); font-size: 14px; font-weight: 500; }

.view-title { font-size: 30px; line-height: 1.1; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-2);
  flex: none;
}

.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  margin: 8px 0 0;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--late-soft);
  color: var(--late);
  font-size: 14px;
  font-weight: 500;
}

.view { outline: none; }

.section { margin-top: 28px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-head h2 { font-size: 20px; }

.section-head .count { color: var(--ink-3); font-size: 14px; font-weight: 600; }

.empty {
  padding: 18px;
  border: 1.5px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--ink-3);
  font-size: 15px;
  text-align: center;
}

/* ---------- dose ring hero ---------- */

.hero {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 20px;
  align-items: center;
  margin-top: 12px;
  padding: 20px;
  background: var(--ink);
  color: #F3F6FA;
  border-radius: var(--r-lg);
}

.ring { position: relative; width: 132px; height: 132px; }

.ring svg { width: 132px; height: 132px; transform: rotate(-90deg); }

.ring circle { fill: none; stroke-width: 12; }

.ring .ring-track { stroke: rgba(255, 255, 255, 0.12); }

.ring .ring-seg { stroke-linecap: butt; transition: stroke 0.35s ease; }

.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.ring-label strong { font: 800 34px/1 var(--display); }

.ring-label span { font-size: 12px; color: rgba(243, 246, 250, 0.7); margin-top: 4px; }

.hero-copy h2 { font-size: 22px; line-height: 1.2; }

.hero-copy p { margin: 6px 0 0; color: rgba(243, 246, 250, 0.75); font-size: 15px; }

.hero-stats { display: flex; gap: 16px; margin-top: 14px; flex-wrap: wrap; }

.hero-stats div { font-size: 13px; color: rgba(243, 246, 250, 0.7); }

.hero-stats b { display: block; font: 700 20px/1.1 var(--display); color: #F3F6FA; }

/* ---------- task rows ---------- */

.list { display: grid; gap: 10px; }

.task {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 14px 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--due);
  border-radius: var(--r-md);
}

.task.late { border-left-color: var(--late); }

.task.psm { border-left-color: var(--psm); }

.task.given { border-left-color: var(--given); opacity: 0.6; }

.task-main { min-width: 0; }

.task-title { margin: 0; font-weight: 600; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }

.task.given .task-title { text-decoration: line-through; }

.task-meta { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-3); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--track);
  color: var(--ink-2);
}

.chip.due { background: var(--due-soft); color: #9A6312; }
.chip.late { background: var(--late-soft); color: var(--late); }
.chip.psm { background: var(--psm-soft); color: var(--psm); }
.chip.given { background: var(--given-soft); color: var(--given); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip.due { color: var(--due); }
}

/* the dose tick: a big round target */
.tick {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2.5px solid var(--line);
  background: var(--card);
  display: grid;
  place-items: center;
  color: transparent;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.tick svg { width: 26px; height: 26px; stroke-width: 3; }

.tick:hover { border-color: var(--given); }

.tick:active { transform: scale(0.92); }

.tick[aria-pressed="true"] { background: var(--given); border-color: var(--given); color: #fff; }

.tick:disabled { opacity: 0.5; cursor: progress; }

/* ---------- PSM ---------- */

.progress-card {
  margin-top: 12px;
  padding: 18px;
  background: var(--psm-soft);
  border-radius: var(--r-lg);
}

.progress-card .big { font: 800 40px/1 var(--display); color: var(--psm); }

.progress-card .big small { font-size: 18px; font-weight: 600; color: var(--ink-2); }

.progress-card p { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; }

.bar { height: 10px; margin-top: 14px; background: rgba(107, 79, 181, 0.18); border-radius: 999px; overflow: hidden; }

.bar span { display: block; height: 100%; background: var(--psm); border-radius: 999px; transition: width 0.4s ease; }

.chapter {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 12px 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.chapter.is-today { border: 2px solid var(--psm); }

.chapter-day { font: 700 15px/1 var(--display); color: var(--ink-3); text-align: center; }

.chapter.done .chapter-title { text-decoration: line-through; color: var(--ink-3); }

.chapter-title { margin: 0; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }

.chapter .task-meta { margin-top: 4px; }

/* ---------- mistakes ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }

.stat { padding: 14px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); }

.stat b { display: block; font: 800 24px/1.1 var(--display); }

.stat span { font-size: 13px; color: var(--ink-3); }

.stat.alert b { color: var(--late); }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; margin: 18px -16px 0; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }

.filters::-webkit-scrollbar { display: none; }

.filter {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}

.filter[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.mistake {
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.mistake.revisit { border-color: var(--due); box-shadow: inset 4px 0 0 var(--due); }

.mistake.done { opacity: 0.65; }

.mistake-q { margin: 8px 0 0; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; font-size: 14px; }

.answers div { padding: 8px 10px; border-radius: var(--r-sm); }

.answers .wrong { background: var(--late-soft); }

.answers .right { background: var(--given-soft); }

.answers small { display: block; font-size: 12px; color: var(--ink-3); font-weight: 600; }

.fact {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--given);
  background: var(--paper);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.mistake-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-weight: 600;
  font-size: 14px;
}

.check[aria-pressed="true"] { background: var(--given-soft); border-color: var(--given); color: var(--given); }

.check svg { width: 18px; height: 18px; stroke-width: 3; }

.fab {
  position: fixed;
  right: max(16px, calc(50% - 320px + 16px));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--late);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(207, 68, 54, 0.35);
  z-index: 5;
}

/* ---------- plan ---------- */

.day-group { margin-top: 20px; }

.day-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }

.day-head h3 { font-size: 17px; }

.day-head span { color: var(--ink-3); font-size: 13px; }

.doses { display: inline-flex; gap: 4px; }

.dose { width: 26px; height: 20px; border-radius: 6px; font-size: 11px; font-weight: 700; display: grid; place-items: center; background: var(--track); color: var(--ink-3); }

.dose.given { background: var(--given); color: #fff; }

.dose.due { background: var(--due); color: #fff; }

.dose.late { background: var(--late); color: #fff; }

.plan-row { padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); }

.plan-row .task-title { font-size: 15px; font-weight: 500; }

.sheet-link { display: inline-flex; margin-top: 28px; color: var(--ink-2); font-weight: 600; }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 640px;
  margin: 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 10;
}

.tabbar button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
}

.tabbar button[aria-current="page"] { color: var(--ink); }

.tabbar button[aria-current="page"] svg { stroke-width: 2.5; }

@media (min-width: 680px) {
  .tabbar { border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; }
}

/* ---------- gate, dialog, forms ---------- */

.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }

.gate-card { width: 100%; max-width: 360px; display: grid; gap: 14px; }

.gate-card img { border-radius: 14px; }

.gate-card h1 { font-size: 28px; }

.gate-card p { margin: 0; color: var(--ink-2); }

.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
}

.field textarea { resize: vertical; }

.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--psm); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn-primary {
  min-height: 50px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
  font-size: 16px;
}

.btn-primary:disabled { opacity: 0.6; }

.form-error { margin: 0; min-height: 1em; color: var(--late); font-size: 14px; font-weight: 600; }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  color: var(--ink);
}

@media (min-width: 680px) { .sheet { margin: auto; border-radius: 22px; } }

.sheet::backdrop { background: rgba(10, 16, 30, 0.5); }

.sheet[open] { animation: rise 0.25s ease-out; }

@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.sheet-body { display: grid; gap: 12px; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }

.sheet-head { display: flex; justify-content: space-between; align-items: center; }

.sheet-head h2 { font-size: 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 12px 12px 12px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--r-md);
  box-shadow: 0 10px 30px rgba(10, 16, 30, 0.3);
  font-size: 15px;
  z-index: 20;
}

.toast button { border: 0; background: none; color: #8FD9B8; font-weight: 700; padding: 6px 8px; }

/* skeleton while first load */
.skeleton { height: 76px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--track), var(--card), var(--track)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }

@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 380px) {
  .hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .hero-stats { justify-content: center; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* fixes after review */
.check { white-space: nowrap; flex: none; }
.view:has(.fab) { padding-bottom: 76px; }
.hero-stats { gap: 18px; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; }
