/* ============================================================
   Study Dashboard — design system
   ============================================================ */

:root {
  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-soft: #eef2ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0284c7;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #9ca3af;
  --track: #e9ecf3;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --sidebar-w: 252px;
  --topbar-h: 60px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
  --brand: #818cf8;
  --brand-strong: #a5b4fc;
  --brand-soft: #262a45;
  --ok: #4ade80;
  --ok-soft: #14321f;
  --warn: #fbbf24;
  --warn-soft: #3a2c0c;
  --danger: #f87171;
  --danger-soft: #3b1717;
  --info: #38bdf8;

  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1d212c;
  --border: #272b38;
  --border-strong: #363b4b;
  --text: #e8eaf0;
  --text-2: #a2a9bb;
  --text-3: #6b7280;
  --track: #262b38;

  --shadow-sm: none;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
}

/* ---- AMOLED: true black so OLED pixels switch off entirely (saves battery).
   Inherits every dark-theme colour, then overrides the surfaces. ---- */
html[data-theme="amoled"] {
  --brand: #8b93ff;
  --brand-strong: #aab1ff;
  --brand-soft: #14162b;
  --ok: #3ddc84;
  --ok-soft: #06210f;
  --warn: #ffc63d;
  --warn-soft: #241a00;
  --danger: #ff6b6b;
  --danger-soft: #240a0a;
  --info: #38bdf8;

  --bg: #000000;
  --surface: #000000;
  --surface-2: #0a0a0c;
  --border: #1c1c22;
  --border-strong: #2c2c36;
  --text: #f2f3f7;
  --text-2: #9ba1b0;
  --text-3: #6a7080;
  --track: #17171d;

  --shadow-sm: none;
  --shadow: none;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .9);
}

/* Cards need a visible edge once every surface is pure black. */
/* ============================================================
   Nothing-inspired theme — monochrome canvas, one red accent,
   engineered/technical typography. The dot-matrix look is drawn
   with CSS gradients, so no proprietary font is bundled.
   ============================================================ */

html[data-theme="nothing"] {
  --brand: #d71921;
  --brand-strong: #ff3b40;
  --brand-soft: #1a0708;
  --ok: #e8e8e8;
  --ok-soft: #131313;
  --warn: #d71921;
  --warn-soft: #1a0708;
  --danger: #d71921;
  --danger-soft: #1a0708;
  --info: #b4b4b4;

  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #131313;
  --border: #232323;
  --border-strong: #3a3a3a;
  --text: #f5f5f5;
  --text-2: #a8a8a8;
  --text-3: #6e6e6e;
  --track: #1c1c1c;

  --shadow-sm: none;
  --shadow: none;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .9);

  /* Nothing's hardware look: near-square corners, not pills. */
  --r-sm: 3px;
  --r: 4px;
  --r-lg: 6px;
}

/* Technical, wide-tracked type. */
html[data-theme="nothing"] body {
  font-family: "SF Mono", "Roboto Mono", "DejaVu Sans Mono", ui-monospace, monospace;
  letter-spacing: .01em;
}

/* Headings + labels: uppercase, spaced out, like the Glyph UI. */
html[data-theme="nothing"] .page-title,
html[data-theme="nothing"] .section-title,
html[data-theme="nothing"] .brand-name,
html[data-theme="nothing"] .nav-label {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 600;
}
/* Tighter tracking here — .14em pushed these onto a second line. */
html[data-theme="nothing"] .stat-label {
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
  font-size: 11.5px;
}

/* The signature dot-matrix headline, drawn as a dot grid masked to the text. */
html[data-theme="nothing"] .page-title {
  font-size: 21px;
  background-image: radial-gradient(circle at center, #ffffff 43%, transparent 46%);
  background-size: 3px 3px;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}
/* Numbers stay solid so stats remain instantly readable. */
html[data-theme="nothing"] .stat-value,
html[data-theme="nothing"] .ring-label { letter-spacing: .02em; }

html[data-theme="nothing"] .brand-mark {
  background: var(--brand);
  border-radius: 50%;
}
html[data-theme="nothing"] .brand-sub { letter-spacing: .22em; }

/* Flat panels with a hairline edge — no glow, no gradient. */
html[data-theme="nothing"] .card,
html[data-theme="nothing"] .stat,
html[data-theme="nothing"] .hero,
html[data-theme="nothing"] .topbar,
html[data-theme="nothing"] .sidebar,
html[data-theme="nothing"] .modal {
  background-image: none;
  border-color: var(--border);
}

/* The hero loses its indigo gradient; a red rule carries the accent. */
html[data-theme="nothing"] .hero {
  background: var(--surface) !important;
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
}
html[data-theme="nothing"] .hero * { color: inherit !important; }

/* Buttons: squared, uppercase, mono. */
html[data-theme="nothing"] .btn {
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: 12px;
  font-weight: 600;
}
html[data-theme="nothing"] .btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}
html[data-theme="nothing"] .btn-primary:hover { background: var(--brand-strong); }

html[data-theme="nothing"] .nav-item.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--brand);
}
html[data-theme="nothing"] .filter-btn[aria-pressed="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

/* Progress reads like an LED strip: lit segments on a dim track. */
html[data-theme="nothing"] .bar { background: #1c1c1c; }
html[data-theme="nothing"] .bar > i {
  background-color: var(--text);
  background-image: linear-gradient(90deg, #000 0 1.5px, transparent 1.5px);
  background-size: 7px 100%;
}
html[data-theme="nothing"] .bar.ok > i { background-color: var(--text); }
html[data-theme="nothing"] .bar.warn > i,
html[data-theme="nothing"] .bar.danger > i { background-color: var(--brand); }

/* Completed = white dot, matching the monochrome language. */
html[data-theme="nothing"] .check:checked,
html[data-theme="nothing"] input[type="checkbox"]:checked {
  accent-color: var(--brand);
}

html[data-theme="nothing"] .heat-cell.l1 { background: #2a2a2a; }
html[data-theme="nothing"] .heat-cell.l2 { background: #545454; }
html[data-theme="nothing"] .heat-cell.l3 { background: #9a9a9a; }
html[data-theme="nothing"] .heat-cell.l4 { background: var(--brand); }

/* Chips: squared tags with a hairline edge, no coloured fill. */
html[data-theme="nothing"] .chip {
  border-radius: 2px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  letter-spacing: .06em;
  text-transform: uppercase;
  font-size: 10.5px;
}
html[data-theme="nothing"] .chip.p-high,
html[data-theme="nothing"] .chip.brand {
  color: var(--brand);
  border-color: var(--brand);
  background: transparent;
}
html[data-theme="nothing"] .chip.p-medium,
html[data-theme="nothing"] .chip.p-low {
  color: var(--text-2);
  border-color: var(--border-strong);
  background: transparent;
}

/* Badges over thumbnails stay legible on pure black. */
html[data-theme="nothing"] .v-badge,
html[data-theme="nothing"] .thumb-badge {
  border-radius: 2px;
  border: 1px solid var(--border-strong);
}

/* Dotted texture behind the sidebar brand — subtle Glyph nod. */
html[data-theme="nothing"] .brand {
  background-image: radial-gradient(circle at center, #1e1e1e 40%, transparent 42%);
  background-size: 6px 6px;
}

@media (prefers-reduced-motion: no-preference) {
  html[data-theme="nothing"] .btn { transition: background .12s linear; }
}

html[data-theme="amoled"] .card,
html[data-theme="amoled"] .stat,
html[data-theme="amoled"] .pl-card,
html[data-theme="amoled"] .note-card,
html[data-theme="amoled"] .modal {
  border-color: var(--border);
}

html[data-theme="amoled"] .nav-item.active { color: var(--brand); }
html[data-theme="amoled"] .btn-primary { color: #05050a; }
html[data-theme="amoled"] .filter-btn[aria-pressed="true"] { color: #05050a; }
html[data-theme="amoled"] .check[aria-checked="true"] { color: #04140a; }
html[data-theme="amoled"] .chip.brand { color: var(--brand); }

/* Slightly deeper gradient so the hero doesn't glow against true black. */
html[data-theme="amoled"] .hero {
  background: linear-gradient(135deg, #2f2a80 0%, #4a2a86 100%);
}

html[data-theme="amoled"] .topbar {
  background: rgba(0, 0, 0, .82);
  border-bottom-color: var(--border);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--brand); }
img { display: block; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 300;
  background: var(--brand); color: #fff; padding: 10px 16px;
  border-radius: var(--r-sm); transition: top .15s;
}
.skip-link:focus { top: 8px; }

/* ---------------- Layout ---------------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 60;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 18px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  display: grid; place-items: center; font-size: 18px; flex: none;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 11px; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; }

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); padding: 6px 10px; font-weight: 600;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; margin-bottom: 2px;
  border: 0; background: none; border-radius: var(--r-sm);
  color: var(--text-2); font-size: 14px; font-weight: 500;
  cursor: pointer; text-align: left; text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
html[data-theme="dark"] .nav-item.active { color: var(--brand); }
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; flex: none; }
.nav-item .count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2);
  padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border);
}
.nav-item.active .count { background: var(--surface); border-color: transparent; }

.nav-sub { padding-left: 22px; }
.nav-sub .nav-item { font-size: 13px; padding: 6px 10px; }

.sidebar-foot { padding: 12px; padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 6px)); border-top: 1px solid var(--border); }

/* ---------------- Main ---------------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; gap: 12px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}

.hamburger {
  display: none; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--r-sm); cursor: pointer; font-size: 17px;
}

.search-wrap { position: relative; flex: 1; max-width: 520px; }
.search-input {
  width: 100%; height: 38px; padding: 0 34px 0 34px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { background: var(--surface); border-color: var(--brand); outline: none; }
.search-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 13px; pointer-events: none; }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; cursor: pointer; color: var(--text-3);
  font-size: 16px; line-height: 1; padding: 4px; border-radius: 50%;
}
.search-clear:hover { color: var(--text); }

.search-panel {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  max-height: 62vh; overflow-y: auto; z-index: 80; padding: 6px;
}
.search-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); padding: 8px 10px 4px; font-weight: 700;
}
.search-hit {
  display: flex; gap: 10px; align-items: center; width: 100%;
  padding: 8px 10px; border: 0; background: none; border-radius: var(--r-sm);
  cursor: pointer; text-align: left;
}
.search-hit:hover, .search-hit:focus { background: var(--surface-2); }
.search-hit .h-ico { font-size: 15px; flex: none; }
.search-hit .h-title { font-size: 13.5px; font-weight: 550; }
.search-hit .h-sub { font-size: 11.5px; color: var(--text-3); }
.search-hit mark { background: color-mix(in srgb, var(--warn) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content {
  padding: 22px;
  padding-left: max(22px, env(safe-area-inset-left, 0px));
  padding-right: max(22px, env(safe-area-inset-right, 0px));
  padding-bottom: max(22px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  max-width: 1240px; width: 100%; margin: 0 auto; flex: 1;
}

.page-head {
  display: flex; align-items: flex-start; gap: 14px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-title { font-size: 22px; }
.page-sub { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.page-head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); border-color: var(--brand-strong); }
html[data-theme="dark"] .btn-primary { color: #12141c; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.93); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }

/* ---------------- Cards ---------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px; }

.stat-grid {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 15px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 3px;
}
.stat-top { display: flex; align-items: center; gap: 8px; }
.stat-ico {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  font-size: 15px; background: var(--brand-soft); flex: none;
}
.stat-label { font-size: 12px; color: var(--text-2); font-weight: 550; }
.stat-value { font-size: 25px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.stat-foot { font-size: 11.5px; color: var(--text-3); }

/* ---------------- Progress ---------------- */

.bar {
  height: 8px; border-radius: 999px; background: var(--track);
  overflow: hidden; width: 100%;
}
.bar > i {
  display: block; height: 100%; border-radius: 999px;
  background: var(--brand); transition: width .28s ease;
}
.bar.ok > i { background: var(--ok); }
.bar.thin { height: 6px; }
.bar.tall { height: 12px; }

.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .bar { flex: 1; }
.bar-pct { font-size: 12.5px; font-weight: 700; min-width: 40px; text-align: right; }

.ring { display: grid; place-items: center; position: relative; flex: none; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .ring-track { stroke: var(--track); }
.ring .ring-fill { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset .4s ease; }
.ring .ring-fill.ok { stroke: var(--ok); }
.ring-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; letter-spacing: -.02em;
}

.hero {
  display: flex; gap: 22px; align-items: center; flex-wrap: wrap;
  padding: 20px; border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: #fff; margin-bottom: 18px;
}
.hero h2 { font-size: 18px; }
.hero .hero-main { flex: 1; min-width: 220px; }
.hero .bar { background: rgba(255, 255, 255, .28); height: 12px; }
.hero .bar > i { background: #fff; }
.hero-meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; font-size: 12.5px; opacity: .95; }
.hero-meta b { display: block; font-size: 17px; }
.hero .ring .ring-track { stroke: rgba(255, 255, 255, .3); }
.hero .ring .ring-fill { stroke: #fff; }
.hero .ring-label { color: #fff; }

.ascii-bar {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 1px; font-size: 15px;
}

/* ---------------- Playlist cards ---------------- */

.grid-cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
}

.pl-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; text-align: left;
}
.pl-thumb {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: var(--surface-2); cursor: pointer; border: 0; padding: 0; display: block;
}
.pl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pl-thumb .badge-count {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0, 0, 0, .78); color: #fff;
  font-size: 11px; font-weight: 600; padding: 3px 7px; border-radius: 5px;
}
.pl-done-flag {
  position: absolute; left: 8px; top: 8px; background: var(--ok); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
}
.pl-body { padding: 13px 14px 14px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.pl-title {
  font-size: 14.5px; font-weight: 650; line-height: 1.35; cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pl-title:hover { color: var(--brand); }
.pl-meta { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pl-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; }

/* ---------------- Video list ---------------- */

.video-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.video-row:last-child { border-bottom: 0; }
.video-row:hover { background: var(--surface-2); }
.video-row.done .v-title { color: var(--text-2); }
.video-row.done .v-num { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.video-row.current { background: var(--brand-soft); }

.v-num {
  width: 30px; height: 26px; flex: none; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.v-thumb { width: 92px; aspect-ratio: 16/9; border-radius: 6px; object-fit: cover; flex: none; background: var(--surface-2); }
/* Thumbnails placed inside a fixed-ratio wrapper should fill it exactly. */
.pl-thumb img,
.v-thumb-btn .v-thumb,
.thumb-fill .v-thumb { width: 100%; height: 100%; }
.v-main { flex: 1; min-width: 0; }
.v-title { font-size: 13.8px; font-weight: 550; line-height: 1.4; }
.v-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.v-actions { display: flex; gap: 6px; flex: none; }

.check {
  width: 21px; height: 21px; flex: none; border-radius: 6px;
  border: 2px solid var(--border-strong); background: var(--surface);
  cursor: pointer; display: grid; place-items: center; padding: 0;
  color: transparent; font-size: 12px; font-weight: 900; line-height: 1;
}
.check:hover { border-color: var(--brand); }
.check[aria-checked="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
html[data-theme="dark"] .check[aria-checked="true"] { color: #10261a; }

/* ---------------- To-do ---------------- */

.todo-row {
  display: flex; align-items: flex-start; gap: 11px; padding: 11px 13px;
  border-bottom: 1px solid var(--border);
}
.todo-row:last-child { border-bottom: 0; }
.todo-row:hover { background: var(--surface-2); }
.todo-row.done .t-title { text-decoration: line-through; text-decoration-thickness: 1px; color: var(--text-2); }
.t-main { flex: 1; min-width: 0; }
.t-title { font-size: 14px; font-weight: 550; line-height: 1.4; word-break: break-word; }
.t-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; align-items: center; }

.chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 4px;
}
.chip.p-high { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.p-medium { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.p-low { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.overdue { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.brand { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }
html[data-theme="dark"] .chip.brand { color: var(--brand); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-btn {
  height: 32px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.filter-btn:hover { border-color: var(--border-strong); color: var(--text); }
.filter-btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
html[data-theme="dark"] .filter-btn[aria-pressed="true"] { color: #12141c; }

/* ---------------- Notes ---------------- */

.notes-layout { display: grid; grid-template-columns: 210px 1fr; gap: 16px; align-items: start; }
.folder-list { display: flex; flex-direction: column; gap: 2px; }
.folder-btn {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border: 0; background: none; border-radius: var(--r-sm);
  cursor: pointer; font-size: 13.5px; color: var(--text-2); text-align: left; width: 100%;
}
.folder-btn:hover { background: var(--surface-2); color: var(--text); }
.folder-btn[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
html[data-theme="dark"] .folder-btn[aria-pressed="true"] { color: var(--brand); }
.folder-btn .count { margin-left: auto; font-size: 11px; color: var(--text-3); font-weight: 600; }

.note-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 7px;
  box-shadow: var(--shadow-sm); text-align: left; min-height: 130px;
}
.note-card:hover { border-color: var(--brand); }
.note-title { font-size: 14.5px; font-weight: 650; line-height: 1.35; }
.note-excerpt {
  font-size: 12.5px; color: var(--text-2); line-height: 1.5; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.note-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 11px; color: var(--text-3); }

.editor-toolbar {
  display: flex; gap: 4px; flex-wrap: wrap; padding: 8px;
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--r) var(--r) 0 0; background: var(--surface-2);
  position: sticky; top: var(--topbar-h); z-index: 10;
}
.tool-btn {
  min-width: 32px; height: 30px; padding: 0 8px; border-radius: 6px;
  border: 1px solid transparent; background: none; cursor: pointer;
  font-size: 13px; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center;
}
.tool-btn:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.tool-sep { width: 1px; background: var(--border); margin: 3px 4px; }

.editor {
  min-height: 340px; padding: 18px; border: 1px solid var(--border);
  border-radius: 0 0 var(--r) var(--r); background: var(--surface);
  font-size: 15px; line-height: 1.7; outline: none; overflow-wrap: break-word;
}
.editor:focus { border-color: var(--brand); }
.editor h1 { font-size: 24px; margin: .6em 0 .3em; }
.editor h2 { font-size: 19px; margin: .6em 0 .3em; }
.editor h3 { font-size: 16px; margin: .6em 0 .3em; }
.editor p { margin: 0 0 .6em; }
.editor ul, .editor ol { margin: 0 0 .6em; padding-left: 1.5em; }
.editor li { margin-bottom: .25em; }
.editor mark { background: #fde68a; color: #111827; padding: 0 2px; border-radius: 3px; }
.editor:empty::before { content: attr(data-placeholder); color: var(--text-3); }
.editor blockquote {
  margin: 0 0 .6em; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--text-2);
}

.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 11px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
}
.textarea { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); outline: none; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 130px; }

/* ---------------- Modal / dialog ---------------- */

.overlay {
  position: fixed; inset: 0; background: rgba(15, 17, 23, .5);
  display: grid; place-items: center; padding: 16px; z-index: 200;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); width: min(560px, 100%);
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--border);
}
.modal.wide { width: min(920px, 100%); }

/* A video modal has no business leaving side gutters on a phone. */
@media (max-width: 620px) {
  .overlay:has(.player-stage) { padding: 0; align-items: flex-start; }
  .modal:has(.player-stage) {
    width: 100%;
    max-width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    margin-top: env(safe-area-inset-top, 0px);
  }
  .modal:has(.player-stage) .modal-head { padding: 12px 14px; }
}
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; flex: 1; min-width: 0; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
  flex-wrap: wrap;
}

/* The video fills the modal edge to edge — side padding used to crop it. */
.player-stage {
  width: 100%;
  background: #000;
  display: block;
  line-height: 0;
}
.player-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  background: #000;
  display: block;
}

/* Only reachable while fullscreen — the modal header is off-screen then. */
.player-fs-exit { display: none; }
.player-stage:fullscreen .player-fs-exit,
.player-stage.is-fs .player-fs-exit {
  display: grid;
  place-items: center;
  position: fixed;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 0;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* Fullscreen: letterbox the video, never crop it. */
.player-stage:fullscreen,
.player-stage.is-fs {
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  background: #000;
}
.player-stage:fullscreen .player-frame,
.player-stage.is-fs .player-frame {
  width: 100%;
  height: 100%;
  max-width: calc(100vh * 16 / 9);
  max-height: calc(100vw * 9 / 16);
  aspect-ratio: auto;
}

/* ---------------- Toast ---------------- */

/* ---------------- AI chat ---------------- */

.chat-page { display: flex; flex-direction: column; min-height: 0; }

.chat-log {
  display: flex; flex-direction: column; gap: 10px;
  padding: 4px 0 12px;
  min-height: 240px;
  max-height: 56vh;
  overflow-y: auto;
}

.chat-empty { text-align: center; padding: 34px 16px; }
.chat-empty h3 { font-size: 16px; margin: 8px 0 4px; }

.chat-row { display: flex; }
.chat-row.user { justify-content: flex-end; }

.chat-bubble {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: var(--r);
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--border);
}
.chat-bubble.user {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  border-bottom-right-radius: 3px;
}
.chat-bubble.ai { border-bottom-left-radius: 3px; }
.chat-bubble.err { border-color: var(--danger); color: var(--danger); }

.chat-img { display: block; max-width: 200px; border-radius: var(--r-sm); margin-bottom: 7px; }

.chat-actions {
  margin-top: 9px; padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.chat-action { font-size: 12px; color: var(--ok); font-weight: 600; }

.chat-typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.chat-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3); display: block;
  animation: chatdot 1.1s infinite ease-in-out;
}
.chat-typing i:nth-child(2) { animation-delay: .18s; }
.chat-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes chatdot { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .chat-typing i { animation: none; opacity: .6; } }

.chat-chips {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 4px 0 10px; scrollbar-width: none;
}
.chat-chips::-webkit-scrollbar { display: none; }
.chat-chips .filter-btn { white-space: nowrap; flex: none; font-size: 12px; }

.chat-composer { position: sticky; bottom: 0; background: var(--bg); padding-bottom: 4px; }
.chat-bar { display: flex; gap: 7px; align-items: flex-end; }
.chat-input { flex: 1; resize: none; max-height: 120px; line-height: 1.5; }
.chat-send { flex: none; width: 44px; padding: 0; font-size: 16px; }

.chat-preview { position: relative; display: inline-block; margin-bottom: 8px; }
.chat-preview img { max-height: 82px; border-radius: var(--r-sm); display: block; }
.chat-preview button { position: absolute; top: 3px; right: 3px; background: var(--surface); }

.chat-hint {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-2);
}

.ai-status { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.ai-status.ok { color: var(--ok); }
.ai-status.warn { color: var(--warn); }

/* ---------------- Missions, XP, Journey ---------------- */

.mission-card { border-left: 3px solid var(--brand); }
.mission-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }

.mission-ring {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  background: var(--brand-soft); color: var(--brand-strong);
  border: 2px solid var(--brand);
}
.mission-ring.done { background: var(--ok); color: #fff; border-color: var(--ok); font-size: 20px; }
html[data-theme="dark"] .mission-ring { color: var(--brand); }

.mission-list { display: flex; flex-direction: column; gap: 6px; }
.mission-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: var(--r-sm);
  background: var(--surface-2); font-size: 13px;
}
.mi-box {
  width: 18px; height: 18px; flex: none; border-radius: 5px;
  border: 2px solid var(--border-strong);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 900; color: transparent;
}
.mission-item.done .mi-box { background: var(--ok); border-color: var(--ok); color: #fff; }
.mission-item.done .mi-label { color: var(--text-3); text-decoration: line-through; }
.mi-label { flex: 1; min-width: 0; }
.mi-count { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }

.mission-done-flag {
  margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--ok);
}

.level-head { display: flex; align-items: center; gap: 12px; }
.level-badge {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px;
  background: var(--brand-soft);
}
.level-name { font-size: 15.5px; font-weight: 700; }
.level-xp { text-align: right; flex: none; }
.level-xp strong { font-size: 18px; display: block; line-height: 1.1; }
.level-xp .muted { font-size: 11px; }

.week-race { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.wr-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; }
.wr-row + .wr-row { margin-top: 6px; }
.wr-bar {
  height: 7px; background: var(--track); border-radius: 999px;
  overflow: hidden; margin: 6px 0;
}
.wr-bar > i { display: block; height: 100%; background: var(--brand); }
.wr-verdict { margin-top: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.wr-verdict.win { color: var(--ok); }

.ladder-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  background: var(--surface-2); font-size: 13.5px; opacity: .5;
}
.ladder-row.reached { opacity: 1; }
.ladder-row.current { border: 1px solid var(--brand); background: var(--brand-soft); }
.lr-icon { font-size: 17px; flex: none; }
.lr-name { flex: 1; font-weight: 600; }
.lr-xp { font-size: 11.5px; color: var(--text-3); }

.week-bars {
  display: flex; align-items: flex-end; gap: 8px;
  height: 110px; padding-top: 8px;
}
.wb-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; justify-content: flex-end; }
.wb-bar { width: 100%; max-width: 26px; background: var(--brand); border-radius: 3px 3px 0 0; }
.wb-label { font-size: 9.5px; color: var(--text-3); }

.topic-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2);
}
.topic-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.topic-dot.weak { background: var(--danger); }
.topic-dot.revise { background: var(--warn); }
.topic-dot.strong { background: var(--ok); }
.topic-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 550; overflow-wrap: anywhere; }
.topic-tag { font-size: 10.5px; font-weight: 700; flex: none; text-transform: uppercase; letter-spacing: .04em; }
.topic-tag.weak { color: var(--danger); }
.topic-tag.revise { color: var(--warn); }
.topic-tag.strong { color: var(--ok); }
.topic-score { font-size: 12px; color: var(--text-3); width: 26px; text-align: right; flex: none; font-variant-numeric: tabular-nums; }

/* ---------------- Boss battle ---------------- */

.boss-body { padding: 16px; display: flex; flex-direction: column; }
.boss-top { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; margin-bottom: 8px; }
.boss-label { font-weight: 700; }
.boss-bar { height: 5px; background: var(--track); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.boss-bar > i { display: block; height: 100%; background: var(--brand); }
.boss-grade { display: flex; gap: 8px; margin-top: 12px; }
.boss-grade .btn { flex: 1; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.boss-done { text-align: center; padding: 10px 4px; }
.bd-icon { font-size: 44px; }
.boss-done h3 { font-size: 17px; margin: 6px 0 10px; }
.bd-score { font-size: 34px; font-weight: 800; line-height: 1; }
.bd-pct { font-size: 15px; font-weight: 700; margin-top: 4px; }
.bd-pct.ok { color: var(--ok); }
.bd-pct.warn { color: var(--warn); }

.chapter-boss { margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--text-3); }
.chapter-boss.mastered { color: var(--ok); }
.chapter-boss.ready { color: var(--brand); }

/* ---------------- Focus room ---------------- */

body.focus-open { overflow: hidden; }

.focus-room {
  position: fixed; inset: 0; z-index: 900;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px; padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  text-align: center;
}
.focus-room.is-done { background: color-mix(in srgb, var(--ok) 12%, var(--bg)); }

.fr-task { max-width: 420px; }
.fr-task-label { font-size: 19px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }

.fr-dial { position: relative; width: 220px; height: 220px; display: grid; place-items: center; }
.fr-ring {
  position: absolute; inset: 0; border-radius: 50%;
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 61%);
  mask: radial-gradient(circle, transparent 60%, #000 61%);
}
.fr-clock {
  font-size: 46px; font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}

.fr-status { font-size: 13px; color: var(--text-3); }
.fr-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

@media (max-width: 420px) {
  .fr-dial { width: 180px; height: 180px; }
  .fr-clock { font-size: 38px; }
  .fr-task-label { font-size: 17px; }
}

/* ---------------- Speed drills ---------------- */

.drill-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  border: 1px solid var(--border);
  font: inherit;
  color: var(--text);
}
.drill-card:hover { border-color: var(--brand); }
.dc-icon { font-size: 24px; flex: none; }
.dc-main { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.dc-main strong { font-size: 14.5px; }
.dc-main .muted { font-size: 12px; }
.dc-best { font-size: 11.5px; color: var(--brand); font-weight: 600; margin-top: 2px; }
.dc-go { color: var(--text-3); flex: none; }

.drill-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.drill-body { padding: 18px 16px 20px; display: flex; flex-direction: column; }

.drill-top { display: flex; align-items: center; justify-content: space-between; }

.drill-clock {
  font-size: 30px; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.drill-clock.low { color: var(--danger); }

.drill-score { display: flex; gap: 12px; font-size: 14px; font-weight: 700; }
.ds-ok { color: var(--ok); }
.ds-bad { color: var(--danger); }

.drill-bar {
  height: 5px; background: var(--track); border-radius: 999px;
  overflow: hidden; margin: 12px 0 20px;
}
.drill-bar > i { display: block; height: 100%; background: var(--brand); width: 100%; }

.drill-q {
  font-size: 40px; font-weight: 700; text-align: center;
  padding: 14px 0 18px; line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.drill-input {
  font-size: 26px !important; text-align: center; font-weight: 700;
  padding: 12px !important; font-variant-numeric: tabular-nums;
}

.drill-feedback {
  min-height: 24px; text-align: center; font-weight: 700;
  font-size: 15px; margin-top: 8px;
}
.drill-feedback.ok { color: var(--ok); }
.drill-feedback.bad { color: var(--danger); }

.drill-submit { margin-top: 8px; width: 100%; }

.drill-done { text-align: center; padding: 8px 0 4px; }
.dd-icon { font-size: 44px; }
.drill-done h3 { font-size: 17px; margin: 6px 0 10px; }
.dd-big { font-size: 52px; font-weight: 800; line-height: 1; color: var(--brand); }
.dd-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin: 18px 0 4px;
}
.dd-grid > div { display: flex; flex-direction: column; gap: 2px; }
.dd-grid strong { font-size: 17px; }
.dd-grid .muted { font-size: 11.5px; }

@media (max-width: 420px) {
  .drill-q { font-size: 34px; }
  .dd-big { font-size: 44px; }
}

/* ---------------- Music widget ---------------- */

#music-widget {
  position: fixed;
  left: max(16px, env(safe-area-inset-left, 0px));
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  z-index: 340;
  width: min(320px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
#music-widget[hidden] { display: none; }

.mw-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px 7px 10px;
}

.mw-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  text-align: left;
}
.mw-note { font-size: 15px; flex: none; }
.mw-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mw-x {
  width: 26px; height: 26px; flex: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.mw-x:hover { color: var(--danger); border-color: var(--danger); }

.mw-frame { padding: 0 8px 8px; }
.mw-frame iframe {
  width: 100%;
  height: 152px;
  display: block;
  border-radius: var(--r-sm);
}

.mw-note-text {
  padding: 0 10px 9px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-3);
}

/* Collapsed: just the title bar. */
#music-widget.collapsed { width: auto; max-width: min(230px, calc(100vw - 32px)); }

/* The timer sits bottom-right; on narrow screens stack the music above it. */
@media (max-width: 520px) {
  #music-widget { width: min(300px, calc(100vw - 24px)); left: 12px; }
  #music-widget.collapsed { max-width: 190px; }
  .mw-frame iframe { height: 132px; }
}

/* ---------------- Inbox / Batches ---------------- */

.stack-sm { display: flex; flex-direction: column; gap: 8px; }

.inbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.inbox-row:hover { border-color: var(--border-strong); }
.inbox-row input[type="checkbox"],
.inbox-row input[type="radio"] { margin-top: 2px; flex: none; }

.inbox-ico { font-size: 16px; flex: none; line-height: 1.4; }

.inbox-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.inbox-title {
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.inbox-title.done { text-decoration: line-through; color: var(--text-3); }
.inbox-sub { font-size: 11.5px; color: var(--text-3); overflow-wrap: anywhere; }

.inbox-file {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  margin-bottom: 12px;
}

#inbox-paste {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.6;
}

/* ---- chapters ---- */

.chapter-head { display: flex; align-items: center; gap: 8px; }

.chapter-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  font: inherit;
}
.chapter-toggle .chev { color: var(--text-3); font-size: 12px; flex: none; width: 12px; }
.chapter-name {
  font-size: 14.5px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.chapter-body { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.chapter-flag {
  margin-top: 8px;
  font-size: 12px;
  color: var(--warn);
  font-weight: 600;
}

.batch-card { display: flex; flex-direction: column; }

@media (max-width: 520px) {
  .inbox-row { padding: 8px 9px; }
  .inbox-title { font-size: 13px; }
}

/* ---------------- Install as app ---------------- */

.install-warn {
  padding: 10px 12px;
  border-radius: var(--r);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  font-size: 13px;
  line-height: 1.6;
}

.install-details { margin-top: 10px; }
.install-details > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  padding: 4px 0;
}
.install-details > summary::marker { color: var(--muted); }

.install-steps {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--muted);
}
.install-steps strong { color: var(--text); }

/* ---------------- Heatmap ---------------- */

.heat-scroll { overflow-x: auto; padding-bottom: 4px; }
.heat-grid { display: flex; gap: 3px; min-width: min-content; }
.heat-col { display: flex; flex-direction: column; gap: 3px; }

.heat-cell {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--track);
  flex: none;
}
.heat-cell.l1 { background: color-mix(in srgb, var(--ok) 28%, var(--track)); }
.heat-cell.l2 { background: color-mix(in srgb, var(--ok) 52%, var(--track)); }
.heat-cell.l3 { background: color-mix(in srgb, var(--ok) 76%, var(--track)); }
.heat-cell.l4 { background: var(--ok); }
.heat-cell.today { outline: 2px solid var(--brand); outline-offset: 1px; }
.heat-cell.future { opacity: .28; }

.heat-months {
  display: flex;
  gap: 3px;
  margin-bottom: 4px;
}
.heat-month {
  width: 12px;
  flex: none;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: visible;
}

.heat-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 11.5px;
}
.heat-legend .muted { margin: 0 4px; }

/* ---------------- Flashcards ---------------- */

.flash-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 26px 18px;
  min-height: 190px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
}
.flash-face:hover { border-color: var(--brand); }

.flash-q {
  font-size: 17px;
  font-weight: 650;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.flash-a {
  margin-top: 14px;
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ok);
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.flash-sep {
  width: 46px;
  height: 2px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 12px;
}

@media (max-width: 520px) {
  .flash-face { padding: 20px 14px; min-height: 160px; }
  .flash-q { font-size: 16px; }
}

/* ---------------- PDF attachments ---------------- */

.video-wrap { border-bottom: 1px solid var(--border); }
.video-wrap:last-child { border-bottom: 0; }
.video-wrap .video-row { border-bottom: 0; }

.pdf-drawer {
  padding: 0 12px 12px 12px;
  background: var(--surface-2);
  border-top: 1px dashed var(--border);
}
.pdf-drawer[hidden] { display: none; }
.pdf-drawer > .pdf-grid { padding-top: 10px; }

.pdf-section { margin-top: 4px; }

.pdf-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.pdf-card {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
}

/* Thumbnail keeps a page-like ratio and shows the real first page. */
.pdf-thumb {
  position: relative;
  width: 52px;
  height: 68px;
  flex: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.pdf-thumb:hover { border-color: var(--brand); }
.pdf-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }

.pdf-pages {
  position: absolute;
  right: 2px;
  bottom: 2px;
  background: rgba(0, 0, 0, .74);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
}

.pdf-meta { flex: 1; min-width: 0; }

.pdf-name {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pdf-name:hover { color: var(--brand); }

/* Highlight the paperclip when a video already has PDFs. */
.btn.has-pdf {
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 700;
}

@media (max-width: 520px) {
  .pdf-grid { grid-template-columns: 1fr; }
}

/* ---------------- Study timer widget ---------------- */

#timer-widget {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  z-index: 350;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
}
html[data-theme="amoled"] #timer-widget { border-color: var(--border-strong); }

#timer-widget .tw-time {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
#timer-widget .tw-label {
  font-size: 10.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 110px;
}
#timer-widget .tw-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); flex: none;
  animation: tw-pulse 2s ease-in-out infinite;
}
#timer-widget .tw-dot.paused { background: var(--warn); animation: none; }
@keyframes tw-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

#timer-widget .tw-btn {
  width: 32px; height: 32px; flex: none;
  border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; font-size: 11px; line-height: 1;
  display: grid; place-items: center;
}
#timer-widget .tw-btn:hover { border-color: var(--brand); color: var(--brand); }
#timer-widget .tw-btn.stop:hover { border-color: var(--danger); color: var(--danger); }

/* Keep the widget clear of the toast stack on small screens. */
@media (max-width: 520px) {
  #timer-widget { left: 12px; right: 12px; bottom: 12px; justify-content: center; }
  .toasts { bottom: 74px; }
}

.toasts {
  position: fixed; z-index: 400;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px));
}
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
  padding: 11px 14px; font-size: 13.5px; display: flex; gap: 9px; align-items: flex-start;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ---------------- Empty / misc ---------------- */

.empty {
  text-align: center; padding: 48px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty .e-ico { font-size: 40px; opacity: .55; }
.empty h3 { font-size: 16px; }
.empty p { color: var(--text-2); font-size: 13.5px; max-width: 380px; }
.empty .btn { margin-top: 8px; }

.spinner {
  width: 15px; height: 15px; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list { display: flex; flex-direction: column; }
.section-title { font-size: 15px; font-weight: 650; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section-title .btn { margin-left: auto; }
.muted { color: var(--text-3); font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.subject-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.subject-row .s-name { font-size: 13px; width: 116px; flex: none; }
.subject-row .s-count { font-size: 12px; color: var(--text-3); min-width: 26px; text-align: right; }

.backdrop-mobile { display: none; }

/* ---------------- Responsive ---------------- */

@media (max-width: 1000px) {
  .two-col { grid-template-columns: 1fr; }
  .notes-layout { grid-template-columns: 1fr; }
  .folder-list { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .folder-btn { white-space: nowrap; width: auto; }
}

/* Chrome's "Desktop site" forces a ~980px viewport, so a width-only query never
   fires and the sidebar stays pinned open on a phone. Coarse pointer + no hover
   means a touch device regardless of the faked width. */
@media (max-width: 780px), (pointer: coarse) and (max-width: 1100px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg); height: 100dvh;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop-mobile {
    display: block; position: fixed; inset: 0; background: rgba(15, 17, 23, .45); z-index: 55;
  }
  .hamburger { display: grid; place-items: center; }
  .content {
    padding: 15px;
    padding-left: max(15px, env(safe-area-inset-left, 0px));
    padding-right: max(15px, env(safe-area-inset-right, 0px));
    padding-bottom: max(15px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  }
  .page-title { font-size: 19px; }
  .stat-value { font-size: 22px; }
  /* Only shrink thumbnails inside the video list, not the playlist cover. */
  .video-row .v-thumb { width: 64px; }
  .v-num { display: none; }
  .modal-foot { justify-content: stretch; }
  .modal-foot .btn { flex: 1; }
  .grid-cards { grid-template-columns: 1fr; }
  .hero { padding: 16px; gap: 16px; }
  /* Only the playlist-detail cover goes full-width on small screens.
     Small inline previews (add dialog, Continue Studying) keep their size. */
  .pl-cover { width: 100% !important; }
}

@media (max-width: 620px) {
  /* Give the search box room: top-bar actions collapse to icons. */
  .topbar {
    gap: 8px;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .topbar-actions .btn { padding: 0 10px; }
  .topbar-actions .btn .btn-label { display: none; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 1; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat { padding: 11px 12px; }
  .stat-value { font-size: 19px; }
  /* In the video LIST only, hide the small thumbnail so the title gets full
     width. The playlist cover and other previews (.thumb-fill) must stay. */
  .video-row > .v-thumb-btn,
  .video-row > .v-thumb { display: none; }
  /* Continue Studying: shrink the preview so the title isn't squeezed. */
  .video-row > .thumb-fill { width: 74px !important; }
  .video-row { gap: 10px; padding: 10px; }
  .v-actions { flex-direction: column; gap: 5px; }
  /* The chapter header is a single line — keep its icons side by side. */
  .chapter-head .v-actions,
  .inbox-row .v-actions { flex-direction: row; gap: 4px; }
  .hero { padding: 16px; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
  .hero h2 { font-size: 16px; }
  .hero .hero-main { width: 100%; min-width: 0; }
  .hero .ascii-bar { font-size: 13px; }
  .hero-meta { justify-content: space-between; gap: 12px; text-align: left; }
  .hero-meta > div { flex: 1 1 40%; }
}

@media print {
  .sidebar, .topbar, .btn { display: none !important; }
}
