:root {
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e4e0d6;
  --accent: #2f6fdf;
  --today: #fff6d6;
  --math: #2f6fdf;
  --math-bg: #e8f0fd;
  --science: #1f8a5b;
  --science-bg: #e3f4ec;
  --exam: #c8412f;
  --exam-bg: #fbe7e3;
  --revision: #7a4fc9;
  --revision-bg: #efe8fb;
  --other: #8a6d1f;
  --other-bg: #f6efd9;
  --spelling: #b5487a;
  --spelling-bg: #f9e6ef;
  --good-bg: #e3f4ec;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --card: #1e2125; --ink: #e8e6e1; --muted: #9aa0a8; --line: #2e3238; --accent: #7aa7ff; --today: #332d17;
    --math: #86adff; --math-bg: #1c2a44; --science: #6fd3a3; --science-bg: #17332a; --exam: #ff8a78; --exam-bg: #3d211d;
    --revision: #b9a0ff; --revision-bg: #2a2140; --other: #e3c46b; --other-bg: #332b15; --spelling: #f29ac2; --spelling-bg: #3a1f2d; --good-bg: #17332a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --card: #1e2125; --ink: #e8e6e1; --muted: #9aa0a8; --line: #2e3238; --accent: #7aa7ff; --today: #332d17;
  --math: #86adff; --math-bg: #1c2a44; --science: #6fd3a3; --science-bg: #17332a; --exam: #ff8a78; --exam-bg: #3d211d;
  --revision: #b9a0ff; --revision-bg: #2a2140; --other: #e3c46b; --other-bg: #332b15; --spelling: #f29ac2; --spelling-bg: #3a1f2d; --good-bg: #17332a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Noto Sans CJK SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 1.6rem; margin: 8px 0 4px; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 10px 18px; min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--exam); }
.icon-btn { border: 0; background: none; font-size: 1.5rem; min-width: 44px; min-height: 44px; border-radius: 12px; }

/* Profiles */
.profiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 24px; }
.profile {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 28px 16px;
  text-align: center; font-size: 1.3rem;
}
.profile .emoji { font-size: 4rem; display: block; line-height: 1.2; }
.profile .lvl { color: var(--muted); font-size: 1rem; }

/* Exam countdowns */
.countdowns { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.count {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  border-top: 4px solid var(--c, var(--exam));
}
.count .days { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.count .date-big { font-size: 1.35rem; font-weight: 700; line-height: 1.25; margin-bottom: 2px; }
.count .what { font-weight: 600; }
.tbc { font-size: .75rem; background: var(--other-bg); color: var(--other); border-radius: 6px; padding: 1px 6px; margin-left: 4px; white-space: nowrap; }

/* Agenda */
.week { margin-bottom: 18px; }
.week-label { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px 4px; }
.day { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px; }
.day.today { background: var(--today); }
.day .date { width: 64px; flex: none; text-align: center; }
.day .date b { display: block; font-size: 1.4rem; line-height: 1.1; }
.day .date span { font-size: .8rem; color: var(--muted); }
.items { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.item { border-radius: 10px; padding: 6px 10px; background: var(--b); color: var(--ink); border-left: 4px solid var(--c); }
.item .sub { font-size: .75rem; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: .03em; }
.item .lv { font-size: .75rem; color: var(--muted); margin-left: 6px; }
.s-math { --c: var(--math); --b: var(--math-bg); }
.s-science { --c: var(--science); --b: var(--science-bg); }
.s-exam { --c: var(--exam); --b: var(--exam-bg); }
.s-revision { --c: var(--revision); --b: var(--revision-bg); }
.s-other { --c: var(--other); --b: var(--other-bg); }
.s-spelling { --c: var(--spelling); --b: var(--spelling-bg); }

/* Home */
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 600; white-space: nowrap; }
.test-group { border-left: 4px solid var(--c); }
.test-group .sub, .todo-item .sub { font-size: .75rem; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: .03em; }
.test-row { padding: 6px 0; border-top: 1px solid var(--line); }
.test-group .sub + .test-row { border-top: 0; }
.todo { display: flex; flex-direction: column; gap: 8px; }
.todo-item { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: var(--radius); padding: 12px 14px; min-height: 64px; }
.todo-item .tick { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--c); display: grid; place-items: center; font-weight: 700; color: #fff; }
.todo-item.done .tick { background: var(--c); }
.todo-item.done .todo-title { text-decoration: line-through; color: var(--muted); }
.todo-text { display: flex; flex-direction: column; min-width: 0; }
.todo-title { font-weight: 600; }
.notice.good { background: var(--good-bg); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { display: grid; place-items: center; min-height: 88px; border-radius: var(--radius); background: var(--b); color: var(--c); font-weight: 700; font-size: 1.2rem; text-decoration: none; border: 1px solid var(--line); }
.field { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); padding: 8px 10px; background: var(--bg); }
/* D2: younger learners get bigger targets and type. */
.young { font-size: 1.12em; }
.young .todo-item { min-height: 80px; }
.young .tile { min-height: 110px; font-size: 1.4rem; }

.notice { background: var(--other-bg); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* Settings */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.form label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); gap: 4px; }
.form input, .form select { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; min-height: 44px; }
.form .check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 1rem; }
.form .check input { min-height: auto; width: 22px; height: 22px; }
.days-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.days-pick button { width: 48px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.days-pick button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.err { color: var(--exam); font-size: .9rem; min-height: 1.2em; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  .day .date { width: 48px; }
  .profile .emoji { font-size: 3rem; }
  .count .days { font-size: 1.5rem; }
}
