/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0b0a08;
  --surface:     #111009;
  --surface-2:   #181610;
  --border:      #222018;
  --border-2:    #2c2a22;
  --accent:      #b8935a;
  --accent-dim:  rgba(184,147,90,0.12);
  --accent-faint:rgba(184,147,90,0.05);
  --text-1:      #ddd7cb;
  --text-2:      #7a7568;
  --text-3:      #3a3830;
  --t-image: #5a8fb8;
  --t-text:  #7aad5a;
  --t-link:  #c47a5a;
  --t-note:  #8a6ab8;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-mono:    'IBM Plex Mono', 'Courier New', monospace;
  --r: 2px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
#header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 52px;
  background: rgba(11,10,8,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-name { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: .12em; color: var(--accent); }
.brand-rule { display: inline-block; width: 18px; height: 1px; background: var(--border-2); }
.brand-sub { font-size: 9px; letter-spacing: .2em; color: var(--text-3); padding-top: 1px; }

#section-nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
#section-nav::-webkit-scrollbar { display: none; }

.nav-btn {
  background: none; border: none; color: var(--text-2);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .14em;
  padding: 6px 12px; cursor: pointer; border-radius: var(--r);
  transition: color .15s, background .15s; white-space: nowrap;
}
.nav-btn:hover { color: var(--text-1); background: var(--surface-2); }
.nav-btn.active { color: var(--accent); background: var(--accent-dim); }

.header-right { flex-shrink: 0; margin-left: auto; display: flex; align-items: center; gap: 10px; }
.entry-count { font-size: 10px; letter-spacing: .1em; color: var(--text-3); }

.select-toggle {
  background: none; border: 1px solid var(--border-2); color: var(--text-3);
  font-family: var(--font-mono); font-size: 9px; letter-spacing: .12em;
  padding: 4px 8px; cursor: pointer; border-radius: var(--r);
  transition: all .15s;
}
.select-toggle:hover { color: var(--text-2); border-color: var(--border-2); }
.select-toggle.active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

/* ── Search + Sort bar ──────────────────────────────────────────────────────── */
.search-sort-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#search-input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--border-2);
  color: var(--text-1); font-family: var(--font-mono); font-size: 11px;
  letter-spacing: .08em; padding: 6px 10px; border-radius: var(--r); outline: none;
}
#search-input::placeholder { color: var(--text-3); }
#search-input:focus { border-color: var(--accent); }
#search-input::-webkit-search-cancel-button { filter: invert(1) opacity(.3); cursor: pointer; }

.sort-btns { display: flex; gap: 2px; flex-shrink: 0; }
.sort-btn {
  background: none; border: none; color: var(--text-3);
  font-family: var(--font-mono); font-size: 9px; letter-spacing: .12em;
  padding: 4px 8px; cursor: pointer; border-radius: var(--r); transition: all .15s;
}
.sort-btn:hover { color: var(--text-2); }
.sort-btn.active { color: var(--accent); background: var(--accent-dim); }

/* ── Sub-navs ───────────────────────────────────────────────────────────────── */
.subnav {
  display: flex; gap: 2px; padding: 6px 24px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav-3 { background: var(--bg); padding-left: 40px; }

.subnav-btn {
  background: none; border: none; color: var(--text-3);
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .12em;
  padding: 4px 10px; cursor: pointer; border-radius: var(--r); transition: color .15s, background .15s; white-space: nowrap;
}
.subnav-btn:hover { color: var(--text-2); background: var(--surface); }
.subnav-btn.active { color: var(--accent); background: var(--accent-dim); }

/* ── Type bar ───────────────────────────────────────────────────────────────── */
.type-bar {
  display: flex; gap: 2px; padding: 8px 24px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.type-btn {
  background: none; border: 1px solid transparent; color: var(--text-3);
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .14em;
  padding: 4px 10px; cursor: pointer; border-radius: var(--r); transition: all .15s;
}
.type-btn:hover { color: var(--text-2); border-color: var(--border-2); }
.type-btn.active[data-type="all"]   { color: var(--text-1); border-color: var(--border-2); background: var(--surface-2); }
.type-btn.active[data-type="image"] { color: var(--t-image); border-color: var(--t-image); background: rgba(90,143,184,.08); }
.type-btn.active[data-type="text"]  { color: var(--t-text);  border-color: var(--t-text);  background: rgba(122,173,90,.08); }
.type-btn.active[data-type="link"]  { color: var(--t-link);  border-color: var(--t-link);  background: rgba(196,122,90,.08); }
.type-btn.active[data-type="note"]  { color: var(--t-note);  border-color: var(--t-note);  background: rgba(138,106,184,.08); }

/* ── Grid ───────────────────────────────────────────────────────────────────── */
#main { padding: 20px 24px 120px; }
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); cursor: pointer;
  transition: border-color .15s, transform .12s; overflow: hidden;
  display: flex; flex-direction: column;
  position: relative;
}
.card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.card-pinned { grid-column: span 2; border-color: var(--accent-dim); }
.card.selected { border-color: var(--accent); background: var(--accent-faint); }

.card-meta {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.card-type { font-size: 9px; letter-spacing: .16em; font-weight: 500; padding: 2px 6px; border-radius: 1px; }
.type-image { color: var(--t-image); background: rgba(90,143,184,.1); }
.type-text  { color: var(--t-text);  background: rgba(122,173,90,.1); }
.type-link  { color: var(--t-link);  background: rgba(196,122,90,.1); }
.type-note  { color: var(--t-note);  background: rgba(138,106,184,.1); }

.card-section { font-size: 9px; letter-spacing: .1em; color: var(--text-3); }
.card-date { font-size: 9px; color: var(--text-3); margin-left: auto; white-space: nowrap; }

.card-pin {
  background: none; border: none; color: var(--text-3);
  font-size: 11px; cursor: pointer; padding: 0 2px; line-height: 1;
  transition: color .15s; flex-shrink: 0;
}
.card-pin:hover { color: var(--accent); }
.card-pin.pinned { color: var(--accent); }

.card-edit {
  display: inline-flex; align-items: center;
  font-size: 9px; letter-spacing: .1em; color: var(--text-3);
  background: none; border: 1px solid var(--border); border-radius: var(--r);
  padding: 2px 7px; cursor: pointer; font-family: var(--font-mono);
  text-decoration: none; flex-shrink: 0; transition: color .15s, border-color .15s;
}
.card-edit:hover { color: var(--accent); border-color: var(--accent); }

.card-select-box {
  width: 16px; height: 16px; border: 1px solid var(--border-2); border-radius: 2px;
  background: var(--surface-2); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--accent); transition: all .12s;
}
.card-select-box.checked { background: var(--accent-dim); border-color: var(--accent); }

.card-image-wrap { width: 100%; aspect-ratio: 16/9; overflow: hidden; background: var(--surface-2); }
.card-image-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; cursor: zoom-in; }
.card:hover .card-image-wrap img { transform: scale(1.02); }
.card-caption { font-size: 11px; color: var(--text-2); padding: 8px 12px 4px; line-height: 1.5; }
.card-title { font-family: var(--font-display); font-size: 16px; font-weight: 500; color: var(--text-1); padding: 8px 12px 4px; line-height: 1.3; }
.card-body { font-size: 11.5px; color: var(--text-2); padding: 6px 12px 10px; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card-body-note { font-size: 11px; color: var(--text-2); border-left: 2px solid var(--t-note); margin: 8px 12px; padding: 6px 10px; background: rgba(138,106,184,.05); border-radius: 0 var(--r) var(--r) 0; }
.card-domain { font-size: 10px; letter-spacing: .06em; color: var(--t-link); padding: 4px 12px 2px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 12px 10px; }
.tag { font-size: 9px; letter-spacing: .08em; color: var(--text-3); border: 1px solid var(--border-2); padding: 2px 6px; border-radius: 1px; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.75); backdrop-filter: blur(4px); }
.modal-panel {
  position: relative; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r); max-width: 680px; width: 100%; max-height: 88vh;
  overflow-y: auto; z-index: 1; animation: modal-in .15s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none;
  border: 1px solid var(--border-2); color: var(--text-2); font-size: 12px;
  width: 26px; height: 26px; cursor: pointer; border-radius: var(--r);
  display: flex; align-items: center; justify-content: center; z-index: 2; transition: color .15s, border-color .15s;
}
.modal-close:hover { color: var(--text-1); border-color: var(--text-2); }
.modal-body { padding: 20px 24px 28px; }
.modal-header { margin-bottom: 16px; }
.modal-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.modal-section { font-size: 10px; letter-spacing: .1em; color: var(--text-3); }
.modal-date { font-size: 10px; color: var(--text-3); margin-left: auto; }
.modal-title { font-family: var(--font-display); font-size: 26px; font-weight: 500; line-height: 1.25; color: var(--text-1); }
.modal-image-wrap { margin: 16px 0; border-radius: var(--r); overflow: hidden; background: var(--surface-2); }
.modal-image-wrap img { width: 100%; display: block; max-height: 480px; object-fit: contain; background: var(--surface-2); cursor: zoom-in; }
.modal-caption { font-size: 11.5px; color: var(--text-2); padding: 10px 12px; border-top: 1px solid var(--border); font-style: italic; }
.modal-text { font-size: 13px; color: var(--text-2); line-height: 1.8; margin-top: 12px; }
.modal-link { display: inline-block; margin-top: 14px; font-size: 11px; color: var(--t-link); word-break: break-all; text-decoration: none; border-bottom: 1px solid rgba(196,122,90,.3); transition: border-color .15s; }
.modal-link:hover { border-color: var(--t-link); }

/* ── Lightbox ───────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 800;
  display: flex; align-items: center; justify-content: center;
  animation: modal-in .12s ease;
}
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.92); }
.lightbox-img {
  position: relative; z-index: 1; max-width: 95vw; max-height: 92vh;
  object-fit: contain; border-radius: var(--r);
  box-shadow: 0 0 60px rgba(0,0,0,.8);
}
.lightbox-close {
  position: absolute; top: 16px; right: 18px; z-index: 2;
  background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.15);
  color: #fff; font-size: 14px; width: 32px; height: 32px;
  cursor: pointer; border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
}

/* ── Floating + button ──────────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: 28px; right: 24px; z-index: 200;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: var(--bg);
  font-size: 26px; line-height: 1; font-weight: 300;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; box-shadow: 0 4px 20px rgba(184,147,90,.35);
  transition: transform .15s, box-shadow .15s;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(184,147,90,.5); }
.fab.hidden-fab { display: none; }

/* ── Back to top ────────────────────────────────────────────────────────────── */
.back-to-top {
  position: fixed; bottom: 88px; right: 27px; z-index: 200;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border-2);
  color: var(--text-2); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.back-to-top:hover { border-color: var(--accent); color: var(--accent); }

/* ── Bulk bar ───────────────────────────────────────────────────────────────── */
.bulk-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 300;
  background: var(--surface-2); border-top: 1px solid var(--border-2);
  padding: 12px 24px; display: flex; align-items: center; gap: 12px;
  backdrop-filter: blur(8px);
  animation: slide-up .15s ease;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.bulk-count { font-size: 11px; letter-spacing: .1em; color: var(--accent); flex-shrink: 0; }
.bulk-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.bulk-select {
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text-2);
  font-family: var(--font-mono); font-size: 11px; padding: 5px 8px;
  border-radius: var(--r); outline: none; cursor: pointer;
}
.bulk-btn {
  background: none; border: 1px solid var(--border-2); color: var(--text-2);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .1em;
  padding: 5px 12px; border-radius: var(--r); cursor: pointer; transition: all .15s;
}
.bulk-btn:hover { border-color: var(--accent); color: var(--accent); }
.bulk-btn-del:hover { border-color: #c47a5a; color: #c47a5a; }

/* ── States ─────────────────────────────────────────────────────────────────── */
.empty-state { display: flex; align-items: center; justify-content: center; height: 40vh; font-size: 10px; letter-spacing: .2em; color: var(--text-3); }
.loading-state { display: flex; align-items: center; justify-content: center; height: 40vh; }
.loading-dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .2; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.2); } }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #header { padding: 0 14px; gap: 12px; }
  #main   { padding: 14px 14px 120px; }
  .type-bar, .search-sort-bar { padding: 8px 14px; }
  .subnav { padding: 6px 14px; }
  .entry-grid { grid-template-columns: 1fr; }
  .card-pinned { grid-column: span 1; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-panel { max-height: 90vh; border-radius: var(--r) var(--r) 0 0; max-width: 100%; }
  .fab { bottom: 20px; right: 18px; }
  .back-to-top { bottom: 80px; right: 20px; }
  .bulk-bar { padding: 10px 14px; }
}

/* ── Gallery / file badges ──────────────────────────────────────────────────── */
.card-image-wrap { position: relative; cursor: zoom-in; }
.gallery-badge, .file-badge {
  position: absolute; bottom: 8px; right: 8px;
  background: rgba(0,0,0,.7); color: #fff; font-size: 9px;
  letter-spacing: .08em; padding: 3px 7px; border-radius: var(--r);
}
.file-badge { position: static; display: inline-block; background: rgba(196,122,90,.15); color: var(--t-link); }

.card-files { display: flex; flex-direction: column; gap: 4px; padding: 6px 12px 10px; }
.file-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; letter-spacing: .04em; color: var(--t-link);
  text-decoration: none; padding: 4px 8px;
  border: 1px solid rgba(196,122,90,.2); border-radius: var(--r);
  transition: border-color .15s; word-break: break-all;
}
.file-link:hover { border-color: var(--t-link); }

.modal-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 6px; margin: 14px 0; }
.modal-gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r); cursor: zoom-in; background: var(--surface-2); }
.modal-files { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }

/* ── Lightbox nav ───────────────────────────────────────────────────────────── */
.lightbox-nav {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 2; display: flex; align-items: center; gap: 16px;
  background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px; padding: 6px 12px;
}
.lightbox-arrow { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; padding: 0 6px; }
.lightbox-counter { color: #ccc; font-size: 11px; letter-spacing: .1em; }

/* ── Tag panel ──────────────────────────────────────────────────────────────── */
.tag-panel { position: fixed; inset: 0; z-index: 600; display: flex; align-items: flex-start; justify-content: center; padding: 80px 24px 24px; }
.tag-panel-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.75); backdrop-filter: blur(4px); }
.tag-panel-content {
  position: relative; z-index: 1; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r); max-width: 520px; width: 100%; max-height: 70vh; overflow-y: auto;
  animation: modal-in .15s ease;
}
.tag-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 11px; letter-spacing: .16em; color: var(--accent); position: sticky; top: 0; background: var(--surface); }
.tag-panel-head .modal-close { position: static; }
.tag-panel-body { padding: 16px 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text-1);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em;
  padding: 5px 10px; border-radius: var(--r); cursor: pointer; transition: all .15s;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip-count { font-size: 9px; color: var(--text-3); }

.tag { cursor: pointer; transition: color .15s, border-color .15s; }
.tag:hover { color: var(--accent); border-color: var(--accent); }
