/* app.css — OpenCourse Scroll
 *
 * No external assets: no web fonts, no icon CDN, no framework. Everything here
 * ships with the site so it works offline and on Cloudflare Pages with nothing
 * but static files.
 *
 * Stacking order in the root context (this matters for the feed):
 *   10  .card-bg        poster / placeholder
 *   20  .card-scrim     legibility gradient
 *   30  #stage          the actual video pixels
 *   40  .card-body .card-rail   text and buttons, in front of the video
 *   60  .tabbar
 *   90  .sheet-host
 *  120  .splash
 */

/* ------------------------------------------------------------------ */
/* tokens                                                             */
/* ------------------------------------------------------------------ */

:root {
  --bg: #07080b;
  --bg-2: #0c0e14;
  --surface: #12141c;
  --surface-2: #171a24;
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #f3f5f9;
  --muted: #99a1b3;
  --muted-2: #6f7789;
  --accent: #7ea8ff;
  --accent-2: #a78bfa;
  --good: #4ade9b;
  --danger: #ff5f73;
  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 24px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.booting { overflow: hidden; }
body.sheet-open { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
::selection { background: var(--accent); color: #07121f; }

.ic { display: inline-flex; width: 1.15em; height: 1.15em; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; }

.view-root {
  position: relative;
  min-height: 100%;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
body.in-feed .view-root { height: 100dvh; min-height: 0; padding-bottom: 0; overflow: hidden; }
body.in-course .view-root { height: 100dvh; min-height: 0; padding-bottom: 0; overflow-y: auto; }

.view { max-width: 920px; margin: 0 auto; padding: 18px 16px 40px; }
@media (min-width: 900px) { .view { padding: 26px 24px 64px; } }

/* ------------------------------------------------------------------ */
/* splash                                                             */
/* ------------------------------------------------------------------ */

.splash {
  position: fixed; inset: 0; z-index: 120;
  display: grid; place-items: center;
  background: radial-gradient(120% 80% at 50% 0%, #151a2b 0%, var(--bg) 60%);
  transition: opacity .45s ease, visibility .45s ease;
}
.splash.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-inner { text-align: center; padding: 24px; display: grid; gap: 10px; justify-items: center; }
.brand-mark { width: 76px; height: 76px; margin-bottom: 6px; animation: floaty 3.4s ease-in-out infinite; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font-size: 25px; letter-spacing: -0.03em; }
.brand-tag { color: var(--muted); font-size: 14px; max-width: 30ch; }
.splash-status { color: var(--muted-2); font-size: 12.5px; margin-top: 10px; min-height: 1.2em; }
.splash.error .splash-status { color: var(--danger); }
@keyframes floaty { 50% { transform: translateY(-7px); } }

/* ------------------------------------------------------------------ */
/* stage (the video pixels)                                           */
/* ------------------------------------------------------------------ */

.stage {
  position: fixed; inset: 0; z-index: 30;
  pointer-events: none;
  background: transparent;
  opacity: 0;
  transition: opacity .26s ease;
}
body.in-feed .stage { opacity: 1; }
.stage.stage-hidden { opacity: 0 !important; transition-duration: .14s; }
.stage-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .3s ease;
  background: #05060a;
}
.stage-video.is-active { opacity: 1; }
/* "Fit" mode: no cropping, letterboxed over a blurred copy of the same frame. */
.stage.fit .stage-video { object-fit: contain; }
.stage-video.prefetch {
  width: 2px; height: 2px; left: -20px; top: -20px;
  opacity: .01; inset: auto;
}

.mute-btn {
  position: fixed; z-index: 70;
  right: 14px; top: calc(var(--safe-t) + 12px);
  display: none; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--line-2);
  background: rgba(10, 12, 18, 0.72);
  backdrop-filter: blur(14px);
  font-size: 12.5px; color: var(--text);
  cursor: pointer;
}
body.in-feed .mute-btn { display: inline-flex; }
.mute-btn .mute-hint { display: none; }
.mute-btn.muted .mute-hint { display: inline; }
.mute-btn.muted { color: var(--accent); border-color: rgba(126, 168, 255, .45); }
.mute-btn.muted .ic { display: none; }

/* ------------------------------------------------------------------ */
/* feed                                                               */
/* ------------------------------------------------------------------ */

.feed-shell { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.feed-header {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) 14px 10px;
  background: linear-gradient(180deg, rgba(7,8,11,.96), rgba(7,8,11,0));
  position: relative; z-index: 50;
  flex: none;
}
.feed-header-text { display: grid; }
.feed-header-text strong { font-size: 15.5px; letter-spacing: -0.01em; }
.feed-header-text span { color: var(--muted); font-size: 12px; }

.feed {
  flex: 1; min-height: 0;
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--bg);
}
.feed::-webkit-scrollbar { display: none; }
.feed-track { position: relative; }

.card {
  position: relative;
  /* `--card-h` is set by FeedView.measure() to the scroll container's exact
     client height, so snap points and the stage always agree. */
  height: var(--card-h, 100dvh);
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
}
.card.pressing .card-body { transform: scale(.995); }

.card-bg {
  position: absolute; inset: 0; z-index: 10;
  background: var(--card-accent, #101218);
  overflow: hidden;
}
/* The archive.org poster thumbnails are tiny (180x124). Rather than upscale a
   mush, we use one deliberately as an ambient blurred backdrop and let the
   video supply the real image. It also gives the loader something to show. */
.card-poster {
  position: absolute; inset: -12%;
  width: 124%; height: 124%;
  object-fit: cover; display: block;
  filter: blur(34px) saturate(1.35) brightness(.62);
  transform: scale(1.05);
  opacity: 0;
  transition: opacity .5s ease;
}
.card-poster.loaded { opacity: 1; }
.card-poster.broken { opacity: 0; }
.card-poster[src=""] { opacity: 0; }
body.fit-mode .card-poster { filter: blur(34px) saturate(1.5) brightness(.5); }

/* Loading shimmer while the first bytes of the clip arrive. */
.card[data-playback="loading"] .card-bg::after,
.card[data-playback="ready"] .card-bg::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.06) 45%, transparent 60%);
  background-size: 220% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -80% 0; } }
.card[data-playback="failed"] .card-bg::after {
  content: ''; position: absolute; inset: 0; background: rgba(120, 20, 30, .18);
}

.card-scrim {
  position: absolute; inset: 0; z-index: 20; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(4,5,8,.72) 0%, rgba(4,5,8,.06) 26%, rgba(4,5,8,.12) 52%, rgba(4,5,8,.86) 88%, rgba(4,5,8,.95) 100%),
    linear-gradient(90deg, rgba(4,5,8,.5) 0%, rgba(4,5,8,0) 46%);
}
.card-tap-sentinel { position: absolute; inset: 0; z-index: 24; pointer-events: none; }

/* Autoplay refused: show a play affordance so the card is obviously tappable. */
.card.needs-tap::after {
  content: '';
  position: absolute; z-index: 42; left: 50%; top: 44%;
  width: 74px; height: 74px; margin: -37px 0 0 -37px;
  border-radius: 999px;
  background: rgba(8,10,16,.6) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M7 4.5 19.5 12 7 19.5Z'/%3E%3C/svg%3E") center / 34px 34px no-repeat;
  border: 1px solid rgba(255,255,255,.4);
  backdrop-filter: blur(8px);
  animation: pulse 2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse { 50% { transform: scale(1.07); } }

.card-body {
  position: absolute; z-index: 40;
  left: 0; right: 78px; bottom: 0;
  padding: 0 18px calc(14px + var(--safe-b) + var(--tabbar-h));
  display: grid; gap: 9px;
  transition: transform .18s ease;
}
@media (min-width: 720px) { .card-body { right: 96px; padding: 0 26px calc(20px + var(--safe-b) + var(--tabbar-h)); max-width: 780px; } }

.card-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(8px);
  color: var(--text);
}
.chip.inst { background: linear-gradient(135deg, rgba(126,168,255,.34), rgba(167,139,250,.3)); border-color: rgba(167,139,250,.45); }
.chip.ghost { background: rgba(255,255,255,.05); color: var(--muted); text-transform: capitalize; }

.card-title {
  font-size: clamp(21px, 5.6vw, 34px);
  line-height: 1.12;
  letter-spacing: -0.03em;
  text-shadow: 0 2px 18px rgba(0,0,0,.6);
}
.card-sub {
  color: #d7dcea; font-size: 13.5px;
  text-shadow: 0 1px 12px rgba(0,0,0,.7);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-topics { display: flex; flex-wrap: wrap; gap: 6px; }
.topic {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: rgba(126,168,255,.14); border: 1px solid rgba(126,168,255,.28);
  color: #cfe0ff;
}
.topic.major { background: rgba(167,139,250,.14); border-color: rgba(167,139,250,.3); color: #e3d9ff; }

/* segment progress */
.seg { display: grid; gap: 6px; position: relative; }
.seg-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #cfd6e6; }
.seg-kind { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.seg-timer {
  margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.12);
  border: 1px solid var(--line-2); font-size: 11.5px;
}
.seg-timer.low { color: var(--accent); border-color: rgba(126,168,255,.5); }
.seg-track {
  height: 4px; border-radius: 999px; background: rgba(255,255,255,.2); overflow: hidden;
}
.seg-fill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width .18s linear;
}
.seg-scrub {
  position: absolute; left: 0; right: 0; bottom: -12px; height: 30px;
  cursor: pointer; touch-action: none;
}

.card-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 17px; border-radius: 999px;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #08101f; font-weight: 650; font-size: 14px;
  cursor: pointer; text-decoration: none;
  transition: transform .12s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: rgba(255,255,255,.07); border-color: var(--line-2); color: var(--text); }
.btn.ghost.on { background: rgba(126,168,255,.2); border-color: rgba(126,168,255,.5); color: #dbe7ff; }
.btn.danger { background: rgba(255,95,115,.16); border-color: rgba(255,95,115,.4); color: #ffc4cc; }
.btn.small { padding: 8px 13px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.btn.open-course { background: rgba(255,255,255,.95); color: #0a0d15; }

.reason-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(10,12,18,.6); border: 1px solid var(--line-2);
  backdrop-filter: blur(10px);
  font-size: 12px; color: #cbd3e4;
  cursor: pointer;
}
.reason-chip:hover { border-color: rgba(126,168,255,.5); }
.reason-chip.resume { color: var(--accent); border-color: rgba(126,168,255,.4); }
.reason-chip .ic { color: var(--accent-2); }

/* right rail */
.card-rail {
  position: absolute; z-index: 40;
  right: 10px; bottom: calc(14px + var(--safe-b) + var(--tabbar-h));
  display: grid; gap: 13px; justify-items: center;
}
@media (min-width: 720px) { .card-rail { right: 20px; bottom: calc(20px + var(--safe-b) + var(--tabbar-h)); } }
.rail-btn {
  display: grid; justify-items: center; gap: 4px;
  background: none; border: 0; padding: 0; cursor: pointer;
  color: #e7ebf5;
}
.rail-ic {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 999px;
  background: rgba(12,14,20,.55);
  border: 1px solid var(--line-2);
  backdrop-filter: blur(12px);
  transition: transform .16s cubic-bezier(.2,1.5,.5,1), background .16s ease;
}
.rail-ic svg { width: 21px; height: 21px; }
.rail-btn:active .rail-ic { transform: scale(.9); }
.rail-label { font-size: 10.5px; color: #dfe4ef; text-shadow: 0 1px 6px rgba(0,0,0,.8); }
.rail-btn.on { color: var(--accent); }
.rail-btn.on .rail-ic { background: rgba(126,168,255,.22); border-color: rgba(126,168,255,.55); color: var(--accent); }
.rail-btn[data-key="like"].on .rail-ic { color: #ff5f8d; background: rgba(255,95,141,.18); border-color: rgba(255,95,141,.5); }

/* ------------------------------------------------------------------ */
/* tabbar                                                             */
/* ------------------------------------------------------------------ */

.tabbar {
  position: fixed; z-index: 60;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 130px));
  justify-content: center;
  gap: 6px;
  background: rgba(8, 9, 13, 0.86);
  backdrop-filter: blur(22px) saturate(1.3);
  border-top: 1px solid var(--line);
}
body.in-course .tabbar { display: none; }
.tab {
  display: grid; place-items: center; gap: 3px;
  background: none; border: 0; cursor: pointer;
  color: var(--muted-2); padding: 8px 0 6px;
  transition: color .16s ease;
}
.tab .tab-ic { display: block; }
.tab .tab-ic svg { width: 23px; height: 23px; }
.tab-label { font-size: 10.5px; font-weight: 600; letter-spacing: .02em; }
.tab.on { color: var(--text); }
.tab.on .tab-ic { color: var(--accent); filter: drop-shadow(0 0 12px rgba(126,168,255,.5)); }

/* ------------------------------------------------------------------ */
/* shared view chrome                                                 */
/* ------------------------------------------------------------------ */

.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
.view-head h1 { font-size: 30px; letter-spacing: -0.035em; }
.view-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.block { margin: 0 0 30px; }
.block-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.block-head h2 { font-size: 17px; letter-spacing: -0.02em; }
.block-note { color: var(--muted-2); font-size: 12px; }
.about-copy { color: var(--muted); font-size: 13.5px; margin-bottom: 12px; max-width: 68ch; }

.empty { text-align: center; padding: 44px 22px; display: grid; gap: 10px; justify-items: center; }
.empty h3 { font-size: 19px; }
.empty p { color: var(--muted); font-size: 13.5px; max-width: 46ch; }
.empty-card { display: grid; place-items: center; }
.empty-wrap { display: grid; place-items: center; }

/* ---------- search ---------- */
.search-block { display: flex; gap: 9px; margin-bottom: 24px; }
.search-input {
  flex: 1; min-width: 0;
  padding: 12px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text); font-size: 14.5px;
}
.search-input:focus { outline: 2px solid rgba(126,168,255,.5); outline-offset: 1px; }

/* ---------- topics strip ---------- */
.topic-strip { display: flex; gap: 9px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.topic-strip::-webkit-scrollbar { display: none; }
.topic-pill {
  flex: none; display: grid; gap: 7px; min-width: 140px;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text); text-decoration: none;
}
.topic-pill-name { font-size: 13px; font-weight: 600; }
.topic-pill-bar { height: 4px; border-radius: 999px; background: rgba(255,255,255,.1); overflow: hidden; }
.topic-pill-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- profession tracks ---------- */
.prof-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.prof-card {
  position: relative; text-align: left; cursor: pointer;
  display: grid; gap: 6px; align-content: start;
  padding: 15px 16px 16px; border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--accent) 30%, transparent) 0%, transparent 62%),
    var(--surface);
  border: 1px solid var(--line);
  transition: transform .16s ease, border-color .16s ease;
}
.prof-card:hover { transform: translateY(-2px); border-color: var(--line-2); }
.prof-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.prof-ic {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: #eaf1ff;
}
.prof-ic svg { width: 15px; height: 15px; }
.prof-lect { color: var(--muted-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.prof-name { font-size: 16px; letter-spacing: -0.02em; }
.prof-blurb { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.prof-meta { color: var(--muted-2); font-size: 11.5px; margin-top: 2px; }

/* ---------- major grid ---------- */
.major-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); }
.major-card {
  position: relative; text-align: left;
  display: grid; grid-template-columns: 74px 1fr; gap: 14px; align-items: center;
  padding: 14px; border-radius: var(--radius-lg);
  background: linear-gradient(150deg, color-mix(in srgb, var(--accent) 22%, var(--surface)) 0%, var(--surface) 62%);
  border: 1px solid var(--line);
  cursor: pointer; overflow: hidden;
  transition: transform .16s ease, border-color .16s ease;
}
.major-card:hover { transform: translateY(-2px); border-color: var(--line-2); }
.major-stack { position: relative; width: 74px; height: 74px; }
.major-stack-img {
  position: absolute; inset: 0;
  border-radius: 13px; background-size: cover; background-position: center;
  border: 1px solid rgba(255,255,255,.16);
  transform: translate(calc(var(--i) * 5px), calc(var(--i) * 5px)) rotate(calc(var(--i) * 4deg));
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
  opacity: calc(1 - var(--i) * 0.30);
}
.major-body { display: grid; gap: 5px; min-width: 0; }
.major-body h3 { font-size: 15.5px; letter-spacing: -0.02em; }
.major-body p { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.major-stats { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted-2); font-size: 11.5px; }
.major-stats span { display: inline-flex; align-items: center; gap: 4px; }
.major-play {
  position: absolute; right: 14px; top: 14px;
  width: 30px; height: 30px; border-radius: 999px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.14); border: 1px solid var(--line-2);
}
.major-play svg { width: 14px; height: 14px; }

.inst-row { display: flex; flex-wrap: wrap; gap: 9px; }
.inst-chip {
  display: grid; gap: 1px; text-align: left;
  padding: 11px 15px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer;
}
.inst-chip:hover { border-color: var(--line-2); }
.inst-chip strong { font-size: 13.5px; }
.inst-chip span { color: var(--muted-2); font-size: 11.5px; }

.source-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: grid; gap: 5px; }

/* ---------- shelf ---------- */
.shelf-row { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 10px; scroll-snap-type: x proximity; scrollbar-width: none; }
.shelf-row::-webkit-scrollbar { display: none; }
.tile {
  flex: none; width: 208px; text-align: left;
  background: none; border: 0; padding: 0; cursor: pointer;
  scroll-snap-align: start;
  display: grid; gap: 9px;
}
.tile-thumb {
  position: relative; display: block;
  aspect-ratio: 16 / 10; border-radius: var(--radius);
  background: var(--surface-2) center/cover no-repeat;
  border: 1px solid var(--line); overflow: hidden;
}
.tile-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.5));
  color: #fff; opacity: 0; transition: opacity .16s ease;
}
.tile:hover .tile-play { opacity: 1; }
.tile-play svg { width: 34px; height: 34px; }
.ring { position: absolute; right: 8px; top: 8px; width: 30px; height: 30px; color: var(--accent); }
.ring svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); }
.tile-body { display: grid; gap: 2px; }
.tile-inst { color: var(--accent); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.tile-title { font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-sub { color: var(--muted-2); font-size: 12px; }

/* ---------- row list ---------- */
.row-list { display: grid; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px;
}
.row-main { flex: 1; min-width: 0; display: flex; gap: 13px; align-items: center; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.row-thumb { flex: none; width: 74px; height: 52px; border-radius: 10px; background: var(--surface-2) center/cover no-repeat; border: 1px solid var(--line); }
.row-body { display: grid; gap: 3px; min-width: 0; }
.row-inst { color: var(--muted-2); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.row-title { font-size: 14.5px; }
.row-sub { color: var(--muted); font-size: 12.5px; }
.row-bar { display: block; height: 3px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; margin-top: 3px; }
.row-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  cursor: pointer; color: var(--text); padding: 0; flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn.danger { color: var(--danger); }
.icon-btn .ic svg { width: 19px; height: 19px; }

/* ------------------------------------------------------------------ */
/* me                                                                 */
/* ------------------------------------------------------------------ */

.me-stats { margin-bottom: 26px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat {
  display: grid; gap: 2px; justify-items: start;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.stat-ic { color: var(--accent); margin-bottom: 3px; }
.stat strong { font-size: 21px; letter-spacing: -0.02em; }
.stat span:last-child { color: var(--muted-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.me-note { color: var(--muted-2); font-size: 12.5px; margin-top: 10px; }

.list-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.list-card {
  text-align: left; padding: 0; overflow: hidden; cursor: pointer;
  border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line);
  display: grid;
}
.list-card:hover { border-color: var(--line-2); }
.list-covers { display: grid; grid-template-columns: 1fr 1fr; aspect-ratio: 16 / 9; gap: 1px; background: var(--bg); }
.list-cover { background: var(--surface-2) center/cover no-repeat; }
.list-cover.empty { grid-column: span 2; display: grid; place-items: center; color: var(--muted-2); }
.list-cover.empty svg { width: 34px; height: 34px; }
.list-card-body { padding: 12px 14px 14px; display: grid; gap: 3px; }
.list-name { display: inline-flex; align-items: center; gap: 7px; font-weight: 650; font-size: 14.5px; }
.list-name .ic { color: var(--accent); }
.list-count { color: var(--muted-2); font-size: 12px; }

.hist-list { display: grid; gap: 9px; }
.hist-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 9px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
}
.hist-thumb { flex: none; width: 56px; height: 40px; border-radius: 9px; background: var(--surface-2) center/cover no-repeat; }
.hist-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.hist-body strong { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta { display: flex; gap: 10px; color: var(--muted-2); font-size: 11px; }
.hist-like { color: #ff5f8d; }
.hist-bar { flex: none; width: 52px; height: 4px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; }
.hist-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.data-actions { display: flex; flex-wrap: wrap; gap: 9px; }

/* ------------------------------------------------------------------ */
/* course view                                                        */
/* ------------------------------------------------------------------ */

.course-view { padding-bottom: 60px; }
.course-head { display: flex; align-items: flex-start; gap: 12px; margin: 4px 0 16px; }
.course-head-text { flex: 1; min-width: 0; display: grid; gap: 5px; }
.course-title { display: flex; align-items: center; gap: 9px; font-size: 24px; letter-spacing: -0.03em; }
.course-title .ic { color: var(--accent); }
.course-byline { color: var(--muted); font-size: 13px; }
.course-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.course-stage { margin-bottom: 18px; display: grid; gap: 12px; }
.course-video {
  width: 100%; aspect-ratio: 16 / 9; background: #000;
  border-radius: var(--radius); border: 1px solid var(--line);
}
.resume-banner {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 11px 15px; border-radius: var(--radius);
  background: rgba(126,168,255,.12); border: 1px solid rgba(126,168,255,.35);
  color: #d9e6ff; font-size: 13.5px; cursor: pointer; text-align: left;
}
.course-meta { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.course-meta span { display: inline-flex; align-items: center; gap: 5px; }
.course-meta .ok { color: var(--good); }
.course-desc { color: #c8cfdd; font-size: 14px; margin-bottom: 12px; max-width: 76ch; }
.course-topics { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 20px; }

.playlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.playlist-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; position: relative; overflow: hidden;
}
.playlist-item:hover { border-color: var(--line-2); }
.playlist-item.current { border-color: rgba(126,168,255,.55); background: rgba(126,168,255,.1); }
.playlist-item.done .pl-index { color: var(--good); }
.pl-index {
  flex: none; width: 26px; height: 26px; border-radius: 999px;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
  background: rgba(255,255,255,.07); color: var(--muted);
}
.pl-index svg { width: 14px; height: 14px; }
.pl-text { display: grid; gap: 1px; min-width: 0; }
.pl-title { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-sub { color: var(--muted-2); font-size: 11.5px; }
.pl-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255,255,255,.08); }
.pl-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

@media (min-width: 980px) {
  .course-main {
    display: grid; gap: 0 26px;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas: "head head" "stage side" "desc side" "topics side";
    align-content: start;
  }
  .course-head { grid-area: head; }
  .course-stage { grid-area: stage; }
  .course-desc { grid-area: desc; }
  .course-topics { grid-area: topics; }
  .course-side { grid-area: side; position: sticky; top: 18px; align-self: start; max-height: calc(100dvh - 40px); overflow-y: auto; }
}

/* ------------------------------------------------------------------ */
/* debug                                                              */
/* ------------------------------------------------------------------ */

.debug-view .block { margin-bottom: 26px; }
.facts { margin: 0; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.fact-row { display: flex; justify-content: space-between; gap: 14px; background: var(--surface); padding: 10px 14px; }
.fact-row dt { color: var(--muted); font-size: 12.5px; }
.fact-row dd { margin: 0; font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; }

.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th { text-align: left; color: var(--muted-2); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 7px 9px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 7px 9px; border-bottom: 1px solid rgba(255,255,255,.045); }
.data-table tr:hover td { background: rgba(255,255,255,.025); }
.mini-bar { display: inline-flex; align-items: center; gap: 7px; width: 100%; }
.mini-bar i { display: block; height: 4px; min-width: 2px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.mini-bar em { font-style: normal; color: var(--muted-2); font-size: 11px; }
.signed { display: block; height: 5px; border-radius: 999px; background: rgba(255,255,255,.07); overflow: hidden; min-width: 60px; }
.signed i { display: block; height: 100%; }
.signed.pos i { background: var(--good); }
.signed.neg i { background: var(--danger); }
.profile-bars { display: grid; gap: 7px; }
.profile-row { display: grid; grid-template-columns: 180px 1fr; gap: 12px; align-items: center; }
.profile-name { font-size: 12.5px; color: var(--muted); text-transform: capitalize; }
.profile-track { height: 6px; border-radius: 999px; background: rgba(255,255,255,.08); overflow: hidden; }
.profile-track i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
@media (max-width: 520px) { .profile-row { grid-template-columns: 110px 1fr; } }

/* ------------------------------------------------------------------ */
/* sheets & toasts                                                    */
/* ------------------------------------------------------------------ */

.sheet-host { position: relative; z-index: 90; }
.sheet-scrim {
  position: fixed; inset: 0; background: rgba(3,4,7,.66);
  opacity: 0; transition: opacity .2s ease; backdrop-filter: blur(3px);
}
.sheet-scrim.in { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 84dvh; overflow-y: auto;
  background: var(--bg-2);
  border-top: 1px solid var(--line-2);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + var(--safe-b));
  transform: translateY(102%);
  transition: transform .26s cubic-bezier(.22,1,.36,1);
  box-shadow: var(--shadow);
}
.sheet.in { transform: translateY(0); }
@media (min-width: 760px) {
  .sheet { left: 50%; right: auto; width: 560px; transform: translate(-50%, 102%); border-radius: 22px; bottom: 24px; }
  .sheet.in { transform: translate(-50%, 0); }
}
.sheet-grab { width: 42px; height: 4px; border-radius: 999px; background: var(--line-2); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.sheet-head > div:first-child { flex: 1; }
.sheet-title { font-size: 18px; letter-spacing: -0.02em; }
.sheet-sub { color: var(--muted); font-size: 13px; }
.sheet-body { display: grid; gap: 14px; }
.sheet-copy { color: #c8cfdd; font-size: 13.5px; }
.sheet-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; }

.picker-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; text-align: left; margin-bottom: 8px;
}
.picker-row.on { border-color: rgba(126,168,255,.5); background: rgba(126,168,255,.1); }
.picker-ic { color: var(--accent); }
.picker-name { font-weight: 600; font-size: 14px; }
.picker-meta { margin-left: auto; color: var(--muted-2); font-size: 11.5px; }
.picker-check { color: var(--accent); width: 20px; }
.new-list-row { display: flex; gap: 8px; margin-top: 6px; }
.new-list-row input {
  flex: 1; min-width: 0; padding: 10px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
}
.why-head { display: grid; gap: 6px; }
.why-reason { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 650; font-size: 14px; }
.why-lecture { color: var(--muted); font-size: 12.5px; }
.why-bars { display: grid; gap: 13px; }
.why-row { display: grid; gap: 5px; }
.why-top { display: flex; justify-content: space-between; font-size: 12.5px; }
.why-val { color: var(--muted); font-variant-numeric: tabular-nums; }
.why-track { height: 5px; border-radius: 999px; background: rgba(255,255,255,.08); overflow: hidden; }
.why-track i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.why-note { color: var(--muted-2); font-size: 11.5px; }
.why-foot { color: var(--muted-2); font-size: 11.5px; border-top: 1px solid var(--line); padding-top: 12px; }

.toast-host {
  position: fixed; z-index: 130;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  display: grid; gap: 8px; justify-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  padding: 11px 17px; border-radius: 999px;
  background: rgba(20,23,32,.95); border: 1px solid var(--line-2);
  color: var(--text); font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px);
  transition: opacity .22s ease, transform .22s ease;
  backdrop-filter: blur(14px);
}
.toast.in { opacity: 1; transform: translateY(0); }

.heart-burst {
  position: fixed; z-index: 125;
  width: 96px; height: 96px; margin: -48px 0 0 -48px;
  color: #ff5f8d; pointer-events: none;
  animation: burst .85s cubic-bezier(.2,1.3,.4,1) forwards;
  filter: drop-shadow(0 6px 20px rgba(255,95,141,.6));
}
.heart-burst svg { width: 100%; height: 100%; }
@keyframes burst {
  0% { opacity: 0; transform: scale(.3) rotate(-12deg); }
  35% { opacity: 1; transform: scale(1.15) rotate(4deg); }
  60% { transform: scale(1) rotate(0deg); }
  100% { opacity: 0; transform: scale(1.1) translateY(-40px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
