/* 作品广场 (gallery.js). The page rides on body.tools-page-open, which already
   hides the create form, results and the other pages; it only has to hide the
   tools page itself. */
.auth-mode #galleryView, .auth-mode .gallery-detail { display: none !important; }
body.gallery-page-open #toolsView { display: none !important; }
#mobileNav [data-mobile-tab="gallery"][hidden] { display: none !important; }

.gallery-view {
  --g-surface: var(--v2-surface, #161c22);
  --g-raised: var(--v2-raised, #1e252c);
  --g-line: var(--v2-line, #2b343b);
  --g-text: var(--v2-text, #eef2f4);
  --g-muted: var(--v2-muted, #9aa6ae);
  --g-accent: var(--v2-accent, #d8ff4f);
  --g-accent-ink: var(--v2-accent-ink, #11150a);
  display: grid; gap: 14px; min-width: 0;
}
.gallery-page-heading { display: flex !important; align-items: end; justify-content: space-between; gap: 12px; }
.gallery-mine-button { flex: none; min-height: 38px; padding: 0 16px; border: 1px solid var(--g-line); border-radius: 999px; background: var(--g-surface); color: var(--g-text); font: inherit; font-size: 13px; cursor: pointer; }
.gallery-mine-button:hover { border-color: #d8ff4f55; }
.gallery-intro { margin: -4px 0 0; }

.gallery-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; min-width: 0; }
.gallery-tabs { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--g-line); border-radius: 999px; background: var(--g-surface); }
.gallery-tab { min-height: 34px; padding: 0 18px; border: 0; border-radius: 999px; background: transparent; color: var(--g-muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.gallery-tab.active { background: var(--g-accent); color: var(--g-accent-ink); }
.gallery-filter { position: relative; flex: none; }
.gallery-filter.hidden { display: none; }
.gallery-filter-button { display: inline-flex; align-items: center; gap: 10px; min-height: 42px; max-width: 280px; padding: 0 12px 0 16px; border: 1px solid var(--g-line); border-radius: 999px; background: var(--g-surface); color: var(--g-text); font: inherit; font-size: 13px; cursor: pointer; }
.gallery-filter-button:hover, .gallery-filter.open .gallery-filter-button { border-color: #d8ff4f55; }
.gallery-filter.is-filtered .gallery-filter-button { border-color: #d8ff4f66; background: #d8ff4f14; }
.gallery-filter-label { display: inline-flex; align-items: baseline; gap: 8px; min-width: 0; }
.gallery-filter-label > span { color: var(--g-muted); font-size: 12px; }
.gallery-filter-value { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.gallery-filter.is-filtered .gallery-filter-value { color: var(--g-accent); }
.gallery-filter-chevron { display: grid; place-items: center; color: var(--g-muted); transition: transform .2s ease; }
.gallery-filter-chevron svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.gallery-filter.open .gallery-filter-chevron { transform: rotate(180deg); }
.gallery-filter-menu { position: absolute; left: 0; top: calc(100% + 8px); z-index: 30; width: min(560px, calc(100vw - 32px)); max-height: min(420px, 60vh); overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; padding: 10px; border: 1px solid var(--g-line); border-radius: 16px; background: var(--g-raised); box-shadow: 0 18px 48px rgba(0, 0, 0, .55); overscroll-behavior: contain; }
.gallery-filter-menu[hidden] { display: none; }
.gallery-filter-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 0 12px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--g-text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.gallery-filter-option span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-filter-option small { flex: none; color: var(--g-muted); font-size: 11px; }
.gallery-filter-option:hover { background: #ffffff0d; }
.gallery-filter-option[aria-selected="true"] { border-color: #d8ff4f55; background: #d8ff4f14; color: var(--g-accent); }
.gallery-filter-option:first-child { grid-column: 1 / -1; }

/* masonry: pictures keep their own shape */
.gallery-grid { columns: 4 220px; column-gap: 14px; min-width: 0; }
.gallery-grid[aria-busy="true"] { opacity: .55; transition: opacity .2s; }
.gallery-card { display: block; width: 100%; margin: 0 0 14px; padding: 0; overflow: hidden; break-inside: avoid; border: 1px solid var(--g-line); border-radius: 14px; background: var(--g-surface); color: var(--g-text); font: inherit; text-align: left; cursor: pointer; transition: border-color .2s, transform .2s; }
.gallery-card:hover { border-color: #d8ff4f40; }
.gallery-card:active { transform: scale(.985); }
.gallery-card:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }
.gallery-card-media { position: relative; display: block; background: #0b0f13; }
.gallery-card-media img { display: block; width: 100%; height: auto; }
.gallery-card-featured { position: absolute; left: 8px; top: 8px; display: inline-flex; align-items: center; gap: 3px; padding: 3px 8px 3px 6px; border-radius: 999px; background: rgba(13, 17, 21, .78); color: var(--g-accent); font-size: 11px; font-weight: 700; backdrop-filter: blur(6px); }
.gallery-card-featured svg { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.gallery-card-info { display: grid; gap: 4px; padding: 10px 12px 11px; }
.gallery-card-info b { overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.gallery-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--g-muted); font-size: 12px; }
.gallery-card-author { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-card-likes { flex: none; display: inline-flex; align-items: center; gap: 4px; }
.gallery-card-likes svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.gallery-card-likes.liked { color: #ff7a8a; }
.gallery-card-likes.liked svg { fill: currentColor; }

.gallery-empty { display: grid; gap: 6px; padding: 48px 16px; border: 1px dashed var(--g-line); border-radius: 16px; color: var(--g-muted); text-align: center; }
.gallery-empty b { color: var(--g-text); font-size: 15px; font-weight: 600; }
.gallery-empty.hidden { display: none; }
.gallery-more { justify-self: center; min-width: 160px; }
.gallery-more.hidden { display: none; }

/* flag on a card in 作品 */
.history-library-item { position: relative; }
.gallery-flag { position: absolute; left: 8px; top: 8px; z-index: 2; padding: 3px 8px; border-radius: 999px; background: rgba(13, 17, 21, .82); color: #cfd8de; font-size: 11px; font-weight: 600; pointer-events: none; backdrop-filter: blur(6px); }
.gallery-flag.is-approved { color: #d8ff4f; }
.gallery-flag.is-pending { color: #ffcf7a; }
.gallery-flag.is-rejected { color: #ff9aa4; }

/* detail */
.gallery-detail { width: min(1120px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0; overflow: hidden; border: 1px solid var(--v2-line, #2b343b); border-radius: 20px; background: var(--v2-surface, #161c22); color: var(--v2-text, #eef2f4); box-shadow: 0 24px 72px rgba(0, 0, 0, .55); }
.gallery-detail[open] { display: grid; grid-template-columns: minmax(0, 1fr) 360px; }
.gallery-detail::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(3px); }
.gallery-detail-media { display: grid; place-items: center; min-width: 0; min-height: 320px; max-height: calc(100dvh - 32px); background: #06090c; }
.gallery-detail-media img { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 34px); object-fit: contain; }
.gallery-detail-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; max-height: calc(100dvh - 32px); padding: 24px 20px 20px; overflow-y: auto; }
.gallery-detail-side h2 { margin: 0 40px 0 0; font-size: 19px; font-weight: 600; line-height: 1.4; word-break: break-word; }
.gallery-detail-byline { margin: -8px 0 0; color: var(--v2-muted, #9aa6ae); font-size: 13px; }
.gallery-detail-close { position: absolute; right: 10px; top: 10px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 12px; background: rgba(13, 17, 21, .6); color: var(--v2-text, #eef2f4); cursor: pointer; }
.gallery-detail-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.gallery-detail-facts { display: grid; gap: 1px; overflow: hidden; border: 1px solid var(--v2-line, #2b343b); border-radius: 12px; background: var(--v2-line, #2b343b); }
.gallery-detail-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 8px 14px; background: var(--v2-surface, #161c22); font-size: 13px; }
.gallery-detail-row span { flex: none; color: var(--v2-muted, #9aa6ae); }
.gallery-detail-row b { display: inline-flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; text-align: right; word-break: break-word; }
.gallery-detail-avatar { width: 26px; height: 26px; flex: none; border-radius: 50%; object-fit: cover; }
.gallery-detail-prompt { display: grid; gap: 8px; padding: 12px 14px; border-radius: 12px; background: var(--v2-raised, #1e252c); font-size: 13px; }
.gallery-detail-prompt.is-negative p { max-height: 140px; color: var(--v2-muted, #9aa6ae); }
.gallery-detail-prompt p { margin: 0; max-height: 220px; overflow-y: auto; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.gallery-detail-prompt.is-private { color: var(--v2-muted, #9aa6ae); }
.gallery-detail-prompt-head { display: flex; align-items: center; justify-content: space-between; color: var(--v2-muted, #9aa6ae); font-size: 12px; }
.gallery-copy { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 0 10px; border: 1px solid var(--v2-line, #2b343b); border-radius: 999px; background: transparent; color: var(--v2-text, #eef2f4); font: inherit; font-size: 12px; cursor: pointer; }
.gallery-copy svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.gallery-detail-actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; margin-top: auto; }
.gallery-like, .gallery-same { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 18px; border-radius: 14px; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
.gallery-like { border: 1px solid var(--v2-line, #2b343b); background: transparent; color: var(--v2-text, #eef2f4); }
.gallery-like svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.gallery-like.liked { border-color: #ff7a8a66; color: #ff7a8a; }
.gallery-like.liked svg { fill: currentColor; }
.gallery-same { border: 0; background: var(--v2-accent, #d8ff4f); color: var(--v2-accent-ink, #11150a); }
.gallery-like:disabled, .gallery-same:disabled { opacity: .6; }
.gallery-withdraw { align-self: center; color: var(--v2-muted, #9aa6ae); }

/* publish sheet + 我的发布 (ui-v2 sheets) */
.gallery-publish-sheet .v2-sheet-body { display: grid; gap: 14px; }
.gallery-publish-preview { display: block; width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; background: #06090c; }
.gallery-publish-facts { margin: 0; color: var(--v2-text, #eef2f4); font-size: 13px; }
.gallery-field { display: grid; gap: 6px; }
.gallery-field span { color: var(--v2-muted, #9aa6ae); font-size: 12px; }
.gallery-field input { min-height: 46px; padding: 0 14px; border: 1px solid var(--v2-line, #2b343b); border-radius: 12px; background: var(--v2-bg, #0d1115); color: var(--v2-text, #eef2f4); font: inherit; font-size: 16px; }
.gallery-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.gallery-check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: #d8ff4f; }
.gallery-check span { display: grid; gap: 2px; }
.gallery-check b { font-size: 14px; font-weight: 600; }
.gallery-check small { color: var(--v2-muted, #9aa6ae); font-size: 12px; line-height: 1.5; }
.gallery-publish-prompt { margin: -4px 0 0; max-height: 160px; overflow-y: auto; padding: 10px 12px; border-radius: 10px; background: var(--v2-raised, #1e252c); font-size: 12px; line-height: 1.6; word-break: break-word; }
.gallery-publish-prompt p { margin: 0; }
.gallery-publish-prompt b { display: block; margin-top: 8px; color: var(--v2-muted, #9aa6ae); font-size: 11px; font-weight: 600; }
.gallery-publish-prompt.hidden { display: none; }
.gallery-publish-rules { margin: 0; color: var(--v2-muted, #9aa6ae); font-size: 12px; line-height: 1.6; }
.gallery-publish-submit { min-height: 48px; border: 0; border-radius: 12px; background: var(--v2-accent, #d8ff4f); color: var(--v2-accent-ink, #11150a); font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
.gallery-publish-submit:disabled { opacity: .55; }
.gallery-action-button[hidden] { display: none !important; }

.gallery-mine-summary { margin: 0 0 12px; color: var(--v2-muted, #9aa6ae); font-size: 13px; line-height: 1.6; }
.gallery-mine-list { display: grid; gap: 10px; }
.gallery-mine-item { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--v2-line, #2b343b); border-radius: 12px; }
.gallery-mine-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: #06090c; }
.gallery-mine-copy { display: grid; gap: 3px; min-width: 0; }
.gallery-mine-copy b { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.gallery-mine-copy small { color: var(--v2-muted, #9aa6ae); font-size: 12px; }
.gallery-status { font-size: 12px; color: var(--v2-muted, #9aa6ae); }
.gallery-status.is-approved { color: #d8ff4f; }
.gallery-status.is-pending { color: #ffcf7a; }
.gallery-status.is-rejected, .gallery-status.is-removed { color: #ff9aa4; }

/* phone: two columns, a five-slot nav bar, a full-screen detail */
@media (max-width: 619px) {
  .gallery-grid { columns: 2; column-gap: 10px; }
  .gallery-card { margin-bottom: 10px; border-radius: 12px; }
  .gallery-card-info { padding: 8px 10px 9px; }
  .gallery-bar { gap: 10px; }
  .gallery-tabs { flex: none; }
  .gallery-filter { flex: 1 1 auto; min-width: 0; }
  .gallery-filter-button { width: 100%; max-width: none; justify-content: space-between; }
  /* The menu opens across the whole bar, not just under the button. */
  .gallery-bar { position: relative; }
  .gallery-filter { position: static; }
  .gallery-filter-menu { left: 0; right: 0; width: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 55vh; }

  .studio-layout:not(.auth-mode) #mobileNav.has-gallery:not(.hidden) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  #mobileNav.has-gallery .mobile-nav-indicator { width: calc((100% - 12px) / 5); }
  #mobileNav.has-gallery[data-active-tab="works"] .mobile-nav-indicator { transform: translate3d(100%, 0, 0); }
  #mobileNav.has-gallery[data-active-tab="gallery"] .mobile-nav-indicator { transform: translate3d(200%, 0, 0); }
  #mobileNav.has-gallery[data-active-tab="tools"] .mobile-nav-indicator { transform: translate3d(300%, 0, 0); }
  #mobileNav.has-gallery[data-active-tab="account"] .mobile-nav-indicator { transform: translate3d(400%, 0, 0); }
  html.ui-v2 .studio-layout:not(.auth-mode) #mobileNav.has-gallery .mobile-nav-indicator { width: calc((100% - 16px) / 5); }
  html.ui-v2 .studio-layout:not(.auth-mode) #mobileNav.has-gallery[data-active-tab="works"] .mobile-nav-indicator { transform: translate3d(100%, 0, 0); }
  html.ui-v2 .studio-layout:not(.auth-mode) #mobileNav.has-gallery[data-active-tab="gallery"] .mobile-nav-indicator { transform: translate3d(200%, 0, 0); }
  html.ui-v2 .studio-layout:not(.auth-mode) #mobileNav.has-gallery[data-active-tab="tools"] .mobile-nav-indicator { transform: translate3d(300%, 0, 0); }
  html.ui-v2 .studio-layout:not(.auth-mode) #mobileNav.has-gallery[data-active-tab="account"] .mobile-nav-indicator { transform: translate3d(400%, 0, 0); }

  .gallery-detail { width: 100vw; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
  .gallery-detail[open] { display: block; overflow-y: auto; }
  .gallery-detail-media { min-height: 0; max-height: none; }
  .gallery-detail-media img { max-height: 70dvh; }
  .gallery-detail-side { max-height: none; overflow: visible; padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px)); }
  .gallery-detail-actions { position: sticky; bottom: 0; padding-top: 8px; background: var(--v2-surface, #161c22); }
}
@media (prefers-reduced-motion: reduce) {
  .gallery-card { transition: none; }
}
html.ui-v2 .mobile-tab-entering #galleryView { animation: v2TabSlide .34s cubic-bezier(.2, .82, .24, 1) both; }
