/* ---------- app shell: sidebar + topbar + content ---------- */
.app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: var(--sp-4); gap: var(--sp-4); overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; padding: var(--sp-1) var(--sp-2); }
.sidebar-brand img { height: 34px; width: auto; }
.nav { display: grid; gap: 2px; }
.nav-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--gray-400); padding: var(--sp-3) var(--sp-3) var(--sp-1); font-weight: 600; }
.nav a { display: flex; align-items: center; gap: var(--sp-3); padding: 9px var(--sp-3); border-radius: var(--radius-sm);
  color: var(--gray-700); font-weight: 520; transition: background var(--t-fast), color var(--t-fast); text-decoration: none; }
.nav a:hover { background: var(--gray-100); }
.nav a[aria-current="page"] { background: var(--brand-50); color: var(--brand-700); }
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-foot { margin-top: auto; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5); background: rgba(248,249,251,.82); backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--border); }
.topbar-spacer { flex: 1; }
.menu-btn { display: none; }
.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--sp-6) var(--sp-5) var(--sp-8); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { margin: 0; }
.page-head p { margin: var(--sp-1) 0 0; color: var(--text-muted); }

/* ---------- grids ---------- */
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
.grid > *, .stack > * { min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row-between { justify-content: space-between; }

/* ---------- auth / centered pages ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-5);
  background: radial-gradient(900px 420px at 50% -10%, var(--brand-100), transparent), var(--bg); }
.auth-card { width: min(420px, 100%); }
.auth-card .logo { height: 52px; width: auto; margin: 0 auto var(--sp-5); }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(290px, 86vw); z-index: 60; transform: translateX(-102%); visibility: hidden;
    transition: transform var(--t-slow) var(--ease); box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; visibility: visible; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(11,11,15,.4); z-index: 50; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 var(--sp-4); }
  .content { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  h1 { font-size: var(--fs-xl); }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; width: 100%; }
}

/* ---------- shell extras: popovers, bell, disabled nav ---------- */
.popover-wrap { position: relative; }
.popover { position: absolute; right: 0; top: calc(100% + 8px); width: min(340px, calc(100vw - 2rem)); max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 70; animation: fade-up var(--t) var(--ease) both; }
.popover-head { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.popover > .btn { margin: var(--sp-2); width: calc(100% - 1rem); }
.bell { position: relative; padding: 0 var(--sp-2); }
.bell-count { position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red-600); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.avatar { border: 0; cursor: pointer; }
.notif { display: grid; gap: 2px; width: 100%; text-align: left; padding: var(--sp-3) var(--sp-4); background: none; border: 0; border-bottom: 1px solid var(--gray-100); cursor: pointer; }
.notif:hover { background: var(--gray-50); }
.notif.unread { background: var(--brand-50); } .notif.unread .notif-title::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand-600); margin-right: 8px; }
.notif-title { font-weight: 600; }
.nav .nav-soon { color: var(--gray-400); cursor: default; } .nav .nav-soon:hover { background: none; }
.list { display: grid; gap: 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--gray-100); }
.list-item:last-child { border-bottom: 0; }
.list-item .meta { color: var(--text-muted); font-size: var(--fs-sm); }
.password-meter { height: 4px; border-radius: 2px; background: var(--gray-100); overflow: hidden; } .password-meter span { display: block; height: 100%; width: 0; transition: width var(--t), background var(--t); }

/* ---------- users / profile ---------- */
.toolbar { display: grid; grid-template-columns: 1fr 170px 170px; gap: var(--sp-3); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-4); }
.avatar-lg { width: 72px; height: 72px; font-size: var(--fs-lg); }
@media (max-width: 640px) { .toolbar { grid-template-columns: 1fr; } }

/* ---------- courses ---------- */
.course-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.course-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; color: inherit; text-decoration: none; }
.course-card:hover { text-decoration: none; }
.thumb { aspect-ratio: 16 / 9; width: 100%; background: linear-gradient(135deg, var(--brand-700), var(--brand-500, #0A5FC4)); display: grid; place-items: center; color: #fff; font-weight: 650; font-size: var(--fs-xl); letter-spacing: .02em; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.course-card .body { padding: var(--sp-4); display: grid; gap: var(--sp-2); }
.course-card h3 { margin: 0; font-size: var(--fs-md); line-height: 1.3; overflow-wrap: anywhere; }
.course-hero { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
@media (max-width: 720px) { .course-hero { grid-template-columns: minmax(0, 1fr); } }
.toolbar-2 { display: grid; grid-template-columns: 1fr 190px; gap: var(--sp-3); }
@media (max-width: 640px) { .toolbar-2 { grid-template-columns: 1fr; } }
.pick-list { max-height: 280px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.pick-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--gray-100); cursor: pointer; }
.pick-item:last-child { border-bottom: 0; } .pick-item:hover { background: var(--gray-50); }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- lessons ---------- */
.check { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--gray-300); display: inline-grid; place-items: center; font-size: 13px; line-height: 1; color: #fff; }
.check-done { background: var(--green-500, #3A9A2F); border-color: var(--green-500, #3A9A2F); }
.player { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius-lg); overflow: hidden; }
.player video, .player iframe { width: 100%; height: 100%; border: 0; display: block; }
.pdf-frame { width: 100%; height: min(80vh, 900px); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); max-width: 960px; }
.lesson-nav { display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }

/* ---------- messages ---------- */
.chat { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: var(--sp-4); height: calc(100dvh - 170px); min-height: 460px; }
.chat-list, .chat-thread { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.chat-list-body, .chat-scroll { overflow-y: auto; flex: 1; min-height: 0; }
.chat-item { display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-3) var(--sp-4); width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; font: inherit; color: inherit; }
.chat-item:hover, .chat-item.active { background: var(--gray-50); }
.chat-item .grow { min-width: 0; flex: 1; }
.chat-item .name { font-weight: 560; display: flex; justify-content: space-between; gap: var(--sp-2); }
.chat-item .name span:first-child, .chat-item .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .preview { color: var(--text-muted); font-size: 0.85rem; }
.chat-item .dot { background: var(--brand-600); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; font-size: 0.75rem; display: inline-grid; place-items: center; padding: 0 6px; }
.chat-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.chat-scroll { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
.msg { max-width: min(78%, 560px); padding: var(--sp-2) var(--sp-3); border-radius: 14px; background: var(--gray-100); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: var(--brand-600); color: #fff; }
.msg .who { font-size: 0.75rem; font-weight: 600; opacity: 0.75; margin-bottom: 2px; }
.msg .when { font-size: 0.7rem; opacity: 0.7; margin-top: 2px; }
.msg a { color: inherit; text-decoration: underline; }
.msg img { max-width: 100%; border-radius: 8px; display: block; margin-top: 4px; }
.chat-compose { display: flex; gap: var(--sp-2); align-items: flex-end; padding: var(--sp-3); border-top: 1px solid var(--border); }
.chat-compose textarea { flex: 1; min-height: 42px; max-height: 140px; resize: none; }
.chat-empty { margin: auto; text-align: center; color: var(--text-muted); padding: var(--sp-6); }
.ann-card.pinned { border-left: 4px solid var(--orange-500); }
@media (max-width: 800px) {
  .chat { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 150px); }
  .chat[data-view="thread"] .chat-list, .chat[data-view="list"] .chat-thread { display: none; }
  .msg { max-width: 88%; }
}
@media (min-width: 801px) { .chat-back { display: none; } }

/* ---------- accessibility ---------- */
.skip-link { position: absolute; left: var(--sp-3); top: -60px; z-index: 1000; background: var(--brand-700); color: #fff; padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm); font-weight: 600; text-decoration: none; }
.skip-link:focus { top: var(--sp-3); }
#page:focus { outline: none; }
@media (prefers-reduced-motion: reduce) {
  /* everything calms down except the brand splash/transitions, which are short and always play */
  *:not(.splash):not(.splash *):not(.rl-trans):not(.rl-trans *), *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .splash::before, .splash::after, .splash *::before, .splash *::after, .rl-trans *::before, .rl-trans *::after { animation-duration: revert !important; animation-iteration-count: revert !important; }
}
@media print { .sidebar, .topbar, .skip-link, .toast-region { display: none !important; } .app { display: block; } }

/* ---------- global search ---------- */
.search-btn { gap: var(--sp-2); color: var(--text-muted); }
.search-kbd { font: inherit; font-size: 0.7rem; border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; background: var(--gray-50); }
@media (max-width: 640px) { .search-label, .search-kbd { display: none; } }
.palette-backdrop { position: fixed; inset: 0; background: rgba(11,11,15,.45); z-index: 200; display: flex; justify-content: center; align-items: flex-start; padding: 10vh var(--sp-3) var(--sp-3); }
.palette { width: min(640px, 100%); max-height: 75vh; display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; }
.palette-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); color: var(--text-muted); }
.palette-head input { flex: 1; border: 0; outline: 0; background: transparent; font-size: var(--fs-md); color: var(--text); min-width: 0; }
.palette-body { overflow-y: auto; padding: var(--sp-2); }
.palette-msg { margin: 0; padding: var(--sp-5) var(--sp-4); color: var(--text-muted); text-align: center; }
.palette-group { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: var(--sp-3) var(--sp-3) var(--sp-1); }
.palette-item { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); color: inherit; text-decoration: none; }
.palette-item.active { background: var(--brand-50); outline: 2px solid var(--brand-500); outline-offset: -2px; }
.palette-item .t { font-weight: 560; overflow-wrap: anywhere; }
.palette-item .s { font-size: 0.82rem; color: var(--text-muted); overflow-wrap: anywhere; }
.palette-head input::-webkit-search-cancel-button { display: none; }

/* ---------- Calendar ---------- */
.cal-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); }
.cal-bar h2 { margin: 0; font-size: var(--fs-lg); min-width: 11ch; }
.cal-filters { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-bottom: var(--sp-3); }
.cal-filters label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); cursor: pointer; }
.cal-grid { width: 100%; table-layout: fixed; border-collapse: collapse; }
.cal-grid th { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); text-align: center; padding: var(--sp-2) 0; }
.cal-grid td { padding: 0; border: 1px solid var(--border); height: 84px; vertical-align: top; }
.cal-day { display: flex; flex-direction: column; align-items: stretch; gap: 3px; width: 100%; height: 100%; padding: 6px; background: transparent; border: 0; text-align: left; cursor: pointer; font: inherit; color: var(--text); }
.cal-day:hover { background: var(--gray-50); }
.cal-day:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.cal-day .num { font-size: var(--fs-sm); font-weight: 560; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.out { color: var(--gray-400); background: var(--gray-50); }
.cal-day.today .num { background: var(--primary); color: #fff; }
.cal-day.sel { background: var(--brand-50); box-shadow: inset 0 0 0 2px var(--primary); }
.cal-chip { font-size: 11px; line-height: 1.25; padding: 1px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip.live { background: var(--brand-100); color: var(--brand-700); }
.cal-chip.assignment { background: var(--orange-100); color: #9A5B00; }
.cal-chip.quiz_open { background: var(--green-100); color: var(--green-600); }
.cal-chip.quiz_close { background: var(--red-100); color: var(--red-600); }
.cal-more { font-size: 11px; color: var(--text-muted); }
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; }
.cal-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.cal-dots i.assignment { background: var(--orange-500); } .cal-dots i.quiz_open { background: var(--green-500); } .cal-dots i.quiz_close { background: var(--red-600); }
@media (max-width: 640px) {
  .cal-grid td { height: 52px; }
  .cal-day { align-items: center; padding: 4px 2px; }
  .cal-chip, .cal-more { display: none; }
  .cal-dots { display: flex; justify-content: center; }
}

/* =====================================================================
   Polish: softer surfaces, clearer hierarchy, richer course screens
   ===================================================================== */
:root { --bg: #F5F7FB; --border: #E4E8F0; }
body { background: var(--bg); }
h1 { letter-spacing: -0.02em; font-weight: 680; }
.card { border-color: var(--border); box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.04); }
.page-head h1 { font-size: 1.75rem; }
.btn { font-weight: 580; }
.btn-secondary { border-color: var(--gray-300); box-shadow: 0 1px 1px rgba(16,24,40,.04); }
.btn-danger-soft { background: var(--red-100); color: var(--red-600); }
.btn-danger-soft:hover { background: #F9D5D1; }
.btn-ghost.btn-sm { color: var(--gray-700); }
.nav a[aria-current="page"] { background: var(--brand-50); color: var(--brand-700); box-shadow: inset 3px 0 0 var(--brand-700); font-weight: 600; }

/* Tabs: a soft segmented bar, no ugly scrollbar */
.tabs { gap: 2px; padding: 4px; background: var(--gray-100); border: 0; border-radius: 12px; margin-bottom: var(--sp-5); width: fit-content; max-width: 100%;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 16px; border: 0; border-radius: 9px; margin: 0; color: var(--gray-700); font-size: var(--fs-sm); }
.tab:hover { color: var(--ink); background: rgba(255,255,255,.6); }
.tab[aria-selected="true"] { background: #fff; color: var(--brand-700); box-shadow: 0 1px 3px rgba(16,24,40,.12); }
.tab:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 1px; }

/* Thumbnails: four brand gradients so courses are easy to tell apart */
.thumb { background: linear-gradient(135deg, #0B3C95, #2B7BE0); }
.thumb[data-g="1"] { background: linear-gradient(135deg, #2F8A27, #5BC04E); }
.thumb[data-g="2"] { background: linear-gradient(135deg, #0B3C95, #3A9A2F); }
.thumb[data-g="3"] { background: linear-gradient(135deg, #E08A00, #F5B445); }

/* Courses list */
.summary-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: calc(-1 * var(--sp-2)) 0 var(--sp-4); }
.summary-chips span { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 4px 12px; font-size: var(--fs-sm); color: var(--text-muted); }
.summary-chips strong { color: var(--ink); }
.course-tools { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.course-tools .search-field { position: relative; flex: 1 1 260px; max-width: 420px; display: block; }
.course-tools .search-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
.course-tools .search-field .input { padding-left: 38px; border-radius: 999px; background: #fff; }
.course-tools .select { width: auto; min-width: 150px; border-radius: 999px; background: #fff; }
.course-grid { gap: var(--sp-5); grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.course-card { border-radius: 18px; transition: box-shadow var(--t) var(--ease), transform var(--t) var(--ease); }
.course-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(16,24,40,.12); border-color: var(--gray-300); }
.course-card .thumb { aspect-ratio: 16 / 8; font-size: 2rem; }
.course-card .body { padding: var(--sp-4) var(--sp-4) var(--sp-4); gap: var(--sp-2); flex: 1; align-content: start; }
.course-card h3 { font-size: 1.0625rem; font-weight: 640; color: var(--ink); }
.course-teacher::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--green-500); margin-right: 6px; vertical-align: 1px; }
.course-foot { display: flex; justify-content: space-between; align-items: center; margin-top: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--gray-100); font-size: var(--fs-sm); color: var(--text-muted); }
.course-open { color: var(--brand-700); font-weight: 600; transition: transform var(--t-fast); }
.course-card:hover .course-open { transform: translateX(3px); }

/* Course page header */
.course-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-4); margin: var(--sp-3) 0 var(--sp-5);
  padding: var(--sp-5); border-radius: 20px; color: #fff; background: linear-gradient(120deg, #0B3C95 0%, #1E62C9 60%, #2B7BE0 100%); position: relative; overflow: hidden; }
.course-top[data-g="1"] { background: linear-gradient(120deg, #1F6B1A 0%, #3A9A2F 70%, #5BC04E 100%); }
.course-top[data-g="2"] { background: linear-gradient(120deg, #0B3C95 0%, #1C7A55 100%); }
.course-top[data-g="3"] { background: linear-gradient(120deg, #B35F00 0%, #E08A00 70%, #F5B445 100%); }
.course-top::after { content: ""; position: absolute; right: -60px; top: -80px; width: 260px; height: 260px; border-radius: 50%; background: rgba(255,255,255,.09); pointer-events: none; }
.course-top-main { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; flex: 1 1 380px; position: relative; z-index: 1; }
.course-top-thumb { width: 96px; height: 96px; aspect-ratio: 1; border-radius: 18px; flex: none; font-size: 1.6rem; border: 2px solid rgba(255,255,255,.55); background: rgba(255,255,255,.18) !important; }
.course-top h1 { color: #fff; margin: 6px 0 4px; font-size: 1.6rem; overflow-wrap: anywhere; }
.course-top .badge { background: rgba(255,255,255,.2); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.course-top-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-sm); color: rgba(255,255,255,.88); }
.course-top-actions { position: relative; z-index: 1; }
.course-top-actions .btn-secondary { background: #fff; border-color: #fff; color: var(--brand-700); }
.course-top-actions .btn-danger-soft { background: rgba(255,255,255,.18); color: #fff; }
.course-top-actions .btn-danger-soft:hover { background: rgba(217,45,32,.85); }
@media (max-width: 640px) { .course-top { padding: var(--sp-4); border-radius: 16px; } .course-top-thumb { width: 64px; height: 64px; border-radius: 14px; font-size: 1.1rem; } .course-top h1 { font-size: 1.25rem; } }

/* Content tab: numbered modules, typed lessons */
.mod-head { margin-bottom: var(--sp-3); align-items: center; }
.mod-num { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--brand-50); color: var(--brand-700); font-weight: 700; }
.ltype { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--brand-50); color: var(--brand-700); }
.ltype svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ltype-pdf { background: var(--red-100); color: var(--red-600); }
.ltype-text { background: var(--green-100); color: var(--green-600); }
.ltype-locked { background: var(--gray-100); color: var(--gray-500); }
[data-lesson].list-item { padding: var(--sp-3); margin: 0 calc(-1 * var(--sp-3)); border-radius: 12px; border-bottom: 0; transition: background var(--t-fast); }
[data-lesson].list-item:hover { background: var(--gray-50); }
[data-lesson] .btn-ghost.btn-sm { height: 30px; padding: 0 10px; }
[data-lesson] [data-ldel], [data-mdel] { color: var(--red-600); }

/* =====================================================================
   Mastery map, lesson questions, live pulse, study plan
   ===================================================================== */
.chip-warn { background: var(--orange-100) !important; border-color: transparent !important; color: #8A4B00 !important; }
.chip-warn strong { color: #8A4B00 !important; }
.qa-link { background: none; border: 0; padding: 0; font: inherit; font-size: var(--fs-sm); color: var(--brand-700); cursor: pointer; font-weight: 560; }
.qa-link:hover { text-decoration: underline; }
.qa-link:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; border-radius: 4px; }
.qa-danger { color: var(--red-600); }

/* mastery */
.mgrid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.mcard { padding: var(--sp-4); display: grid; gap: var(--sp-2); align-content: start; border-top: 4px solid var(--gray-300); }
.mcard-strong { border-top-color: var(--green-500); } .mcard-ok { border-top-color: var(--brand-500); } .mcard-weak { border-top-color: var(--orange-500); }
.mcard-title { margin: 0; font-size: 1.0625rem; overflow-wrap: anywhere; }
.mcard-pct { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.mbar { height: 8px; background: var(--gray-100); border-radius: 999px; overflow: hidden; }
.mbar > span { display: block; height: 100%; border-radius: inherit; background: var(--gray-300); }
.mbar-strong { background: var(--green-500) !important; } .mbar-ok { background: var(--brand-500) !important; } .mbar-weak { background: var(--orange-500) !important; }
.mrev { margin-top: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--gray-100); display: grid; gap: 6px; }
.mlesson { font-size: var(--fs-sm); color: var(--brand-700); overflow-wrap: anywhere; }
.mlesson-done { color: var(--green-600); } .mlesson-locked { color: var(--gray-500); }
.mfocus { border-left: 4px solid var(--orange-500); }
.mfocus-list { display: grid; gap: var(--sp-2); }
.mfocus-item { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 0; border-top: 1px solid var(--gray-100); }
.mfocus-item:first-child { border-top: 0; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { border: 1px solid var(--gray-300); background: #fff; border-radius: 999px; padding: 4px 12px; font: inherit; font-size: var(--fs-sm); color: var(--gray-700); cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast); }
.tag-chip:hover:not(:disabled) { border-color: var(--brand-500); }
.tag-chip[aria-pressed="true"] { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.tag-chip:disabled { opacity: .45; cursor: not-allowed; }
.tag-chip:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; }
.tag-static { cursor: default; display: inline-flex; align-items: center; gap: 6px; background: var(--brand-50); border-color: transparent; color: var(--brand-700); }
.tag-x { border: 0; background: none; font-size: 1.1rem; line-height: 1; color: var(--gray-500); cursor: pointer; padding: 0 2px; }
.tag-x:hover { color: var(--red-600); }
.tagrow { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--gray-100); flex-wrap: wrap; }
.tagrow:last-child { border-bottom: 0; }
.tagrow-name { min-width: 0; flex: 1 1 220px; overflow-wrap: anywhere; }

/* lesson questions */
.qa-moments { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: var(--sp-3); }
.qa-time { border: 0; background: var(--brand-50); color: var(--brand-700); border-radius: 999px; padding: 2px 10px; font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.qa-time:hover:not(:disabled) { background: var(--brand-100); }
.qa-form { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.qa-form-row { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.qa-at { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); }
.qa-at .input { width: 90px; padding: 6px 10px; }
.qa-list { display: grid; gap: var(--sp-3); }
.qa-item { padding: var(--sp-3) var(--sp-3); border: 1px solid var(--border); border-radius: 14px; background: #fff; }
.qa-done { background: var(--gray-50); }
.qa-focus { box-shadow: 0 0 0 3px var(--brand-100); border-color: var(--brand-500); }
.qa-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.qa-body { margin: var(--sp-1) 0 var(--sp-2); overflow-wrap: anywhere; }
.qa-reply { margin: var(--sp-2) 0 0 var(--sp-3); padding: var(--sp-2) var(--sp-3); border-left: 3px solid var(--brand-100); background: var(--gray-50); border-radius: 0 10px 10px 0; }
.qa-actions { display: flex; gap: var(--sp-4); flex-wrap: wrap; margin-top: var(--sp-1); }
.qa-reply-form { margin-top: var(--sp-2); display: grid; gap: var(--sp-2); }

/* live pulse and polls */
.pulse-btns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.pulse-btn { padding: var(--sp-4) var(--sp-3); border-radius: 16px; border: 2px solid var(--gray-300); background: #fff; font: inherit; font-size: 1.05rem; font-weight: 650; cursor: pointer; transition: transform var(--t-fast), background var(--t-fast); min-height: 56px; }
.pulse-btn:active { transform: scale(.98); }
.pulse-btn:focus-visible { outline: 3px solid var(--brand-500); outline-offset: 2px; }
.pulse-btn-ok:hover, .pulse-btn-ok[aria-pressed="true"] { background: var(--green-100); border-color: var(--green-500); color: var(--green-600); }
.pulse-btn-lost:hover, .pulse-btn-lost[aria-pressed="true"] { background: var(--orange-100); border-color: var(--orange-500); color: #8A4B00; }
.pulse-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); margin-bottom: var(--sp-3); }
.pulse-num { text-align: center; padding: var(--sp-3); border-radius: 14px; background: var(--gray-50); }
.pulse-num strong { display: block; font-size: 2rem; line-height: 1.1; letter-spacing: -0.03em; }
.pulse-num span { font-size: var(--fs-sm); color: var(--text-muted); }
.pulse-ok { background: var(--green-100); } .pulse-ok strong { color: var(--green-600); }
.pulse-lost { background: var(--orange-100); } .pulse-lost strong { color: #8A4B00; }
.pulse-track { display: flex; height: 10px; border-radius: 999px; background: var(--gray-100); overflow: hidden; }
.pulse-seg-ok { background: var(--green-500); } .pulse-seg-lost { background: var(--orange-500); }
.polls { margin-top: var(--sp-4); display: grid; gap: var(--sp-4); border-top: 1px solid var(--gray-100); padding-top: var(--sp-4); }
.poll { display: grid; gap: var(--sp-2); }
.popts { display: grid; gap: 6px; }
.popt { position: relative; display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); width: 100%; text-align: left; padding: 10px 14px; border: 1px solid var(--gray-300); border-radius: 12px; background: #fff; font: inherit; overflow: hidden; }
button.popt { cursor: pointer; } button.popt:hover { border-color: var(--brand-500); }
button.popt:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; }
.popt-mine { border-color: var(--brand-700); }
.pbar { position: absolute; inset: 0 auto 0 0; background: var(--brand-50); z-index: 0; transition: width var(--t-slow) var(--ease); }
.pbar-label, .pbar-num { position: relative; z-index: 1; }
.pbar-num { font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* study plan */
.plan-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); align-items: start; }
.plan-day { padding: var(--sp-4); display: grid; gap: var(--sp-2); }
.plan-today { border-color: var(--brand-500); box-shadow: 0 0 0 1px var(--brand-500), var(--shadow-sm); }
.plan-heavy { background: #FFFBF3; }
.plan-heavy-text { color: #8A4B00; font-weight: 600; }
.plan-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-2); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--gray-100); }
.plan-item { display: flex; gap: var(--sp-2); align-items: flex-start; padding: var(--sp-2) 0; }
.plan-item.plan-live { flex-direction: column; gap: 2px; padding: var(--sp-2) var(--sp-3); background: var(--green-100); border-radius: 12px; color: inherit; }
.plan-main { display: grid; gap: 2px; min-width: 0; }
.plan-title { font-weight: 580; overflow-wrap: anywhere; }
.plan-kind { align-self: flex-start; font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--brand-700); }
.plan-kind-assignment { color: #8A4B00; } .plan-kind-revise { color: var(--red-600); } .plan-kind-lesson { color: var(--green-600); }
.plan-check { padding-top: 3px; } .plan-check input { width: 18px; height: 18px; accent-color: var(--brand-700); cursor: pointer; }
.plan-done .plan-title { text-decoration: line-through; color: var(--gray-500); }
.plan-done .plan-main { opacity: .65; }
.plan-overdue .plan-title { color: var(--red-600); }

/* small screens: rows with a long title and a button wrap instead of pushing the page sideways */
.list-item > * { min-width: 0; }
@media (max-width: 640px) { .list-item { flex-wrap: wrap; } .list-item > div:first-child { flex: 1 1 12rem; overflow-wrap: anywhere; } }

/* ======================================================================
   Fits every screen: phones, tablets, laptops, large and ultra-wide monitors,
   landscape phones, notched phones, touch and mouse.
   ====================================================================== */
html { font-size: clamp(16px, 0.35vw + 11.5px, 19px); }                  /* 16px up to 1280px wide, then grows gently to 19px */
:root { --content-max: clamp(1200px, 80vw, 1640px); --sidebar-w: clamp(232px, 15vw, 290px); }
h1 { font-size: clamp(1.5rem, 1.15rem + 1.1vw, 2.25rem); }
h2 { font-size: clamp(1.25rem, 1.05rem + .6vw, 1.625rem); }
.content { padding-left: max(var(--sp-5), env(safe-area-inset-left)); padding-right: max(var(--sp-5), env(safe-area-inset-right)); padding-bottom: max(var(--sp-8), calc(var(--sp-6) + env(safe-area-inset-bottom))); }
.topbar { padding-left: max(var(--sp-5), env(safe-area-inset-left)); padding-right: max(var(--sp-5), env(safe-area-inset-right)); }
.toast-region { bottom: max(var(--sp-4), env(safe-area-inset-bottom)); right: max(var(--sp-4), env(safe-area-inset-right)); }

/* full-height areas follow the visible screen on phones (the address bar comes and goes) */
@supports (height: 100dvh) {
  .app, .center-page { min-height: 100dvh; }
  .sidebar { height: 100dvh; }
  .modal { max-height: 90dvh; }
}
.sidebar { overflow-y: auto; overscroll-behavior: contain; padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); }

/* big grids use the space on large screens, and never get cramped on small ones */
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
@media (min-width: 1500px) { .course-grid, .mgrid, .plan-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); } }

/* tablets: the menu stays a slide-in drawer up to 1024 so the content gets the room */
@media (max-width: 1024px) and (min-width: 861px) { :root { --sidebar-w: 216px; } .content { padding-left: var(--sp-4); padding-right: var(--sp-4); } }
@media (max-width: 860px) {
  .topbar { padding-left: max(var(--sp-3), env(safe-area-inset-left)); padding-right: max(var(--sp-3), env(safe-area-inset-right)); }
  .content { padding-left: max(var(--sp-4), env(safe-area-inset-left)); padding-right: max(var(--sp-4), env(safe-area-inset-right)); }
  .page-head { align-items: stretch; }
  .page-head > .row, .page-head > .actions { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .page-head .btn { flex: 1 1 auto; }
  .modal-actions { flex-wrap: wrap; } .modal-actions .btn { flex: 1 1 8rem; }
  .tabs { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; } .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; white-space: nowrap; }
}
@media (max-width: 360px) { html { font-size: 15px; } .content { padding-left: var(--sp-3); padding-right: var(--sp-3); } }

/* landscape phones and other short screens */
@media (max-height: 520px) {
  :root { --topbar-h: 48px; }
  .modal-backdrop { align-items: start; padding: var(--sp-2); } .modal { max-height: calc(100dvh - 1rem); }
  .sidebar .nav-link, .sidebar a { padding-top: 6px; padding-bottom: 6px; }
}

/* touch screens: comfortable tap targets (about 44px) */
@media (pointer: coarse) {
  .btn, .btn-sm { min-height: 44px; } .btn-sm { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .input, .select, .textarea { min-height: 44px; font-size: max(16px, 1rem); }      /* 16px stops iOS zooming into fields */
  .tab { min-height: 44px; display: inline-flex; align-items: center; }
  .sidebar a { min-height: 44px; }
  .menu-btn, .icon-btn, .topbar button { min-width: 44px; min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
}

/* wide tables scroll inside their own box, with a soft edge that shows there is more */
.table-wrap { max-width: 100%; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  background: linear-gradient(to right, var(--surface) 30%, transparent), linear-gradient(to left, var(--surface) 30%, transparent), linear-gradient(to right, rgba(16,24,40,.12), transparent), linear-gradient(to left, rgba(16,24,40,.12), transparent);
  background-position: left center, right center, left center, right center; background-repeat: no-repeat; background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%; background-attachment: local, local, scroll, scroll; }
.table td, .table th { overflow-wrap: anywhere; } .table th { white-space: nowrap; }

/* media never overflows its box */
img, video, iframe, canvas, svg { max-width: 100%; } .player iframe, .player video { width: 100%; }
pre, code { overflow-wrap: anywhere; } pre { overflow-x: auto; }

/* people who prefer larger text or high zoom: let rows wrap instead of clipping */
.row { flex-wrap: wrap; } .page-head h1, .card h3 { overflow-wrap: anywhere; }
.callout { padding: var(--sp-4); border-radius: var(--radius); background: var(--brand-50, #EEF3FD); border: 1px solid var(--brand-100, #D6E2FB); }
.stack-sm { display: grid; gap: var(--sp-2); }
.chip-ok { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--green-100, #E3F3E0); color: #1F6B17; }
.chip-off { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--gray-100); color: var(--gray-700); }
