/* ── Library (src/library.js) ── */
#library-view {
  position: fixed; left: 0; right: 0; bottom: 0; top: 0; z-index: 900; /* (top: under the top bar, set when shown) */
  display: flex; flex-direction: column; background: #141414; color: #e0e0e0; font-size: 0.8rem;
}
#library-view[hidden] { display: none; }
/* the main area: the actions, a line and the drawings, together in the middle of the view (from the
   top once they no longer fit) */
.lib-body {
  flex: 1; min-height: 0; overflow: auto; padding: 48px 24px; display: flex;
  scrollbar-width: thin; scrollbar-color: #3a3a3a transparent;
}
.lib-body::-webkit-scrollbar { width: 8px; }
.lib-body::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 4px; border: 2px solid #141414; }
.lib-center { position: relative; margin: auto; display: flex; align-items: flex-start; gap: 48px; max-width: 100%; }
.lib-center::before { content: ''; position: absolute; top: 0; bottom: 0; left: 252px; width: 1px; background: #2a2a2a; } /* (side + half the gap) */
.lib-side { width: 228px; flex-shrink: 0; position: sticky; top: 0; display: flex; flex-direction: column; gap: 4px; }
.lib-side-item {
  display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: #e0e0e0; font: inherit; text-align: left; cursor: pointer;
}
.lib-side-item:hover, .lib-side-item:focus-visible { background: #ffffff0d; border-color: #2e2e2e; outline: none; }
.lib-side-item svg { flex-shrink: 0; margin-top: 1px; color: #9a9a9a; }
.lib-side-item:hover svg { color: #e0e0e0; }
.lib-side-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.lib-side-text b { font-weight: 600; }
.lib-side-text span { color: #888; font-size: 0.72rem; line-height: 1.4; }
.lib-side-item:disabled { opacity: 0.4; cursor: default; background: none; border-color: transparent; }
/* the editor's floating windows and tools stay hidden under it */
body.library-open #tools-sidebar, body.library-open .dock, body.library-open #layers-panel, body.library-open #tool-settings,
body.library-open #preview-widget, body.library-open #palette-panel, body.library-open #colors-panel, body.library-open #history-panel, body.library-open #tileset-panel, body.library-open #tile-editor { visibility: hidden; }
/* the top bar keeps only the logo (no File menu, no colors on phones) */
body.library-open #toolbar > :not(h1):not(#btn-account) { visibility: hidden; }
/* the cards (wrapping when the view is narrow) */
/* the cards, with the Select bar above their top right corner (it takes no room: nothing moves when it shows) */
.lib-main { flex: 0 1 auto; min-width: 0; position: relative; }
.lib-grid { min-width: 0; display: flex; flex-wrap: wrap; gap: 16px; align-content: flex-start; }
/* Start new (a blank canvas, the templates) above Recent (the drawings) — each under a small heading */
.lib-main { display: flex; flex-direction: column; gap: 32px; }
.lib-h { margin: 0 0 12px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #8a8a8a; line-height: 28px; }
/* the whole view: the Start new banner on top, the actions and the drawings under it — together in the middle */
.lib-stack { margin: auto; width: min(1180px, 100%); display: flex; flex-direction: column; gap: 40px; }
.lib-stack .lib-center { margin: 0; width: 100%; }
.lib-stack .lib-main { flex: 1; }
/* Start new: a banner across the top, set apart from the plain Recent grid — centred, big pictures, a glow on hover */
.lib-start {
  position: relative; padding: 34px 32px 36px; border-radius: 18px; overflow: hidden; text-align: center;
  background:
    radial-gradient(60% 120% at 50% 0%, #2c4573 0%, transparent 65%),
    radial-gradient(50% 90% at 0% 100%, #24324f 0%, transparent 70%),
    radial-gradient(50% 90% at 100% 100%, #3a2a55 0%, transparent 70%),
    linear-gradient(135deg, #1a2030, #17161f);
  border: 1px solid #2f3a52; box-shadow: 0 20px 50px #0007, inset 0 1px 0 #ffffff12;
}
.lib-start::before { /* (a faint pixel grid over the glow) */
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background-image: linear-gradient(#ffffff08 1px, transparent 1px), linear-gradient(90deg, #ffffff08 1px, transparent 1px);
  background-size: 12px 12px; mask-image: linear-gradient(180deg, #000, transparent 70%);
}
.lib-start-head { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 26px; }
.lib-start-head h2 { margin: 0; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; color: #fff; text-wrap: balance; }
.lib-start-head p { margin: 0; color: #a9b4cc; font-size: 0.9rem; }
.lib-start-row { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
.lib-start-row .tpl-card { text-align: left; }
.lib-start-row .tpl-card {
  width: 196px; flex-shrink: 0; padding: 0 0 12px; gap: 4px; overflow: hidden; border-radius: 12px;
  background: #12151ccc; border: 1px solid #ffffff14; box-shadow: 0 6px 18px #0006;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.lib-start-row .tpl-card:hover, .lib-start-row .tpl-card:focus-visible {
  transform: translateY(-4px); border-color: #6c9cff; background: #12151ccc;
  box-shadow: 0 14px 30px #0008, 0 0 0 1px #6c9cff55, 0 0 28px #4a7fcb55;
}
.lib-start-row .tpl-card > b, .lib-start-row .tpl-card > span:not(.tpl-pic) { padding: 0 12px; }
.lib-start-row .tpl-card > b { margin-top: 8px; font-size: 0.92rem; color: #fff; }
.lib-start-row .tpl-card > span:not(.tpl-pic) { color: #98a2b8; }
.lib-start-row .tpl-pic { border-radius: 0; }
.lib-start-row .tpl-pic canvas { border-radius: 0; transition: transform 0.25s ease; }
.lib-start-row .tpl-card:hover .tpl-pic canvas { transform: scale(1.04); }
/* the blank canvas: a white sheet waiting */
.lib-start-row .lib-blank-pic { display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #262c3a, #1b1f2a); }
.lib-start-row .lib-blank-plus {
  width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: #4a7fcb; color: #fff; box-shadow: 0 6px 20px #4a7fcb66; transition: transform 0.16s ease;
}
.lib-blank:hover .lib-blank-plus, .lib-blank:focus-visible .lib-blank-plus { transform: scale(1.1); }
@media (prefers-reduced-motion: reduce) {
  .lib-start-row .tpl-card, .lib-start-row .tpl-pic canvas, .lib-blank-plus { transition: none; }
  .lib-start-row .tpl-card:hover, .lib-start-row .tpl-card:hover .tpl-pic canvas, .lib-blank:hover .lib-blank-plus { transform: none; }
}
.lib-recent { position: relative; }
.lib-empty { flex-basis: 100%; max-width: 760px; color: #888; line-height: 1.5; }
.lib-card {
  position: relative; display: flex; flex-direction: column; width: 180px; flex-shrink: 0;
  background: #202020; border: 1px solid #2e2e2e; border-radius: 8px; overflow: hidden;
  transition: border-color 0.12s, transform 0.12s;
}
.lib-card:hover { border-color: #4a4a4a; }
.lib-thumb {
  aspect-ratio: 1; width: 100%; padding: 14px; border: none; cursor: pointer; background: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
}
/* the drawing in its own shape (a wide one is a wide picture), centred in the square */
.lib-pic { display: block; max-width: 100%; max-height: 100%; }
.lib-thumb img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.lib-meta { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 9px; border-top: 1px solid #2a2a2a; min-width: 0; }
/* the name: click to rename */
.lib-name { align-self: flex-start; max-width: 100%; margin: -2px -5px -1px; padding: 2px 5px 1px; border-radius: 4px; cursor: text; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-name:hover { background: #ffffff12; box-shadow: inset 0 0 0 1px #3a3a3a; }
.selecting .lib-name { cursor: inherit; }
.selecting .lib-name:hover { background: none; box-shadow: none; }
.lib-name-input {
  width: 100%; height: 22px; padding: 0 6px; margin: -2px 0 -1px -6px;
  background: #141414; border: 1px solid #4a7fcb; border-radius: 4px; color: #e0e0e0; font: inherit; font-weight: 600; outline: none;
}
.lib-info { color: #888; font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.lib-actions {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 4px;
  opacity: 0; transition: opacity 0.12s;
}
.lib-card:hover .lib-actions, .lib-card:focus-within .lib-actions { opacity: 1; }
.lib-act {
  width: 26px; height: 26px; padding: 0; display: flex; align-items: center; justify-content: center;
  background: #161616e6; border: 1px solid #3a3a3a; border-radius: 6px; color: #ccc; cursor: pointer;
}
.lib-act:hover { background: #2a2a2a; color: #fff; }
.lib-del:hover { background: #4a2020; color: #ff8a8a; border-color: #6a3030; }
.lib-foot { padding: 10px 24px; border-top: 1px solid #262626; color: #8a7a4a; font-size: 0.72rem; }
.lib-foot.kept { color: #6f8f6f; }
.lib-foot.warn { color: #c9a24a; }
.lib-foot-link { padding: 0; border: none; background: none; color: #8fb4f0; font: inherit; cursor: pointer; text-decoration: underline; }
.lib-expire { display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; color: #c9a24a; font-size: 0.7rem; cursor: help; }
.lib-expire svg { flex-shrink: 0; } /* (signed out: when it's deleted — cloud.js) */
@media (max-width: 760px) {
  /* phones: the actions in a row on top, without their descriptions */
  .lib-body { padding: 12px; }
  .lib-center { flex-direction: column; gap: 12px; }
  .lib-center { align-items: center; }
  .lib-center::before { display: none; }
  .lib-side { position: static; width: 100%; display: grid; grid-template-columns: 1fr 1fr; padding: 0 0 12px; border-bottom: 1px solid #2a2a2a; }
  .lib-side-item { flex: 1; align-items: center; gap: 8px; padding: 8px; white-space: nowrap; }
  .lib-side-text span { display: none; }
  .lib-grid { gap: 10px; justify-content: center; }
  .lib-card, .lib-start-row .tpl-card { width: 140px; }
  .lib-start { padding: 16px; }
  .lib-start-row { justify-content: center; }
  .lib-actions { opacity: 1; } /* (no hover on a phone) */
  .lib-body { padding: 12px; }
  .lib-main { align-self: stretch; }
  /* phones: the bar sits over the top of the cards, sticking while they scroll */
  .lib-main .lib-selbar { position: sticky; top: 0; bottom: auto; margin: 0 0 10px auto; width: max-content; max-width: 100%; }
  .lib-check { opacity: 1; }
}

/* ── Select ── */
/* the round box, top left (opposite Duplicate / Delete): on hover, and always while selecting */
.lib-check {
  position: absolute; top: 9px; left: 9px; z-index: 1; width: 22px; height: 22px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  background: #161616cc; border: 1.5px solid #8a8a8a; color: transparent;
  opacity: 0; transition: opacity 0.12s;
}
.lib-check:hover { border-color: #e0e0e0; color: #8a8a8a; }
.lib-card:hover .lib-check, .lib-check:focus-visible, .selecting .lib-check { opacity: 1; }
.selecting .lib-card { cursor: pointer; }
.selecting .lib-card .lib-thumb { cursor: inherit; }
.selecting .lib-actions { display: none; }
.selecting .lib-card:hover .lib-check { border-color: #e0e0e0; }
.selecting .lib-check { pointer-events: none; } /* (the card takes the click) */
.lib-card.picked { border-color: #4a7fcb; box-shadow: 0 0 0 1px #4a7fcb; }
.lib-card.picked .lib-check { background: #4a7fcb; border-color: #4a7fcb; color: #fff; }
/* the bar at the bottom while selecting */
.lib-selbar {
  position: absolute; right: 0; top: -4px; z-index: 2; /* (over the Recent heading's right end) */
  display: flex; align-items: center; gap: 2px; padding: 4px 4px 4px 14px; white-space: nowrap;
  background: #222; border: 1px solid #3a3a3a; border-radius: 8px; box-shadow: 0 6px 20px #0008;
}
.lib-selbar[hidden] { display: none; }
.lib-selbar.from-left { right: auto; left: 0; }
#sel-count { margin-right: 6px; color: #ccc; font-variant-numeric: tabular-nums; }
.sel-sep { width: 1px; height: 20px; margin: 0 4px; background: #3a3a3a; }
.sel-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  background: transparent; border: none; border-radius: 6px; color: #e0e0e0; font: inherit; cursor: pointer;
}
.sel-btn svg { color: #aaa; }
.sel-btn:hover:not(:disabled) { background: #ffffff14; }
.sel-btn:disabled { opacity: 0.4; cursor: default; }
.sel-del:hover:not(:disabled) { background: #4a2020; color: #ff8a8a; }
.sel-del:hover:not(:disabled) svg { color: #ff8a8a; }
.sel-x { width: 28px; padding: 0; justify-content: center; color: #aaa; }
.sel-x:hover { color: #fff; }
/* ── Export selected (a small dialog, styled like Export) ── */
#lx-backdrop { position: fixed; inset: 0; z-index: 2400; background: #000a; display: flex; align-items: center; justify-content: center; padding: 16px; }
#lx-backdrop[hidden] { display: none; }
#lx-dialog {
  width: 400px; max-width: 100%; display: flex; flex-direction: column;
  background: #1a1a1a; border: 1px solid #3a3a3a; border-radius: 10px; box-shadow: 0 20px 60px #000c;
  color: #e0e0e0; font-size: 0.8rem; overflow: hidden;
}
#lx-dialog:focus { outline: none; }
#lx-dialog .panel-min-btn { margin-left: auto; }
.lx-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 16px; }
.lx-body .xd-note { line-height: 1.45; }
#lx-png[hidden] { display: none; }
.lx-gap { flex: 1; }
