:root {
  --bg: #f5f1ed;
  --surface: #ffffff;
  --surface-hover: #faf8f6;
  --text: #1a1a1a;
  --text-2: #8b8680;
  --text-3: #b5afa8;
  --border: #e8e4df;
  --accent: #1a1a1a;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.14);
  --sidebar-w: 232px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ─── Sidebar ─── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 720;
  font-size: 15px;
  padding: 0 8px;
}

.logo-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background 120ms, color 120ms;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}

.nav-item svg { flex-shrink: 0; }

.nav-item kbd {
  margin-left: auto;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-3);
  font-size: 11px;
  font-family: inherit;
  line-height: 1.4;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-label {
  padding: 0 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.sidebar-categories {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cat-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background 120ms, color 120ms;
}

.cat-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.cat-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.cat-count {
  font-size: 12px;
  opacity: 0.55;
}

.cat-btn.is-active .cat-count { opacity: 0.7; }

.sidebar-bottom {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg);
}

.sidebar-note {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.65;
}

.sidebar-version {
  font-size: 11px;
  color: var(--text-3, #999);
  margin-top: 8px;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 28;
  background: rgba(0, 0, 0, 0.25);
}

.sidebar-backdrop[hidden] { display: none; }

/* ─── Main ─── */

.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 0 20px 88px;
}

/* ─── Toolbar ─── */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  background: var(--bg);
}

.toolbar::after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: linear-gradient(var(--bg), transparent);
  pointer-events: none;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.tab-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 140ms;
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tab-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tool-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  transition: all 140ms;
}

.tool-btn:hover {
  border-color: var(--text-2);
  color: var(--text);
}

.result-count {
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
}

/* ─── Masonry ─── */

.masonry {
  position: relative;
  padding-top: 4px;
  transition: opacity 150ms ease;
}

/* ─── Card ─── */

.card {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color 180ms, box-shadow 180ms, transform 180ms;
  animation: cardFadeIn 400ms ease both;
  animation-delay: var(--delay, 0ms);
}
.card.no-delay { animation-delay: 0ms; }
@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.card:hover {
  border-color: transparent;
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.card-image {
  position: relative;
  overflow: hidden;
}

.card-image img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transition: opacity 400ms ease, transform 350ms ease;
}

.card-image img.is-loaded {
  opacity: 1;
}

.card-image img.is-error {
  opacity: 0;
  position: absolute;
}

.card:hover .card-image img {
  transform: scale(1.04);
}

/* Card hover overlay */
.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 200ms;
  pointer-events: none;
}

.card:hover .card-overlay {
  opacity: 1;
  pointer-events: auto;
}

.overlay-btn {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  backdrop-filter: blur(4px);
  transition: background 120ms;
}

.overlay-btn:hover { background: #fff; }

.card-model {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.card-body {
  padding: 12px 14px 14px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-author {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-2);
}

.card-stats {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-3);
}

/* Card image max height */
.card-image {
  max-height: 520px;
}

/* ─── Infinite Scroll 加载提示 ─── */
.gallery-sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 0 48px;
  width: 100%;
}
.sentinel-text {
  font-size: 13px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}
.sentinel-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--text-2);
  border-radius: 50%;
  animation: sentinel-spin 0.6s linear infinite;
}
@keyframes sentinel-spin {
  to { transform: rotate(360deg); }
}

/* ─── Empty State ─── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-2);
}

.empty-state[hidden] { display: none; }

.empty-state svg { color: var(--text-3); }

.empty-state h2 {
  font-size: 18px;
  color: var(--text);
}

.empty-state p {
  font-size: 14px;
  color: var(--text-2);
}

/* ─── Search Modal ─── */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: start center;
  padding-top: 14vh;
}

.search-overlay[hidden] { display: none; }

.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(6px);
}

.search-dialog {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: searchIn 160ms ease;
}

@keyframes searchIn {
  from { opacity: 0; transform: scale(0.97) translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

.search-header input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
}

.search-header input::placeholder { color: var(--text-3); }

.search-header kbd {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-3);
  font-size: 11px;
  font-family: inherit;
}

.search-results {
  max-height: 420px;
  overflow-y: auto;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 20px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 100ms;
  font-family: inherit;
}

.search-item:hover { background: var(--bg); }

.search-item img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.search-item-info { flex: 1; min-width: 0; }

.search-item-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item-meta {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}

.search-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}

/* ─── Detail Modal ─── */

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.detail-overlay[hidden] { display: none; }

.detail-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.45);
  cursor: default;
  backdrop-filter: blur(6px);
}

.detail-dialog {
  position: relative;
  z-index: 1;
  width: min(1400px, calc(100vw - 48px));
  height: calc(100vh - 48px);
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  animation: detailIn 200ms ease;
}

@keyframes detailIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}

.detail-image {
  position: relative;
  flex: 0 0 60%;
  background: var(--bg);
  overflow: hidden;
}

.detail-image img {
  position: absolute;
  inset: 24px;
  width: calc(100% - 48px);
  height: calc(100% - 48px);
  object-fit: contain;
  border-radius: var(--radius);
}

.detail-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  min-height: 0;
  overflow: hidden;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.detail-eyebrow {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
}

.detail-title {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 6px;
}

.close-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  transition: all 120ms;
}

.close-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-tag {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
}

.detail-prompt-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.detail-prompt-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 8px;
}

.detail-prompt {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.detail-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.detail-nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-ghost {
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: all 140ms;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--text);
}

.btn-ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-ghost:disabled:hover {
  border-color: var(--border);
  color: var(--text-2);
}

.btn-primary {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition: background 150ms;
}

.btn-primary:hover { background: #333; }

/* ─── Dock ─── */

.dock {
  position: fixed;
  bottom: 20px;
  left: calc(var(--sidebar-w) + (100vw - var(--sidebar-w)) / 2);
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.dock-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  transition: all 140ms;
}

.dock-btn:hover {
  background: var(--bg);
  color: var(--text);
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 200ms ease;
}

.toast[hidden] { display: none; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Responsive ─── */

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: none;
  }

  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main {
    margin-left: 0;
    padding: 0 14px 88px;
  }

  .menu-btn { display: flex; }

  .dock { left: 50%; }

  .detail-dialog {
    flex-direction: column;
    width: calc(100vw - 32px);
    height: calc(100vh - 32px);
  }

  .detail-image {
    flex: 0 0 auto;
    height: 40vh;
    max-height: 360px;
  }
}

@media (max-width: 560px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .toolbar-left,
  .toolbar-right {
    flex-wrap: wrap;
  }

  .detail-dialog {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    border-radius: var(--radius-lg);
  }

  .detail-image { height: 32vh; max-height: 280px; }

  .dock-btn span { display: none; }
  .dock-btn { padding: 10px 12px; }
}

