/**
 * Library design tokens — Wayground-inspired, Quizzman-refined.
 * Loaded after QMF tokens; overrides --q-* for Explore shell only.
 */
:root {
  --lib-brand: #d82b7d;
  --lib-brand-deep: #b91c6a;
  --lib-brand-soft: #fce7f3;
  --lib-accent: #8b5cf6;
  --lib-accent-soft: #ede9fe;
  --lib-warm: #f97316;
  --lib-page: #f8fafc;
  --lib-ink: #0f172a;
  --lib-ink-muted: #64748b;
  --lib-line: #e2e8f0;
  --lib-card: #ffffff;
  --lib-radius-xl: 22px;
  --lib-radius-lg: 16px;
  --lib-radius-md: 12px;
  --lib-radius-pill: 999px;
  --lib-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --lib-shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06);
  --lib-shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.08);

  /* bridge to explore.css --q-* */
  --q-bg: var(--lib-page);
  --q-page-bg: var(--lib-page);
  --q-surface: var(--lib-card);
  --q-primary: var(--lib-brand);
  --q-primary-soft: var(--lib-brand-soft);
  --q-text: var(--lib-ink);
  --q-text-secondary: #334155;
  --q-muted: var(--lib-ink-muted);
  --q-border: var(--lib-line);
  --q-radius: var(--lib-radius-xl);
  --q-radius-sm: var(--lib-radius-md);
  --q-shadow-md: var(--lib-shadow-md);
  --q-shadow-lg: var(--lib-shadow-lg);
  --q-sidebar-width: 232px;
  --q-panel-width: 304px;
}

html[data-theme='dark'] {
  color-scheme: dark;

  --lib-brand-soft: #3b1a2e;
  --lib-accent-soft: #2e1f4a;
  --lib-page: #0f1419;
  --lib-ink: #e8edf5;
  --lib-ink-muted: #94a3b8;
  --lib-line: #2a3441;
  --lib-card: #1a2332;
  --lib-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --lib-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --lib-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.42);

  --q-bg: var(--lib-page);
  --q-page-bg: var(--lib-page);
  --q-surface: var(--lib-card);
  --q-primary-soft: color-mix(in srgb, var(--lib-brand) 22%, transparent);
  --q-text: var(--lib-ink);
  --q-text-secondary: #cbd5e1;
  --q-muted: var(--lib-ink-muted);
  --q-border: var(--lib-line);
}

html[data-theme='dark'] .lib-hero-wg {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--lib-brand) 16%, transparent) 0%,
    transparent 72%
  );
}

html[data-theme='dark'] .lib-appearance__seg {
  background: color-mix(in srgb, var(--q-border) 55%, transparent);
  border-color: var(--q-border);
}

html[data-theme='dark'] .lib-appearance__btn.is-active {
  background: var(--q-surface-elevated, var(--q-surface));
  color: var(--q-text);
}

html[data-theme='dark'] .lib-ic {
  color: #94a3b8;
}

html[data-theme='dark'] .lib-sidebar .lib-nav-item .lib-ic {
  color: #94a3b8;
}

html[data-theme='dark'] .lib-sidebar .lib-nav-item.active .lib-ic {
  color: #f9a8d4;
}

.lib-appearance {
  display: grid;
  gap: 8px;
}

.lib-appearance__label,
.lib-theme-select-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--lib-ink-muted);
}

.lib-appearance__seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--lib-line) 40%, transparent);
  border: 1px solid var(--lib-line);
}

.lib-appearance__btn {
  border: 0;
  border-radius: 9px;
  padding: 7px 6px;
  font-size: 0.72rem;
  font-weight: 800;
  background: transparent;
  color: var(--lib-ink-muted);
  cursor: pointer;
}

.lib-appearance__btn.is-active {
  background: var(--lib-card);
  color: var(--lib-ink);
  box-shadow: var(--lib-shadow-sm);
}

.qlib-appearance-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
}

#lib-boot.lib-boot--dark {
  --lib-boot-ink: #e8edf5;
  --lib-boot-soft: #243044;
  background: #0f1419;
}

#lib-boot.lib-boot--dark .lib-boot__shape--b {
  background: #334155;
}

.lib-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: #94a3b8;
  flex-shrink: 0;
}

.lib-sidebar .lib-nav-item .lib-ic {
  color: #94a3b8;
}

.lib-sidebar .lib-nav-item:hover .lib-ic {
  color: #64748b;
}

.lib-sidebar .lib-nav-item.active .lib-ic {
  color: var(--lib-brand-deep);
}

.lib-ic-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Wayground-style hero ── */
.lib-hero-wg {
  position: relative;
  padding: var(--q-space-6) 0 var(--q-space-3);
  background: linear-gradient(180deg, var(--lib-brand-soft) 0%, transparent 72%);
  border-radius: var(--lib-radius-xl);
  margin-bottom: var(--q-space-3);
}

.lib-hero-wg .lib-hero-ambient { display: none; }

.lib-hero-greeting {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 2.4vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--lib-ink);
  text-align: center;
}

.lib-hero-lead {
  margin: 0 0 var(--q-space-5);
  text-align: center;
  color: var(--lib-ink-muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.lib-hero-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: var(--q-space-5);
}

.lib-hero-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--q-border);
  border-radius: var(--lib-radius-pill);
  background: var(--q-surface);
  color: var(--q-text);
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  box-shadow: var(--lib-shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.lib-hero-chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--lib-shadow-md);
  border-color: color-mix(in srgb, var(--lib-brand) 35%, var(--lib-line));
}

.lib-hero-chip .lib-ic { color: var(--lib-brand-deep); }

/* Search bar — pill + CTA (fixed width, content does not resize bar) */
.lib-search-bar {
  display: flex;
  align-items: center;
  gap: 0;
  width: min(640px, 100%);
  max-width: 640px;
  min-width: min(320px, 100%);
  min-height: 56px;
  margin: 0 auto;
  padding: 6px 6px 6px 16px;
  box-sizing: border-box;
  background: var(--q-surface);
  border: 1px solid var(--q-border);
  border-radius: var(--lib-radius-pill);
  box-shadow: var(--lib-shadow-md);
  color: var(--q-text);
}

.lib-hero-wg .lib-search-bar,
.lib-hero-inner .lib-search-bar {
  width: 100%;
  max-width: 640px;
}

.lib-search-bar .lib-ic {
  width: 20px;
  height: 20px;
  color: var(--lib-ink-muted);
}

.lib-search-bar__input {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--lib-ink);
  outline: none;
  min-width: 0;
}

.lib-search-bar__input::placeholder { color: #94a3b8; font-weight: 500; }

.lib-search-bar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--lib-brand), var(--lib-brand-deep));
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.lib-search-bar__btn:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 18px rgba(216, 43, 125, 0.28);
}

.lib-search-bar__btn .lib-ic { color: #fff; width: 20px; height: 20px; }

.lib-search-bar__field {
  flex: 1 1 0;
  width: 0;
  display: block;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  font: 600 0.95rem/1.4 var(--q-font);
  color: var(--q-text);
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
}

.lib-search-bar__field .lib-search-ph {
  display: block;
  color: var(--q-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.ex-body {
  background: var(--lib-page);
}

.lib-content,
.lib-main {
  background: transparent;
}

/* Sidebar — clean rail */
.lib-sidebar .lib-nav-item {
  border-radius: var(--lib-radius-md);
  font-weight: 700;
}

.lib-sidebar .lib-nav-item.active {
  background: var(--lib-brand-soft);
  color: var(--lib-brand-deep);
  box-shadow: none;
}

.lib-sidebar .lib-nav-item.active .lib-ic { color: var(--lib-brand-deep); }

.lib-sidebar .lib-nav-svg { display: none; }

.lib-side-brand-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 14px;
  margin-bottom: 6px;
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: -0.03em;
  color: var(--lib-ink);
}

.lib-side-brand-mini span {
  background: linear-gradient(90deg, var(--lib-brand), var(--lib-accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Section cards */
.lib-section-surface {
  border-radius: var(--lib-radius-lg);
  border: 1px solid var(--lib-line);
  box-shadow: var(--lib-shadow-sm);
}

.lib-section-title {
  font-weight: 800;
  letter-spacing: -0.02em;
}

.ex-card {
  border-radius: var(--lib-radius-lg);
  border: 1px solid var(--lib-line);
  box-shadow: var(--lib-shadow-sm);
}

.ex-card:hover {
  box-shadow: var(--lib-shadow-md);
}

.lib-ic-spin {
  animation: lib-ic-spin 0.75s linear infinite;
}

@keyframes lib-ic-spin {
  to { transform: rotate(360deg); }
}

.ex-loading .lib-ic,
.ex-overlay-head .lib-ic {
  color: var(--lib-brand);
}

/* ── Page motion ── */
@media (prefers-reduced-motion: no-preference) {
  .lib-home {
    animation: lib-page-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .lib-hero-wg {
    animation: lib-hero-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .lib-section {
    animation: lib-section-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .lib-section:nth-child(2) { animation-delay: 0.05s; }
  .lib-section:nth-child(3) { animation-delay: 0.1s; }
  .lib-section:nth-child(4) { animation-delay: 0.15s; }
  .lib-section:nth-child(5) { animation-delay: 0.2s; }

  .ex-card,
  .ex-continue-card {
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease, border-color 0.22s ease;
  }

  .ex-card:hover,
  .ex-continue-card:hover {
    transform: translateY(-3px);
  }

  .lib-hero-chip {
    transition: transform 0.2s cubic-bezier(0.34, 1.4, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s ease;
  }

  .lib-hero-chip:active {
    transform: scale(0.97);
  }

  .lib-nav-item {
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .lib-nav-item:hover {
    transform: translateX(2px);
  }

  .lib-nav-item.active {
    animation: lib-nav-pop 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .lib-search-bar {
    transition: box-shadow 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
  }

  .lib-search-bar:focus-within {
    transform: translateY(-1px);
    box-shadow: 0 8px 28px rgba(216, 43, 125, 0.12);
    border-color: color-mix(in srgb, var(--lib-brand) 40%, var(--lib-line));
  }

  .ex-loading {
    display: inline-flex;
    align-items: center;
    gap: 10px;
  }

  .ex-skel-line,
  .ex-quiz-detail__preview-skel .ex-skel-line {
    background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 45%, #f1f5f9 90%);
    background-size: 200% 100%;
    animation: lib-shimmer 1.2s ease-in-out infinite;
  }
}

@keyframes lib-page-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes lib-hero-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes lib-section-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes lib-nav-pop {
  0% { transform: scale(0.96); }
  60% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes lib-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ── Smart thumb (type catalog) ── */
.lib-thumb-smart {
  --thumb-accent: #6366f1;
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 84px;
  border-radius: 14px;
  overflow: hidden;
  background: color-mix(in srgb, var(--thumb-accent) 7%, #f8fafc);
  isolation: isolate;
}

.lib-thumb-smart::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(90% 70% at 100% 0%, color-mix(in srgb, var(--thumb-accent) 16%, transparent), transparent 58%),
    radial-gradient(60% 50% at 0% 100%, color-mix(in srgb, var(--thumb-accent) 8%, transparent), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

.lib-thumb-smart__wm {
  position: absolute;
  right: 2px;
  top: -8px;
  font-size: clamp(36px, 5vw, 48px);
  line-height: 1;
  opacity: 0.2;
  filter: saturate(0.85);
  pointer-events: none;
  z-index: 0;
  user-select: none;
}

.lib-thumb-smart__mono {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: color-mix(in srgb, var(--thumb-accent) 55%, #334155);
  z-index: 1;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-thumb-smart__tag {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--thumb-accent) 65%, #475569);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(4px);
}

.lib-thumb-smart__body {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  padding: 10px 10px 9px;
  pointer-events: none;
}

.lib-thumb-smart__topic {
  position: absolute;
  right: 4px;
  top: -6px;
  font-size: clamp(32px, 4.5vw, 42px);
  line-height: 1;
  opacity: 0.18;
  filter: saturate(0.9);
}

.lib-thumb-smart__kind {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--thumb-accent) 70%, #334155);
}

.lib-thumb-smart__title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.lib-thumb-smart__stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
}

.lib-thumb-smart__dot {
  opacity: 0.55;
}

.lib-thumb-smart__shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.04) 0%, rgba(15, 23, 42, 0.55) 100%);
  pointer-events: none;
}

.lib-thumb-smart__overlay {
  position: absolute;
  inset: auto 0 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px 9px;
  pointer-events: none;
}

.lib-thumb-smart--img .lib-thumb-smart__overlay .lib-thumb-smart__title {
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.lib-thumb-smart--img .lib-thumb-smart__overlay .lib-thumb-smart__kind {
  color: rgba(255, 255, 255, 0.92);
}

.lib-thumb-smart--img .lib-thumb-smart__overlay .lib-thumb-smart__stats {
  color: rgba(255, 255, 255, 0.88);
}

.lib-thumb-smart--img .ex-cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.lib-thumb-smart--img::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(15, 23, 42, 0.12) 100%);
  z-index: 1;
  pointer-events: none;
}

.lib-thumb-smart--sm {
  width: 72px;
  min-height: 56px;
  aspect-ratio: auto;
  height: 56px;
  border-radius: 10px;
  flex-shrink: 0;
}

.lib-thumb-smart--sm .lib-thumb-smart__wm {
  font-size: 28px;
  top: -4px;
  right: 0;
}

.lib-thumb-smart--sm .lib-thumb-smart__mono {
  font-size: 12px;
  left: 8px;
  bottom: 6px;
}

.lib-thumb-smart--sm .lib-thumb-smart__tag {
  font-size: 8px;
  padding: 1px 5px;
  top: 5px;
  left: 5px;
}

.ex-chip-mini.ex-chip-muted {
  background: #f1f5f9;
  color: #64748b;
  border: 0;
}

/* Type catalog grid — card chrome in explore.css */
.lib-type-grid {
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
  gap: 20px 16px;
}

.lib-detail-list .lib-detail-row {
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  border-radius: 0;
  padding: 12px 0;
  background: transparent;
  box-shadow: none;
}

.lib-detail-list .lib-detail-row:hover {
  background: #fafbfc;
  transform: none;
  box-shadow: none;
}

/* ── Assignments MFE (Phiên) — native module, shared styles ── */
.lib-assign-host {
  min-height: calc(100vh - var(--qmf-header-h, 58px) - 48px);
}

.lib-assign-mfe {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 55vh;
}

.lib-assign-tabs {
  margin-bottom: 12px;
}

.lib-assign-body { min-height: 200px; }

.lib-assign-loading,
.lib-assign-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 40vh;
  color: #64748b;
  text-align: center;
}

.lib-assign-report-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.lib-assign-report-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #f1f5f9;
}

.lib-assign-report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lib-assign-meta { font-size: 12px; color: #94a3b8; }

.qa-assignments-host .qa-lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.qa-assignments-host .qa-lib-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: #fafbfc;
  border: 1px solid #f1f5f9;
  min-height: 100px;
}

.qa-assignments-host .qa-lib-tile__main {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
}

.qa-assignments-host .qa-lib-copy strong {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
}

.lib-my-resources-search {
  display: block;
  margin: 12px 0;
}

.qa-assignments-host .qa-lib-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.qa-assignments-host .qa-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--lib-brand, #d82b7d);
  border-radius: 50%;
  animation: lib-assign-spin 0.7s linear infinite;
}

@keyframes lib-assign-spin {
  to { transform: rotate(360deg); }
}

.qa-filter-count {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  background: color-mix(in srgb, var(--lib-brand, #d82b7d) 12%, #fff);
  color: var(--lib-brand-deep, #b91c6a);
}

.qa-filter-tab.is-active .qa-filter-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.qa-lib-tile__thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 10px;
  background: #f1f5f9 center/cover no-repeat;
  border: 1px solid #e2e8f0;
}

.qa-lib-tile__thumb--quiz {
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
}

.qa-lib-tile__thumb--quiz[style*="background-image"] {
  background-color: #f1f5f9;
}

.qa-lib-tile__thumb--slide {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
}

.qa-lib-tile--claimed {
  border-color: color-mix(in srgb, var(--lib-brand, #d82b7d) 18%, #e2e8f0);
}

.qa-lib-tile__sub {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: #94a3b8;
  font-weight: 600;
}

.qa-btn--danger {
  color: #b91c1c !important;
}

.qa-btn--danger:hover {
  background: #fef2f2 !important;
}
