:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f3f9;
  --text: #171a21;
  --muted: #646b7a;
  --line: #e3e6ef;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --red: #dc2626; --red-bg: #fde8e8;
  --orange: #c2410c; --orange-bg: #ffedd5;
  --green: #15803d; --green-bg: #dcfce7;
  --blue: #1d4ed8; --blue-bg: #dbeafe;
  --purple: #7e22ce; --purple-bg: #f3e8ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --panel-2: #1e222b; --text: #e8eaf0; --muted: #9aa1b0; --line: #2a2f3a;
    --accent: #818cf8; --accent-text: #0f1115;
    --red: #f87171; --red-bg: #3a1a1a; --orange: #fb923c; --orange-bg: #3a2414;
    --green: #4ade80; --green-bg: #143020; --blue: #93c5fd; --blue-bg: #172540; --purple: #d8b4fe; --purple-bg: #2c1a40;
    --shadow: none;
    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 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 .4rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#sidebar {
  position: fixed; inset: 0 auto 0 0; width: 260px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto; padding: 14px 10px;
}
#wrap { margin-left: 260px; min-height: 100vh; }
#topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
}
#topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#main { max-width: 1100px; padding: 4px 20px 40px; }
#tabbar { display: none; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); padding: 4px 10px 14px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-nav a span:last-child { overflow: hidden; text-overflow: ellipsis; }
.side-nav a:hover { background: var(--panel-2); }
.side-nav a.on { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.side-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 18px 10px 6px; }
.side-foot { margin-top: auto; padding: 14px 10px 4px; display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; }

@media (max-width: 899px) {
  #sidebar { display: none; }
  #wrap { margin-left: 0; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  #topbar { padding: calc(8px + env(safe-area-inset-top)) 14px 8px; }
  #main { padding: 4px 14px 24px; }
  #tabbar {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 10; background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: .72rem; color: var(--muted); }
  #tabbar a span { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
  #tabbar a.on { color: var(--accent); font-weight: 600; }
  #tabbar a.on span { filter: none; opacity: 1; }
}

/* ---------- controls ---------- */
.icon-btn {
  border: 0; background: transparent; color: var(--text); font-size: 1.35rem; width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); }
#refresh.spin { animation: spin .9s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
input[type=text], input[type=url], input[type=password], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { resize: vertical; }

/* ---------- cards & rows ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card.list { padding: 0; overflow: hidden; }
.card > h2:first-child { margin-top: 0; }
.list .row + .row, .list .row + .subheader, .list .subheader + .row { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text); min-width: 0; }
a.row:hover, .rowlink:hover { background: var(--panel-2); }
.rowlink { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; color: var(--text); margin: -12px 0; padding: 12px 0; }
.row.planner { padding: 0 14px; }
.row.planner .rowlink { margin: 0; }
.grow { flex: 1; min-width: 0; }
.t { font-weight: 600; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: .85rem; }
.preview { color: var(--muted); font-size: .85rem; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row.unread .t::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: middle; }
.row.done .t { text-decoration: line-through; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ico { flex: none; width: 22px; text-align: center; }
.ext { color: var(--muted); font-size: .85em; }
.pts, .grade { color: var(--muted); font-size: .9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.grade { color: var(--text); font-weight: 600; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.count { background: var(--red); color: #fff; border-radius: 99px; font-size: .75rem; padding: 1px 8px; vertical-align: middle; }
.check {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); background: transparent;
  color: var(--accent-text); font-size: .75rem; font-weight: 800; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.check:hover { border-color: var(--accent); }
.done .check { background: var(--accent); border-color: var(--accent); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty.err b { color: var(--text); display: block; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* ---------- dashboard ---------- */
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; }
.dash-main > section:first-child h2, .dash-side > section:first-child h2 { margin-top: .4rem; }
.card.warn { border-color: color-mix(in srgb, var(--red) 40%, var(--line)); padding: 0; overflow: hidden; }
.card.warn h2 { margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card.warn .row + .row { border-top: 1px solid var(--line); }
.past summary { cursor: pointer; color: var(--muted); padding: 10px 0; }
.course-cards { display: grid; gap: 10px; }
.course-card {
  display: block; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: var(--radius);
  padding: 12px 14px; color: var(--text); box-shadow: var(--shadow);
}
.course-card:hover { background: var(--panel-2); }
.cc-name { font-weight: 650; }
.cc-sub { color: var(--muted); font-size: .82rem; }
.cc-grade { margin-top: 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 1099px) { .dash { grid-template-columns: 1fr; } }
#main > .course-cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ---------- course ---------- */
.course-head { margin: 0 0 14px; }
.course-title { display: flex; align-items: center; gap: 10px; }
.course-title h1 { margin: 0; flex: 1; font-size: 1.3rem; }
.course-title .bar { width: 6px; align-self: stretch; border-radius: 3px; background: var(--c); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 6px 13px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); color: var(--text); white-space: nowrap; font-size: .9rem; }
.tabs a.on { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.module { padding: 0; overflow: hidden; }
.module summary { display: flex; align-items: center; gap: 8px; padding: 12px 14px; cursor: pointer; font-weight: 700; background: var(--panel-2); list-style: none; }
.module summary::-webkit-details-marker { display: none; }
.module summary::before { content: "▸"; transition: transform .15s; color: var(--muted); }
.module[open] summary::before { transform: rotate(90deg); }
.mname { flex: 1; }
.module .list { border-top: 1px solid var(--line); }
.subheader { padding: 10px 14px; font-weight: 700; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.mitem.locked { opacity: .6; }
.req { color: var(--muted); font-weight: 700; }
.req.ok { color: var(--green); }
.crumbs { margin-bottom: 10px; color: var(--muted); }

/* ---------- details ---------- */
.detail { max-width: 860px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: .9rem; margin-bottom: 14px; }
.meta b { color: var(--text); font-weight: 600; }
.callout { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.callout.quiz { border-color: color-mix(in srgb, var(--purple) 45%, var(--line)); background: color-mix(in srgb, var(--purple-bg) 60%, var(--panel)); }
.sub-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sub-head h2 { margin: 0; }
.big-grade { font-size: 1.8rem; font-weight: 800; margin: 6px 0; font-variant-numeric: tabular-nums; }
.big-grade small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.file { display: block; padding: 6px 0; overflow-wrap: anywhere; }
.prose { overflow-wrap: anywhere; overflow-x: auto; }
.prose img, .prose video { max-width: 100%; height: auto; }
.prose table { border-collapse: collapse; max-width: 100%; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 8px; }
.prose pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.embed-link { display: inline-block; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 8px; margin: 4px 0; }
.embed-link::after { content: " ↗"; }
.rubric { width: 100%; border-collapse: collapse; }
.rubric td { border-top: 1px solid var(--line); padding: 10px 6px; vertical-align: top; }
.rpts { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rcomment { margin-top: 4px; font-style: italic; }
.grade-summary { display: flex; flex-direction: column; gap: 2px; }

.submit { display: flex; flex-direction: column; gap: 12px; }
.submit h2 { margin: 0; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); cursor: pointer; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.drop { display: grid; place-items: center; text-align: center; padding: 26px 14px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; color: var(--muted); }
.drop:hover { border-color: var(--accent); color: var(--text); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.picked { margin: 8px 0 0; padding-left: 20px; }
.submit .btn.primary { align-self: flex-start; padding: 11px 26px; }
.progress { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cmeta { color: var(--muted); font-size: .85rem; }
.cmeta b { color: var(--text); }
.inline-form { display: flex; gap: 8px; margin-top: 12px; align-items: flex-start; }
.inline-form.col { flex-direction: column; }
.inline-form.col .btn { align-self: flex-start; }
.entries { margin-top: 8px; }
.entry { border-left: 3px solid var(--line); padding: 8px 0 8px 14px; margin: 8px 0; }
.entry.unread { border-left-color: var(--accent); }
.emeta { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
.emeta b { color: var(--text); }
.avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.replies { margin-left: 4px; }
.entry .link-btn { font-size: .85rem; margin-top: 4px; }

/* ---------- misc ---------- */
.skeleton div { height: 64px; border-radius: var(--radius); margin: 12px 0; background: linear-gradient(90deg, var(--panel) 0%, var(--panel-2) 50%, var(--panel) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); color: #fff; }
#toast.ok { background: var(--green); color: #fff; }
@media (min-width: 900px) { #toast { bottom: 24px; } }

/* ---------- nav badge, toolbars ---------- */
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: .7rem; border-radius: 99px; padding: 1px 7px; }
#tabbar a { position: relative; }
#tabbar .nav-badge { position: absolute; top: 4px; left: calc(50% + 6px); margin: 0; }
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.link-btn.danger { color: var(--red); }

/* ---------- inbox ---------- */
.inbox-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.inbox-head .tabs { padding: 0; }
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; max-width: 760px; }
.msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; }
.compose { display: flex; flex-direction: column; gap: 12px; max-width: 760px; }
.compose h2 { margin: 0; }
.compose label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; position: relative; }
.compose select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--text); border-radius: 99px; padding: 3px 4px 3px 11px; font-weight: 600; font-size: .85rem; }
.chip button { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0 5px; }
.results { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; max-height: 280px; overflow-y: auto; margin-top: 4px; }
.results .row { width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.results .row:hover { background: var(--panel-2); }
.check-line { flex-direction: row !important; align-items: center; font-weight: 400 !important; }
.attach, .compose label.attach { display: flex; flex-direction: row; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; flex-wrap: wrap; }
.attach input { max-width: 100%; font: inherit; color: var(--muted); }
.avatar.lg { width: 36px; height: 36px; }

/* ---------- discussions extras, peer review ---------- */
.e-actions { display: flex; gap: 14px; margin-top: 4px; align-items: center; }
.like.on { color: var(--red); }
.review { border-top: 1px solid var(--line); padding: 12px 0; }
.review:first-of-type { border-top: 0; }
.sub-head .badge { margin-left: 8px; }

/* ---------- quizzes ---------- */
.quiz-bar { position: sticky; top: 56px; z-index: 4; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: space-between; }
.timer { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.timer.low { color: var(--red); }
.question { border: 1px solid var(--line); margin: 0 0 12px; }
.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.q-head .save-state { margin-left: auto; font-size: .82rem; }
.save-state.ok { color: var(--green); }
.save-state.err { color: var(--red); font-weight: 700; }
.flag { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 8px; padding: 2px 9px; cursor: pointer; font-size: 1rem; }
.flag.on { color: var(--orange); border-color: var(--orange); background: var(--orange-bg); }
.q-text { margin-bottom: 12px; }
.q-text input.blank, .q-text select { width: auto; min-width: 120px; display: inline-block; margin: 2px 4px; padding: 5px 8px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.matching { width: 100%; border-collapse: collapse; }
.matching td { padding: 6px; border-top: 1px solid var(--line); }
.matching select, .question select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px; max-width: 100%; }
.blank-line { display: block; margin-top: 8px; }
.quiz-foot { display: flex; justify-content: flex-end; margin: 6px 0 30px; }
@media (max-width: 899px) { .quiz-bar { top: calc(52px + env(safe-area-inset-top)); } }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card img { align-self: center; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.login-card .err { color: var(--red); font-weight: 600; }
