/* Scoped to the studio so the host can replace its navigation independently. */
dialog.lib-studio {
  --surface: #fff;
  --well: #f4f5f6;
  --line: #dadee3;
  --ink: #191c22;
  --muted: #535b66;
  --accent: #164ec5;
  --tint: #eaf1ff;
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(624px, calc(100% - 28px));
  max-width: none;
  height: fit-content;
  max-height: min(90vh, 820px);
  max-height: min(90dvh, 820px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 68px rgb(14 20 32 / 25%);
  font: 14px/1.5 system-ui, "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
[data-mantine-color-scheme="dark"] dialog.lib-studio {
  --surface: #202124;
  --well: #2c2e33;
  --line: #494e54;
  --ink: #f3f4f5;
  --muted: #bac0c9;
  --accent: #94b7ff;
  --tint: #273955;
  color-scheme: dark;
}
dialog.lib-studio[open] {
  inset: 0;
  display: flex;
  flex-direction: column;
  transform: none;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
dialog.lib-studio:not([open]), .lib-studio [hidden], .studio-toast[hidden] { display: none !important; }
dialog.lib-studio::backdrop { background: rgb(13 17 24 / 48%); }
html:has(dialog.lib-studio[open]) { overflow: hidden; }
.lib-studio *, .lib-studio *::before { box-sizing: border-box; }
.lib-studio h2, .lib-studio p, .lib-studio figure { margin: 0; }
.lib-studio h2 { font-family: inherit; font-size: 19px; line-height: 1.3; font-weight: 650; }
.lib-studio button {
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  padding: 6px 10px;
  min-height: 32px;
  color: inherit;
  background: var(--well);
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}
.lib-studio button:hover:enabled { border-color: var(--line); }
.lib-studio button:disabled { opacity: .6; cursor: not-allowed; }
.lib-studio :is(button, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lib-studio .studio-head, .lib-studio .studio-foot {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}
.lib-studio .studio-head { border-bottom: 1px solid var(--line); }
.lib-studio .studio-head h2, .lib-studio .studio-summary { margin-right: auto; }
.lib-studio .studio-summary { min-width: 0; }
.lib-studio #lbgCredits { color: var(--ink); font-weight: 600; }
.lib-studio #lbgRedeem { display: inline-block; padding-block: 4px; color: var(--accent); text-underline-offset: 3px; }
.lib-studio .studio-head .x {
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  width: 34px;
  height: 34px;
  padding: 0;
}
.lib-studio .studio-body {
  display: block;
  border: 0;
  padding: 17px 20px 20px;
  margin: 0;
  min-inline-size: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.lib-studio #lbgFields {min-inline-size:0;padding:0;border:0;margin:0}
.lib-studio .studio-tools, .lib-studio .studio-choices,
.lib-studio .studio-actions, .lib-studio .studio-ref {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}
.lib-studio .studio-choices button.active {
  background: var(--tint);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.lib-studio .studio-tools { margin: 0 0 7px; }
.lib-studio .studio-tools label { font-weight: 600; margin-right: 4px; }
.lib-studio .studio-tools button { background: transparent; color: var(--muted); }
.lib-studio small, .lib-studio .studio-meta, .lib-studio #lbgCost, .lib-studio .lbgen-tplhint {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.lib-studio #lbgLen { margin-left: auto; font-variant-numeric: tabular-nums; }
.lib-studio textarea.lbgen-prompt {
  display: block;
  width: 100%;
  min-height: 86px;
  max-height: 32vh;
  padding: 10px 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
  caret-color: var(--accent);
  box-shadow: none;
}
.lib-studio textarea::placeholder { color: var(--muted); }
.lib-studio .lbgen-tplhint { margin-top: 6px; }
.lib-studio .studio-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  margin-top: 12px;
}
.lib-studio .studio-row > span { color: var(--muted); }
.lib-studio #lbgRefHelp { display: block; margin-top: 3px; }
.lib-studio #lbgRefPreview { width: 58px; height: 58px; object-fit: contain; background: var(--well); border-radius: 4px; }
.lib-studio .studio-ref { gap: 9px; }
.lib-studio .studio-foot { border-top: 1px solid var(--line);background:var(--surface); }
.lib-studio .studio-foot .lbgen-go {
  padding: 9px 20px;
  min-width: 105px;
  border-radius: 6px;
  color: #fff;
  background: #1857d2;
  font-size: 14px;
  font-weight: 600;
  box-shadow: none;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}
.lib-studio .studio-foot a.lbgen-go:hover {filter:brightness(1.09)}
.lib-studio .studio-message { color: var(--muted); padding: 26px 0; text-align: center; }
.lib-studio .studio-message button { margin-inline-start: 8px; }
.lib-studio .lbgen-hcard + .lbgen-hcard { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.lib-studio .studio-history-prompt { margin: 5px 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.lib-studio .studio-images { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.lib-studio .studio-images figure { min-width: 0; }
.lib-studio .studio-thumb { display: block; width: 100%; padding: 0; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; }
.lib-studio .studio-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.lib-studio .studio-save { width: 100%; margin-top: 2px; background: transparent; color: var(--accent); }
.lib-studio .studio-actions { justify-content: flex-end; margin-top: 6px; }
.lib-studio .studio-actions button { color: var(--ink); background: var(--well); }
.lib-studio .studio-actions .danger { color: #bb343d; }
[data-mantine-color-scheme="dark"] .lib-studio .studio-actions .danger { color: #ffa6a8; }
dialog.lib-studio.lbgen-lb {
  width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  border-radius: 0;
  padding: 54px 16px max(16px, env(safe-area-inset-bottom));
  background: #151619;
  color: #fff;
  align-items: stretch;
  justify-content: stretch;
  gap: 14px;
}
.lib-studio.lbgen-lb .x { top: 8px; right: 12px; width: 36px; height: 36px; position: absolute; color: #fff; background: #343539; padding: 0; display: grid; place-items: center; }
.lib-studio .studio-stage { min-height: 0; flex: 1; display: grid; place-items: center; pointer-events: none; }
.lib-studio .studio-stage img { width: auto; height: auto; max-width: 100%; max-height: 100%; min-height: 0; object-fit: contain; border-radius: 0; box-shadow: none; pointer-events: auto; }
.lib-studio.lbgen-lb .bar, .lib-studio.lbgen-lb .act.dl { position: static; transform: none; }
.lib-studio.lbgen-lb .bar, .lib-studio .studio-pager { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.lib-studio.lbgen-lb .bar { flex: none; }
.lib-studio.lbgen-lb .bar button { background: #35373c; color: #fff; border-radius: 5px; padding: 7px 12px; }
.lib-studio .studio-pager span { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.lib-studio .studio-pager i { display: inline-block; width: 8px; height: 8px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg); }
.lib-studio .studio-pager .prev i { transform: rotate(135deg); }
.lib-studio .studio-copy-input { position: fixed; width: 1px; height: 1px; opacity: 0; }
.lib-studio .studio-toast, .lbgen-toast.studio-toast {
  position: fixed;
  z-index: 10000;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(90vw, 550px);
  margin: 0;
  padding: 9px 16px;
  border-radius: 6px;
  background: #25272b;
  color: #fff;
  font: 14px/1.45 system-ui, sans-serif;
  white-space: normal;
  overflow-wrap: anywhere;
  pointer-events: none;
}
.lbgen-toast.studio-toast.err { background: #972b31; }

.discovery-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--shell-line);
  margin-bottom: 12px;
}
.discovery-strip[hidden] { display: none; }
.discovery-strip h1 {
  margin: 0;
  font: 700 30px/1.25 "Songti SC","STSong","Noto Serif CJK SC","SimSun",serif;
}
.discovery-strip nav { display: flex; flex-wrap: wrap; gap: 8px; }
.discovery-strip a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--shell-line);
  border-radius: 6px;
  color: var(--shell-fg);
  text-decoration: none;
  font-weight: 600;
}
.discovery-strip a:hover { background: var(--shell-soft); }
.discovery-strip .discovery-create { color: #fff; background: #aa392b; border-color: #aa392b; }
.discovery-strip .discovery-create:hover { background: #913024; }
@media (max-width: 760px) {
  .discovery-strip { gap: 8px; padding: 0 0 12px; margin-bottom: 8px; }
  .discovery-strip h1 { font-size: 24px; }
  .discovery-strip a { min-height: 44px; padding-inline: 9px; gap: 4px; }
  .discovery-strip i { width: 16px; height: 16px; }
}
@media (max-width: 520px) {
  dialog.lib-studio { max-height: 94dvh; }
  .lib-studio .studio-body, .lib-studio .studio-head, .lib-studio .studio-foot { padding-inline: 14px; }
  .lib-studio .studio-row { grid-template-columns: 42px minmax(0, 1fr); gap: 5px; }
  .lib-studio .studio-choices button { padding-inline: 8px; }
  .lib-studio .studio-images { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lib-studio textarea.lbgen-prompt { font-size: 16px; }
  .lib-studio .studio-foot {display:grid;grid-template-columns:minmax(0,1fr) auto;gap:6px 12px}
  .lib-studio .studio-foot:has(#lbgHealthRetry:not([hidden])) .studio-summary {grid-column:1/-1}
  .lib-studio #lbgHealthRetry {justify-self:start}
  .lib-studio .studio-foot .lbgen-go {grid-column:2;justify-self:end}
}
