:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a2027;
  --muted: #67707c;
  --line: #e3e6ea;
  --accent: #3565d6;
  --danger: #c93a3a;
  --done: #8a929c;
  --overdue: #c93a3a;
  --chip-bg: #e9ecf0;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --card: #1a2027;
    --text: #e8ebee;
    --muted: #97a0ab;
    --line: #2a323c;
    --accent: #6d95f0;
    --danger: #e26060;
    --done: #6b7480;
    --overdue: #e26060;
    --chip-bg: #232b34;
    --shadow: 0 1px 3px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px;
}
.login-card {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 24px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 16px;
}
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.login-err { color: var(--danger); font-size: 14px; margin: 12px 0 0; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px calc(10px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 0 0 auto; }
.view-toggle {
  display: flex; background: var(--chip-bg); border-radius: 10px; padding: 3px; margin-left: auto;
}
.view-toggle button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
.view-toggle button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 20px; padding: 4px 10px; border-radius: 8px;
}
.menu {
  position: absolute; right: 10px; top: 54px; z-index: 30;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; min-width: 200px;
}
.menu-row { display: flex; gap: 8px; align-items: center; padding: 10px 12px; font-size: 15px; width: 100%; }
.menu-btn { border: 0; background: none; color: var(--danger); text-align: left; }

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--chip-bg);
  color: var(--text); border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 500;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.view { padding: 4px 14px 120px; max-width: 720px; margin: 0 auto; }

/* ---------- task list ---------- */
.group-h {
  margin: 18px 2px 8px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.group-h.overdue { color: var(--overdue); }
.group-h .count { font-weight: 500; }
.task {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.task input[type=checkbox] {
  width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto;
}
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 500; word-wrap: break-word; }
.task.done .task-title { color: var(--done); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 4px; font-size: 13px; color: var(--muted); align-items: center; }
.course-tag {
  display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12px;
  padding: 1px 8px; border-radius: 999px; color: #fff;
}
.badge { font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--chip-bg); }
.badge.ec { background: #8a6d1a22; color: #b08900; }
.due.overdue { color: var(--overdue); font-weight: 600; }
.due.today { color: var(--accent); font-weight: 600; }
.task-notes { margin-top: 6px; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px; }
.cal-head h2 { font-size: 17px; margin: 0; }
.cal-head .icon-btn { font-size: 24px; }
.cal-dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow div { text-align: center; font-size: 11px; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal-day {
  min-height: 52px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); padding: 4px; font-size: 12px; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
.cal-day.out { opacity: .35; }
.cal-day.today { border-color: var(--accent); border-width: 2px; }
.cal-day.sel { background: var(--accent); color: #fff; }
.cal-day .n { font-weight: 600; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; max-width: 100%; }
.cal-dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.agenda { margin-top: 14px; }
.agenda h3 { font-size: 14px; color: var(--muted); margin: 16px 2px 8px; }
.ev {
  display: flex; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--muted); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px;
}
.ev-time { flex: 0 0 auto; font-size: 13px; color: var(--muted); min-width: 64px; }
.ev-body { min-width: 0; }
.ev-title { font-weight: 500; font-size: 15px; }
.ev-sub { font-size: 13px; color: var(--muted); }

/* ---------- fab & sheet ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
dialog#sheet {
  border: 0; border-radius: 20px 20px 0 0; padding: 0;
  width: 100%; max-width: 560px; margin: auto auto 0;
  background: var(--card); color: var(--text);
}
dialog#sheet::backdrop { background: rgba(0,0,0,.45); }
#sheet-form { padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 4px; }
#sheet h2 { font-size: 17px; margin: 8px 0 14px; }
#sheet label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
#sheet .hint { font-weight: 400; }
#sheet input, #sheet select, #sheet textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px 12px; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; align-items: center; }
.sheet-actions .spacer { flex: 1; }
.sheet-actions button { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--chip-bg); color: var(--text); }
.sheet-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.sheet-actions .danger { background: transparent; border-color: var(--danger); color: var(--danger); }

@media (min-width: 700px) {
  dialog#sheet { border-radius: 16px; margin: auto; }
  .cal-day { min-height: 74px; }
}
