.studio-gallery {
  --library-bg: #f4f6f9;
  --library-ink: #172334;
  --library-muted: #4f5e71;
  --library-line: #d8e0ea;
  --library-blue: #234c7f;
  --library-navy: #15263d;
  --library-soft: #eaf1fb;
  background: var(--library-bg);
  color: var(--library-ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.studio-gallery .library-shell {
  width: min(100%, 1344px);
  max-width: none;
  margin-inline: auto;
  padding-inline: clamp(18px, 4vw, 56px);
}

.library-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--library-navy);
  color: #fff;
}

.library-header .library-shell,
.library-footer,
.library-intro,
.setup-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.library-header .library-shell { min-height: 58px; gap: 16px; }
.library-logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; white-space: nowrap; }
.library-logo svg { color: #adc9ee; }
.library-header nav,
.library-footer nav { display: flex; align-items: center; gap: clamp(12px, 2.5vw, 26px); }
.library-header nav a { color: #dbe7f6; font-size: 13px; padding-block: 9px; white-space: nowrap; }
.library-header nav a:hover { color: #fff; text-decoration: underline; text-underline-offset: 4px; }

.studio-gallery :is(h1, h2, h3) { font-family: inherit; letter-spacing: -.025em; }
.studio-gallery :focus-visible { outline: 2px solid #2a67b2; outline-offset: 3px; }
.library-header :focus-visible { outline-color: #bfd8fa; }
#templates, #pipeline { scroll-margin-top: 50px; }
#templates:focus { outline: none; }

.library-intro { gap: 28px; padding-block: 38px 30px; }
.library-intro .library-eyebrow { color: var(--library-blue); font-size: 12px; font-weight: 650; }
.library-intro h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.13; margin: 7px 0 10px; }
.library-intro p { color: var(--library-muted); }
.library-totals {
  display: flex;
  flex: 0 0 auto;
  margin: 0;
  border: 1px solid var(--library-line);
  border-radius: 10px;
  background: #fff;
}
.library-totals div { display: flex; flex-direction: column-reverse; min-width: 101px; padding: 12px 17px; }
.library-totals div + div { border-left: 1px solid var(--library-line); }
.library-totals dt { color: var(--library-muted); font-size: 11px; }
.library-totals dd { margin: 0; font-size: 23px; line-height: 1.3; font-weight: 700; font-variant-numeric: tabular-nums; }

.library-toolbar {
  display: grid;
  grid-template-columns: 1fr minmax(210px, 310px);
  align-items: center;
  gap: 14px 18px;
  padding: 15px 18px 16px;
  border: 1px solid var(--library-line);
  border-radius: 10px;
  background: #fff;
}
.library-toolbar h2, .setup-heading h2 { font-size: 20px; font-weight: 700; }
.library-search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 40px;
  padding-inline: 10px;
  border: 1px solid var(--library-line);
  border-radius: 6px;
  color: var(--library-muted);
  background: #f9fafc;
}
.library-search:focus-within { outline: 2px solid #2a67b2; outline-offset: 1px; }
.library-search svg { flex-shrink: 0; }
#gallery-search {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  min-height: 0;
  margin: 0;
  padding: 7px 0;
  font-size: 13px;
  background: transparent;
  color: var(--library-ink);
}
.library-search input:focus-visible { outline: none; }
.library-search input::placeholder { color: var(--library-muted); }

.library-toolbar .filter-buttons { grid-column: 1 / -1; gap: 7px; }
.library-toolbar .filter-buttons button {
  padding: 7px 11px;
  min-height: 38px;
  border: 1px solid var(--library-line);
  border-radius: 6px;
  color: var(--library-ink);
  background: #fff;
  font-size: 12px;
  font-weight: 600;
}
.library-toolbar .filter-buttons button:hover { background: #f4f7fb; border-color: #aabbd1; }
.library-toolbar .filter-buttons button.active {
  border-color: #a7bfdc;
  color: var(--library-blue);
  background: var(--library-soft);
}
.library-toolbar .filter-buttons small { margin-left: 4px; opacity: 1; font-size: 11px; color: var(--library-muted); }
.library-results {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 16px;
  padding-block: 12px;
  font-size: 12px;
  color: var(--library-muted);
}
.library-results p { margin: 0; }
#gallery-count { font-weight: 650; color: var(--library-ink); }

.studio-gallery .template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.studio-gallery .template-card {
  border: 1px solid var(--library-line);
  border-radius: 10px;
  background: #fff;
}
.studio-gallery .template-card:focus-within { border-color: #7b9cc8; }
.studio-gallery .card-preview {
  height: 216px;
  border: 0;
  border-bottom: 1px solid var(--library-line);
  border-radius: 9px 9px 0 0;
  transition: none;
}
.studio-gallery .card-preview:hover { transform: none; box-shadow: none; }
.studio-gallery .card-preview:focus-visible { outline-offset: -3px; }
.studio-gallery .mini-frame { margin-top: 14px; padding-top: 12px; }
.studio-gallery .mini-title { margin-block: 12px; }
.studio-gallery .mini-split {
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: 5px 10px;
}
.studio-gallery .mini-partner { padding-block: 9px; }
.studio-gallery .mini-tool { margin-top: 9px; padding: 8px 11px; }
.studio-gallery .mini-tool i { margin-top: 6px; }
.studio-gallery .preview-open {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  font: 650 12px/1.45 system-ui, sans-serif;
  color: var(--library-blue);
  background: #fff;
  border-color: #c6d3e3;
}
.studio-gallery .card-preview:hover .preview-open { color: #fff; background: var(--library-blue); border-color: var(--library-blue); }
.studio-gallery .card-meta { gap: 8px; padding: 13px 14px 15px; }
.studio-gallery .card-meta h3 { font-size: 18px; margin-top: 6px; }
.studio-gallery .card-meta p { font-size: 12px; color: var(--library-muted); margin-top: 4px; }
.card-label {
  display: flex;
  align-items: center;
  gap: 4px 8px;
  flex-wrap: wrap;
  font-size: 11px;
  font-weight: 650;
  color: var(--library-blue);
}
.card-label span + span { color: var(--library-muted); font-weight: 500; font-size: 10px; letter-spacing: .035em; }
.studio-gallery .save-template {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--library-line);
  border-radius: 6px;
  background: #fff;
  color: var(--library-muted);
  font-size: 21px;
  line-height: 1;
}
.studio-gallery .save-template:hover,
.studio-gallery .save-template[aria-pressed="true"] {
  border-color: #a7bfdc;
  color: var(--library-blue);
  background: var(--library-soft);
}

.library-empty {
  border: 1px dashed #b4c3d4;
  border-radius: 10px;
  padding: 30px 16px;
  background: #fff;
  text-align: center;
}
.library-empty h3 { font-size: 17px; }
.library-empty p { margin: 6px 0 14px; color: var(--library-muted); }
.library-empty button {
  border: 1px solid #a7bfdc;
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--library-blue);
  background: var(--library-soft);
  font-size: 13px;
  font-weight: 650;
}

.library-setup {
  margin-block: 30px 20px;
  border: 1px solid var(--library-line);
  border-radius: 10px;
  background: #fff;
}
.setup-heading {
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--library-line);
}
.setup-heading p { margin-top: 5px; color: var(--library-muted); font-size: 13px; }
.setup-heading a { color: var(--library-blue); font-size: 13px; font-weight: 650; white-space: nowrap; }
.setup-heading a:hover, .library-footer a:hover { text-decoration: underline; text-underline-offset: 3px; }
.setup-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}
.setup-list li { padding: 17px 20px 20px; }
.setup-list li + li { border-left: 1px solid var(--library-line); }
.step-index {
  display: inline-block;
  border-radius: 4px;
  padding: 2px 6px;
  background: var(--library-soft);
  color: var(--library-blue);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.setup-list h3 { font-size: 15px; margin-block: 8px 5px; }
.setup-list p { color: var(--library-muted); font-size: 12px; }
.setup-list code { font-size: 11px; white-space: nowrap; }
.library-footer { min-height: 65px; flex-wrap: wrap; gap: 8px 20px; color: var(--library-muted); font-size: 12px; }

@media (max-width: 960px) {
  .studio-gallery .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-totals div { min-width: 88px; padding-inline: 13px; }
  .setup-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setup-list li:nth-child(3) { border-left: 0; }
  .setup-list li:nth-child(n+3) { border-top: 1px solid var(--library-line); }
}

@media (max-width: 640px) {
  .library-intro { flex-direction: column; align-items: stretch; gap: 17px; padding-block: 23px 19px; }
  .library-totals div { flex: 1; min-width: 0; padding: 9px 12px; }
  .library-totals dd { font-size: 19px; }
  .library-toolbar { grid-template-columns: minmax(0, 1fr); gap: 11px; padding: 13px; }
  .studio-gallery .template-grid { grid-template-columns: minmax(0, 1fr); }
  .library-header nav { gap: 12px; }
  .library-header nav a { font-size: 12px; }
  .setup-heading { flex-wrap: wrap; }
  .setup-list li { padding-inline: 15px; }
  .library-footer { padding-block: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  html:has(.studio-gallery) { scroll-behavior: auto; }
}
