:root {
  --bg:         #f3f1eb;
  --surface:    #eceae3;
  --surface2:   #e4e2da;
  --border:     #d7d6ca;
  --text:       rgb(63, 58, 51);
  --text-muted: rgba(63, 58, 51, 0.8);
  --text-faint: rgba(63, 58, 51, 0.45);
  --dark:       rgb(42, 38, 32);
  --font:       "Rethink Sans", sans-serif;
  --radius:     12px;
  --radius-sm:  8px;
  --nav-h:      64px;
  --ease-out:   cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, ::after { box-sizing: border-box; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.6;
  color: var(--text); background: var(--bg);
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
h1,h2,h3,h4,h5,h6,p,figure { margin: 0; }
button { font-family: var(--font); cursor: pointer; }

/* ── Nav ── */
#nav {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: var(--nav-h);
}
#nav-left { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text-muted); }
#logo { height: 28px; object-fit: contain; display: block; }
#nav-left .sep { color: var(--text-faint); }
.active-tag-badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text-muted); }
#navDot { width: 8px; height: 8px; border-radius: 50%; background: #dfaa40; flex-shrink: 0; transition: background 0.3s var(--ease-out); }
#uploadBtn {
  font-size: 15px; font-weight: 500; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 16px;
  transition: background 0.15s, transform 0.15s var(--ease-out);
}
#uploadBtn:hover { background: var(--surface2); }
#uploadBtn:active { transform: scale(0.97); }
#signOutBtn {
  background: none; border: none; padding: 5px; cursor: pointer;
  color: var(--text-faint); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
#signOutBtn:hover { color: var(--text-muted); background: var(--surface); }

/* ── Layout ── */
#body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: 220px; flex-shrink: 0; background: var(--bg);
  padding: 20px 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 20px;
}
.sidebar-label {
  font-size: 12px; font-weight: 500; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0 20px; margin-bottom: 2px;
}
.sidebar-quick { display: flex; flex-direction: column; }
.sidebar-quick-item {
  padding: 6px 20px; font-size: 15px; color: var(--text-muted);
  cursor: pointer; transition: background 0.12s, color 0.12s;
}
.sidebar-quick-item:hover { background: var(--surface); color: var(--text); }
.sidebar-quick-item.active { color: var(--text); font-weight: 500; }
#tagList { display: flex; flex-direction: column; }
.sidebar-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 20px; cursor: pointer; transition: background 0.12s;
}
.sidebar-item:hover { background: var(--surface); }
.sidebar-item.active { background: var(--surface); }
.sidebar-item-left { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text-muted); }
.sidebar-item.active .sidebar-item-left { color: var(--text); font-weight: 500; }
.sidebar-item .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sidebar-item-count { font-size: 12px; color: var(--text-faint); }

/* ── Main ── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#collection-header { padding: 24px 24px 0; }
#collection-title {
  font-family: "IM Fell English", "Times New Roman", serif;
  font-size: 42px; font-weight: 400; line-height: 1.3;
  color: var(--text); margin-bottom: 2px;
}
#collection-desc { font-size: 15px; color: var(--text-muted); }
#grid-area { flex: 1; overflow-y: auto; padding: 20px 24px 24px; }
#grid { columns: 4; column-gap: 10px; }

.image-card {
  break-inside: avoid; margin-bottom: 10px;
  cursor: pointer; border-radius: 6px; overflow: hidden; position: relative;
  transition: transform 0.25s var(--ease-out), box-shadow 0.2s;
  animation: cardIn 0.4s var(--ease-out) both;
}
.image-card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0,0,0,0.13); }
.image-card:active { transform: scale(0.98); }
.image-card img { display: block; width: 100%; height: auto; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#empty-state {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  height: 240px; color: var(--text-faint); font-size: 15px; gap: 6px;
}
#empty-state.visible { display: flex; animation: cardIn 0.3s var(--ease-out); }

/* ── Shared backdrop ── */
.overlay-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 27, 22, 0.52);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s var(--ease-out);
}
.overlay-backdrop.open { opacity: 1; pointer-events: auto; }

/* ── Upload modal ── */
#upload-modal {
  background: var(--bg); border-radius: var(--radius);
  width: 520px; max-width: calc(100vw - 48px); overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  transform: translateY(14px) scale(0.97); opacity: 0;
  transition: transform 0.38s var(--ease-out), opacity 0.3s var(--ease-out);
}
#upload-backdrop.open #upload-modal { transform: translateY(0) scale(1); opacity: 1; }
#step1 { padding: 28px; display: flex; flex-direction: column; gap: 14px; }
#step1.gone { display: none; }
.drop-zone {
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 38px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; border: 1.5px dashed transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.2s var(--ease-out);
}
.drop-zone:hover { background: var(--surface2); }
.drop-zone.dragover { background: var(--surface2); border-color: var(--border); transform: scale(1.01); }
.drop-zone-icon { color: var(--text-muted); opacity: 0.65; }
.drop-zone-label { font-size: 17px; font-weight: 500; color: var(--text-muted); }
.or-divider { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 14px; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.paste-btn {
  width: 100%; padding: 14px; background: var(--surface2); border: none;
  border-radius: var(--radius-sm); font-size: 16px; font-weight: 500; color: var(--text-muted);
  transition: background 0.15s, color 0.15s, transform 0.15s var(--ease-out);
}
.paste-btn:hover { background: var(--border); color: var(--text); }
.paste-btn:active { transform: scale(0.99); }
#urlField {
  display: none; font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; width: 100%; outline: none;
  transition: border-color 0.15s; animation: cardIn 0.2s var(--ease-out);
}
#urlField.visible { display: block; }
#urlField:focus { border-color: var(--text-faint); }
#urlField::placeholder { color: var(--text-faint); }
#urlField.error { border-color: #da4241; }
.modal-note { font-size: 13px; color: var(--text-faint); text-align: center; }
#step2 { display: none; flex-direction: column; }
#step2.visible { display: flex; animation: cardIn 0.32s var(--ease-out) both; }
#step2-inner { display: flex; }
#preview-col {
  width: 190px; flex-shrink: 0; background: var(--surface);
  overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 220px;
}
#preview-col img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity 0.3s var(--ease-out); }
#form-col { flex: 1; padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.form-label { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
#notesField {
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  resize: vertical; min-height: 88px; outline: none; line-height: 1.5; width: 100%;
  transition: border-color 0.15s;
}
#notesField:focus { border-color: var(--text-faint); }
#notesField::placeholder { color: var(--text-faint); }
#tag-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; font-size: 13px; color: var(--text-muted);
  cursor: pointer; user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.15s var(--ease-out);
}
.tag-pill .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.tag-pill:hover { background: var(--surface2); }
.tag-pill:active { transform: scale(0.93); }
.tag-pill.selected { background: var(--dark); border-color: var(--dark); color: var(--bg); }
#new-tag-input {
  font-family: var(--font); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 99px; padding: 4px 10px; outline: none; width: 90px;
  transition: border-color 0.15s, width 0.2s var(--ease-out);
}
#new-tag-input:focus { border-color: var(--text-faint); width: 130px; }
#new-tag-input::placeholder { color: var(--text-faint); }
#step2-footer { border-top: 1px solid var(--border); padding: 16px 22px; }
.btn-upload {
  width: 100%; padding: 13px; background: var(--dark); color: var(--bg);
  border: none; border-radius: var(--radius-sm); font-size: 16px; font-weight: 500;
  transition: opacity 0.15s, transform 0.15s var(--ease-out);
}
.btn-upload:hover { opacity: 0.88; }
.btn-upload:active { transform: scale(0.99); }
.btn-upload:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ── Image detail modal ── */
#detail-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 27, 22, 0.6);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s var(--ease-out);
}
#detail-backdrop.open { opacity: 1; pointer-events: auto; }
#detail-modal {
  background: var(--bg); border-radius: var(--radius);
  width: min(860px, calc(100vw - 48px)); max-height: calc(100vh - 64px);
  overflow: hidden; display: flex;
  box-shadow: 0 28px 72px rgba(0,0,0,0.28);
  transform: translateY(16px) scale(0.97); opacity: 0;
  transition: transform 0.4s var(--ease-out), opacity 0.32s var(--ease-out);
}
#detail-backdrop.open #detail-modal { transform: translateY(0) scale(1); opacity: 1; }
#detail-img-col {
  position: relative;
  flex: 0 0 55%; background: var(--dark); overflow: hidden;
  display: flex; align-items: center; justify-content: center; min-height: 420px;
}
#detail-img-col img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: opacity 0.35s var(--ease-out);
}
#detail-info-col {
  flex: 1; padding: 32px 28px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 28px;
}
#detail-meta { display: flex; flex-direction: column; gap: 4px; }
#detail-source {
  font-size: 13px; color: var(--text-faint);
  display: flex; align-items: center; gap: 5px;
}
#detail-source a { color: var(--text-muted); text-decoration: none; font-weight: 500; transition: color 0.12s; }
#detail-source a:hover { color: var(--text); }
#detail-source svg { opacity: 0.5; flex-shrink: 0; }
#detail-date { font-size: 12px; color: var(--text-faint); }
#detail-notes-wrap { display: flex; flex-direction: column; gap: 6px; }
.detail-section-label { font-size: 13px; font-weight: 500; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
#detail-notes {
  font-size: 15px; color: var(--text-muted); line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  outline: none; border-radius: var(--radius-sm);
  padding: 6px 8px; margin: -6px -8px;
  transition: background 0.15s; cursor: text;
}
#detail-notes:hover { background: var(--surface); }
#detail-notes:focus { background: var(--surface); }
#detail-notes-save {
  font-size: 12px; color: var(--text-faint); background: none; border: none;
  padding: 0; cursor: pointer; font-family: var(--font);
  transition: color 0.12s; display: none;
}
#detail-notes-save:hover { color: var(--text-muted); }
#detail-notes-save.visible { display: inline; }
#detail-notes.empty::after {
  content: 'Add a note…'; color: var(--text-faint);
  font-style: italic; pointer-events: none;
}
#detail-tags-wrap { display: flex; flex-direction: column; gap: 8px; }
#detail-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.detail-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; font-size: 13px; color: var(--text-muted); transition: background 0.12s;
}
.detail-tag .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.detail-tag .remove-tag {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%;
  font-size: 10px; line-height: 1; color: var(--text-faint);
  cursor: pointer; margin-left: 2px; transition: background 0.12s, color 0.12s;
}
.detail-tag .remove-tag:hover { background: var(--border); color: var(--text); }
#detail-tag-input {
  font-family: var(--font); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 99px; padding: 4px 10px; outline: none; width: 88px;
  transition: border-color 0.15s, width 0.2s var(--ease-out);
}
#detail-tag-input:focus { border-color: var(--text-faint); width: 120px; }
#detail-tag-input::placeholder { color: var(--text-faint); }
#detail-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.detail-btn {
  width: 100%; padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 500; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  transition: background 0.15s, color 0.15s, transform 0.15s var(--ease-out);
  text-align: center; text-decoration: none; display: block;
}
.detail-btn:hover { background: var(--surface2); color: var(--text); }
.detail-btn:active { transform: scale(0.99); }
.detail-btn.danger { background: #2a1010; border-color: #5c1f1f; color: #f87171; }
.detail-btn.danger:hover { background: #3a1515; }
.detail-btn.download { background: var(--dark); border-color: var(--dark); color: var(--bg); }
.detail-btn.download:hover { opacity: 0.88; background: var(--dark); color: var(--bg); }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  z-index: 999; display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px 9px 12px; border-radius: 99px;
  font-size: 14px; font-weight: 500; font-family: var(--font);
  white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity 0.25s var(--ease-out), transform 0.35s var(--ease-out);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error  { background: #3a1212; color: #f87171; border: 1px solid #7f2020; }
#toast.success { background: #0f2b1a; color: #4ade80; border: 1px solid #1a5c33; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Nav right ── */
#nav-right { display: flex; align-items: center; gap: 8px; }
#tagSettingsBtn {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-faint); border-radius: var(--radius-sm);
  display: none; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
#tagSettingsBtn:hover { color: var(--text-muted); background: var(--surface); }
#tagSettingsBtn.visible { display: flex; }
#settingsBtn {
  background: none; border: none; padding: 5px; cursor: pointer;
  color: var(--text-faint); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
#settingsBtn:hover { color: var(--text-muted); background: var(--surface); }

/* ── Favorite star on grid cards ── */
.image-card .fav-star {
  position: absolute; top: 7px; left: 7px;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(243,241,235,0.88); backdrop-filter: blur(3px);
  border: none; padding: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 2;
  opacity: 0; transition: opacity 0.15s, transform 0.15s var(--ease-out);
  color: var(--text-faint);
}
.image-card:hover .fav-star { opacity: 1; }
.image-card .fav-star.active { opacity: 1; color: #dfaa40; }
.image-card .fav-star:active { transform: scale(0.85); }
.image-card .fav-star svg { width: 13px; height: 13px; flex-shrink: 0; }
.image-card .fav-star.active svg { fill: #dfaa40; stroke: #dfaa40; }

/* ── Favorite star in detail modal ── */
#detail-fav-btn {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-faint); display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-family: var(--font); transition: color 0.15s;
  border-radius: var(--radius-sm);
}
#detail-fav-btn:hover { color: var(--text-muted); }
#detail-fav-btn.active { color: #dfaa40; }
#detail-fav-btn.active svg { fill: #dfaa40; stroke: #dfaa40; }

/* ── Tag management modal ── */
#tag-mgmt-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 27, 22, 0.55);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 300; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s var(--ease-out);
}
#tag-mgmt-backdrop.open { opacity: 1; pointer-events: auto; }
#tag-mgmt-modal {
  background: var(--bg); border-radius: var(--radius);
  width: 480px; max-width: calc(100vw - 48px);
  max-height: calc(100vh - 80px); overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  transform: translateY(12px) scale(0.97); opacity: 0;
  transition: transform 0.35s var(--ease-out), opacity 0.28s var(--ease-out);
}
#tag-mgmt-backdrop.open #tag-mgmt-modal { transform: translateY(0) scale(1); opacity: 1; }
#tag-mgmt-header {
  padding: 20px 24px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
#tag-mgmt-title { font-size: 17px; font-weight: 500; color: var(--text); }
#tag-mgmt-close {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-faint); border-radius: 4px; transition: color 0.12s, background 0.12s;
}
#tag-mgmt-close:hover { color: var(--text); background: var(--surface); }
#tag-mgmt-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; }
#tag-rename-wrap { display: flex; flex-direction: column; gap: 8px; }
.mgmt-label { font-size: 12px; font-weight: 500; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
#tag-rename-input {
  font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; outline: none;
  transition: border-color 0.15s;
}
#tag-rename-input:focus { border-color: var(--text-faint); }
#tag-color-wrap { display: flex; flex-direction: column; gap: 10px; }
#tag-color-palette { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  border: 2.5px solid transparent;
  transition: transform 0.15s var(--ease-out), border-color 0.12s; flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.18); }
.color-swatch.selected { border-color: var(--text); }
#tag-merge-wrap { display: flex; flex-direction: column; gap: 8px; }
#tag-merge-select {
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; outline: none; cursor: pointer;
}
#tag-mgmt-footer {
  border-top: 1px solid var(--border); padding: 16px 24px;
  display: flex; flex-direction: column; gap: 8px;
}
.mgmt-btn {
  width: 100%; padding: 11px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 500; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s var(--ease-out);
  font-family: var(--font);
}
.mgmt-btn:hover { background: var(--surface2); color: var(--text); }
.mgmt-btn:active { transform: scale(0.99); }
.mgmt-btn.primary { background: var(--dark); border-color: var(--dark); color: var(--bg); }
.mgmt-btn.primary:hover { opacity: 0.88; background: var(--dark); color: var(--bg); }
.mgmt-btn.danger { background: #2a1010; border-color: #5c1f1f; color: #f87171; }
.mgmt-btn.danger:hover { background: #3a1515; }

/* ── Auth modal ── */
#auth-backdrop {
  position: fixed; inset: 0; background: rgba(30, 27, 22, 0.85);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
}
#auth-modal {
  background: var(--bg); border-radius: var(--radius);
  width: 420px; max-width: calc(100vw - 48px);
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
  padding: 36px; display: flex; flex-direction: column; gap: 20px;
}
#auth-step1, #auth-step2, #auth-step3 { display: flex; flex-direction: column; gap: 14px; }
#auth-modal h2 {
  font-family: "IM Fell English", serif; font-weight: 400;
  font-size: 28px; color: var(--text); margin: 0;
}
#auth-modal p { font-size: 14px; color: var(--text-muted); margin: 0; line-height: 1.6; }
.auth-input {
  font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 14px; width: 100%;
  outline: none; transition: border-color 0.15s; box-sizing: border-box;
}
.auth-input:focus { border-color: var(--text-faint); }
.auth-input::placeholder { color: var(--text-faint); }
.auth-input.error { border-color: #da4241; }
.auth-btn {
  width: 100%; padding: 13px; background: var(--dark); color: var(--bg);
  border: none; border-radius: var(--radius-sm); font-size: 15px;
  font-weight: 500; font-family: var(--font); cursor: pointer;
  transition: opacity 0.15s, transform 0.15s var(--ease-out);
}
.auth-btn:hover { opacity: 0.88; }
.auth-btn:active { transform: scale(0.99); }
.auth-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.auth-error { font-size: 13px; color: #f87171; display: none; }
.auth-error.visible { display: block; }
.auth-back {
  background: none; border: none; font-family: var(--font);
  font-size: 13px; color: var(--text-faint); cursor: pointer;
  padding: 0; text-align: left; transition: color 0.12s;
}
.auth-back:hover { color: var(--text-muted); }
.otp-inputs { display: flex; gap: 8px; }
.otp-digit {
  flex: 1; text-align: center; font-size: 22px; font-weight: 500;
  font-family: var(--font); color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 0; outline: none;
  transition: border-color 0.15s; min-width: 0;
}
.otp-digit:focus { border-color: var(--text-faint); }

/* ── Settings modal ── */
#settings-modal {
  background: var(--bg); border-radius: var(--radius);
  width: 400px; max-width: calc(100vw - 48px);
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(12px) scale(0.97); opacity: 0;
  transition: transform 0.35s var(--ease-out), opacity 0.28s var(--ease-out);
}
#settings-backdrop.open #settings-modal { transform: translateY(0) scale(1); opacity: 1; }
#settings-header {
  padding: 20px 24px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
#settings-title { font-size: 17px; font-weight: 500; color: var(--text); }
#settings-close {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-faint); border-radius: 4px; transition: color 0.12s, background 0.12s;
}
#settings-close:hover { color: var(--text); background: var(--surface); }
#settings-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 24px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-label { font-size: 15px; color: var(--text-muted); flex-shrink: 0; }
.settings-slider-wrap { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: flex-end; }
.settings-slider-wrap input[type=range] { width: 120px; accent-color: var(--dark); cursor: pointer; }
.settings-slider-wrap span { font-size: 13px; color: var(--text-faint); min-width: 36px; text-align: right; }
.settings-mode-btns { display: flex; gap: 6px; }
.mode-btn {
  padding: 6px 14px; border-radius: var(--radius-sm); font-size: 13px;
  font-family: var(--font); font-weight: 500; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.mode-btn:hover { background: var(--surface2); }
.mode-btn.active { background: var(--dark); border-color: var(--dark); color: var(--bg); }
#tag-sort-select {
  font-family: var(--font); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px; outline: none; cursor: pointer;
}

/* ── Dark mode ── */
body.dark {
  --bg:         #1a1917;
  --surface:    #232220;
  --surface2:   #2a2927;
  --border:     #38362f;
  --text:       rgb(235, 230, 220);
  --text-muted: rgba(235, 230, 220, 0.75);
  --text-faint: rgba(235, 230, 220, 0.38);
  --dark:       rgb(235, 230, 220);
}

/* ── Nested tags & drag-to-reorder ── */
  .sidebar-item.child { padding-left: 36px; }
  .sidebar-item.drag-over { background: var(--surface2); outline: 2px solid var(--border); outline-offset: -2px; }
  .sidebar-item.dragging { opacity: 0.4; }
  .sidebar-item[draggable] { cursor: grab; }
  .sidebar-item[draggable]:active { cursor: grabbing; }

  .sidebar-collapse-btn {
    background: none; border: none; padding: 0 2px; cursor: pointer;
    color: var(--text-faint); display: flex; align-items: center; justify-content: center;
    border-radius: 3px; transition: color 0.12s, background 0.12s;
    flex-shrink: 0; margin-right: -2px;
}
.sidebar-collapse-btn:hover { color: var(--text-muted); background: var(--surface2); }

.sidebar-children-collapsed .sidebar-item.child { display: none; }

#tag-parent-select {
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; outline: none; cursor: pointer; width: 100%;
}

/* ── Select button ── */
#selectBtn {
  background: none; border: none; padding: 5px; cursor: pointer;
  color: var(--text-faint); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
#selectBtn:hover { color: var(--text-muted); background: var(--surface); }
#selectBtn.active { color: var(--text); background: var(--surface); }

/* ── Selectable cards ── */
.image-card.selectable::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 6px; border: 2.5px solid transparent;
  transition: border-color 0.15s;
  pointer-events: none;
}
.image-card.selected::after { border-color: var(--dark); }
.image-card .select-check {
  position: absolute; top: 7px; right: 7px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(243,241,235,0.88); backdrop-filter: blur(3px);
  border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s, transform 0.15s var(--ease-out);
  pointer-events: none; flex-shrink: 0;
}
.image-card.selectable .select-check { opacity: 1; }
.image-card.selected .select-check {
  background: var(--dark); border-color: var(--dark); color: var(--bg);
}
.image-card.selected .select-check::after {
  content: '✓'; font-size: 11px; font-weight: 700; color: var(--bg);
  font-family: var(--font);
}

/* ── Bulk action bar ── */
#bulk-bar {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  z-index: 500; display: flex; align-items: center; gap: 10px;
  background: var(--dark); border-radius: 99px;
  padding: 10px 10px 10px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.28);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease-out), transform 0.35s var(--ease-out);
  white-space: nowrap;
}
#bulk-bar.visible { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
#bulk-count { font-size: 14px; font-weight: 500; color: var(--bg); opacity: 0.7; }
#bulk-actions { display: flex; gap: 6px; }
.bulk-btn {
  font-family: var(--font); font-size: 14px; font-weight: 500;
  padding: 7px 14px; border-radius: 99px; border: none; cursor: pointer;
  background: rgba(255,255,255,0.12); color: var(--bg);
  transition: background 0.15s, transform 0.12s var(--ease-out);
}
.bulk-btn:hover { background: rgba(255,255,255,0.2); }
.bulk-btn:active { transform: scale(0.96); }
.bulk-btn.danger { background: rgba(218,66,65,0.75); }
.bulk-btn.danger:hover { background: rgba(218,66,65,0.95); }
#bulk-cancel-btn { background: rgba(255,255,255,0.07); }

/* ── Bulk tag modal ── */
#bulk-tag-modal {
  background: var(--bg); border-radius: var(--radius);
  width: 480px; max-width: calc(100vw - 48px);
  max-height: calc(100vh - 80px); overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  transform: translateY(12px) scale(0.97); opacity: 0;
  transition: transform 0.35s var(--ease-out), opacity 0.28s var(--ease-out);
  
}
#bulk-tag-backdrop.open #bulk-tag-modal { transform: translateY(0) scale(1); opacity: 1; }
#bulk-tag-header {
  padding: 20px 24px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
#bulk-tag-backdrop { z-index: 600; }

#bulk-tag-title { font-size: 17px; font-weight: 500; color: var(--text); }
#bulk-tag-close {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-faint); border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
#bulk-tag-close:hover { color: var(--text); background: var(--surface); }
#bulk-tag-body { padding: 20px 24px; display: flex; flex-direction: column; overflow-y: auto; }
#bulk-add-pills, #bulk-remove-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
#bulk-tag-footer { border-top: 1px solid var(--border); padding: 16px 24px; }

/* ── Skeleton screens ── */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position: 600px 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 600px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 6px;
}

.skeleton-card {
  break-inside: avoid;
  margin-bottom: 10px;
  border-radius: 6px;
  overflow: hidden;
}

.skeleton-card .skeleton-img {
  width: 100%;
  display: block;
}

.skeleton-tag {
  height: 28px;
  border-radius: 99px;
  margin: 5px 20px;
}

/* ── Video cards ── */
.image-card video {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.image-card .video-badge {
  position: absolute;
  bottom: 7px;
  left: 7px;
  background: rgba(30, 27, 22, 0.6);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  pointer-events: none;
  letter-spacing: 0.04em;
}

#detail-img-col video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#detail-fullscreen-btn {
  position: absolute; bottom: 10px; right: 10px;
  background: rgba(30, 27, 22, 0.5); backdrop-filter: blur(4px);
  border: none; border-radius: var(--radius-sm); padding: 7px;
  color: #fff; cursor: pointer; opacity: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s, transform 0.15s var(--ease-out);
}
#detail-img-col:hover #detail-fullscreen-btn { opacity: 1; }
#detail-fullscreen-btn:active { transform: scale(0.92); }

/* ── Search ── */
#search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

#searchBtn {
  background: none; border: none; padding: 5px; cursor: pointer;
  color: var(--text-faint); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  position: relative; z-index: 1; flex-shrink: 0;
}
#searchBtn:hover { color: var(--text-muted); background: var(--surface); }
#searchBtn.active { color: var(--text); background: var(--surface); }

#searchInput {
  font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 12px;
  outline: none; width: 0; opacity: 0; pointer-events: none;
  position: absolute; right: 100%; top: 50%; transform: translateY(-50%);
  transition: width 0.25s var(--ease-out), opacity 0.2s var(--ease-out);
}
#searchInput.visible {
  width: 220px; opacity: 1; pointer-events: auto;
}
#searchInput::placeholder { color: var(--text-faint); }
#searchInput:focus { border-color: var(--text-faint); }

/* ── Mobile bottom nav ── */
#mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  #mobile-nav {
    display: flex;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    border-radius: 99px;
    padding: 12px 12px;
    gap: 16px;
    align-items: center;
    justify-content: center;
    /* Light mode */
    background: rgba(236, 234, 227, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0,0,0,0.10);
  }

  body.dark #mobile-nav {
    background: rgba(26, 25, 23, 0.80);
    border-color: rgba(255,255,255,0.07);
    box-shadow: 0 8px 32px rgba(0,0,0,0.40);
  }

  .mobile-nav-btn {
    background: none;
    border: none;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 6px;
    transition: color 0.15s;
    min-width: 32px;
  }

  .mobile-nav-btn.active {
    color: var(--text);
  }

  .mobile-nav-btn svg {
    width: 22px;
    height: 22px;
  }
}

@media (max-width: 768px) {
  #sidebar {
    display: none;
  }
}

@media (max-width: 768px) {
  #grid {
    columns: 2;
    column-gap: 8px;
  }

  #grid-area {
    padding: 12px 12px 100px; /* bottom padding clears the floating nav */
  }
}

/* ── Tags sheet (mobile) ── */
#tags-sheet-backdrop {
  display: none;
}

@media (max-width: 768px) {
  #tags-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(30, 27, 22, 0.52);
    backdrop-filter: blur(5px);
    z-index: 350;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease-out);
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }

  #tags-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  #tags-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 351;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.38s var(--ease-out);
    padding-bottom: env(safe-area-inset-bottom);
  }

  #tags-sheet-backdrop.open #tags-sheet {
    transform: translateY(0);
  }

  #tags-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    margin: 12px auto 8px;
    flex-shrink: 0;
  }

  #tags-sheet-header {
    padding: 4px 20px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
  }

  #tags-sheet-list {
    overflow-y: auto;
    padding: 0 0 16px;
  }

  .tags-sheet-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    font-size: 16px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s;
  }

  .tags-sheet-item:active {
    background: var(--surface);
  }

  .tags-sheet-item.active {
    color: var(--text);
    font-weight: 500;
  }

  .tags-sheet-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .tags-sheet-item .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .tags-sheet-item-count {
    font-size: 13px;
    color: var(--text-faint);
  }
}

/* ── Search sheet (mobile) ── */
#search-sheet-backdrop {
  display: none;
}

@media (max-width: 768px) {
  #search-sheet-backdrop {
    position: fixed;
    display: block;
    inset: 0;
    background: rgba(30, 27, 22, 0.52);
    backdrop-filter: blur(5px);
    z-index: 350;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease-out);
  }

  #search-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  #search-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 351;
    padding: 16px 20px 32px;
    transform: translateY(100%);
    transition: transform 0.38s var(--ease-out);
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }

  #search-sheet-backdrop.open #search-sheet {
    transform: translateY(0);
  }

  #search-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    margin: 0 auto 16px;
  }

  #search-sheet-input {
    font-family: var(--font);
    font-size: 16px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    width: 100%;
    outline: none;
  }

  #search-sheet-input:focus {
    border-color: var(--text-faint);
  }

  #search-sheet-input::placeholder {
    color: var(--text-faint);
  }
}

@media (max-width: 768px) {
  #detail-modal {
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    overflow-y: auto;
  }

  #detail-img-col {
    flex: 0 0 auto;
    min-height: 280px;
    max-height: 50vh;
    width: 100%;
  }

  #detail-img-col img,
  #detail-img-col video {
    object-fit: cover;
    width: 100%;
    height: 100%;
  }

  #detail-info-col {
    flex: 1;
    padding: 20px 16px;
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
    overflow-y: visible; /* parent scrolls */
  }
}

@media (max-width: 768px) {
  #upload-modal {
    width: calc(100vw - 32px);
    max-height: 85vh;
    overflow-y: auto;
  }

  #step2-inner {
    flex-direction: column;
  }

  #preview-col {
    width: 100%;
    min-height: 200px;
  }

  #form-col {
    padding: 16px;
  }
}

@media (max-width: 768px) {
  /* Hide entire top nav on mobile */
  #nav {
    display: none;
  }

  #collection-header {
    padding: 28px 16px 16px;
    text-align: center;
    position: relative;
  }

  #collection-header > div {
    justify-content: center;
  }

  #collection-title {
    font-size: 36px;
  }

  #collection-desc {
    text-align: center;
  }
}

@media (max-width: 768px) {
  #detail-mobile-close {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 8px 16px;
    color: var(--text-muted);
    font-size: 14px;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    align-self: flex-start;
    margin-bottom: 8px;
    transition: background 0.12s;
  }

  #detail-mobile-close:hover {
    background: var(--surface2);
  }
}
