:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #141824;
  --muted: #5b6275;
  --border: #e3e6ef;
  --accent: #1d4ed8;
  --accent-soft: #dbe5ff;
  --ok: #15803d;
  --warn: #c2410c;
  --done-text: #8a90a2;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1118;
    --surface: #171b25;
    --text: #e8eaf1;
    --muted: #9aa1b5;
    --border: #262c3a;
    --accent: #7aa2ff;
    --accent-soft: #1e2a4d;
    --ok: #4ade80;
    --warn: #fb923c;
    --done-text: #6b7185;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
p { margin: 0.25rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

button, .button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.secondary, .button.secondary { background: var(--accent-soft); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type=password], input[type=date] {
  font: inherit;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  margin: 0.35rem 0 0.75rem;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.85rem 16px 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.ring {
  --pct: 0;
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--accent-soft) 0);
}
.ring span {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
}
.bar { height: 4px; background: var(--accent-soft); }
.bar > div { height: 100%; background: var(--accent); transition: width 0.3s ease; }
.bar.small { height: 6px; border-radius: 3px; overflow: hidden; margin: 0.5rem 0 0.25rem; }

/* Tabs */
.tabs {
  max-width: 720px;
  margin: 0.75rem auto 0;
  padding: 0 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}
.tabs button { background: transparent; color: var(--muted); padding: 0.55rem; }
.tabs button[aria-selected=true] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.75rem 16px calc(2rem + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.card h2 { margin-bottom: 0.35rem; }
.pace.ok strong { color: var(--ok); }
.pace.behind strong { color: var(--warn); }

.week-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 0.5rem;
}
.week-title { flex: 1; text-align: center; }
button.icon {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Lessons */
.lessons {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
details .lessons { border: 0; border-radius: 0; margin: 0; }
.lesson { display: flex; align-items: center; gap: 0.5rem; border-top: 1px solid var(--border); }
.lesson:first-child { border-top: 0; }
.lesson label {
  flex: 1;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.7rem 0 0.7rem 0.85rem;
  cursor: pointer;
  min-width: 0;
}
.lesson input[type=checkbox] {
  width: 20px;
  height: 20px;
  margin: 0.1rem 0 0;
  flex: none;
  accent-color: var(--accent);
}
.lesson-text { display: flex; flex-direction: column; min-width: 0; }
.lesson-title { overflow-wrap: anywhere; }
.lesson-meta { font-size: 0.8rem; color: var(--muted); }
.lesson.done .lesson-title { color: var(--done-text); text-decoration: line-through; }
.lesson .open {
  flex: none;
  padding: 0.7rem 0.85rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
}

.phase-head { display: flex; justify-content: space-between; align-items: baseline; }
.pct { font-weight: 600; color: var(--accent); }
details { border-top: 1px solid var(--border); margin: 0.75rem -1rem -1rem; }
details + details { margin-top: 0; }
summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
}
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; color: var(--muted); margin-right: -0.5rem; }
details[open] summary::before { content: "▾"; }
summary span:first-of-type { flex: 1; }

.steps { padding-left: 1.2rem; margin: 0.5rem 0 1rem; }
.steps li { margin-bottom: 0.35rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  z-index: 10;
}

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem 1.5rem;
  text-align: center;
}
.login-card form { text-align: left; margin-top: 1.25rem; }
.login-card button { width: 100%; }
.turnstile { min-height: 65px; margin-bottom: 0.75rem; }
.error { color: var(--warn); min-height: 1.4em; font-size: 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  .bar > div { transition: none; }
}
