/* assets/library.css — halaman Prompt AI & Script Kode (daftar dan detail) */

.lib-wrap { max-width: 1080px; margin: 0 auto; padding: 22px 16px 56px; }
.lib-hero { text-align: center; padding: 18px 0 10px; }
.lib-hero h1 { font-size: clamp(26px, 5vw, 38px); font-weight: 800; letter-spacing: -.02em; margin: 0 0 8px; }
.lib-hero p { margin: 0 auto 16px; max-width: 620px; color: var(--muted); }

.lib-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 14px 0 6px; }
.lib-bar .search { flex: 1 1 280px; margin: 0; max-width: none; }
.lib-sort {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--glass-strong); font: inherit; font-size: 13.5px; color: var(--ink);
}
.lib-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0 16px; }
.lib-more { display: flex; justify-content: center; margin: 22px 0 4px; }
@media (max-width: 767px) {
  /* dibungkus ke beberapa baris, tanpa digeser */
  .lib-chips { gap: 6px; margin: 8px 0 12px; justify-content: center; }
  .lib-chips .chip { min-height: 36px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
}
.lib-count { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.lib-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.lib-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px;
}
.lib-card h2, .lib-card h3 { margin: 0; font-size: 16px; line-height: 1.3; }
.lib-card h3 a { color: inherit; text-decoration: none; }
.lib-card h3 a:hover { color: var(--brand-dark); }
.lib-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.lib-snip { margin: 0; color: #334155; font-size: 13.5px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.lib-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }
.lib-actions .btn { flex: 1; justify-content: center; }
.lib-lang {
  display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft);
  color: var(--brand-dark); font-weight: 700; font-size: 11px; text-transform: uppercase;
}

/* Kartu script dengan foto pratinjau */
.lib-card-media { padding: 0 0 16px; overflow: hidden; }
.lib-card-media > :not(.lib-card-cover) { margin-left: 18px; margin-right: 18px; }
.lib-card-cover {
  display: block; aspect-ratio: 16 / 9; background: var(--grad-soft); overflow: hidden;
  border-bottom: 1px solid var(--line);
}
.lib-card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.lib-card-cover:hover img { transform: scale(1.03); }
.lib-card-empty { display: grid; place-items: center; color: var(--brand-dark); }
.lib-card-empty .icon { width: 38px; height: 38px; }

/* Detail script */
.lib-script-grid { display: grid; gap: 22px; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; margin-top: 10px; }
.lib-script-grid:not(:has(.lib-media)) { grid-template-columns: minmax(0, 1fr); max-width: 680px; }
.lib-gallery { display: grid; gap: 10px; }
.lib-cover {
  width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; display: block;
  border-radius: var(--radius); border: 1px solid var(--glass-border); box-shadow: var(--shadow); background: #fff;
}
.lib-thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-thumb {
  width: 72px; height: 48px; padding: 0; border: 2px solid transparent; border-radius: 10px;
  overflow: hidden; cursor: pointer; background: #fff; opacity: .75;
}
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-thumb.on, .lib-thumb:hover { border-color: var(--brand); opacity: 1; }
.lib-desc { font-size: 15px; line-height: 1.7; color: #334155; }
.lib-dl { font-size: 16px; padding: 13px 22px; }
@media (max-width: 760px) { .lib-script-grid { grid-template-columns: 1fr; } }

/* Detail */
.lib-crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.lib-crumbs a { color: var(--brand-dark); text-decoration: none; font-weight: 600; }
.lib-wrap h1 { font-size: clamp(24px, 4.5vw, 34px); font-weight: 800; letter-spacing: -.02em; margin: 4px 0 8px; }
.lib-pre {
  white-space: pre-wrap; word-break: break-word; margin: 14px 0;
  background: var(--glass-strong); border: 1px solid var(--glass-border); border-radius: var(--radius-sm);
  padding: 16px 18px; font: inherit; font-size: 14.5px; line-height: 1.65; color: var(--ink);
}
.lib-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.55; white-space: pre; overflow: auto; max-height: 520px; }
.lib-pre-edit { cursor: text; outline: none; border-color: rgba(16, 185, 129, .55); }
.lib-pre-edit:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); background: #fff; }
.lib-var-hl { background: rgba(250, 204, 21, .35); border-radius: 4px; padding: 0 2px; }
.lib-vars { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 12px 0; }
.lib-vars label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 700; }
.lib-vars input, .lib-vars textarea {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, .9); font: inherit; font-size: 13.5px; color: var(--ink);
}
.lib-vars input:focus, .lib-vars textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); }
.lib-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.lib-tabs { display: flex; gap: 6px; margin: 14px 0 0; }
.lib-tabs .btn[aria-selected="true"] { background: var(--brand-soft); border-color: rgba(16, 185, 129, .5); color: var(--brand-dark); }
.lib-preview {
  width: 100%; height: 440px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; margin-top: 10px; display: block;
}
.lib-note { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.lib-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.lib-tags .tag {
  display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--glass-strong);
  border: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.lib-related { margin-top: 28px; }
.lib-related h2 { font-size: 17px; margin: 0 0 8px; }
.lib-related ul { margin: 0; padding-left: 18px; }
.lib-related li { margin: 4px 0; }
.lib-related a { color: var(--brand-dark); font-weight: 600; }

@media (max-width: 560px) {
  .lib-preview { height: 360px; }
  .lib-bar .lib-sort { width: 100%; }
}

/* Gambar referensi pada halaman prompt */
.lib-refs { margin: 14px 0 6px; }
.lib-refs h2 { font-size: 17px; margin: 0 0 4px; }
.lib-ref-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 300px)); margin-top: 10px; }
.lib-ref { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lib-ref img {
  width: 100%; height: auto; display: block; border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border); box-shadow: var(--shadow); background: #fff;
}
.lib-ref .btn { align-self: flex-start; }
.lib-card-ref { aspect-ratio: 4 / 3; }
.lib-grid .lib-card-media .lib-snip { margin-top: 0; }

/* Daftar prompt: 2 kolom di HP */
@media (max-width: 600px) {
  .lib-grid.is-prompt { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .lib-grid.is-prompt .lib-card { padding: 12px; gap: 6px; border-radius: 14px; }
  .lib-grid.is-prompt .lib-card-media { padding: 0 0 12px; }
  .lib-grid.is-prompt .lib-card-media > :not(.lib-card-cover) { margin-left: 12px; margin-right: 12px; }
  .lib-grid.is-prompt .lib-card h3 { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
  .lib-grid.is-prompt .lib-meta { font-size: 11px; }
  .lib-grid.is-prompt .lib-meta span + span { display: none; }
  .lib-grid.is-prompt .lib-snip {
    font-size: 12px; line-height: 1.45;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  }
  .lib-grid.is-prompt .lib-actions { margin-top: auto; }
  .lib-grid.is-prompt .lib-actions .btn { width: 100%; justify-content: center; }
  .lib-ref-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

/* Animasi memuat (kerangka kartu) */
.lib-skel { pointer-events: none; }
.lib-skel .sk {
  display: block; border-radius: 8px;
  background: linear-gradient(90deg, rgba(148, 163, 184, .18) 25%, rgba(148, 163, 184, .34) 50%, rgba(148, 163, 184, .18) 75%);
  background-size: 200% 100%; animation: sk-shine 1.2s linear infinite;
}
.sk-s { height: 11px; width: 40%; }
.sk-t { height: 18px; width: 80%; margin-top: 4px; }
.sk-l { height: 11px; width: 100%; }
.sk-b { height: 36px; width: 100%; border-radius: 12px; margin-top: 8px; }
@keyframes sk-shine { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .lib-skel .sk { animation: none; } }

/* Template & File: jenis berkas, video pratinjau */
.lib-media { display: grid; gap: 14px; min-width: 0; }
.lib-video { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--glass-border); box-shadow: var(--shadow); background: #000; }
.lib-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.lib-ext {
  display: inline-block; padding: 2px 9px; border-radius: 999px; background: rgba(16, 185, 129, .14); color: var(--brand-dark);
  font-weight: 800; font-size: 11px; letter-spacing: .04em;
}
.lib-filetype { margin: 4px 0 0; display: flex; align-items: center; gap: 8px; }

/* Pratinjau yang bukan 16:9 dipotong dari atas, bukan dari tengah */
.lib-card-cover img, .lib-cover, .lib-thumb img { object-position: center top; }

/* Tautan HTML awal sebelum JavaScript menggantinya dengan kartu */
.lib-ssr { display: inline-block; margin: 0 8px 8px 0; font-size: 13.5px; color: #065f46; }
