/* ─── Custom properties ─────────────────────────────────────── */
:root {
  --bg:          #0d0c0b;
  --sidebar-bg:  #131110;
  --sidebar-hov: #1c1917;
  --border:      rgba(255, 235, 195, 0.07);
  --border-lt:   rgba(255, 235, 195, 0.12);
  --text:        #ddd0b8;
  --text-dim:    rgba(221, 208, 184, 0.50);
  --text-muted:  rgba(221, 208, 184, 0.28);
  --accent:      #c4884a;
  --accent-glow: rgba(196, 136, 74, 0.12);
  --sidebar-w:   272px;
  --tab-w:       20px;
  --header-h:    48px;
  --ease:        cubic-bezier(0.4, 0, 0.2, 1);
  --dur:         0.22s;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; }
button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; }

/* ─── App shell ──────────────────────────────────────────────── */
#app  { height: 100vh; }
#main { width: 100%; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }

#main::-webkit-scrollbar       { width: 5px; }
#main::-webkit-scrollbar-track { background: transparent; }
#main::-webkit-scrollbar-thumb { background: var(--border-lt); border-radius: 3px; }

/* ─── Sidebars — default (compact + mobile): position:fixed overlays ─ */
.sidebar {
  position: fixed;
  top: 0;
  height: 100vh;
  z-index: 150;
  background: var(--sidebar-bg);
  overflow: hidden;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur);
}

#left-sidebar {
  left: 0;
  width: var(--sidebar-w);
  border-right: 1px solid var(--border-lt);
  transform: translateX(calc(-1 * var(--sidebar-w)));
}

#right-sidebar {
  right: 0;
  width: var(--sidebar-w);
  border-left: 1px solid var(--border-lt);
  transform: translateX(var(--sidebar-w));
}

/* ─── Sidebar content wrapper ────────────────────────────────── */
/* Default: fills the sidebar as an absolute overlay */
.sidebar-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Sidebar panels (collections / members) ─────────────────── */
.sidebar-panel { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* Compact/mobile: switch visible panel via data-mode attribute */
body.compact #left-sidebar[data-mode="collections"] #panel-members,
body.mobile  #left-sidebar[data-mode="collections"] #panel-members { display: none; }
body.compact #left-sidebar[data-mode="members"] #panel-collections,
body.mobile  #left-sidebar[data-mode="members"] #panel-collections { display: none; }

/* ─── Collapse tabs — hidden by default, shown in wide mode ──── */
.collapse-tab { display: none; }

/* ─── Sidebar header ─────────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: var(--header-h);
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  flex: 1;
  min-width: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-header-back {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0 0.25rem;
  border-radius: 4px;
  color: var(--text-dim);
  transition: color var(--dur), background var(--dur);
}
.sidebar-header-back:hover { color: var(--text); background: rgba(255,235,195,0.06); }
.sidebar-header-back .sidebar-title { color: inherit; }

.icon-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
  transition: color var(--dur), background var(--dur);
}
.icon-btn:hover { color: var(--text); background: rgba(255,235,195,0.06); }

/* Close/back buttons — only shown inside compact and mobile drawers */
.close-btn { display: none; }
body.compact .close-btn,
body.mobile  .close-btn { display: flex; }

/* ─── Sidebar scroll area ────────────────────────────────────── */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.375rem 0;
}
.sidebar-scroll::-webkit-scrollbar       { width: 3px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border-lt); border-radius: 2px; }

/* ─── Sidebar back-to-site link ──────────────────────────────── */
.sidebar-back-btn {
  display: block;
  flex-shrink: 0;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
  transition: background var(--dur), color var(--dur);
}
.sidebar-back-btn:hover { background: var(--sidebar-hov); color: var(--text); }

/* ─── Collection list items ──────────────────────────────────── */
.collection-item {
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--dur);
}
.collection-item:hover  { background: var(--sidebar-hov); }
.collection-item.active { background: var(--accent-glow); }

.item-title { font-size: 0.875rem; font-weight: 500; line-height: 1.3; color: var(--text); }
.collection-item.active .item-title { color: var(--accent); }
.item-meta  { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.2rem; }

.section-label {
  padding: 0.8rem 0.9rem 0.3rem;
  font-size: 0.63rem; font-weight: 700;
  letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--text-muted);
}

/* ─── Member list items ──────────────────────────────────────── */
.member-item {
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--dur);
}
.member-item:hover  { background: var(--sidebar-hov); }
.member-item.active { background: var(--accent-glow); }
.member-item.active .item-title { color: var(--accent); }

/* ─── Right sidebar empty state ──────────────────────────────── */
.right-empty {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ─── Welcome screen ─────────────────────────────────────────── */
#welcome[hidden] { display: none; }
#welcome {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.25rem;
  padding: 3rem 2rem;
  text-align: center;
  pointer-events: none; user-select: none;
}
.welcome-rule { width: 48px; height: 1px; background: var(--accent); opacity: 0.35; }
.welcome-title {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: clamp(2rem, 5vw, 3.25rem);
  font-weight: 400; color: var(--text); letter-spacing: 0.03em;
}
.welcome-sub { font-size: 0.875rem; color: var(--text-dim); max-width: 32ch; line-height: 1.65; }

/* ─── Story content + centering wrapper ──────────────────────── */
#story-content { flex: 1; display: flex; flex-direction: column; }

.story-inner {
  width: min(100%, 740px);
  margin: 0 auto;
  display: flex; flex-direction: column; flex: 1;
}

.story-header { padding: 2.5rem 2rem 1.75rem; border-bottom: 1px solid var(--border); }

.story-kicker {
  font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.6rem;
}

.story-title {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: clamp(1.6rem, 3.5vw, 2.4rem);
  font-weight: 400; color: var(--text); line-height: 1.2;
}

.story-meta { font-size: 0.73rem; color: var(--text-muted); margin-top: 0.6rem; }

/* ─── Story body prose ───────────────────────────────────────── */
.story-body {
  padding: 2.5rem 2rem 5rem;
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 1.175rem; line-height: 1.85; color: var(--text);
}
.story-body p  { margin-bottom: 1.2em; }
.story-body em { font-style: italic; }
.story-body strong { font-weight: 600; }
.story-body h1, .story-body h2, .story-body h3 {
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 400; color: var(--text);
  margin: 2em 0 0.75em; line-height: 1.25;
}
.story-body h2 { font-size: 1.4rem; }
.story-body h3 { font-size: 1.15rem; }
.story-body blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 1.25rem; color: var(--text-dim); font-style: italic; margin: 1.5em 0;
}
.story-body hr { border: none; text-align: center; color: var(--text-muted); margin: 2.25em 0; }
.story-body hr::after { content: '· · ·'; font-size: 1rem; letter-spacing: 0.4em; }

/* ─── Story nav (prev / next) ────────────────────────────────── */
.story-nav {
  display: flex;
  flex-shrink: 0;
}

#story-nav-top    { border-bottom: 1px solid var(--border); }
#story-nav-bottom { border-top:    1px solid var(--border); }

.story-nav-btn {
  flex: 1;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  cursor: pointer;
  text-align: left;
  transition: background var(--dur);
  min-width: 0;
}

.story-nav-btn.next { text-align: right; }

.story-nav-btn:hover { background: var(--sidebar-hov); }

.story-nav-btn + .story-nav-btn { border-left: 1px solid var(--border); }

.story-nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--accent);
}

.story-nav-title {
  font-size: 0.875rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loading-text {
  padding: 4rem 2rem; text-align: center;
  color: var(--text-dim); font-size: 0.875rem; font-family: system-ui, sans-serif;
}

/* ════════════════════════════════════════════════════════════════
   WIDE MODE (≥ 1100 px)
   Both sidebars are layout elements in a flex row. Full-height
   collapse tabs on the inner edges. No overlays, no hover zones.
════════════════════════════════════════════════════════════════ */
body.wide #app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

body.wide #main {
  flex: 1;
  min-width: 0;
  width: auto;
}

/* Override sidebars from fixed overlays to flex row items */
body.wide #left-sidebar,
body.wide #right-sidebar {
  position: relative;
  transform: none;
  height: 100vh;
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  transition: width var(--dur) var(--ease);
  box-shadow: none;
  z-index: auto;
}

body.wide #left-sidebar  { width: var(--sidebar-w); }
body.wide #right-sidebar { width: var(--sidebar-w); }

/* Sidebar content: override absolute to flex item */
body.wide #left-sidebar  .sidebar-content,
body.wide #right-sidebar .sidebar-content {
  position: relative;
  inset: auto;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--dur) var(--ease);
}

/* Wide left sidebar shows collections only */
body.wide #left-sidebar #panel-members { display: none; }

/* ─── Wide: collapse tabs ────────────────────────────────────── */
body.wide .collapse-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tab-w);
  flex-shrink: 0;
  height: 100%;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur), color var(--dur);
}

/* Left tab sits on the right edge of the left sidebar */
body.wide #left-sidebar .collapse-tab {
  border-left: 1px solid var(--border);
  order: 2;
}

/* Right tab sits on the left edge of the right sidebar */
body.wide #right-sidebar .collapse-tab {
  border-right: 1px solid var(--border);
  order: -1;
}

body.wide .collapse-tab:hover {
  background: rgba(255,235,195,0.06);
  color: var(--text);
}

/* ─── Wide: collapsed state ──────────────────────────────────── */
body.wide #left-sidebar.collapsed  { width: var(--tab-w); cursor: pointer; }
body.wide #right-sidebar.collapsed { width: var(--tab-w); cursor: pointer; }

body.wide #left-sidebar.collapsed  .sidebar-content,
body.wide #right-sidebar.collapsed .sidebar-content {
  opacity: 0;
  pointer-events: none;
}

body.wide #left-sidebar.collapsed:hover,
body.wide #right-sidebar.collapsed:hover { background: var(--sidebar-hov); }

body.wide #left-sidebar.collapsed:hover  .collapse-tab,
body.wide #right-sidebar.collapsed:hover .collapse-tab { color: var(--text); }

/* ─── Wide: chevron direction ────────────────────────────────── */
.tab-chevron { transform-origin: center; transition: transform var(--dur) var(--ease); }

/* Left tab: ‹ when expanded (collapse), › when collapsed (expand) */
#left-collapse-tab  .tab-chevron { transform: none; }
body.wide #left-sidebar.collapsed  #left-collapse-tab  .tab-chevron { transform: scaleX(-1); }

/* Right tab: › when expanded (collapse), ‹ when collapsed (expand) */
#right-collapse-tab .tab-chevron { transform: scaleX(-1); }
body.wide #right-sidebar.collapsed #right-collapse-tab .tab-chevron { transform: none; }

/* ════════════════════════════════════════════════════════════════
   COMPACT MODE (768 px – 1099 px)
   Left drawer. Full-height left-edge tab as the open trigger.
════════════════════════════════════════════════════════════════ */
body.compact #right-sidebar { display: none; }

body.compact #left-sidebar.open {
  transform: translateX(0);
  box-shadow: 4px 0 40px rgba(0,0,0,0.5);
}

/* Full-height left-edge tab */
#compact-tab {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: var(--tab-w);
  height: 100vh;
  z-index: 200;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-lt);
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}

#compact-tab:hover {
  background: var(--sidebar-hov);
  color: var(--text);
  border-right-color: var(--accent);
}

body.compact             #compact-tab { display: flex; }
body.compact.drawer-open #compact-tab { display: none; }

/* ════════════════════════════════════════════════════════════════
   MOBILE MODE (< 768 px)
   Right-side drawer. Pill tab at bottom-right as the open trigger.
════════════════════════════════════════════════════════════════ */
body.mobile #right-sidebar { display: none; }

/* Flip left sidebar to right side */
body.mobile #left-sidebar {
  left:  auto;
  right: 0;
  height: 100dvh;
  border-right: none;
  border-left: 1px solid var(--border-lt);
  transform: translateX(var(--sidebar-w));
}

body.mobile #left-sidebar.open {
  transform: translateX(0);
  box-shadow: -4px 0 40px rgba(0,0,0,0.5);
}

/* Pill tab at bottom-right */
#mobile-tab {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  right: 1rem;
  z-index: 200;
  padding: 0.55rem 0.85rem;
  background: var(--accent);
  color: #1a0e00;
  border-radius: 9999px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.45);
  align-items: center;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.3s var(--ease);
}

#mobile-tab:active { opacity: 0.75; }

body.mobile             #mobile-tab { display: flex; }
body.mobile.drawer-open #mobile-tab { display: none; }

/* Slide pill away when scrolling down */
body.mobile.scroll-down #mobile-tab {
  transform: translateY(calc(100% + 2rem));
  opacity: 0;
  pointer-events: none;
}

/* ─── Mobile: bottom-anchor nav via full-height spacer ──────────
   .nav-spacer is a direct flex child of .sidebar-scroll.
   flex-basis: 100% resolves against the scroll container's definite
   height, making the spacer one full container-height tall. This
   creates a scrollable range even when the real item list is short. */
.nav-spacer { display: none; }

body.mobile .nav-spacer {
  display: block;
  height: 100dvh;
}

/* ─── Mobile: header moves to bottom of panel ───────────────── */
body.mobile .sidebar-scroll  { order: 1; }
body.mobile .sidebar-header  { order: 2; border-bottom: none; border-top: 1px solid var(--border); }
body.mobile .sidebar-back-btn { order: 3; }

/* ─── Shared drawer backdrop ─────────────────────────────────── */
#backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 140;
  backdrop-filter: blur(2px);
}
body.drawer-open #backdrop { display: block; }

/* ─── Small screen adjustments ───────────────────────────────── */
@media (max-width: 500px) {
  :root { --sidebar-w: min(88vw, 300px); }
  .story-header { padding: 2rem 1.25rem 1.5rem; }
  .story-body   { padding: 2rem 1.25rem 4rem; font-size: 1.1rem; }
}

/* ─── Mobile: page-level scroll so browser address bar auto-hides ─
   Sidebars are position:fixed in mobile so they're unaffected.
   100svh uses the small viewport height (address bar visible) as
   the minimum, so there's always enough content to scroll. ────── */
html.mobile-layout,
html.mobile-layout body { height: auto; overflow-y: visible; }
html.mobile-layout #app  { height: auto; }
html.mobile-layout #main { height: auto; min-height: 100svh; overflow-y: visible; }
