:root {
  --bg: #f6f8fa; --card: #ffffff; --text: #1f2328; --muted: #656d76; --line: #d8dee4;
  --accent: #1f6feb; --accent-text: #ffffff;
  --red: #cf222e; --red-bg: #ffebe9; --amber: #9a6700; --amber-bg: #fff8c5;
  --blue: #0969da; --blue-bg: #ddf4ff; --green: #1a7f37; --gray-bg: #eaeef2;
  --radius: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #8d96a0; --line: #30363d;
    --accent: #2f81f7; --red: #ff7b72; --red-bg: #3a1d1f; --amber: #e3b341; --amber-bg: #3a2e12;
    --blue: #79c0ff; --blue-bg: #122a44; --green: #3fb950; --gray-bg: #21262d; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 96px; }
h1 { font-size: 18px; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
code { background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top form { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 7px; }

/* ---------- inputs & buttons (scoped to the app's own classes) ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.add input:not([type=checkbox]), .add select, .add textarea,
.edit input:not([type=checkbox]), .edit select, .edit textarea,
.toolbar input, .login input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; min-width: 0;
}
.add input:focus, .add select:focus, .add textarea:focus, .edit input:focus, .edit select:focus,
.edit textarea:focus, .toolbar input:focus, .login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; min-height: 40px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--red); }
.err { color: var(--red); margin: 8px 0 0; font-size: 14px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 12px; }
.stat { border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; }
.stat b { font-size: 24px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.red { background: var(--red-bg); } .stat.red b { color: var(--red); }
.stat.amber { background: var(--amber-bg); } .stat.amber b { color: var(--amber); }
.stat.blue { background: var(--blue-bg); } .stat.blue b { color: var(--blue); }
.stat.gray { background: var(--gray-bg); }
.stat.zero b { color: var(--muted); }

/* ---------- schoology sync ---------- */
.sync { display: flex; align-items: center; gap: 10px; margin: -4px 0 12px; padding: 4px 4px 4px 10px; font-size: 13px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.sync .msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sync[hidden] { display: none; }
.sync.bad { border-color: var(--red); color: var(--red); }
.src { background: #e8f1e4; color: #2d6a1f; border-radius: 5px; padding: 0 6px; font-size: 12px; }
@media (prefers-color-scheme: dark) { .src { background: #1c3319; color: #7ee07a; } }

/* ---------- add form ---------- */
.add { display: flex; flex-direction: column; gap: 8px; }
.add #add-title { flex: 1; font-size: 16px; }
.add .row.wrap > input[name=course] { flex: 2 1 160px; }
.add .row.wrap > select { flex: 1 1 120px; }
.add .row.wrap > input[type=date] { flex: 1 1 140px; }
.add .row.wrap > input[type=time] { flex: 1 1 110px; }
.add .row.wrap > input[type=url] { flex: 1 1 240px; }
.add textarea { width: 100%; margin-top: 8px; resize: vertical; }
.quick { flex-wrap: wrap; gap: 6px; }
.hint { color: var(--muted); font-size: 13px; }
.more summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 2px 0; }
.more[open] summary { margin-bottom: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.chip { min-height: 30px; padding: 3px 11px; border-radius: 999px; font-size: 13px; background: var(--card); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------- toolbar ---------- */
.toolbar { margin: 16px 0 4px; display: flex; flex-direction: column; gap: 8px; }
.toolbar input { width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- list ---------- */
.group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 6px; display: flex; gap: 8px; align-items: center; }
.group.g-overdue h2 { color: var(--red); }
.group.g-today h2 { color: var(--amber); }
.count { background: var(--gray-bg); color: var(--muted); border-radius: 999px; padding: 0 8px; font-size: 12px; }

.item {
  display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--line); border-radius: 10px; padding: 10px 8px 10px 10px; margin-bottom: 6px;
}
.item.b-overdue { border-left-color: var(--red); }
.item.b-today { border-left-color: var(--amber); }
.item.b-tomorrow, .item.b-week { border-left-color: var(--blue); }
.item.done { opacity: .6; border-left-color: var(--green); }
.item.done .title { text-decoration: line-through; }
.item .body { flex: 1; min-width: 0; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.title a { color: inherit; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.star { color: #d4a72c; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 2px; align-items: center; }
.b-overdue .due { color: var(--red); font-weight: 600; }
.b-today .due { color: var(--amber); font-weight: 600; }
.kind { background: var(--gray-bg); border-radius: 5px; padding: 0 6px; font-size: 12px; }
.kind.k-test, .kind.k-quiz { background: var(--red-bg); color: var(--red); }
.kind.k-project { background: var(--blue-bg); color: var(--blue); }
.kind.k-form { background: var(--amber-bg); color: var(--amber); }
.notes { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin-top: 4px; overflow-wrap: anywhere; }

.tick { position: relative; width: 26px; height: 26px; flex: none; margin-top: 1px; cursor: pointer; }
.tick input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.tick .box { position: absolute; inset: 0; border: 2px solid var(--muted); border-radius: 50%; }
.tick input:checked + .box { background: var(--green); border-color: var(--green); }
.tick input:checked + .box::after { content: ""; position: absolute; left: 8px; top: 3px; width: 6px; height: 12px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.tick input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; gap: 2px; flex: none; }
button.icon { border: 0; background: transparent; min-height: 34px; min-width: 34px; padding: 4px; color: var(--muted); font-size: 16px; }
button.icon:hover { background: var(--gray-bg); color: var(--text); }

.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.done-wrap { margin-top: 20px; }
.done-head { display: flex; justify-content: space-between; align-items: center; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 16px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.edit { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.edit h2 { margin: 0 0 4px; font-size: 17px; }
.edit label:not(.check) { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
/* flex-basis 只能给 .row 里的横排 label —— 落在纵向的 .edit 上会变成 160px 高度。 */
.edit .row > label { flex: 1 1 160px; }
.edit label input, .edit label select, .edit label textarea { color: var(--text); font-size: 15px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); border-radius: 10px; padding: 8px 8px 8px 14px;
  display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px); z-index: 10;
}
.toast[hidden] { display: none; }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 40%, transparent); min-height: 32px; padding: 3px 10px; }

/* ---------- login ---------- */
.login-body { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; }
.login { width: min(360px, calc(100vw - 32px)); margin-top: 14vh; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login .brand { margin-bottom: 18px; }
.login form { display: flex; flex-direction: column; gap: 8px; }
.login label { font-size: 13px; color: var(--muted); }
.login button { margin-top: 6px; background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .add .row.wrap > input[name=course] { flex-basis: 100%; }
}
