/* Marginalia — custom styles
 * Editorial / notebook aesthetic: warm paper on deep ink
 */

* { -webkit-tap-highlight-color: transparent; }

body {
  background-color: #0F1115;
  /* Subtle warm grain for depth */
  background-image:
    radial-gradient(at 20% 0%, rgba(217, 165, 116, 0.04) 0px, transparent 50%),
    radial-gradient(at 80% 100%, rgba(217, 165, 116, 0.03) 0px, transparent 60%);
  background-attachment: fixed;
  font-feature-settings: "ss01", "cv11";
  letter-spacing: -0.005em;
}

/* Typography refinements */
.font-display {
  font-feature-settings: "ss01", "ss02", "ss03";
  letter-spacing: -0.02em;
}

/* Display headings have tighter tracking and italic flair */
h1.title, .display-title {
  font-family: 'Fraunces', serif;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 50, "WONK" 1;
}

/* Card paper texture — very subtle */
.card-paper {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(240, 237, 228, 0.015) 27px,
      rgba(240, 237, 228, 0.015) 28px
    );
}

/* Card color variants — warm, low-saturation */
.card-color-default { background-color: #1C1A18; }
.card-color-coral   { background-color: #2E1F1B; }
.card-color-mustard { background-color: #2A2418; }
.card-color-sage    { background-color: #1C2620; }
.card-color-slate   { background-color: #1B2129; }
.card-color-plum    { background-color: #271A23; }
.card-color-sand    { background-color: #261F18; }

.card-color-default:hover { background-color: #211F1C; }
.card-color-coral:hover   { background-color: #352421; }
.card-color-mustard:hover { background-color: #30291D; }
.card-color-sage:hover    { background-color: #212C26; }
.card-color-slate:hover   { background-color: #21282F; }
.card-color-plum:hover    { background-color: #2D1F29; }
.card-color-sand:hover    { background-color: #2C241D; }

/* Color picker swatches (lighter for visibility) */
.swatch-default { background-color: #2A2724; }
.swatch-coral   { background-color: #4D332D; }
.swatch-mustard { background-color: #463B26; }
.swatch-sage    { background-color: #2D3F35; }
.swatch-slate   { background-color: #2C3641; }
.swatch-plum    { background-color: #3F2A37; }
.swatch-sand    { background-color: #3D3326; }

/* Masonry via CSS columns. Cards must be break-inside: avoid */
.masonry {
  column-gap: 1rem;
  column-count: 1;
}
@media (min-width: 640px)  { .masonry { column-count: 2; } }
@media (min-width: 1024px) { .masonry { column-count: 3; } }
@media (min-width: 1440px) { .masonry { column-count: 4; } }
@media (min-width: 1920px) { .masonry { column-count: 5; } }

.masonry > * {
  break-inside: avoid;
  margin-bottom: 1rem;
  display: block;
}

/* Note card */
.note-card {
  border: 1px solid rgba(240, 237, 228, 0.06);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
  position: relative;
  overflow: hidden;
}
.note-card:hover {
  border-color: rgba(240, 237, 228, 0.14);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}
.note-card.is-pinned {
  border-color: rgba(217, 165, 116, 0.28);
}
.note-card.is-pinned::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #D9A574, transparent);
}
.note-card.is-done {
  opacity: 0.55;
}
.note-card.is-done .note-content {
  text-decoration: line-through;
  text-decoration-color: rgba(240, 237, 228, 0.4);
}

/* Show actions on hover/touch */
.card-actions {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.note-card:hover .card-actions,
.note-card:focus-within .card-actions,
.note-card.actions-visible .card-actions {
  opacity: 1;
}
@media (hover: none) {
  .card-actions { opacity: 1; }
}

/* Action buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: rgba(240, 237, 228, 0.65);
  transition: background-color 0.15s, color 0.15s, transform 0.15s;
}
.icon-btn:hover {
  background-color: rgba(240, 237, 228, 0.08);
  color: #F0EDE4;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.active { color: #D9A574; }

/* Pin animation */
.pin-icon { transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.icon-btn.active .pin-icon { transform: rotate(-30deg); }

/* Markdown rendered content */
.note-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
  line-height: 1.55;
  color: rgba(240, 237, 228, 0.92);
}
.note-content h1, .note-content h2, .note-content h3 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  margin: 0.5em 0 0.25em;
  letter-spacing: -0.015em;
}
.note-content h1 { font-size: 1.25rem; }
.note-content h2 { font-size: 1.1rem; }
.note-content h3 { font-size: 1rem; }
.note-content p { margin: 0.4em 0; }
.note-content ul, .note-content ol { margin: 0.4em 0; padding-left: 1.5em; }
.note-content li { margin: 0.15em 0; }
.note-content code {
  font-family: 'JetBrains Mono', monospace;
  background: rgba(240, 237, 228, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.86em;
}
.note-content pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.note-content pre code {
  background: transparent;
  padding: 0;
}
.note-content blockquote {
  border-left: 2px solid rgba(217, 165, 116, 0.5);
  padding-left: 0.8em;
  margin: 0.5em 0;
  color: rgba(240, 237, 228, 0.75);
  font-style: italic;
}
.note-content a {
  color: #D9A574;
  text-decoration: underline;
  text-decoration-color: rgba(217, 165, 116, 0.4);
  text-underline-offset: 2px;
}
.note-content a:hover { text-decoration-color: #D9A574; }
.note-content hr {
  border: none;
  border-top: 1px solid rgba(240, 237, 228, 0.1);
  margin: 0.75em 0;
}
.note-content [type="checkbox"] {
  margin-right: 0.4em;
  accent-color: #D9A574;
}

/* Link preview chip */
.link-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-top: 8px;
  border-radius: 8px;
  background: rgba(240, 237, 228, 0.04);
  border: 1px solid rgba(240, 237, 228, 0.08);
  font-size: 0.8rem;
  color: rgba(240, 237, 228, 0.85);
  text-decoration: none;
  transition: background-color 0.15s;
}
.link-chip:hover { background: rgba(240, 237, 228, 0.08); }
.link-chip img { width: 16px; height: 16px; flex-shrink: 0; border-radius: 3px; }
.link-chip .lc-host { color: rgba(240, 237, 228, 0.5); font-size: 0.72rem; }

/* Attachment preview */
.attach-grid {
  display: grid;
  gap: 4px;
  margin: -14px -16px 10px -16px;
  border-radius: 12px 12px 0 0;
  overflow: hidden;
}
.attach-grid.attach-1 { grid-template-columns: 1fr; }
.attach-grid.attach-2 { grid-template-columns: 1fr 1fr; }
.attach-grid.attach-3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.attach-grid.attach-3 > :first-child { grid-row: 1 / span 2; }
.attach-grid.attach-many { grid-template-columns: 1fr 1fr; }

.attach-tile {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 10;
  overflow: hidden;
}
.attach-tile img, .attach-tile video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.attach-tile .attach-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  color: #F0EDE4; font-weight: 600; font-size: 1.2rem;
}
.attach-audio {
  margin: 8px 0;
  width: 100%;
}
.attach-audio audio { width: 100%; }

/* Composer (top-of-grid quick add) */
.composer {
  background: #1A1816;
  border: 1px solid rgba(240, 237, 228, 0.08);
  border-radius: 14px;
  padding: 12px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: rgba(217, 165, 116, 0.28);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.composer textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: #F0EDE4;
  font-family: 'Manrope', sans-serif;
  font-size: 0.95rem;
  line-height: 1.55;
  resize: none;
  min-height: 24px;
}
.composer textarea::placeholder { color: rgba(240, 237, 228, 0.4); }

/* Composer drag-over state */
.composer.is-dropping {
  border-color: rgba(217, 165, 116, 0.5);
  box-shadow: 0 0 0 3px rgba(217, 165, 116, 0.12), 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Composer attachments preview row */
.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(240, 237, 228, 0.06);
}
.composer-attachments.hidden { display: none; }

.composer-attach-tile {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(240, 237, 228, 0.08);
  flex-shrink: 0;
}
.composer-attach-tile img,
.composer-attach-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.composer-attach-tile.is-audio,
.composer-attach-tile.is-file {
  width: auto;
  min-width: 100px;
  max-width: 180px;
  height: 64px;
  background: rgba(240, 237, 228, 0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
}
.composer-attach-audio-label {
  font-size: 1.1rem;
  color: #D9A574;
  line-height: 1;
}
.composer-attach-name {
  font-size: 0.7rem;
  color: rgba(240, 237, 228, 0.7);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.composer-attach-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #F0EDE4;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.4;
}
.composer-attach-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #F0EDE4;
  font-size: 12px;
  line-height: 1;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background-color 0.15s;
}
.composer-attach-remove:hover {
  background: rgba(220, 80, 80, 0.85);
}

.composer-upload-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 64px;
  padding: 0 12px;
  font-size: 0.75rem;
  color: rgba(240, 237, 228, 0.55);
  border: 1px dashed rgba(240, 237, 228, 0.15);
  border-radius: 8px;
}

/* Search bar */
.search-bar {
  background: rgba(240, 237, 228, 0.04);
  border: 1px solid rgba(240, 237, 228, 0.08);
  border-radius: 999px;
  padding: 8px 16px;
  transition: background-color 0.15s, border-color 0.15s, max-width 0.3s ease;
  display: flex; align-items: center; gap: 10px;
}
.search-bar:focus-within {
  background: rgba(240, 237, 228, 0.06);
  border-color: rgba(217, 165, 116, 0.28);
}
.search-bar input {
  background: transparent;
  border: none;
  outline: none;
  color: #F0EDE4;
  flex: 1;
  font-size: 0.9rem;
}
.search-bar input::placeholder { color: rgba(240, 237, 228, 0.4); }

/* Filter chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(240, 237, 228, 0.05);
  color: rgba(240, 237, 228, 0.7);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.chip:hover { background: rgba(240, 237, 228, 0.08); }
.chip.active {
  background: rgba(217, 165, 116, 0.15);
  color: #D9A574;
  border-color: rgba(217, 165, 116, 0.3);
}
.chip.tag-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 17, 21, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; }
.modal-container {
  background: #16161B;
  border: 1px solid rgba(240, 237, 228, 0.1);
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(8px);
  transition: transform 0.2s ease;
}
.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.modal-footer {
  flex-shrink: 0;
  background: #16161B;
}
.modal-overlay.active .modal-container { transform: translateY(0); }

/* Toasts */
.toast {
  pointer-events: auto;
  background: #1F1F25;
  border: 1px solid rgba(240, 237, 228, 0.1);
  border-radius: 999px;
  padding: 8px 16px;
  color: #F0EDE4;
  font-size: 0.85rem;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-error { border-color: rgba(220, 80, 80, 0.4); }
.toast.toast-success { border-color: rgba(217, 165, 116, 0.4); }
.toast button {
  margin-left: 8px;
  padding: 2px 8px;
  background: rgba(240, 237, 228, 0.1);
  border-radius: 999px;
  font-size: 0.78rem;
}

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(240, 237, 228, 0.2);
  border-top-color: #D9A574;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: rgba(240, 237, 228, 0.5);
}
.empty-state .display-title {
  color: rgba(240, 237, 228, 0.7);
  font-size: 1.5rem;
  margin-bottom: 8px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(240, 237, 228, 0.08);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(240, 237, 228, 0.16); background-clip: padding-box; }

/* Form inputs (setup page) */
.form-input {
  width: 100%;
  background: rgba(240, 237, 228, 0.04);
  border: 1px solid rgba(240, 237, 228, 0.1);
  border-radius: 10px;
  padding: 10px 14px;
  color: #F0EDE4;
  font-size: 0.92rem;
  font-family: 'Manrope', sans-serif;
  transition: border-color 0.15s, background-color 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: rgba(217, 165, 116, 0.4);
  background: rgba(240, 237, 228, 0.06);
}
.form-input::placeholder { color: rgba(240, 237, 228, 0.35); }
.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(240, 237, 228, 0.55);
  margin-bottom: 6px;
}
.form-help {
  font-size: 0.78rem;
  color: rgba(240, 237, 228, 0.4);
  margin-top: 4px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.88rem;
  font-family: 'Manrope', sans-serif;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: #D9A574;
  color: #0F1115;
}
.btn-primary:hover { background: #E2B284; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: rgba(240, 237, 228, 0.05);
  color: #F0EDE4;
  border-color: rgba(240, 237, 228, 0.1);
}
.btn-ghost:hover { background: rgba(240, 237, 228, 0.1); }
.btn-danger {
  background: transparent;
  color: #DC5050;
  border-color: rgba(220, 80, 80, 0.3);
}
.btn-danger:hover { background: rgba(220, 80, 80, 0.1); }

/* Section header */
.section-header {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(240, 237, 228, 0.4);
  margin: 24px 0 12px;
  padding-left: 4px;
}

/* Clickable variant — used for the Pinned section toggle */
.section-header-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px 10px 4px 4px;
  margin: 24px 0 12px;
  border-radius: 6px;
  color: rgba(240, 237, 228, 0.4);
  transition: background-color 0.15s ease, color 0.15s ease;
  /* override .section-header's default block margin since this is inline-flex */
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: inherit;
}
.section-header-toggle:hover {
  background: rgba(240, 237, 228, 0.05);
  color: rgba(240, 237, 228, 0.7);
}
.section-header-toggle:focus-visible {
  outline: 2px solid rgba(217, 165, 116, 0.5);
  outline-offset: 2px;
}
.section-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
  color: rgba(240, 237, 228, 0.55);
}
.section-header-toggle.is-collapsed .section-chevron {
  transform: rotate(-90deg);
}
.section-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.02em;
  color: rgba(240, 237, 228, 0.35);
  background: rgba(240, 237, 228, 0.05);
  padding: 1px 6px;
  border-radius: 999px;
}

/* Dropdown menu */
.menu {
  position: absolute;
  background: #1F1F25;
  border: 1px solid rgba(240, 237, 228, 0.1);
  border-radius: 10px;
  padding: 4px;
  min-width: 180px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 50;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: #F0EDE4;
  cursor: pointer;
  transition: background-color 0.1s;
  text-align: left;
  width: 100%;
}
.menu-item:hover { background: rgba(240, 237, 228, 0.08); }
.menu-item.danger { color: #DC5050; }
.menu-divider { height: 1px; background: rgba(240, 237, 228, 0.08); margin: 4px 0; }

/* Page transitions */
.page-enter {
  animation: pageEnter 0.3s ease-out;
}
@keyframes pageEnter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* FAB (mobile) */
.fab-wrap {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
}
@media (min-width: 1024px) { .fab-wrap { display: none; } }

.fab-wrap .fab-icon { transition: transform 0.18s ease; display: inline-flex; }
.fab-wrap.is-open .fab-icon { transform: rotate(45deg); }

.fab {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #D9A574;
  color: #0F1115;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(217, 165, 116, 0.3);
  transition: transform 0.15s;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

.fab-menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.16s ease, transform 0.18s ease;
}
.fab-wrap.is-open .fab-menu { pointer-events: auto; opacity: 1; transform: translateY(0) scale(1); }

.fab-menu-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.85rem;
  border-radius: 999px;
  background: var(--color-card, #2a2622);
  color: var(--color-paper, #f0ede4);
  border: 1px solid var(--color-border, #3a342e);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  font-size: 0.88rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
.fab-menu-item:hover { background: var(--color-card-hover, #322c26); }
.fab-menu-item:active { transform: scale(0.97); }
.fab-menu-icon { display: inline-flex; }

/* Safe areas (notch) */
.safe-top { padding-top: max(env(safe-area-inset-top), 0px); }
.safe-bottom { padding-bottom: max(env(safe-area-inset-bottom), 0px); }

/* ==========================================================================
   Settings page
   ========================================================================== */

.settings-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.settings-section {
  margin-bottom: 2.5rem;
}

.settings-section.danger { border-top: 1px solid var(--border); padding-top: 1.5rem; }

.settings-section-title {
  font-family: var(--font-display, 'Fraunces', serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--paper, #F0EDE4);
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

.settings-section.danger .settings-section-title { color: rgb(220, 120, 120); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stat-tile {
  background: var(--card, #1C1A18);
  border: 1px solid var(--border, rgba(240, 237, 228, 0.08));
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted, #918B7E);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-family: var(--font-display, 'Fraunces', serif);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--paper, #F0EDE4);
  line-height: 1.1;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border, rgba(240, 237, 228, 0.06));
}

.settings-row:last-child { border-bottom: none; }

.settings-row-label {
  font-weight: 500;
  color: var(--paper, #F0EDE4);
  font-size: 0.95rem;
}

.settings-row-sub {
  font-size: 0.8rem;
  margin-top: 2px;
}

.settings-footer {
  margin-top: 3rem;
  text-align: center;
  padding: 1rem 0;
}

/* ==========================================================================
   Setup page
   ========================================================================== */

.setup-shell {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
}

.setup-card {
  width: 100%;
  max-width: 560px;
  background: var(--card, #1C1A18);
  border: 1px solid var(--border, rgba(240, 237, 228, 0.08));
  border-radius: 16px;
  padding: 2rem;
}

.setup-header {
  text-align: center;
  margin-bottom: 2rem;
}

.setup-header h1 {
  font-family: 'Fraunces', serif;
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  color: var(--paper, #F0EDE4);
}

.setup-form .setup-section {
  margin-bottom: 1.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border, rgba(240, 237, 228, 0.06));
}

.setup-form .setup-section:last-of-type { border-bottom: none; }

.setup-form .setup-section h2 {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--paper, #F0EDE4);
}

.setup-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .setup-card { padding: 1.5rem 1.25rem; }
}

/* ==========================================================================
   Tabs (used in import dialog)
   ========================================================================== */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  color: var(--muted, #918B7E);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.tab.active {
  color: var(--ochre, #D9A574);
  border-bottom-color: var(--ochre, #D9A574);
  font-weight: 500;
}

.tab-panel.hidden { display: none; }

.form-error {
  color: rgb(220, 120, 120);
  font-size: 0.8rem;
  margin-top: 0.5rem;
  min-height: 1em;
}

/* ==========================================================================
   Lightbox overlay
   ========================================================================== */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 150;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.lightbox-overlay.active {
  opacity: 1;
}

/* Header */
.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  flex-shrink: 0;
}
.lightbox-counter {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: rgba(240, 237, 228, 0.6);
}
.lightbox-counter.hidden { display: none; }

.lightbox-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(240, 237, 228, 0.08);
  color: #F0EDE4;
  font-size: 1.4rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover {
  background: rgba(240, 237, 228, 0.15);
}

/* Stage */
.lightbox-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0 48px;
  overflow: hidden;
  min-height: 0;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.lightbox-img.loaded {
  opacity: 1;
}

/* Nav arrows */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(240, 237, 228, 0.08);
  color: #F0EDE4;
  font-size: 1.5rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
  z-index: 2;
}
.lightbox-nav:hover {
  background: rgba(240, 237, 228, 0.18);
}
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }
.lightbox-nav.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Caption */
.lightbox-caption {
  text-align: center;
  padding: 12px 20px 20px;
  font-size: 0.85rem;
  color: rgba(240, 237, 228, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .lightbox-overlay,
  .lightbox-img,
  .lightbox-nav,
  .lightbox-close {
    transition: none !important;
  }
}

/* Mobile: larger tap targets */
@media (max-width: 640px) {
  .lightbox-stage {
    padding: 0 12px;
  }
  .lightbox-nav {
    width: 40px;
    height: 40px;
  }
  .lightbox-nav.prev { left: 4px; }
  .lightbox-nav.next { right: 4px; }
}

/* ==========================================================================
   Mobile drawer (left-side nav for narrow viewports)
   ========================================================================== */

.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;                                  /* above sticky header (30), below modal (100) */
  background: rgba(15, 17, 21, 0);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition: background 0.2s ease, backdrop-filter 0.2s ease, -webkit-backdrop-filter 0.2s ease;
  display: flex;
}

.mobile-drawer-overlay.active {
  background: rgba(15, 17, 21, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.mobile-drawer {
  width: min(82vw, 320px);
  height: 100%;
  background: #1A1816;
  border-right: 1px solid rgba(240, 237, 228, 0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: max(env(safe-area-inset-bottom), 0px);
}

.mobile-drawer-overlay.active .mobile-drawer {
  transform: translateX(0);
}

.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(240, 237, 228, 0.06);
  flex-shrink: 0;
}

.mobile-drawer-header h2 {
  font-family: Fraunces, serif;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: #F0EDE4;
}

.mobile-drawer-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  flex: 1;
}

.mobile-drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;                           /* ~46px tall — comfortable thumb target */
  border-radius: 10px;
  font-size: 0.92rem;
  font-family: Manrope, sans-serif;
  color: rgba(240, 237, 228, 0.65);
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  width: 100%;
}

.mobile-drawer-item:hover,
.mobile-drawer-item:focus-visible {
  background: rgba(240, 237, 228, 0.05);
  color: #F0EDE4;
}

.mobile-drawer-item:focus-visible {
  outline: 2px solid rgba(217, 165, 116, 0.5);
  outline-offset: -2px;
}

.mobile-drawer-item.is-active {
  background: rgba(240, 237, 228, 0.06);
  color: #F0EDE4;
}

.mobile-drawer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.mobile-drawer-footer {
  border-top: 1px solid rgba(240, 237, 228, 0.06);
  padding: 10px 8px 12px;
  flex-shrink: 0;
}

/* Drawer is mobile-only — sidebar takes over at lg breakpoint.
   Defensive guard in case openMobileDrawer() is ever called on desktop. */
@media (min-width: 1024px) {
  .mobile-drawer-overlay { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-drawer-overlay,
  .mobile-drawer {
    transition: none !important;
  }
}
