/* ============================================================
   Modals — shared
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 500;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; }

/* Modals that open on top of the story reader need higher stacking */
#new-story-modal, #chapter-modal, #story-delete-modal { z-index: 600; }

.modal {
  background: var(--modal-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
}
.modal-sm { max-width: 380px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
}
.modal-header h2 { font-size: 1rem; font-weight: 800; }

.modal-body {
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-close {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: rgba(255,255,255,.08); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; }

.settings-divider {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
  padding-bottom: 10px; margin: 8px 0 16px;
  border-bottom: 1px solid var(--card-border);
}

/* ============================================================
   Compose dialog
   ============================================================ */
.compose-dialog {
  background: var(--modal-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
}

.compose-dialog-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
}
.compose-avatar img, .compose-avatar .avatar-letter {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.compose-avatar .avatar-letter { font-size: 0.95rem; }
.compose-dialog-title { font-weight: 700; font-size: 0.95rem; flex: 1; }

.compose-dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; flex: 1; }

.compose-title-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 1.05rem;
  font-weight: 700;
  background: transparent;
  color: var(--text);
  padding: 0;
}
.compose-title-input::placeholder { color: var(--text-subtle); font-weight: 700; }

.compose-textarea {
  width: 100%;
  border: none; outline: none;
  resize: none;
  background: transparent;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
  min-height: 80px;
}
.compose-textarea::placeholder { color: var(--text-muted); }

.compose-previews { display: flex; flex-wrap: wrap; gap: 8px; }
.compose-previews:empty { display: none; }

.compose-preview-item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255,255,255,.06);
  max-width: 160px;
}
.compose-preview-item img  { width: 160px; height: 100px; object-fit: cover; display: block; }
.compose-preview-item .file-label {
  padding: 8px 10px; font-size: 0.8rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; max-width: 200px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.compose-preview-item .file-label svg { width: 16px; height: 16px; flex-shrink: 0; }
.compose-preview-remove {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.7); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; line-height: 1;
  transition: background 0.15s;
}
.compose-preview-remove:hover { background: var(--danger); }

/* Background swatch picker */
.compose-bg-section {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}
.compose-bg-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; flex-shrink: 0; }

.bg-swatches {
  display: flex;
  flex-wrap: nowrap;      /* single scrollable row */
  overflow-x: auto;
  gap: 6px;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.2) transparent;
  flex: 1;
  min-width: 0;
}
.bg-swatches::-webkit-scrollbar { height: 3px; }
.bg-swatches::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 2px; }

.accent-swatches, .site-bg-swatches {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.swatch:hover  { transform: scale(1.2); }
.swatch.active { border-color: #fff; transform: scale(1.15); }
.swatch.default {
  background: rgba(255,255,255,.15);
  border: 2px dashed rgba(255,255,255,.3);
}

/* Custom card preset controls */
.swatch { position: relative; }
.swatch-add-custom {
  width: 24px; height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px dashed rgba(255,255,255,.3);
  background: transparent;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  font-weight: 300;
  line-height: 1;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.swatch-add-custom:hover { border-color: var(--accent); color: var(--accent); }

/* Custom background color/gradient picker popover */
.custom-bg-popover {
  position: fixed;
  z-index: 9999;
  background: var(--modal-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.cbp-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.cbp-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cbp-color-native {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--card-border);
  padding: 2px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}
.cbp-color-hex {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: monospace;
}
/* Direction dropdown for gradient picker */
.cbp-dir-sel {
  background: var(--surface-1);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
}
.cbp-preview-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.cbp-preview {
  flex: 1;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
}

.compose-dialog-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}
.compose-tools { display: flex; gap: 2px; }
.compose-tool {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
}
.compose-tool:hover { background: var(--accent-dim); }
.compose-tool svg { width: 19px; height: 19px; }

.compose-footer-right { display: flex; align-items: center; gap: 10px; }

/* Privacy toggle */
.privacy-toggle { cursor: pointer; }
.privacy-toggle input { display: none; }
.privacy-pill {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.8rem; font-weight: 700;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--accent);
  color: var(--accent);
  transition: all 0.15s;
  user-select: none;
}
.privacy-pill svg { width: 13px; height: 13px; }
.privacy-pill .icon-private { display: none; }
.privacy-toggle input:checked + .privacy-pill {
  color: var(--private-color);
  border-color: var(--private-color);
  background: var(--private-dim);
}
.privacy-toggle input:checked + .privacy-pill .icon-public  { display: none; }
.privacy-toggle input:checked + .privacy-pill .icon-private { display: block; }
.privacy-toggle input:checked + .privacy-pill .privacy-text::before { content: 'XCLUSIVE'; }
.privacy-pill .privacy-text::before { content: 'Public'; }
.privacy-pill .privacy-text { display: none; }
@media (min-width: 400px) { .privacy-pill .privacy-text { display: inline; } }

/* ============================================================
   Post expand modal
   ============================================================ */
.post-modal-overlay {
  align-items: center;
  padding: 20px;
}

.post-modal {
  background: var(--modal-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  position: relative;
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
}

.post-modal-body {
  overflow-y: auto;
  flex: 1;
}

.post-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  color: rgba(255,255,255,.9);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.post-modal-close:hover { background: rgba(255,255,255,.15); color: #fff; }
.post-modal-close svg { width: 18px; height: 18px; }

/* Expand modal content */
.expand-media { }
.expand-photo-grid { display: grid; gap: 3px; }
.expand-photo-grid[data-count="1"] { grid-template-columns: 1fr; }
.expand-photo-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.expand-photo-grid[data-count="3"] { grid-template-columns: 1fr 1fr; grid-template-rows: 220px 220px; }
.expand-photo-grid[data-count="3"] .expand-photo:first-child { grid-row: 1/3; }
.expand-photo-grid[data-count="4"] { grid-template-columns: 1fr 1fr; }

.expand-photo {
  overflow: hidden;
  cursor: zoom-in;
}
/* Single photo: natural aspect ratio, no forced crop */
.expand-photo-grid[data-count="1"] .expand-photo { max-height: 72vh; display: flex; align-items: center; justify-content: center; background: #000; }
.expand-photo-grid[data-count="1"] .expand-photo img {width: 100%;height: auto;max-height: 72vh;object-fit: contain;background-color: var(--card-bg);}
/* Multi-photo: fixed height grid with cover crop */
.expand-photo-grid:not([data-count="1"]) .expand-photo {min-height: 180px;/* max-height: 300px; */}
.expand-photo-grid:not([data-count="1"]) .expand-photo img {width: 100%;height: 100%;object-fit: cover;transition: transform 0.3s ease;}
.expand-photo:hover img { transform: scale(1.02); }

.expand-video { width: 100%; }
.expand-video video { width: 100%; max-height: 400px; display: block; background: #000; }

.expand-audio {
  margin: 0 20px;
  background: rgba(255,255,255,.05);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.expand-audio-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--accent-dim); color: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.expand-audio-icon svg { width: 24px; height: 24px; }
.expand-audio-info { flex: 1; min-width: 0; }
.expand-audio-name { font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expand-audio-info audio { width: 100%; height: 34px; }

.expand-yt { aspect-ratio: 16/9; margin: 0; }
.expand-yt iframe { width: 100%; height: 100%; border: none; display: block; }

.expand-lp-image { background: #000; text-align: center; }
.expand-lp-image img { max-width: 100%; max-height: 55vh; object-fit: contain; display: block; margin: 0 auto; }
.expand-body { padding: 14px 18px 18px; text-align: center; }
.expand-title { font-size: 1.4rem; font-weight: 900; margin-bottom: 6px; line-height: 1.2; }
.expand-body .card-link-preview {margin: 0 0 8px;padding: 10px 14px;border-radius: var(--radius-md);border: 1px solid var(--card-border);background: rgb(0 0 0 / 53%);}
.compose-link-preview .card-link-preview { border-radius: var(--radius-md); border: 1px solid var(--card-border); margin: 0; }
.expand-body .clp-description { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }
.expand-text  { font-size: 0.95rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word; color: var(--text-muted); text-align: left; }
.expand-text a { color: var(--accent); }

/* ── Bottom app bar ───────────────────────────────────────────── */
.expand-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  /* background: var(--card-bg); */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}

/* Date text — plain, no pill */
.expand-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.expand-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Right side button cluster */
.expand-footer-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* On small screens: date goes full-width above the buttons */
@media (max-width: 520px) {
  .expand-footer { flex-direction: column; align-items: flex-start; gap: 6px; }
  .expand-meta   { order: -1; width: 100%; }
  .expand-date   { text-align: center; width: 100%; }
  .expand-footer-right { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
}

.expand-admin-actions {
  display: flex;
  gap: 4px;
}

.expand-admin-btn,
.expand-share-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  font-size: 0.76rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  letter-spacing: 0.01em;
}

/* Default admin button */
.expand-admin-btn {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: var(--text-muted);
}
.expand-admin-btn:hover {
  background: rgba(255,255,255,.12);
  color: var(--text);
  border-color: rgba(255,255,255,.18);
}
.expand-admin-btn.active {
  color: var(--accent);
  border-color: rgba(167,139,250,.4);
  background: rgba(167,139,250,.1);
}
.expand-admin-btn.is-private {
  color: var(--private-color);
  border-color: rgba(247,37,133,.3);
  background: rgba(247,37,133,.08);
}
.expand-admin-btn.delete {
  border-color: transparent;
  background: transparent;
  color: var(--text-subtle);
}
.expand-admin-btn.delete:hover {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(248,113,113,.3);
}
.expand-admin-btn svg { width: 13px; height: 13px; }

/* Share button — primary action */
.expand-share-btn {
  background: linear-gradient(135deg, rgba(0,245,255,.18), rgba(167,139,250,.18));
  border: 1px solid rgba(0,245,255,.35);
  color: rgba(0,245,255,.9);
}
.expand-share-btn:hover {
  background: linear-gradient(135deg, rgba(0,245,255,.28), rgba(167,139,250,.28));
  box-shadow: 0 0 16px rgba(0,245,255,.2);
  color: #fff;
}
.expand-share-btn svg { width: 13px; height: 13px; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }

/* Toggle row (e.g. transparent header) */
.settings-toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.settings-toggle-row > label:first-child { margin: 0; }

/* Toggle switch pill */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--input-border);
  border-radius: var(--radius-full);
  position: relative;
  transition: background 0.2s;
  display: block;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  display: block;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--accent); }
.toggle-switch input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

.input {
  width: 100%; padding: 9px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-subtle); }

.input-prefix-wrap {
  display: flex; align-items: center;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  background: var(--input-bg);
  overflow: hidden;
  transition: border-color 0.15s;
}
.input-prefix-wrap:focus-within { border-color: var(--accent); }
.input-prefix { padding: 9px 8px 9px 13px; color: var(--text-muted); font-size: 0.9rem; flex-shrink: 0; }
.input-prefixed { border: none; border-radius: 0; padding-left: 0; flex: 1; background: transparent; color: var(--text); }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.banner-upload-wrap { }
.banner-preview {
  width: 100%; height: 90px;
  border-radius: var(--radius-md);
  background: var(--input-bg);
  border: 1px dashed var(--input-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 0.82rem;
  overflow: hidden; cursor: pointer;
}
.banner-preview img { width: 100%; height: 100%; object-fit: cover; }

.avatar-upload-row { display: flex; align-items: center; gap: 16px; }
.avatar-upload-preview {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--input-bg);
  border: 2px dashed var(--input-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 1.1rem;
  overflow: hidden; flex-shrink: 0;
}
.avatar-upload-preview img { width: 100%; height: 100%; object-fit: cover; }

.alert { padding: 9px 13px; border-radius: var(--radius-md); font-size: 0.85rem; margin-bottom: 10px; }
.alert-error   { background: var(--danger-dim);  color: var(--danger);  border: 1px solid var(--danger); }
.alert-success { background: var(--success-dim); color: var(--success); border: 1px solid var(--success); }

#profile-msg, #settings-msg { margin-top: 0; }

/* ============================================================
   Lightbox
   ============================================================ */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.93);
  display: flex; align-items: center; justify-content: center;
}
.lightbox.hidden { display: none; }

.lightbox-img-wrap {
  max-width: 92vw; max-height: 92vh;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-img-wrap img {
  max-width: 92vw; max-height: 92vh;
  object-fit: contain; border-radius: var(--radius-md);
}

.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.1);
  color: #fff; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,.2); }
.lightbox-close svg { width: 22px; height: 22px; }

.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,.1); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.lightbox-nav:hover { background: rgba(255,255,255,.2); }
.lightbox-nav svg { width: 24px; height: 24px; }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

.lightbox-counter {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.5); color: #fff;
  font-size: 0.83rem; padding: 4px 14px; border-radius: var(--radius-full);
}

/* ============================================================
