/* Shared template library — extends Whisperer's warm editorial system. */
.template-library-detail,
.template-library-page {
  --library-ink: #17160f;
  --library-paper: #eceae2;
  --library-panel: #fbfaf7;
  --library-coral: #e8593a;
}

.template-library-detail .site-header,
.template-library-page .site-header {
  position: relative;
  z-index: 5;
}

.template-library-detail .nav .active,
.template-library-page .nav .active {
  color: var(--accent);
}

.library-back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-decoration: none;
  text-transform: uppercase;
}

.library-back:hover {
  color: var(--accent);
}

.multi-template-hero {
  padding-bottom: clamp(2.8rem, 6vw, 4.8rem);
}

.multi-template-hero h1 {
  font-size: clamp(2.65rem, 6.5vw, 5.35rem);
}

.template-aliases {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1.2rem;
}

.template-aliases span {
  padding: 0.34rem 0.56rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 0.57rem;
}

.multi-template-editor {
  grid-template-columns: minmax(330px, 380px) minmax(0, 1fr);
  min-height: 690px;
}

.multi-template-controls {
  max-height: 860px;
  overflow-y: auto;
  scrollbar-color: rgba(23, 22, 15, 0.25) transparent;
  scrollbar-width: thin;
}

.multi-caption-list {
  display: grid;
  gap: 0.55rem;
}

.multi-caption-field {
  position: relative;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(23, 22, 15, 0.025);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.multi-caption-field::before {
  position: absolute;
  top: 0.72rem;
  right: 0.7rem;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  content: '';
  transition: background 0.15s, box-shadow 0.15s;
}

.multi-caption-field.active {
  border-color: rgba(232, 89, 58, 0.5);
  background: rgba(232, 89, 58, 0.045);
  box-shadow: 0 0 0 3px rgba(232, 89, 58, 0.07);
}

.multi-caption-field.active::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 89, 58, 0.12);
}

.multi-caption-field label {
  display: block;
  margin: 0 1.25rem 0.34rem 0;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.multi-caption-input {
  width: 100%;
  min-height: 42px;
  resize: vertical;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: 'Anton', Impact, sans-serif;
  font-size: 0.96rem;
  line-height: 1.25;
  outline: none;
  text-transform: uppercase;
}

.multi-style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.multi-style-grid .field {
  margin: 0;
}

.caption-color-input {
  width: 100%;
  height: 40px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(23, 22, 15, 0.035);
  cursor: pointer;
}

.multi-template-stage {
  min-width: 0;
  min-height: 690px;
}

.multi-canvas-wrap {
  min-height: 570px;
  padding: 1rem;
}

#memeCanvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(720px, 72vh);
  border-radius: 5px;
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.5);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#memeCanvas.dragging {
  cursor: grabbing;
}

.multi-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.multi-suggestions button {
  min-height: 40px;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--f-mono);
  font-size: 0.57rem;
  line-height: 1.35;
  text-align: left;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.multi-suggestions button:hover {
  border-color: rgba(232, 89, 58, 0.45);
  background: var(--accent-soft);
  color: var(--text);
}

.template-dimensions {
  font-variant-numeric: tabular-nums;
}

.template-story-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 5vw, 4rem);
}

.template-story-card {
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.template-story-card .lp-h2 {
  margin-bottom: 0.75rem;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
}

.template-related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  margin-top: 1.5rem;
}

.template-related-card {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 0.8rem;
  align-items: center;
  min-width: 0;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.16s, border-color 0.16s, box-shadow 0.16s;
}

.template-related-card:hover {
  border-color: rgba(232, 89, 58, 0.4);
  box-shadow: var(--shadow-soft);
  transform: translateY(-2px);
}

.template-related-card img {
  display: block;
  width: 82px;
  height: 68px;
  object-fit: cover;
  border-radius: 7px;
}

.template-related-card strong {
  display: block;
  font-size: 0.75rem;
  line-height: 1.35;
}

.template-related-card span {
  display: block;
  margin-top: 0.3rem;
  color: var(--accent);
  font-family: var(--f-mono);
  font-size: 0.56rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Template library hub */
.library-hero {
  position: relative;
  width: min(100% - 3rem, 1120px);
  margin: 0 auto;
  padding: clamp(4.5rem, 10vw, 8rem) 0 clamp(2.8rem, 6vw, 5rem);
}

.library-hero::after {
  position: absolute;
  top: 2.5rem;
  right: 4%;
  width: clamp(130px, 20vw, 230px);
  aspect-ratio: 1;
  border: 1px solid rgba(232, 89, 58, 0.24);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 89, 58, 0.2) 0 2px, transparent 3px) 0 0 / 20px 20px;
  content: '';
  opacity: 0.65;
  pointer-events: none;
}

.library-hero .eyebrow,
.library-hero h1,
.library-hero > p {
  position: relative;
  z-index: 1;
}

.library-hero h1 {
  max-width: 880px;
  margin: 1.2rem 0 1.3rem;
  font-size: clamp(3.2rem, 8vw, 7rem);
  line-height: 0.9;
  letter-spacing: -0.06em;
}

.library-hero > p:not(.eyebrow) {
  max-width: 670px;
  color: var(--muted);
  font-size: clamp(0.96rem, 1.5vw, 1.1rem);
  line-height: 1.75;
}

.library-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: rgba(236, 234, 226, 0.93);
  backdrop-filter: blur(16px);
}

.library-toolbar-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  width: min(100% - 3rem, 1120px);
  margin: 0 auto;
  padding: 0.9rem 0;
}

.library-search-wrap {
  position: relative;
}

.library-search-wrap svg {
  position: absolute;
  top: 50%;
  left: 0.9rem;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.library-search {
  width: 100%;
  min-height: 46px;
  padding: 0.7rem 1rem 0.7rem 2.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.library-search:focus {
  border-color: rgba(232, 89, 58, 0.55);
  box-shadow: 0 0 0 3px rgba(232, 89, 58, 0.08);
}

.library-count {
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.library-main {
  width: min(100% - 3rem, 1120px);
  margin: 0 auto;
  padding: 2rem 0 clamp(5rem, 10vw, 8rem);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.library-card {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(23, 22, 15, 0.045);
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}

.library-card:hover {
  border-color: rgba(232, 89, 58, 0.38);
  box-shadow: 0 18px 38px rgba(23, 22, 15, 0.1);
  transform: translateY(-3px);
}

.library-card-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 235px;
  overflow: hidden;
  background: #17181f;
}

.library-card-media::after {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  content: '';
  pointer-events: none;
}

.library-card img {
  display: block;
  width: 100%;
  height: 235px;
  object-fit: contain;
  transition: transform 0.25s;
}

.library-card:hover img {
  transform: scale(1.025);
}

.library-card-body {
  display: flex;
  min-height: 150px;
  flex: 1;
  flex-direction: column;
  padding: 1rem;
}

.library-card-kicker {
  color: var(--accent);
  font-family: var(--f-mono);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-card h2 {
  margin: 0.55rem 0 0.5rem;
  font-size: 1.05rem;
  line-height: 1.25;
}

.library-card p {
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.55;
}

.library-card-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 0.9rem;
  color: var(--text);
  font-family: var(--f-mono);
  font-size: 0.59rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.library-card-action span:last-child {
  color: var(--accent);
  font-size: 1rem;
  transition: transform 0.18s;
}

.library-card:hover .library-card-action span:last-child {
  transform: translateX(3px);
}

.library-empty {
  display: none;
  padding: 4rem 1rem;
  color: var(--muted);
  text-align: center;
}

.library-empty.visible {
  display: block;
}

.library-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  margin-top: 1.5rem;
  padding: 1rem;
  border: 1px solid rgba(232, 89, 58, 0.2);
  border-radius: 12px;
  background: rgba(232, 89, 58, 0.05);
}

.library-note span {
  color: var(--accent);
  font-family: var(--f-mono);
  font-size: 0.62rem;
  font-weight: 700;
}

.library-note p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.65;
}

.library-guide .lp-p,
.library-how .steps,
.library-faq .faq {
  max-width: 780px;
}

.library-popular-links {
  padding-top: 0.35rem;
}

.library-popular-links a {
  white-space: nowrap;
}

.library-how {
  background: rgba(255, 255, 255, 0.28);
}

.library-faq {
  padding-bottom: clamp(5rem, 10vw, 8rem);
}

@media (max-width: 900px) {
  .multi-template-editor {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .template-related-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 740px) {
  .multi-template-editor {
    grid-template-columns: 1fr;
  }

  .multi-template-controls {
    max-height: none;
    overflow: visible;
  }

  .multi-template-stage {
    min-height: 0;
  }

  .multi-canvas-wrap {
    min-height: 480px;
  }

  .template-story-grid {
    grid-template-columns: 1fr;
  }

  .library-toolbar-inner {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .library-count {
    padding-left: 0.2rem;
  }
}

@media (max-width: 560px) {
  .multi-template-hero h1 {
    font-size: clamp(2.45rem, 12vw, 3.8rem);
  }

  .multi-style-grid,
  .multi-suggestions {
    grid-template-columns: 1fr;
  }

  .multi-canvas-wrap {
    min-height: calc(100vw - 2.75rem);
    padding: 0.35rem;
  }

  #memeCanvas {
    max-height: 70vh;
  }

  .library-hero,
  .library-toolbar-inner,
  .library-main {
    width: min(100% - 2rem, 1120px);
  }

  .library-hero h1 {
    font-size: clamp(3.1rem, 18vw, 5rem);
  }

  .library-grid {
    grid-template-columns: 1fr;
  }

  .library-card-media,
  .library-card img {
    height: 220px;
    min-height: 220px;
  }
}
