/* Story library landing page (/ without ?story=) */
.library {
  position: fixed; inset: 0; z-index: 40; overflow-y: auto;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(94, 63, 160, .18), transparent 55%),
    radial-gradient(ellipse at 90% 15%, rgba(28, 110, 120, .16), transparent 55%),
    #08090d;
  color: var(--ink);
}
.library-head {
  height: 68px; padding: 0 clamp(16px, 4vw, 56px);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  background: rgba(8, 9, 13, .6); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 2;
}
.lib-brand { display: flex; align-items: center; gap: 12px; font-size: 14px; letter-spacing: .05em; }
.library-head a { font-size: 12px; color: var(--muted); transition: .16s ease; }
.library-head a:hover { color: var(--accent); }
.library-main { max-width: 1240px; margin: 0 auto; padding: clamp(38px, 7vh, 82px) clamp(16px, 4vw, 40px) 54px; }
.library-intro { margin-bottom: 40px; animation: libFade .6s ease both; }
.lib-kicker { font-size: 11px; letter-spacing: .36em; color: var(--accent); font-weight: 600; }
.library-intro h1 {
  margin: 18px 0 12px; font-size: clamp(32px, 5vw, 56px);
  font-weight: 600; letter-spacing: .04em; line-height: 1.2;
}
.library-intro p { margin: 0; color: var(--muted); font-size: 14px; letter-spacing: .04em; }

.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.story-card {
  --card-accent: #ff6b81;
  display: block; width: 100%; padding: 0; text-align: left; color: inherit;
  background: rgba(255, 255, 255, .035); border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 14px; overflow: hidden; cursor: pointer;
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
  animation: libFade .55s ease both;
}
.story-card:hover, .story-card:focus-visible {
  transform: translateY(-5px); border-color: var(--card-accent); outline: none;
  box-shadow: 0 22px 55px rgba(0, 0, 0, .5), 0 0 0 1px color-mix(in srgb, var(--card-accent) 35%, transparent);
}
.story-cover {
  aspect-ratio: 16 / 9; position: relative; overflow: hidden;
  background: linear-gradient(135deg, color-mix(in srgb, var(--card-accent) 26%, #11131f), #0a0c14);
}
.story-cover::before {
  content: attr(data-index);
  position: absolute; left: 16px; bottom: 2px; z-index: 1;
  font-size: 82px; font-weight: 700; line-height: 1; letter-spacing: -.05em;
  color: rgba(255, 255, 255, .1); pointer-events: none;
}
.story-cover video, .story-cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .72; }
.story-cover::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, transparent 35%, rgba(8, 9, 13, .88));
}
.cover-no {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 62px; font-weight: 700; color: rgba(255, 255, 255, .14); letter-spacing: .1em;
}
.cover-badge {
  position: absolute; top: 12px; left: 12px; z-index: 2;
  font-size: 10px; letter-spacing: .1em; padding: 4px 9px; border-radius: 5px;
  background: rgba(8, 9, 13, .72); border: 1px solid rgba(255, 255, 255, .18);
  color: rgba(255, 255, 255, .82);
}
.cover-badge.warn { color: #ffcf85; border-color: rgba(255, 190, 100, .45); }
.cover-index {
  position: absolute; right: 14px; bottom: 10px; z-index: 2;
  font-size: 10px; letter-spacing: .22em; color: rgba(255, 255, 255, .6);
}
.story-body { padding: 18px 20px 20px; }
.story-body h2 { margin: 0 0 7px; font-size: 19px; font-weight: 600; letter-spacing: .03em; }
.story-body p {
  margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.7;
  min-height: 42px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.story-meta { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 15px; }
.story-meta span {
  font-size: 10.5px; color: rgba(255, 255, 255, .55);
  background: rgba(255, 255, 255, .06); padding: 4px 9px; border-radius: 5px;
}
.story-go {
  margin-top: 18px; display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 600; color: var(--card-accent);
}
.story-go .arrow { font-size: 18px; transition: transform .2s ease; }
.story-card:hover .arrow { transform: translateX(5px); }

.library-empty { text-align: center; padding: 80px 20px; color: var(--muted); font-size: 14px; }
.library-foot {
  max-width: 1240px; margin: 0 auto; padding: 22px clamp(16px, 4vw, 40px) 36px;
  border-top: 1px solid rgba(255, 255, 255, .06);
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 11px; color: rgba(255, 255, 255, .34); letter-spacing: .05em;
}
@keyframes libFade { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- content discovery ---------- */
.lib-head-links { display: flex; gap: 18px; align-items: center; }
.lib-featured {
  --feat-accent: #ff6b81;
  display: grid; grid-template-columns: 1.15fr 1fr; gap: 0;
  margin-bottom: 34px; border-radius: 16px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .12);
  background: linear-gradient(120deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
  animation: libFade .6s ease both;
}
.feat-cover {
  position: relative; min-height: 260px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--feat-accent) 30%, #11131f), #0a0c14);
}
.feat-cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .85; }
.feat-cover::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 60%, rgba(12, 13, 20, .55));
}
.feat-body { padding: 30px 32px; display: flex; flex-direction: column; justify-content: center; }
.feat-kicker { font-size: 11px; letter-spacing: .26em; color: var(--feat-accent); }
.feat-body h2 { margin: 14px 0 10px; font-size: clamp(24px, 3vw, 34px); font-weight: 600; line-height: 1.3; }
.feat-body p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.8; }
.feat-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 22px; }
.feat-meta span {
  font-size: 11px; color: rgba(255,255,255,.62);
  background: rgba(255,255,255,.07); padding: 5px 10px; border-radius: 6px;
}
.feat-btn {
  align-self: flex-start; border: 0; border-radius: 9px; padding: 11px 20px;
  background: var(--feat-accent); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.feat-btn:hover { filter: brightness(1.1); }

.lib-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.lib-search { position: relative; flex: 1 1 auto; min-width: 0; }
.lib-search input {
  width: 100%; padding: 11px 40px 11px 14px; border-radius: 9px; outline: none;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.12);
  color: var(--ink); font-size: 13px;
}
.lib-search input:focus { border-color: var(--accent); }
.lib-search input::placeholder { color: rgba(255,255,255,.35); }
.lib-search span { position: absolute; right: 14px; top: 8px; font-size: 20px; color: rgba(255,255,255,.4); }
.lib-sort {
  flex: 0 0 auto; padding: 11px 32px 11px 12px; border-radius: 9px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.12);
  color: var(--ink); font-size: 12.5px; outline: none; cursor: pointer;
}
.lib-sort option { background: #14161f; color: #fff; }
.lib-cats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.cat-chip {
  border: 1px solid rgba(255,255,255,.13); background: rgba(255,255,255,.04);
  color: rgba(255,255,255,.6); font-size: 11.5px; padding: 6px 13px;
  border-radius: 20px; cursor: pointer; transition: .16s ease;
}
.cat-chip:hover { color: #fff; border-color: rgba(255,255,255,.3); }
.cat-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.lib-result { font-size: 11.5px; color: rgba(255,255,255,.4); margin-bottom: 14px; letter-spacing: .04em; }

.story-byline {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 11px; color: rgba(255,255,255,.45);
}
.story-cat {
  color: var(--card-accent); border: 1px solid color-mix(in srgb, var(--card-accent) 45%, transparent);
  padding: 1px 7px; border-radius: 4px; font-size: 10px;
}
.cover-pick {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  font-size: 10px; letter-spacing: .08em; padding: 4px 9px; border-radius: 5px;
  background: var(--card-accent); color: #fff;
}

/* ---------- story detail modal ---------- */
.detail-modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(4, 5, 9, .78); backdrop-filter: blur(6px); }
.detail-card {
  --detail-accent: #ff6b81;
  position: relative; z-index: 1; width: min(840px, 94vw); max-height: 86vh; overflow: auto;
  display: grid; grid-template-columns: 1fr 1fr;
  background: #14161f; border: 1px solid rgba(255,255,255,.13); border-radius: 16px;
  box-shadow: 0 34px 90px rgba(0,0,0,.6); animation: libFade .28s ease both;
}
.detail-close {
  position: absolute; right: 12px; top: 10px; z-index: 3;
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2);
  background: rgba(10,11,16,.7); color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
}
.detail-cover {
  min-height: 340px; position: relative;
  background: linear-gradient(150deg, color-mix(in srgb, var(--detail-accent) 34%, #11131f), #0a0c14);
}
.detail-cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .88; }
.detail-cover::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 55%, #14161f);
}
.detail-body { padding: 38px 34px 34px; display: flex; flex-direction: column; }
.detail-kicker { font-size: 11px; letter-spacing: .2em; color: var(--detail-accent); }
.detail-body h2 { margin: 14px 0 6px; font-size: 27px; font-weight: 600; line-height: 1.35; }
.detail-author { margin: 0 0 18px; font-size: 11.5px; color: rgba(255,255,255,.42); }
.detail-desc { margin: 0; font-size: 13px; line-height: 1.9; color: rgba(255,255,255,.72); }
.detail-tags { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 16px; }
.detail-tags span {
  font-size: 11px; color: rgba(255,255,255,.55);
  background: rgba(255,255,255,.06); padding: 4px 9px; border-radius: 5px;
}
.detail-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 24px 0; }
.detail-stats div { border: 1px solid rgba(255,255,255,.09); border-radius: 9px; padding: 12px 8px; text-align: center; }
.detail-stats strong { display: block; font-size: 19px; font-weight: 600; color: #fff; }
.detail-stats span { display: block; margin-top: 3px; font-size: 10px; color: rgba(255,255,255,.45); }
.detail-start {
  margin-top: auto; border: 0; border-radius: 9px; padding: 13px 18px;
  background: var(--detail-accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.detail-start:hover { filter: brightness(1.1); }

@media (max-width: 720px) {
  .library-head { height: 58px; }
  .story-grid { grid-template-columns: 1fr; gap: 14px; }
  .library-main { padding-top: 32px; }
  .library-foot { font-size: 10px; }
  .lib-featured { grid-template-columns: 1fr; }
  .feat-cover { min-height: 180px; }
  .feat-body { padding: 22px; }
  .lib-toolbar { flex-wrap: wrap; }
  .lib-sort { flex: 1 1 auto; }
  .detail-card { grid-template-columns: 1fr; }
  .detail-cover { min-height: 180px; }
  .detail-cover::after { background: linear-gradient(180deg, transparent 55%, #14161f); }
  .detail-body { padding: 24px 22px 26px; }
  .detail-stats { margin: 18px 0; }
}
