/* ── Code library (/library/) ──
   Leans on css/variables.css tokens and the shared c-* classes from
   courses/courses.css; only library-specific pieces live here. */

.lib-main { width: 100%; flex: 1; }

/* The hidden attribute must always win, even against the display:flex/grid
   rules below (author display beats the UA [hidden] rule in some engines). */
.library-page [hidden] { display: none !important; }

.lib-hero { padding-bottom: var(--sp-4); }

/* ── Search + chips ── */
.lib-controls { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.lib-search {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 0 var(--sp-4);
  max-width: 560px; box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.lib-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.lib-search i { color: var(--text-muted); }
.lib-search input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-family: var(--font); font-size: var(--text-md); color: var(--text);
  padding: 12px 0;
}
.lib-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.lib-chip {
  font-family: var(--font); font-size: var(--text-sm); font-weight: 600;
  color: var(--text-secondary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.lib-chip:hover { color: var(--text); border-color: var(--text-muted); }
.lib-chip.is-active { color: var(--primary-dark); background: var(--primary-light); border-color: transparent; }

/* ── Cards ── */
.lib-cover-wrap { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: var(--primary-light); }
.lib-cover { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform var(--transition-slow); }
.lib-card:hover .lib-cover { transform: scale(1.03); }
.lib-cover-wrap .c-card-cover--gen { position: absolute; inset: 0; }
.lib-play {
  position: absolute; right: 10px; bottom: 10px;
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.72); color: #fff; font-size: 12px;
  opacity: 0; transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.lib-card:hover .lib-play { opacity: 1; transform: translateY(0); }
.lib-card-title { font-size: var(--text-md); line-height: 1.35; }
.lib-card-sub {
  font-size: var(--text-base);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-card-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-top: auto; padding-top: var(--sp-2); }
.lib-types { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-type {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: var(--primary-light); color: var(--primary-dark);
}
.lib-type i { font-size: 10px; }
.lib-type--prompt { background: #fdf0e7; color: #9a3d12; }
.lib-type--snippet { background: var(--excel-light); color: var(--excel); }
.lib-type--link { background: var(--border-light); color: var(--text-secondary); }
.lib-meta { display: inline-flex; align-items: center; gap: 10px; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
.lib-meta-dl { display: inline-flex; align-items: center; gap: 4px; }

/* Loading skeletons */
.lib-skel {
  border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: linear-gradient(100deg, var(--surface) 40%, var(--border-light) 50%, var(--surface) 60%);
  background-size: 200% 100%; animation: libshimmer 1.2s linear infinite;
  min-height: 260px;
}
@keyframes libshimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .lib-skel { animation: none; }
  .lib-cover, .lib-play { transition: none; }
}

/* ── Entry page ── */
.lib-back {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text-secondary); text-decoration: none;
  font-size: var(--text-md); font-weight: 600;
  margin: var(--sp-6) 0 var(--sp-4);
}
.lib-back:hover { color: var(--primary); }
.lib-entry-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px;
  gap: var(--sp-6); align-items: start; margin-bottom: var(--sp-8);
}
.lib-embed {
  position: relative; aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg); overflow: hidden;
  background: #000; box-shadow: var(--shadow-md);
}
.lib-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Waiting state, shown until the video is public (see comingSoonHtml). */
.lib-embed--soon {
  /* YouTube red, not the site accent: the mark should read as "a video is
     coming", and the yellow made it look like a site badge. The text tone is
     lighter than the brand red, which is too dark against this navy at small
     uppercase sizes. */
  --soon-red: #ff0000;
  --soon-red-text: #ff7a7a;
  background: linear-gradient(155deg, #1c2c4a 0%, #0f172a 55%, #0a1120 100%);
  /* Not the player's fixed 16:9: aspect-ratio never yields to content, so a
     long title on a narrow phone had the button clipped off the bottom. */
  aspect-ratio: auto; min-height: 300px;
}
/* In normal flow, not inset like the iframe, so the panel's own height is
   what the box grows to. */
.lib-soon {
  min-height: 300px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2); padding: var(--sp-5); text-align: center; color: #fff;
}
.lib-soon-mark {
  width: 58px; height: 58px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--soon-red, #ff0000); color: #fff; font-size: 26px;
  animation: lib-soon-pulse 2.8s ease-out infinite;
}
@keyframes lib-soon-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 0, 0, .45); }
  70% { box-shadow: 0 0 0 20px rgba(255, 0, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}
.lib-soon-kicker {
  margin-top: var(--sp-1, 4px);
  font-size: var(--text-xs); font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--soon-red-text, #ff7a7a);
}
.lib-soon-title {
  font-size: var(--text-2xl); line-height: 1.25; letter-spacing: -.01em;
  margin: 0; max-width: 24ch; color: #fff;
}
.lib-soon-sub {
  font-size: var(--text-md); line-height: 1.55; margin: 0;
  max-width: 42ch; color: #cbd5e1;
}
.lib-soon-when { color: #fff; font-weight: 600; white-space: nowrap; }

.lib-countdown {
  display: flex; gap: var(--sp-2); margin-top: var(--sp-2);
  justify-content: center; flex-wrap: wrap;
}
.lib-cd-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 58px; padding: 7px 10px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius-md);
}
.lib-cd-num {
  font-size: var(--text-xl); font-weight: 700; line-height: 1.1; color: #fff;
  /* Fixed-width digits, or the seconds cell twitches on every tick. */
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.lib-cd-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: #94a3b8;
}
.lib-cd-live {
  font-size: var(--text-md); font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--soon-red-text, #ff7a7a);
}
@media (prefers-reduced-motion: reduce) { .lib-soon-mark { animation: none; } }
@media (max-width: 560px) {
  .lib-embed--soon, .lib-soon { min-height: 220px; }
  .lib-soon { padding: var(--sp-4) var(--sp-3); gap: 6px; }
  .lib-soon-mark { width: 44px; height: 44px; font-size: 20px; }
  .lib-soon-title { font-size: var(--text-lg); }
  .lib-soon-sub { font-size: var(--text-base); max-width: 34ch; }
  .lib-cd-cell { min-width: 48px; padding: 5px 8px; }
  .lib-cd-num { font-size: var(--text-lg); }
}
.lib-side h1 { font-size: var(--text-2xl); line-height: 1.25; letter-spacing: -.01em; margin-bottom: var(--sp-2); }
.lib-desc { font-size: var(--text-md); line-height: 1.6; margin-bottom: var(--sp-3); }
.lib-tagrow { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.lib-tag { padding: 5px 12px; }

.lib-note {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  background: var(--warning-light); border: 1px solid #f5dc9f;
  border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-base); line-height: 1.5; margin-top: var(--sp-4);
}
.lib-note i { color: #92400e; margin-top: 2px; }

/* "Download everything" */
.lib-dl-all { margin: 0 0 var(--sp-4); }
.lib-dl-all .c-btn {
  padding: 14px 18px; font-size: var(--text-lg);
  box-shadow: var(--shadow); border-radius: var(--radius-lg);
}
.lib-dl-all .c-btn i { font-size: 18px; }
.lib-dl-all-note {
  text-align: center; font-size: var(--text-xs);
  color: var(--text-muted); margin-top: 7px;
}

/* Blocks */
.lib-blocks { display: flex; flex-direction: column; gap: var(--sp-3); }
.lib-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.lib-block-head { display: flex; align-items: center; gap: var(--sp-3); }
.lib-block-icon { color: var(--primary); font-size: 16px; width: 20px; text-align: center; }

/* File-type tiles: soft-tinted rounded squares that make each row instantly
   recognizable (Excel green workbook, Python blue, amber zip, ...). */
.lib-tile {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; transition: transform var(--transition-fast);
}
.lib-block:hover .lib-tile { transform: scale(1.06); }
.lib-tile--excel  { background: var(--excel-light); color: var(--excel); }
.lib-tile--python { background: #e8f0fa; color: #3776ab; }
.lib-tile--vba    { background: var(--primary-light); color: var(--primary-dark); }
.lib-tile--zip    { background: var(--warning-light); color: #92400e; }
.lib-tile--pdf    { background: var(--error-light); color: var(--error); }
.lib-tile--word   { background: #e7edf7; color: #2b579a; }
.lib-tile--ppt    { background: #fbeae5; color: #d24726; }
.lib-tile--img    { background: var(--accent-soft, #fff8d1); color: var(--accent-deep, #d9bb02); }
.lib-tile--prompt { background: var(--primary-light); color: var(--primary); }
.lib-tile--snippet{ background: var(--excel-light); color: var(--excel); }
.lib-tile--link   { background: var(--border-light); color: var(--text-secondary); }
.lib-tile--html   { background: #fdebe5; color: #e34f26; }
.lib-tile--js     { background: #fff8d1; color: #a68b00; }
.lib-tile--code   { background: var(--primary-light); color: var(--primary-dark); }
.lib-tile--text   { background: var(--border-light); color: var(--text-secondary); }
.lib-tile--file   { background: var(--border-light); color: var(--text-muted); }
@media (prefers-reduced-motion: reduce) {
  .lib-block:hover .lib-tile { transform: none; }
}
.lib-block-label {
  flex: 1; min-width: 0; font-size: var(--text-md); font-weight: 600; line-height: 1.35;
  overflow-wrap: anywhere;
}
/* Second meta line under the filename: "code preview inside" / View code. */
.lib-block-meta { display: block; margin-top: 3px; }
.lib-block-file {
  display: block; font-family: var(--font-mono); font-weight: 400;
  font-size: var(--text-xs); color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-block-size { margin-left: 8px; }
.lib-copy-btn {
  transition: background var(--transition-fast), border-color var(--transition-fast),
              color var(--transition-fast);
}
.lib-copy-btn.is-copied {
  background: var(--success-light); border-color: var(--success);
  color: var(--excel); animation: libpop 320ms ease;
}
@keyframes libpop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .lib-copy-btn.is-copied { animation: none; }
}

.lib-pre {
  margin-top: var(--sp-3); background: var(--vscode-bg); color: var(--vscode-text);
  border-radius: var(--radius); padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.55;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow-y: auto;
}
/* Code preview inside file blocks */
.lib-view-code {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font); font-size: var(--text-xs); font-weight: 600;
  color: var(--primary); background: none; border: 0; cursor: pointer;
  padding: 0; border-radius: var(--radius);
  white-space: nowrap;
}
.lib-view-code:hover { text-decoration: underline; }
.lib-preview-hint {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap;
}
.lib-preview.is-open { animation: libreveal 220ms ease; }
@keyframes libreveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .lib-preview.is-open { animation: none; }
}
.lib-preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); margin-top: var(--sp-3);
}
.lib-preview-bar .lib-block-file { display: inline; }
.lib-preview .lib-pre { margin-top: var(--sp-2); }

/* Prism supplies token COLORS only; the box, font and sizing stay ours
   (prism-tomorrow's code[class*="language-"] rules would otherwise swap the
   font stack and add a text shadow). */
.lib-pre code[class*="language-"] {
  font-family: inherit; font-size: inherit; line-height: inherit;
  text-shadow: none; white-space: inherit; word-break: inherit;
  background: transparent; padding: 0;
}

.lib-locked {
  margin-top: var(--sp-3); display: flex; flex-direction: column; gap: 7px;
}
.lib-locked span {
  height: 10px; border-radius: 5px; background: var(--border-light);
}
.lib-locked span:nth-child(1) { width: 92%; }
.lib-locked span:nth-child(2) { width: 78%; }
.lib-locked span:nth-child(3) { width: 55%; }
/* Blurred opening lines of a gated prompt/snippet (server-capped teaser). */
.lib-teaser {
  position: relative; margin-top: var(--sp-3); max-height: 64px; overflow: hidden;
  pointer-events: none; user-select: none;
}
.lib-teaser-text {
  margin: 0; font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.55;
  color: var(--text-secondary); white-space: pre-wrap; word-break: break-word;
  filter: blur(2.5px);
}
.lib-teaser::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 10%, var(--surface) 100%);
}
.lib-gate-note {
  margin-top: var(--sp-4); font-size: var(--text-base); color: var(--text-secondary);
  display: flex; gap: 8px; align-items: baseline; line-height: 1.5;
}
.lib-gate-note i { color: var(--primary); }

.lib-h2 { font-size: var(--text-xl); font-weight: 700; margin: var(--sp-6) 0 var(--sp-4); }

/* ── Course banner ── */
.lib-course-cta {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-5); flex-wrap: wrap;
  background: linear-gradient(120deg, var(--primary-dark), var(--primary));
  color: #fff; border-radius: var(--radius-lg);
  padding: var(--sp-6) var(--sp-8); margin: var(--sp-8) 0 var(--sp-10);
  box-shadow: var(--shadow-md);
}
.lib-course-cta h3 { font-size: var(--text-xl); margin-bottom: 4px; }
.lib-course-cta p { color: rgba(255, 255, 255, 0.85); font-size: var(--text-md); line-height: 1.55; max-width: 560px; }
.lib-course-cta .c-btn--primary { background: var(--accent, #ffdc03); color: #4a3b00; white-space: nowrap; }
.lib-course-cta .c-btn--primary:hover { background: #f3d102; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .lib-entry-grid { grid-template-columns: 1fr; }
  .lib-course-cta { padding: var(--sp-5); }
}
