/* =========================================================
   THE FOLIO — styles
   Mobile-first. Warm paper palette. Editorial typography.
   ========================================================= */

/* ---------- Tokens ---------- */
:root {
  /* Warm paper light theme (default daytime) */
  --paper:        #f4ead5;
  --paper-2:      #ede0c4;
  --paper-3:      #e4d4b1;
  --ink:          #1f1a14;
  --ink-2:        #3b3327;
  --ink-3:        #6b5d48;
  --ink-mute:     #8e7e64;
  --rust:         #b35a2b;
  --rust-2:       #8a4220;
  --amber:        #c98a2b;
  --sage:         #6f8a6a;
  --line:         rgba(31, 26, 20, 0.12);
  --line-strong:  rgba(31, 26, 20, 0.22);
  --shadow-1:     0 1px 2px rgba(31,26,20,0.04), 0 6px 22px rgba(31,26,20,0.06);
  --shadow-2:     0 2px 6px rgba(31,26,20,0.07), 0 18px 40px rgba(31,26,20,0.10);

  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --mono:  "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --hand:  "Caveat", cursive;

  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(201, 138, 43, 0.18), transparent 60%),
             radial-gradient(900px 600px at -10% 110%, rgba(179, 90, 43, 0.14), transparent 55%),
             linear-gradient(180deg, #f7eed9 0%, #f1e3c4 100%);
}

/* Afternoon — cool parchment */
[data-theme="afternoon"] {
  --paper:        #f1e7d2;
  --paper-2:      #e8d9b9;
  --paper-3:      #ddc99b;
  --bg-grad: radial-gradient(900px 500px at 100% 0%, rgba(159,125,72,0.18), transparent 55%),
             linear-gradient(180deg, #f1e7d2 0%, #e7d6b1 100%);
}

/* Evening / candlelit / dark */
[data-theme="dark"], [data-theme="evening"] {
  --paper:        #18130d;
  --paper-2:      #221a10;
  --paper-3:      #2a2014;
  --ink:          #f1e3c4;
  --ink-2:        #d8c79f;
  --ink-3:        #b3a07a;
  --ink-mute:     #8a7a5c;
  --rust:         #d68455;
  --rust-2:       #b06a3e;
  --amber:        #e0a754;
  --sage:         #9eb39a;
  --line:         rgba(241,227,196,0.10);
  --line-strong:  rgba(241,227,196,0.20);
  --shadow-1:     0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.45);
  --shadow-2:     0 2px 6px rgba(0,0,0,0.5), 0 24px 48px rgba(0,0,0,0.55);
  --bg-grad: radial-gradient(1000px 600px at 90% -10%, rgba(214,132,85,0.22), transparent 60%),
             radial-gradient(900px 600px at -10% 110%, rgba(214,132,85,0.10), transparent 55%),
             linear-gradient(180deg, #14100a 0%, #0e0a06 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--serif);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 17px;
  line-height: 1.55;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  background: var(--bg-grad);
  background-attachment: fixed;
  position: relative;
  /* leave room for bottom nav + safe area */
  padding-bottom: calc(88px + var(--safe-bottom));
}

/* ---------- Decorative paper background ---------- */
.paper-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden;
}
.paper-blob {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: .55;
  mix-blend-mode: multiply;
}
.blob-1 { width: 70vw; height: 70vw; max-width: 640px; max-height: 640px;
  top: -30%; right: -25%;
  background: radial-gradient(circle, rgba(201,138,43,0.6), rgba(201,138,43,0) 70%); }
.blob-2 { width: 80vw; height: 80vw; max-width: 720px; max-height: 720px;
  bottom: -35%; left: -30%;
  background: radial-gradient(circle, rgba(179,90,43,0.4), rgba(179,90,43,0) 70%); }
[data-theme="dark"] .paper-blob, [data-theme="evening"] .paper-blob { mix-blend-mode: screen; opacity: .35; }

.paper-grain {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(rgba(31,26,20,0.05) 1px, transparent 1px),
    radial-gradient(rgba(31,26,20,0.04) 1px, transparent 1px);
  background-size: 3px 3px, 7px 7px;
  background-position: 0 0, 1px 1px;
  opacity: .55;
}
[data-theme="dark"] .paper-grain, [data-theme="evening"] .paper-grain {
  background-image:
    radial-gradient(rgba(241,227,196,0.04) 1px, transparent 1px),
    radial-gradient(rgba(241,227,196,0.03) 1px, transparent 1px);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(244,234,213,0.85), rgba(244,234,213,0));
}
[data-theme="dark"] .topbar, [data-theme="evening"] .topbar {
  background: linear-gradient(180deg, rgba(20,16,10,0.85), rgba(20,16,10,0));
}

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(8px);
  font-family: var(--mono);
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
  cursor: pointer;
  transition: transform .25s ease, background .25s ease;
}
.pill:hover { transform: translateY(-1px); }
[data-theme="dark"] .pill, [data-theme="evening"] .pill {
  background: rgba(255,255,255,0.04);
}
.pill-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--rust);
  box-shadow: 0 0 0 4px rgba(179,90,43,0.18);
}

.icon-btn {
  appearance: none; border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(8px);
  color: var(--ink);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: var(--mono); font-size: 12px;
  transition: transform .2s ease, background .2s ease;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }
[data-theme="dark"] .icon-btn, [data-theme="evening"] .icon-btn {
  background: rgba(255,255,255,0.04);
}

/* ---------- Views ---------- */
.view { display: none; padding: 0 18px 32px; max-width: 880px; margin: 0 auto; }
.view.active { display: block; animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Hero ---------- */
.hero { padding: 36px 6px 8px; text-align: center; position: relative; }
.hero.hero-sm { padding: 22px 6px 4px; }
.eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 10px;
}
.hero-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(40px, 9.5vw, 64px);
  line-height: 1.02;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}
.hero-title.sm { font-size: clamp(32px, 7vw, 44px); }
.hero-sub {
  margin: 8px 0 0;
  color: var(--ink-3);
  font-style: italic;
  font-size: 16px;
}

/* ---------- Envelope ---------- */
.envelope-wrap {
  display: flex; flex-direction: column; align-items: center;
  margin: 28px auto 18px;
}
.envelope {
  appearance: none; background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 0;
}
.envelope-body {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 1.5 / 1;
  perspective: 1000px;
}
.envelope-front {
  position: absolute; inset: 0;
  border-radius: 6px;
  background: linear-gradient(160deg, #ecdcb6 0%, #d8c190 60%, #c4a878 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.4) inset,
    0 -1px 0 rgba(0,0,0,0.05) inset,
    var(--shadow-2);
  overflow: hidden;
}
.envelope-front::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(31,26,20,0.04) 0 6px, transparent 6px 12px);
  opacity: .5;
}
.envelope-flap {
  position: absolute; top: 0; left: 0; right: 0;
  height: 65%;
  background: linear-gradient(170deg, #e6d2a4 0%, #c9ad77 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform .9s cubic-bezier(.6,.05,.3,1);
  z-index: 2;
  filter: drop-shadow(0 4px 10px rgba(31,26,20,0.18));
}
.envelope.opening .envelope-flap { transform: rotateX(170deg); }
.envelope.opening .wax-seal { opacity: 0; transform: translate(-50%,-50%) scale(.7); }

.wax-seal {
  position: absolute; left: 50%; top: 60%;
  transform: translate(-50%,-50%);
  width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c9532e, #7a2d15);
  display: flex; align-items: center; justify-content: center;
  color: #f6dcc1; font-family: var(--serif); font-style: italic;
  font-size: 28px;
  box-shadow: 0 6px 16px rgba(122,45,21,0.5), inset 0 -3px 8px rgba(0,0,0,0.4), inset 0 3px 6px rgba(255,255,255,0.2);
  z-index: 3;
  transition: opacity .4s ease, transform .4s ease;
}
.wax-seal::after {
  content: ""; position: absolute; inset: 4px; border-radius: 50%;
  border: 1px dashed rgba(246,220,193,0.35);
}

.envelope-caption {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-3); margin: 0;
}

.streak-row {
  display: flex; gap: 10px; justify-content: center; margin-top: 10px;
}
.streak-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.4);
  border: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  letter-spacing: 0.06em;
}
[data-theme="dark"] .streak-chip, [data-theme="evening"] .streak-chip {
  background: rgba(255,255,255,0.04);
}

/* ---------- Block / sections ---------- */
.block { margin: 28px 0; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.block-title {
  font-family: var(--serif); font-weight: 500;
  font-size: 22px; margin: 0; letter-spacing: -0.01em;
}
.block-sub { color: var(--ink-3); margin: -4px 0 12px; font-size: 14px; font-style: italic; }
.link-btn {
  appearance: none; background: none; border: 0; cursor: pointer;
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--rust);
}
.meta-chip {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
}

/* ---------- Featured / weekly ---------- */
.featured-slot {
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(255,255,255,0.55), rgba(255,255,255,0.25));
  border: 1px solid var(--line);
  padding: 18px;
  min-height: 100px;
  box-shadow: var(--shadow-1);
}
[data-theme="dark"] .featured-slot, [data-theme="evening"] .featured-slot {
  background: linear-gradient(160deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
}
.featured-slot.empty { display:flex; align-items:center; justify-content:center; }
.empty-msg { color: var(--ink-3); font-style: italic; margin: 0; }

/* ---------- Mood grid (echoes the mockup's tile feel) ---------- */
.mood-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.mood-card {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255,255,255,0.55), rgba(255,255,255,0.2));
  border-radius: var(--radius);
  padding: 16px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-2);
  transition: transform .2s ease, background .2s ease;
}
.mood-card:hover { transform: translateY(-2px); }
.mood-glyph { font-family: var(--serif); font-size: 28px; color: var(--rust); }
[data-theme="dark"] .mood-card, [data-theme="evening"] .mood-card {
  background: linear-gradient(160deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
}

/* ---------- Horizontal scroll rails ---------- */
.hscroll {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding: 4px 2px 14px;
  scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; flex: 0 0 auto; }

/* ---------- Search & filters ---------- */
.search-wrap {
  position: relative; display: flex; align-items: center; gap: 8px;
  margin: 6px 0 12px;
}
.search-icon {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3);
}
.search-input {
  flex: 1;
  padding: 12px 14px 12px 40px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  font-family: var(--serif);
  font-size: 16px;
  color: var(--ink);
  outline: none;
  transition: border-color .2s ease;
}
.search-input:focus { border-color: var(--rust); }
[data-theme="dark"] .search-input, [data-theme="evening"] .search-input {
  background: rgba(255,255,255,0.04);
}

.filter-row {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 0 8px; scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  appearance: none; cursor: pointer;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.4);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
  transition: all .2s ease;
}
.filter-chip.active {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
[data-theme="dark"] .filter-chip, [data-theme="evening"] .filter-chip {
  background: rgba(255,255,255,0.04);
}
[data-theme="dark"] .filter-chip.active, [data-theme="evening"] .filter-chip.active {
  background: var(--paper); color: var(--ink); border-color: var(--paper);
}

.advanced-filters {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  margin-bottom: 12px;
}
.mini-select {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em;
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.4);
  color: var(--ink-2);
}
[data-theme="dark"] .mini-select, [data-theme="evening"] .mini-select {
  background: rgba(255,255,255,0.04);
}

/* ---------- Library grid ---------- */
.library-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}
@media (min-width: 600px) { .library-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .library-grid { grid-template-columns: 1fr 1fr 1fr; } }

.library-grid.list-mode { grid-template-columns: 1fr !important; }

.piece-card {
  position: relative;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(255,255,255,0.6), rgba(255,255,255,0.25));
  border: 1px solid var(--line);
  padding: 18px 18px 18px 22px;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform .2s ease, box-shadow .2s ease;
  overflow: hidden;
}
.piece-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--rust);
}
.piece-card[data-type="poem"]::before { background: var(--sage); }
.piece-card[data-type="short story"]::before { background: var(--rust); }
.piece-card[data-type="essay"]::before { background: var(--amber); }
.piece-card[data-type="other"]::before { background: var(--ink-mute); }
.piece-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }

[data-theme="dark"] .piece-card, [data-theme="evening"] .piece-card {
  background: linear-gradient(160deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
}

.piece-type {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 4px;
}
.piece-title {
  font-family: var(--serif); font-weight: 500; font-size: 22px;
  margin: 0 0 4px; letter-spacing: -0.01em; line-height: 1.15;
}
.piece-author { color: var(--ink-3); margin: 0 0 8px; font-style: italic; font-size: 14px; }
.piece-excerpt {
  font-size: 14px; color: var(--ink-2); margin: 0;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.piece-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; gap: 10px;
}
.piece-tags {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.piece-tag {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(31,26,20,0.06); color: var(--ink-2);
}
[data-theme="dark"] .piece-tag, [data-theme="evening"] .piece-tag {
  background: rgba(255,255,255,0.06);
}
.piece-fav {
  color: var(--rust); font-size: 14px;
}
.piece-dedication {
  font-family: var(--hand); font-size: 18px; color: var(--rust-2);
  margin: 8px 0 0; line-height: 1.1;
}
.piece-passed {
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
  margin-top: 4px;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(96px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2);
  z-index: 25;
  transition: transform .25s ease;
}
.fab:hover { transform: scale(1.05); }
[data-theme="dark"] .fab, [data-theme="evening"] .fab {
  background: var(--rust); color: var(--paper);
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: calc(14px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px;
  padding: 6px;
  background: rgba(255,255,255,0.65);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  z-index: 40;
}
[data-theme="dark"] .bottom-nav, [data-theme="evening"] .bottom-nav {
  background: rgba(20,16,10,0.7);
}
.nav-btn {
  appearance: none; cursor: pointer; border: 0;
  background: transparent;
  color: var(--ink-2);
  width: 60px; height: 56px;
  border-radius: 999px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all .25s ease;
}
.nav-btn span { opacity: 0; height: 0; transition: all .25s ease; }
.nav-btn.active {
  background: var(--ink); color: var(--paper);
  width: 96px;
}
.nav-btn.active span { opacity: 1; height: auto; margin-top: 2px; }
[data-theme="dark"] .nav-btn.active, [data-theme="evening"] .nav-btn.active {
  background: var(--rust); color: var(--paper);
}

/* ---------- Discover ---------- */
.discover-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin: 20px 0 8px;
}
.big-btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255,255,255,0.6), rgba(255,255,255,0.25));
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: left;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow-1);
  color: var(--ink);
  transition: transform .2s ease, box-shadow .2s ease;
  min-height: 130px;
}
.big-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.big-btn-glyph { font-family: var(--serif); font-size: 30px; color: var(--rust); }
.big-btn-label { font-family: var(--serif); font-size: 20px; }
.big-btn-sub { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.big-btn.alt { background: linear-gradient(160deg, rgba(179,90,43,0.15), rgba(201,138,43,0.08)); }
[data-theme="dark"] .big-btn, [data-theme="evening"] .big-btn {
  background: linear-gradient(160deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
}
[data-theme="dark"] .big-btn.alt, [data-theme="evening"] .big-btn.alt {
  background: linear-gradient(160deg, rgba(214,132,85,0.18), rgba(214,132,85,0.06));
}

/* ---------- Shelves ---------- */
.shelves-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
@media (min-width: 700px) { .shelves-grid { grid-template-columns: repeat(3, 1fr); } }
.shelf-card {
  position: relative;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px;
  min-height: 120px;
  display: flex; flex-direction: column; justify-content: space-between;
  color: var(--paper);
  overflow: hidden;
  text-align: left;
  appearance: none;
  font-family: inherit;
}
.shelf-cover-1 { background: linear-gradient(160deg, #b35a2b, #8a4220); }
.shelf-cover-2 { background: linear-gradient(160deg, #6f8a6a, #4a6647); }
.shelf-cover-3 { background: linear-gradient(160deg, #c98a2b, #8a5d18); }
.shelf-cover-4 { background: linear-gradient(160deg, #1f1a14, #3b3327); }
.shelf-cover-5 { background: linear-gradient(160deg, #d8c190, #a98e58); color: var(--ink); }
.shelf-cover-6 { background: linear-gradient(160deg, #6e4d3a, #3d2a20); }
.shelf-card::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0 4px, transparent 4px 8px);
  pointer-events: none;
}
.shelf-name { font-family: var(--serif); font-size: 22px; margin: 0; }
.shelf-meta { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; opacity: .8; }

.shelves-rail .shelf-card { width: 160px; }
.ghost-btn {
  appearance: none; cursor: pointer;
  background: transparent; color: var(--ink);
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 12px 16px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  margin-top: 12px;
  transition: all .2s ease;
}
.ghost-btn:hover { background: rgba(31,26,20,0.05); }
.ghost-btn.sm { padding: 8px 12px; font-size: 10px; }
.ghost-btn.danger { color: var(--rust-2); border-color: rgba(138,66,32,0.4); }

.solid-btn {
  appearance: none; cursor: pointer;
  background: var(--ink); color: var(--paper);
  border: 0; border-radius: 12px;
  padding: 12px 22px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  transition: transform .2s ease;
}
.solid-btn:hover { transform: translateY(-1px); }
.solid-btn.sm { padding: 8px 14px; font-size: 10px; }
[data-theme="dark"] .solid-btn, [data-theme="evening"] .solid-btn {
  background: var(--rust); color: var(--paper);
}

/* ---------- Stats ---------- */
.stat-tiles {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-top: 18px;
}
@media (min-width: 600px) { .stat-tiles { grid-template-columns: repeat(4, 1fr); } }
.stat-tile {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255,255,255,0.5), rgba(255,255,255,0.2));
  padding: 18px;
  text-align: center;
}
[data-theme="dark"] .stat-tile, [data-theme="evening"] .stat-tile {
  background: linear-gradient(160deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
}
.stat-num { font-family: var(--serif); font-size: 32px; margin: 0; color: var(--ink); }
.stat-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); margin: 4px 0 0; }

.balance-wheel {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
@media (min-width: 600px) { .balance-wheel { flex-direction: row; align-items: center; justify-content: center; gap: 32px; } }
.balance-legend { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

.passport {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.passport-pin {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(179,90,43,0.12); color: var(--rust-2);
  border: 1px solid rgba(179,90,43,0.25);
  cursor: pointer;
}

.badges-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
@media (min-width: 600px) { .badges-grid { grid-template-columns: repeat(4, 1fr); } }
.badge-card {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.4);
  padding: 14px;
  text-align: center;
  opacity: .35;
  transition: opacity .3s ease;
}
.badge-card.earned { opacity: 1; background: rgba(201,138,43,0.12); border-color: rgba(201,138,43,0.4); }
.badge-glyph { font-family: var(--serif); font-size: 28px; color: var(--rust); }
.badge-name { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; margin: 4px 0 0; color: var(--ink-2); }

/* ---------- Reader ---------- */
.reader {
  position: fixed; inset: 0; z-index: 60;
  background: var(--paper);
  background-image: var(--bg-grad);
  overflow-y: auto;
  display: none;
  padding-bottom: 60px;
}
.reader.active { display: block; animation: fadeIn .35s ease; }

.reader-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  backdrop-filter: blur(10px);
  background: linear-gradient(180deg, rgba(244,234,213,0.82), rgba(244,234,213,0));
}
[data-theme="dark"] .reader-bar, [data-theme="evening"] .reader-bar {
  background: linear-gradient(180deg, rgba(20,16,10,0.85), rgba(20,16,10,0));
}
.reader-bar h3 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 18px; }
.reader-bar-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.reader-bar-controls .icon-btn { width: 36px; height: 36px; }

.reader-content {
  max-width: 640px; margin: 0 auto; padding: 30px 22px 40px;
  font-size: var(--reader-fs, 19px);
  line-height: 1.65;
}
.reader-content[data-font="mono"] { font-family: var(--mono); }
.reader-eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--rust); margin: 0 0 12px; }
.reader-title { font-family: var(--serif); font-weight: 500; font-size: 36px; margin: 0 0 6px; line-height: 1.1; }
.reader-author { font-style: italic; color: var(--ink-3); margin: 0 0 18px; font-size: 16px; }
.reader-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 24px; }
.reader-text {
  font-family: inherit;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.reader-text p { margin: 0 0 1em; }
.reader-text mark.hl {
  background: rgba(201,138,43,0.28);
  padding: 0 2px;
  border-radius: 2px;
  cursor: pointer;
}
.reader-text mark.hl[data-note]::after {
  content: "•"; color: var(--rust); margin-left: 2px; font-weight: bold;
}

.reader-foot {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--line);
}
.reader-journal {
  margin-top: 24px;
}
.journal-entry {
  border-left: 3px solid var(--rust);
  padding: 8px 14px;
  margin: 8px 0;
  background: rgba(255,255,255,0.3);
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--ink-2);
}
.journal-date {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-3); display: block; margin-bottom: 4px;
}
.reader-highlights {
  margin-top: 24px;
}
.hl-card {
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 12px;
  margin: 8px 0;
  background: rgba(201,138,43,0.06);
}
.hl-card .hl-passage { font-style: italic; }
.hl-card .hl-note { font-family: var(--hand); font-size: 18px; color: var(--rust-2); margin-top: 6px; }

/* Selection toolbar */
.sel-toolbar {
  position: fixed; z-index: 80;
  background: var(--ink); color: var(--paper);
  border-radius: 10px;
  padding: 6px;
  display: none; gap: 4px;
  box-shadow: var(--shadow-2);
}
.sel-toolbar.active { display: flex; }
.sel-toolbar button {
  appearance: none; background: transparent; color: var(--paper);
  border: 0; cursor: pointer;
  padding: 6px 10px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  border-radius: 6px;
}
.sel-toolbar button:hover { background: rgba(255,255,255,0.1); }

/* Ambience tray */
.ambience-tray {
  position: fixed; bottom: calc(20px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  display: none; gap: 6px;
  padding: 8px;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(20px);
  border-radius: 999px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  z-index: 70;
}
.ambience-tray.active { display: flex; }
[data-theme="dark"] .ambience-tray, [data-theme="evening"] .ambience-tray {
  background: rgba(20,16,10,0.8);
}
.amb-btn {
  appearance: none; cursor: pointer;
  background: transparent; color: var(--ink-2);
  border: 0; border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
}
.amb-btn.active { background: var(--ink); color: var(--paper); }
[data-theme="dark"] .amb-btn.active, [data-theme="evening"] .amb-btn.active {
  background: var(--rust); color: var(--paper);
}

/* ---------- Sheet (form) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(31,26,20,0.4);
  display: none;
  align-items: flex-end; justify-content: center;
  backdrop-filter: blur(4px);
}
.sheet.active { display: flex; animation: fadeIn .25s ease; }
.sheet-card {
  background: var(--paper);
  background-image: var(--bg-grad);
  width: 100%; max-width: 700px;
  max-height: 92vh;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 14px 22px calc(28px + var(--safe-bottom));
  overflow-y: auto;
  box-shadow: var(--shadow-2);
  animation: slideUp .35s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 42px; height: 4px; background: var(--ink-mute); border-radius: 999px; margin: 4px auto 14px; opacity: .35; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 26px; }

.url-import {
  display: flex; gap: 6px; margin-bottom: 18px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.4);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.url-import input {
  flex: 1; border: 0; background: transparent;
  font-family: var(--mono); font-size: 12px; outline: none; color: var(--ink);
}
[data-theme="dark"] .url-import, [data-theme="evening"] .url-import {
  background: rgba(255,255,255,0.04);
}

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-3);
}
.field > span em { font-style: normal; opacity: .6; text-transform: none; letter-spacing: 0; font-size: 11px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.5);
  border-radius: 12px;
  font-family: var(--serif);
  font-size: 16px;
  color: var(--ink);
  outline: none;
  transition: border-color .2s ease;
  resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--rust); }
[data-theme="dark"] .field input, [data-theme="dark"] .field select, [data-theme="dark"] .field textarea,
[data-theme="evening"] .field input, [data-theme="evening"] .field select, [data-theme="evening"] .field textarea {
  background: rgba(255,255,255,0.04);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-foot { display: flex; justify-content: space-between; margin-top: 16px; gap: 10px; }
.form-section { font-family: var(--serif); font-weight: 500; font-size: 18px; margin: 12px 0 4px; }
.form-section.danger-section { color: var(--rust-2); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Poster ---------- */
.poster-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: var(--paper); background-image: var(--bg-grad);
  display: none; flex-direction: column;
}
.poster-overlay.active { display: flex; animation: fadeIn .25s ease; }
.poster-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.poster-bar h3 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 18px; }
.poster-stage {
  flex: 1; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.poster-canvas {
  width: min(360px, 90vw);
  aspect-ratio: 4 / 5;
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
  position: relative;
  background: #f4ead5;
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  text-align: center;
}
.poster-canvas .pq { font-family: var(--serif); font-style: italic; font-size: 22px; line-height: 1.35; }
.poster-canvas .pa { font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; margin-top: 18px; }

.poster-controls {
  padding: 14px 16px calc(20px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}
.poster-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.poster-tabs::-webkit-scrollbar { display: none; }
.poster-tab {
  appearance: none; cursor: pointer;
  padding: 8px 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.4);
  border-radius: 999px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}
.poster-tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.palette-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.palette-row::-webkit-scrollbar { display: none; }
.palette-swatch {
  appearance: none; cursor: pointer;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  flex: 0 0 auto;
}
.palette-swatch.active { border-color: var(--ink); }

/* ---------- Swipe ---------- */
.swipe-overlay {
  position: fixed; inset: 0; z-index: 75;
  background: var(--paper); background-image: var(--bg-grad);
  display: none; flex-direction: column;
}
.swipe-overlay.active { display: flex; animation: fadeIn .25s ease; }
.swipe-stage {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.swipe-card {
  position: absolute;
  width: min(90vw, 380px);
  height: min(70vh, 540px);
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, rgba(255,255,255,0.7), rgba(255,255,255,0.4));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  padding: 28px;
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform .3s ease, opacity .3s ease;
  cursor: grab;
  user-select: none;
}
[data-theme="dark"] .swipe-card, [data-theme="evening"] .swipe-card {
  background: linear-gradient(160deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
}
.swipe-card.dragging { transition: none; cursor: grabbing; }
.swipe-card .sc-type { font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--rust); margin: 0 0 10px; }
.swipe-card .sc-title { font-family: var(--serif); font-weight: 500; font-size: 28px; margin: 0 0 6px; line-height: 1.1; }
.swipe-card .sc-author { font-style: italic; color: var(--ink-3); margin: 0 0 14px; }
.swipe-card .sc-text { flex: 1; overflow: hidden; font-size: 15px; line-height: 1.5; color: var(--ink-2);
  display: -webkit-box; -webkit-line-clamp: 12; -webkit-box-orient: vertical;
}
.swipe-card .stamp {
  position: absolute; top: 24px;
  font-family: var(--mono); font-size: 18px; letter-spacing: 0.2em; text-transform: uppercase;
  border: 3px solid currentColor; padding: 4px 12px; border-radius: 6px;
  opacity: 0;
  transform: rotate(-8deg);
}
.swipe-card .stamp.fav { right: 24px; color: var(--sage); transform: rotate(8deg); }
.swipe-card .stamp.skip { left: 24px; color: var(--rust-2); }
.swipe-card.right .stamp.fav { opacity: 1; }
.swipe-card.left .stamp.skip { opacity: 1; }

.swipe-hint {
  display: flex; gap: 24px; justify-content: center;
  padding: 14px 0 calc(20px + var(--safe-bottom));
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- Daily letter overlay (paper view) ---------- */
.letter-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(31,26,20,0.5);
  display: none;
  align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
  padding: 20px;
}
.letter-overlay.active { display: flex; animation: fadeIn .35s ease; }
.letter-paper {
  width: 100%; max-width: 540px;
  max-height: 88vh;
  background: #f6e9c8;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(31,26,20,0.06) 31px 32px);
  padding: 36px 32px;
  border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
  font-family: var(--serif);
  color: var(--ink);
  overflow-y: auto;
  position: relative;
  animation: unfold .8s cubic-bezier(.2,.8,.2,1);
}
@keyframes unfold {
  0% { transform: scale(.6) rotate(-2deg); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.letter-paper .l-title { font-size: 32px; font-weight: 500; margin: 0 0 4px; line-height: 1.1; }
.letter-paper .l-author { font-style: italic; color: var(--ink-3); margin: 0 0 18px; }
.letter-paper .l-text { white-space: pre-wrap; font-size: 17px; line-height: 1.7; }
.letter-paper .l-foot { margin-top: 22px; display: flex; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(110px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper);
  padding: 12px 18px;
  border-radius: 999px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em;
  box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 100;
}
.toast.active { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Reader more menu ---------- */
.more-menu {
  position: fixed;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow-2);
  z-index: 90;
  display: none; flex-direction: column;
  min-width: 180px;
}
.more-menu.active { display: flex; animation: fadeIn .15s ease; }
.more-menu button {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: 10px 14px;
  text-align: left;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-2);
  border-radius: 8px;
}
.more-menu button:hover { background: rgba(31,26,20,0.06); }

/* ---------- Desktop tweaks ---------- */
@media (min-width: 760px) {
  .topbar { padding: calc(var(--safe-top) + 18px) 28px 14px; }
  .view { padding: 0 28px 40px; }
  .hero { padding-top: 48px; }
  .bottom-nav {
    /* keep as floating dock even on desktop — true to the inspiration */
  }
}

/* Ensure nav button labels show on mobile too — already handled by .active */

/* ---------- Tag pill mood-coded for filter ---------- */
.mood-card.active {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
.mood-card.active .mood-glyph { color: var(--paper); }
[data-theme="dark"] .mood-card.active, [data-theme="evening"] .mood-card.active {
  background: var(--rust);
}

/* ---------- Print-y feel — drop caps in reader ---------- */
.reader-text > p:first-child::first-letter {
  font-size: 3.6em;
  float: left;
  line-height: 0.85;
  padding: 6px 8px 0 0;
  font-family: var(--serif);
  font-weight: 600;
  color: var(--rust);
}

/* ---------- Hide scrollbars on hscroll overscroll ---------- */
@supports (-webkit-touch-callout: none) {
  .reader { -webkit-overflow-scrolling: touch; }
}
