:root {
  --bg: #0f1115; --panel: #181b22; --panel2: #20242d; --text: #e8eaf0; --muted: #98a0b3;
  --accent: #6c8cff; --ok: #3ecf8e; --border: #2a2f3a; --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f5f8; --panel: #fff; --panel2: #eceef3; --text: #1b1e27; --muted: #5d6578; --border: #dcdfe7; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
header#top { display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 18px; }
#who { margin-left: auto; color: var(--muted); }
.link { background: none; border: 0; color: var(--accent); padding: 4px; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 24px; margin: 8px 0 16px; }
.muted { color: var(--muted); }
.btn { background: var(--accent); border: 0; color: #fff; padding: 9px 16px; border-radius: 8px; font-weight: 600; }
.btn.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn:disabled { opacity: .5; cursor: default; }

/* login */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 380px; margin: 48px auto; }
.card h1 { margin-top: 0; }
.card label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 13px; }
.card input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); font: inherit; }
.card .btn { width: 100%; margin-top: 18px; }
.err { color: #ff6b6b; margin-top: 12px; min-height: 1.2em; }
.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button { flex: 1; background: var(--panel2); border: 1px solid var(--border); padding: 8px; border-radius: 8px; }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* course grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.course { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; transition: transform .1s, border-color .1s; }
.course:hover { transform: translateY(-2px); border-color: var(--accent); }
.course h3 { margin: 0; font-size: 17px; }
.course .thumb { width: calc(100% + 36px); margin: -18px -18px 0; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius) var(--radius) 0 0; background: var(--panel2); display: block; }
.course .thumb.ph { display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--muted); }
.bar { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.done > i { background: var(--ok); }

/* course page */
.section { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.section > summary { padding: 14px 16px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); }
.row:hover { background: var(--panel2); }
.row.current { background: var(--panel2); box-shadow: inset 3px 0 var(--accent); }
.tick { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); flex: none; display: grid; place-items: center; font-size: 12px; color: #fff; }
.tick.done { background: var(--ok); border-color: var(--ok); }
.row .t { flex: 1; min-width: 0; }
.row .d { color: var(--muted); font-size: 13px; }
.files { padding: 6px 16px 12px 48px; display: flex; flex-wrap: wrap; gap: 8px; }
.file { font-size: 13px; background: var(--panel2); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; }
.file:hover { border-color: var(--accent); }

/* lesson page */
.lesson { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 960px) { .lesson { grid-template-columns: 1fr; } }
.side { max-height: calc(100vh - 100px); overflow: auto; position: sticky; top: 70px; }
@media (max-width: 960px) { .side { position: static; max-height: none; } }
.meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0; }
.meta h1 { flex: 1 1 100%; margin: 0; }

.player { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16/9; user-select: none; }
.player:fullscreen { border-radius: 0; aspect-ratio: auto; }
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player .spin { position: absolute; inset: 0; display: none; place-items: center; pointer-events: none; }
.player.loading .spin { display: grid; }
.spin::after { content: ""; width: 44px; height: 44px; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 28px 12px 8px; background: linear-gradient(transparent, rgba(0,0,0,.8)); color: #fff; transition: opacity .2s; }
.player.idle:not(.paused) .controls { opacity: 0; pointer-events: none; }
.player.idle:not(.paused) { cursor: none; }
.seek { width: 100%; accent-color: var(--accent); margin: 0 0 4px; height: 16px; }
.cbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.cbar button { background: none; border: 0; color: #fff; padding: 6px 8px; border-radius: 6px; font-size: 14px; white-space: nowrap; }
.cbar button:hover { background: rgba(255,255,255,.18); }
.cbar .time { font-variant-numeric: tabular-nums; font-size: 13px; margin: 0 8px; }
.cbar .sp { flex: 1; }
.vol { width: 70px; accent-color: var(--accent); }
.menu { position: relative; }
.menu .pop { position: absolute; bottom: 100%; right: 0; background: rgba(20,22,28,.97); border: 1px solid #333; border-radius: 8px; padding: 4px; display: none; min-width: 110px; margin-bottom: 6px; }
.menu.open .pop { display: block; }
.pop button { display: block; width: 100%; text-align: left; }
.pop button.on::before { content: "✓ "; }
.pop button:not(.on)::before { content: "\00a0\00a0\00a0"; }
.toast { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.75); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.next-up { position: absolute; right: 16px; bottom: 90px; background: rgba(20,22,28,.95); color: #fff; padding: 12px 14px; border-radius: 10px; display: none; gap: 10px; align-items: center; }
.next-up.show { display: flex; }

/* roles + admin */
#adminlink { margin-left: auto; }
#adminlink + #who { margin-left: 8px; }
.badge { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
.badge.admin { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge.editor { border-color: var(--ok); color: var(--ok); }
.titlebar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0 16px; }
.titlebar h1 { margin: 0; }
.titleinput { flex: 1 1 320px; min-width: 0; padding: 9px 12px; font: inherit; font-size: 20px; border-radius: 8px; border: 1px solid var(--accent); background: var(--panel); color: var(--text); }
table.users { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.users th, table.users td { text-align: left; padding: 10px 14px; border-top: 1px solid var(--border); }
table.users th { border-top: 0; color: var(--muted); font-weight: 600; font-size: 13px; }
select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); }
.code { background: var(--panel2); border: 1px solid var(--border); padding: 3px 8px; border-radius: 6px; user-select: all; }
h2 { font-size: 18px; margin: 28px 0 8px; }

/* MFA */
#securitylink { margin-left: auto; }
#securitylink ~ #adminlink, #securitylink ~ #who { margin-left: 8px; }
#adminlink { margin-left: 8px; }
.card.wide { max-width: 480px; }
.steps { padding-left: 20px; line-height: 1.6; }
.steps li { margin-bottom: 10px; }
.qrbox { background: #fff; border-radius: 12px; padding: 10px; width: max-content; margin: 10px 0; }
.qrbox img { display: block; }
code.secret { display: inline-block; margin-top: 8px; font-size: 14px; letter-spacing: .06em; word-break: break-all; }
pre.codes { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; font-size: 16px; line-height: 1.7; user-select: all; columns: 2; }
.notice { background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
