/* =====================================================================
   GT Dynamics — pages/library.css (library.html, accounts stage 2)
   Layout and the blocks unique to the gallery: one-line intro, tabs + filter
   sidebar (collapsible panel ≤ 960 px), toolbar, card grid with the round
   AMOLED "screen" (components.css §28 device bezel), skeletons, the
   detail window (live preview stage + info), report / confirm windows,
   moderator panel, How to publish, rules note.
   Buttons, chips, tabs, badges, tags, panels, callouts, empty states,
   modals, avatars, steps come from components.css.
   Owner: web-pages. Tokens only.
   ===================================================================== */

/* ---------- Intro: one line above the tabs (no page head — the gallery comes first) ---------- */
.lib-intro {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-5);
}
.lib-intro__title { margin: 0; font-size: var(--fs-md); line-height: 1.3; }
.lib-intro__beta { align-self: center; }
.lib-intro__text { flex: 1 1 320px; min-width: 0; margin: 0; color: var(--text-3); font-size: var(--fs-sm); line-height: 1.5; }
.lib-intro__text a { color: var(--text-1); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-3); }
.lib-intro__text a:hover { color: var(--brand); }

/* ---------- Static dial (design without a thumb) ---------- */
.lib-dial { display: block; width: 100%; height: 100%; }
.lib-dial__ring { fill: none; stroke: var(--line-2); stroke-width: 2; }
.lib-dial__tick { stroke: var(--text-4); stroke-width: 3; stroke-linecap: round; }
.lib-dial__tick--major { stroke: var(--text-2); stroke-width: 6; }
.lib-dial__tick--red { stroke: var(--danger); }
.lib-dial__num { fill: var(--text-2); font-family: var(--font-mono); font-size: 30px; font-weight: 500; }
.lib-dial__label { fill: var(--text-3); font-family: var(--font-mono); font-size: 22px; font-weight: 600; letter-spacing: 0.12em; }
.lib-dial__needle { stroke: var(--brand); stroke-width: 7; stroke-linecap: round; }
.lib-dial__cap { fill: var(--bg-5); stroke: var(--brand); stroke-width: 4; }

/* ---------- Tabs ---------- */
.lib { padding-top: var(--sp-8); }
.lib-tabs { margin-bottom: var(--sp-8); }
.lib-tabs .tab__count { background: var(--danger-soft); color: color-mix(in srgb, var(--danger) 80%, var(--text-1)); }

/* ---------- Layout: filters sidebar + results ---------- */
.lib-layout {
  display: grid;
  grid-template-columns: minmax(0, 252px) minmax(0, 1fr);
  align-items: start;
  gap: var(--sp-8);
}
.lib-layout.is-mod, .is-na .lib-layout { grid-template-columns: minmax(0, 1fr); }
.lib-main { min-width: 0; }

.lib-side {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-6));
  max-height: calc(100vh - var(--header-h) - var(--sp-12));
  max-height: calc(100dvh - var(--header-h) - var(--sp-12));
}
.lib-side__body {
  display: grid;
  gap: var(--sp-6);
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-6) transparent;
}
.lib-fgroup { display: grid; gap: var(--sp-3); min-width: 0; }
.lib-fgroup__title { padding: 0; }
.lib-chips { gap: 6px; }
.lib-chip { max-width: 100%; }
.lib-chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.lib-chip__mono { font-family: var(--font-mono); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: 0.06em; }

/* ---------- Toolbar ---------- */
.lib-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.lib-search { flex: 1 1 280px; min-width: 0; max-width: 460px; }
.lib-search .input { padding-right: var(--sp-10); }
.lib-search .input-wrap__end { right: 4px; }
.lib-sort { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }
.lib-sort__label { white-space: nowrap; }
.lib-sort__select { width: auto; min-width: 156px; }
.lib-filters-toggle { display: none; }
.lib-filters-toggle__n { margin-left: 2px; }

.lib-modbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-1);
  border-radius: var(--r-lg);
  background: var(--bg-2);
}
.lib-modbar__hint { flex: 1 1 260px; margin: 0; color: var(--text-3); font-size: var(--fs-xs); line-height: 1.5; }

/* results bar: count (aria-live) · spinner while refreshing · clear */
.lib-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--sp-8);
  margin-bottom: var(--sp-4);
}
.lib-bar__count { margin: 0; }
.lib-bar__spin { width: 14px; height: 14px; }
.lib-bar__reset { margin-left: auto; }
.lib-alert { margin-bottom: var(--sp-5); }
.lib-alert__stale { margin-top: 2px; color: var(--text-3); font-size: var(--fs-xs); }

/* ---------- Grid of cards ---------- */
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 228px), 1fr));
  gap: var(--sp-6);
  margin: 0;
  padding: 0;
  list-style: none;
  transition: opacity var(--dur-2) var(--ease);
}
.lib-grid.is-busy { opacity: 0.55; }
.lib-grid.is-stale { opacity: 0.7; }
.lib-cell { display: flex; min-width: 0; animation: gtd-rise-in var(--dur-3) var(--ease-out) both; }
.lib-cell.is-still, .lib-cell--skel { animation: none; }
.lib-cell > .card { flex: 1 1 auto; }

.lib-card__media {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 5 / 4;
  padding: var(--sp-5);
  overflow: hidden;
  border-bottom: 1px solid var(--line-1);
  border-radius: calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px) 0 0;
  background-color: var(--bg-2);
  background-image: var(--dot-grid);
  background-size: var(--grid-size) var(--grid-size);
}
.lib-card__media::after { /* faint vignette so the bezel sits on the grid */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, transparent 52%, color-mix(in srgb, var(--bg-0) 40%, transparent));
  pointer-events: none;
}
.lib-screen {
  z-index: 1;
  width: min(74%, 210px);
  --device-drop: 0 16px 32px -18px var(--bg-0);
  transition: transform var(--dur-3) var(--ease-out);
}
.lib-screen .device__screen > img,
.lib-screen .device__screen > svg { display: block; width: 100%; height: 100%; object-fit: cover; }
.lib-screen.is-empty .device__screen { background: var(--bg-1); }
.lib-screen.is-empty .lib-dial { opacity: 0.5; }            /* no (valid) thumb: a quiet static dial */
.lib-card:hover .lib-screen { transform: scale(1.035); }
.lib-card__badges {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  right: var(--sp-3);
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  pointer-events: none;
}
.lib-card__badges .badge { max-width: 100%; }
.lib-card__body { gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); }
.lib-card__title { font-size: var(--fs-md); overflow-wrap: anywhere; }
.lib-card__tags { margin-top: auto; }
.lib-card__foot { justify-content: flex-start; gap: var(--sp-5); padding: var(--sp-3) var(--sp-5); }
.lib-card.is-hidden .lib-screen { opacity: 0.62; }

/* author line */
.lib-author { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.3; }
.lib-author__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-author--official .lib-author__name { color: var(--text-1); font-weight: 600; }
.lib-brand-mark { background: var(--bg-2); }
.lib-brand-mark > img { width: 100%; height: 100%; }

/* ♥ likes · uses */
.lib-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lib-stat .icon { width: 15px; height: 15px; color: var(--text-4); }
.lib-stat--likes.is-on, .lib-stat--likes.is-on .icon { color: color-mix(in srgb, var(--danger) 85%, var(--text-1)); }
.lib-stat--likes.is-on .icon { fill: currentColor; }

/* translated static tags (layout, style) — JA uses the body stack */
html[lang="ja"] .lib-tag--tr { font-family: var(--font-body); letter-spacing: 0.04em; }
html[lang="ja"] .lib-bar__count, html[lang="ja"] .lib-more__meta { font-family: var(--font-body); letter-spacing: 0.04em; text-transform: none; }

/* skeleton cards */
.lib-card--skel { pointer-events: none; }
.lib-skel-disc { display: block; width: min(74%, 210px); aspect-ratio: 1; border-radius: 50%; background: var(--bg-4); }
.lib-skel { display: block; width: 72%; height: var(--sp-3); border-radius: var(--r-sm); background: var(--bg-4); }
.lib-skel--title { width: 64%; height: var(--sp-5); }
.lib-skel--short { width: 40%; }
.lib-skel--tiny { width: 30%; }
.lib-skel--line { width: 54%; height: var(--sp-4); }
.lib-skel--block { width: 100%; height: var(--sp-16); }
.lib-skel--btn { width: 100%; height: var(--sp-12); border-radius: var(--r-md); }

/* states */
.lib-state { min-width: 0; }
.lib-empty { padding-block: var(--sp-12); }
.lib-empty--steps { padding-block: var(--sp-12) var(--sp-10); }
.lib-empty__tech { width: 100%; max-width: 46ch; text-align: left; }
.lib-steps--empty { width: 100%; max-width: 860px; margin: var(--sp-6) auto var(--sp-2); text-align: left; }

/* load more */
.lib-more { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); margin-top: var(--sp-10); }
.lib-more .btn { min-width: 200px; }
.lib-more__meta { margin: 0; }

/* ---------- How to publish · rules ---------- */
.lib-steps { margin-top: var(--sp-2); }
.lib-rules {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--sp-6);
  padding: var(--sp-8);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  background-color: var(--bg-2);
  background-image: var(--dot-grid);
  background-size: var(--grid-size) var(--grid-size);
}
.lib-rules__icon { background: var(--bg-4); }
.lib-rules__title { margin: 0; }
.lib-rules__lead { margin: var(--sp-2) 0 0; color: var(--text-2); }
.lib-rules__list { margin-top: var(--sp-5); max-width: 76ch; font-size: var(--fs-sm); line-height: 1.6; color: var(--text-2); }

/* ---------- Detail window ---------- */
.lib-detail .modal__box { width: min(100%, 1000px); }
.lib-detail__head { align-items: flex-start; gap: var(--sp-2); }
.lib-detail__heading { flex: 1 1 auto; min-width: 0; }
.lib-detail__kicker {
  margin: 0 0 2px;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-3);
}
html[lang="ja"] .lib-detail__kicker { font-family: var(--font-body); letter-spacing: 0.04em; }
.lib-detail__title { overflow-wrap: anywhere; }
.lib-detail__title:focus { outline: none; }
.lib-detail__nav { display: flex; gap: var(--sp-1); flex-shrink: 0; }
.lib-detail__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: var(--sp-8);
}
.lib-detail.is-error .lib-detail__body { grid-template-columns: minmax(0, 1fr); }
.lib-detail.is-error .lib-detail__stage, .lib-detail.is-error .lib-detail__nav { display: none; }

.lib-detail__stage { position: sticky; top: 0; z-index: 1; min-width: 0; }
.lib-stage {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: var(--sp-10);
  border: 1px solid var(--line-1);
  border-radius: var(--r-xl);
  background-color: var(--bg-1);
  background-image: radial-gradient(circle at 50% 46%, var(--brand-soft), transparent 62%), var(--dot-grid);
  background-size: auto, var(--grid-size) var(--grid-size);
}
.lib-stage__device { width: 100%; max-width: 380px; }
.lib-stage__screen > .lib-stage__thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--dur-3) var(--ease);
}
.lib-stage__host { position: absolute; inset: 0; display: grid; place-items: center; }
.lib-stage__host > canvas { display: block; width: 100%; height: 100%; }
.lib-stage__ph { display: block; width: 100%; height: 100%; opacity: 0.55; }
.lib-stage__screen.is-live > .lib-stage__thumb { opacity: 0; }
.lib-stage__screen.is-loading::before { /* thin ring while the full design loads */
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--brand-line);
  animation: gtd-spin calc(var(--dur-4) * 2) linear infinite;
  pointer-events: none;
}
.lib-stage__mode { color: var(--text-3); }
.lib-stage__param { max-width: calc(100% - var(--sp-6)); overflow: hidden; text-overflow: ellipsis; }
.lib-stage__bar { display: flex; justify-content: center; gap: var(--sp-2); min-height: var(--sp-8); margin-top: var(--sp-3); }
.lib-stage__safe { max-width: 40ch; margin: var(--sp-2) auto 0; color: var(--text-3); font-size: var(--fs-xs); line-height: 1.5; text-align: center; }

/* info column */
.lib-d { display: grid; gap: var(--sp-5); align-content: start; min-width: 0; }
.lib-d__top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.lib-d__top .lib-author { font-size: var(--fs-base); }
.lib-d__badges { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.lib-d__stats { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6); }
.lib-d__stats .lib-stat { font-size: var(--fs-sm); color: var(--text-2); }
.lib-d__stats .lib-stat .icon { width: 18px; height: 18px; }
html[lang="ja"] .lib-d__stats .lib-stat { font-family: var(--font-body); }
.lib-d__desc {
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  white-space: pre-line;          /* the author's line breaks, never HTML */
  overflow-wrap: anywhere;
}
.lib-d__desc.is-empty { color: var(--text-3); font-size: var(--fs-sm); }
.lib-d__actions { display: grid; gap: var(--sp-3); padding-top: var(--sp-1); }
.lib-d__hint { margin: 0; color: var(--text-3); font-size: var(--fs-xs); line-height: 1.5; }
.lib-d__row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.lib-d__report { margin-left: auto; }
.lib-d__reported {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
  padding-inline: var(--sp-2);
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.lib-d__reported .icon { color: var(--ok); }
.lib-d__reported:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-sm); }

/* Like toggle: pressed = filled heart (pastel coral, not a second yellow) */
.lib-like[aria-pressed="true"] {
  --btn-bg: var(--danger-soft);
  --btn-bg-hover: color-mix(in srgb, var(--danger) 22%, transparent);
  --btn-fg: color-mix(in srgb, var(--danger) 82%, var(--text-1));
  --btn-bd: color-mix(in srgb, var(--danger) 30%, transparent);
}
.lib-like[aria-pressed="true"] .icon { fill: currentColor; }
.lib-like[aria-busy="true"] { cursor: progress; }

.lib-d__specs { margin-top: var(--sp-1); }
.lib-d__specs dd .tags { gap: var(--sp-1); }
.lib-d__note { margin: 0; color: var(--text-3); font-size: var(--fs-xs); line-height: 1.55; }
.lib-d__subhead { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-3); }
.lib-d__subtitle { margin: 0; font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 600; color: var(--text-1); }
.lib-d__owner {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid var(--line-1);
  border-radius: var(--r-lg);
  background: var(--bg-2);
}
.lib-d__empty { padding-block: var(--sp-10); }
.lib-d__skel { display: grid; gap: var(--sp-4); }

/* moderator panel */
.lib-mod__title { display: inline-flex; align-items: center; gap: var(--sp-2); }
.lib-mod__body { display: grid; gap: var(--sp-4); }
.lib-mod__loading { display: flex; align-items: center; gap: var(--sp-2); }
.lib-mod__sum { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); margin: 0; font-size: var(--fs-sm); color: var(--text-2); }
.lib-mod__label { font-weight: 600; color: var(--text-1); }
.lib-mod__count { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-3); }
html[lang="ja"] .lib-mod__count { font-family: var(--font-body); }
.lib-reports { display: grid; gap: var(--sp-2); max-height: 280px; margin: 0; padding: 0; overflow-y: auto; list-style: none; scrollbar-width: thin; scrollbar-color: var(--bg-6) transparent; }
.lib-reports__item {
  display: grid;
  gap: var(--sp-1);
  padding: var(--sp-3);
  border: 1px solid var(--line-1);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-md);
  background: var(--bg-1);
}
.lib-reports__item.is-resolved { border-left-color: var(--line-3); opacity: 0.75; }
.lib-reports__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.lib-reports__reason { font-size: var(--fs-sm); color: var(--text-1); }
.lib-reports__meta { margin: 0; color: var(--text-3); font-size: var(--fs-xs); }
.lib-reports__by { color: var(--text-2); }
.lib-reports__note { margin: 0; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }

/* ---------- Report · confirm ---------- */
.lib-report__body { display: grid; gap: var(--sp-5); }
.lib-report__lead { margin: 0; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.55; }
.lib-report__legend { margin-bottom: var(--sp-2); }
.lib-report__list { display: grid; gap: var(--sp-1); }
.lib-report__reason { display: flex; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line-1); border-radius: var(--r-md); background: var(--bg-2); }
.lib-report__reason:has(input:checked) { border-color: var(--brand-line); background: var(--brand-soft); color: var(--text-1); }
.lib-report__reason:has(input:focus-visible) { box-shadow: var(--ring); }
.lib-report__reason input:focus-visible { outline: none; }
.lib-report__note { min-height: 96px; }
.lib-confirm__body { display: grid; gap: var(--sp-4); }
.lib-confirm__text { margin: 0; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.6; }

/* ---------- ≤ 960: filters collapse under the toolbar ---------- */
@media (max-width: 960px) {
  .lib-layout { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
  .lib-main { display: contents; }
  .lib-toolbar { order: 1; }
  .lib-modbar { order: 2; }
  .lib-side { order: 3; }
  .lib-bar { order: 4; }
  .lib-alert { order: 5; }
  .lib-grid, .lib-state { order: 6; }
  .lib-more { order: 7; }
  .lib-filters-toggle { display: inline-flex; }
  .lib-side {
    display: none;
    position: static;
    max-height: none;
    margin-bottom: var(--sp-5);
  }
  .lib-side.is-open { display: flex; animation: gtd-fade-in var(--dur-2) var(--ease); }
  .lib-side__body { overflow: visible; }
  .lib-search { flex: 1 1 220px; max-width: none; }
  .lib-sort { margin-left: 0; }
  .lib-detail__body { gap: var(--sp-6); }
}

/* ---------- ≤ 760: detail window stacks (bottom sheet ≤ 720 — components.css) ---------- */
@media (max-width: 760px) {
  .lib-detail__body { grid-template-columns: minmax(0, 1fr); }
  .lib-detail__stage { position: static; }
  .lib-stage { aspect-ratio: auto; padding: var(--sp-6); }
  .lib-stage__device { max-width: 260px; }
}

/* ---------- ≤ 720 ---------- */
@media (max-width: 720px) {
  .lib-toolbar { gap: var(--sp-2); }
  .lib-search { flex: 1 1 100%; max-width: none; }
  .lib-sort { flex: 1 1 auto; }
  .lib-sort__select { flex: 1 1 auto; min-width: 0; }
  .lib-rules { grid-template-columns: minmax(0, 1fr); padding: var(--sp-6); gap: var(--sp-4); }
  .lib-tabs { margin-bottom: var(--sp-6); }
  .lib { padding-top: var(--sp-6); }
  .lib-intro { margin-bottom: var(--sp-4); }
}

/* ---------- ≤ 480 ---------- */
@media (max-width: 480px) {
  .lib-sort__label { /* visually hidden — the select keeps its accessible name */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .lib-card__body { padding: var(--sp-4); }
  .lib-card__foot { padding-inline: var(--sp-4); }
  .lib-d__row .btn { flex: 1 1 auto; }
  .lib-d__report, .lib-d__reported { margin-left: 0; }
  .lib-more .btn { width: 100%; }
}

/* ---------- Lite performance tier (DESIGN §13) ---------- */
html[data-perf="lite"] .lib-card:hover .lib-screen { transform: none; }
html[data-perf="lite"] .lib-screen { --device-drop: 0 10px 20px -12px var(--bg-0); }
html[data-perf="lite"] .lib-cell { animation: none; }
html[data-perf="lite"] .lib-stage__screen.is-loading::before { animation: none; border-top-color: transparent; }
