:root {
  --paper: #F9F7F2;
  --raised: #FCFAF5;
  --ink: #2C2C2C;
  --accent: #C07F56;
  --muted: #8E8C89;
  --edge: rgba(192, 127, 86, 0.22);
  --shade: rgba(44, 44, 44, 0.38);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Noto Serif", "Droid Serif", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #000000;
    --raised: #121212;
    --ink: #E6E6E6;
    --accent: #B5B5B5;
    --muted: #7C7C7C;
    --edge: rgba(181, 181, 181, 0.2);
    --shade: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #000000;
  --raised: #121212;
  --ink: #E6E6E6;
  --accent: #B5B5B5;
  --muted: #7C7C7C;
  --edge: rgba(181, 181, 181, 0.2);
  --shade: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

svg { display: block; }

/* ---------- Feed ---------- */

.feed {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  scrollbar-width: none;
  outline: none;
}
.feed::-webkit-scrollbar { display: none; }

.loading {
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.6;
}

.card {
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 96px max(28px, env(safe-area-inset-right)) 120px max(28px, env(safe-area-inset-left));
  text-align: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.card .inner { max-width: 640px; width: 100%; }

.quote {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  color: var(--ink);
  line-height: 1.42;
  font-size: clamp(1.7rem, 2.3vw + 1.2rem, 2.6rem);
  text-wrap: pretty;
}
.quote.m { font-size: clamp(1.5rem, 1.8vw + 1.05rem, 2.2rem); }
.quote.l { font-size: clamp(1.3rem, 1.4vw + 0.95rem, 1.9rem); }
.quote.xl { font-size: clamp(1.15rem, 1vw + 0.9rem, 1.6rem); }

.w { border-radius: 4px; transition: background-color 120ms ease; }
.w.held { background: var(--edge); }

.author {
  margin-top: 1.6em;
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 6px 4px;
}

.era {
  margin-top: 6px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* First-visit welcome card */
.welcome h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.6rem, 4vw + 1.6rem, 3.8rem);
  letter-spacing: 0.02em;
}
.welcome .tag {
  margin: 0.6em 0 2em;
  font-family: var(--serif);
  font-size: 1.25rem;
  color: var(--muted);
}
.welcome ul {
  list-style: none;
  padding: 0;
  margin: 0 auto;
  display: grid;
  gap: 14px;
  max-width: 360px;
  text-align: left;
  font-size: 1rem;
  line-height: 1.45;
}
.welcome li { display: flex; gap: 14px; align-items: baseline; }
.welcome li b { color: var(--accent); font-weight: 600; min-width: 108px; }
.welcome .swipe {
  margin-top: 2.8em;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  animation: nudge 2.4s ease-in-out infinite;
}
@keyframes nudge {
  0%, 100% { transform: translateY(0); opacity: 0.55; }
  50% { transform: translateY(-6px); opacity: 1; }
}

.end h2 { font-family: var(--serif); font-weight: 400; font-size: 1.8rem; margin: 0 0 0.5em; }
.end p { color: var(--muted); line-height: 1.5; }
.end button { margin-top: 1em; color: var(--accent); letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.85rem; }

/* ---------- Chrome ---------- */

.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 22px 0;
  pointer-events: none;
  z-index: 5;
}
.top > * { pointer-events: auto; }

.wordmark {
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 4px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--paper);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.pill svg { width: 17px; height: 17px; }
.pill .fill { fill: var(--accent); }

.bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 34px max(22px, env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 5;
}
.bottom > * { pointer-events: auto; }

.icon-btn { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; }
.icon-btn svg {
  width: 28px; height: 28px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}
#share-btn svg circle { fill: var(--accent); stroke: none; }
#save-btn[aria-pressed="true"] svg { fill: var(--accent); }
.icon-btn:active { transform: scale(0.92); }

.burst {
  position: fixed;
  top: 50%; left: 50%;
  width: 92px; height: 92px;
  margin: -46px 0 0 -46px;
  pointer-events: none;
  opacity: 0;
  z-index: 6;
}
.burst svg { width: 100%; height: 100%; fill: var(--accent); }
.burst.unsave svg { fill: none; stroke: var(--accent); stroke-width: 1.4; }
.burst.go { animation: burst 700ms cubic-bezier(.2,.9,.3,1.2) forwards; }
@keyframes burst {
  0% { opacity: 0; transform: scale(0.4); }
  25% { opacity: 0.95; transform: scale(1.08); }
  60% { opacity: 0.95; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1); }
}

.gloss {
  position: fixed;
  z-index: 20;
  max-width: min(320px, calc(100vw - 32px));
  padding: 12px 16px;
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  font-size: 0.95rem;
  line-height: 1.45;
  text-align: left;
}
.gloss b { display: block; font-family: var(--serif); font-size: 1.1rem; font-weight: 600; margin-bottom: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
  z-index: 30;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--shade);
  z-index: 10;
  opacity: 0;
  transition: opacity 220ms ease;
}
.scrim.show { opacity: 1; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 86vw);
  background: var(--paper);
  border-left: 1px solid var(--edge);
  z-index: 11;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(.2,.8,.2,1);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer.show { transform: none; }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 28px 22px 18px 26px;
  border-bottom: 1px solid var(--edge);
}
.drawer-head h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 1.9rem; }

.close { width: 44px; height: 44px; display: grid; place-items: center; }
.close svg { width: 24px; height: 24px; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; fill: none; }

.drawer-body { flex: 1; overflow-y: auto; padding: 4px 22px 12px; overscroll-behavior: contain; }

.empty { color: var(--muted); line-height: 1.6; padding: 28px 4px; }

.era-group { border-bottom: 1px solid var(--edge); }
.era-head {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 18px 4px;
  text-align: left;
}
.era-head .name { flex: 1; font-family: var(--serif); font-size: 1.2rem; }
.era-head .count { color: var(--accent); font-size: 0.9rem; margin-right: 12px; }
.era-head svg { width: 18px; height: 18px; stroke: var(--muted); stroke-width: 2; fill: none; transition: transform 200ms ease; }
.era-group.open .era-head svg { transform: rotate(180deg); }
.era-items { display: none; padding: 0 0 12px; }
.era-group.open .era-items { display: block; }

.saved-item {
  background: var(--raised);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 16px 16px 10px;
  margin: 0 0 10px;
}
.saved-item p { margin: 0; font-family: var(--serif); font-size: 1.05rem; line-height: 1.5; }
.saved-item .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.saved-item .remove { color: var(--muted); padding: 8px 0 8px 12px; letter-spacing: 0.12em; }

.drawer-foot { padding: 14px 26px 20px; border-top: 1px solid var(--edge); font-size: 0.85rem; }
.drawer-foot .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.drawer-foot .row + .row { margin-top: 10px; }
.link { color: var(--muted); letter-spacing: 0.08em; padding: 6px 0; }
.link:hover { color: var(--accent); }
.note { color: var(--muted); opacity: 0.75; font-size: 0.78rem; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 86vh;
  max-height: 86dvh;
  margin: 0 auto;
  width: min(640px, 100%);
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  z-index: 11;
  padding: 10px 28px calc(28px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 260ms cubic-bezier(.2,.8,.2,1);
  overscroll-behavior: contain;
}
.sheet.show { transform: none; }
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--edge); margin: 4px auto 18px; }

.sheet h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 1.9rem; }
.sheet h3 {
  margin: 1.8em 0 0.6em;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.sheet p, .sheet li { line-height: 1.6; font-size: 1rem; }
.sheet .lede { font-family: var(--serif); font-size: 1.2rem; color: var(--muted); margin-top: 0.3em; }
.sheet .how { padding-left: 1.1em; margin: 0; }
.sheet .how li { margin: 6px 0; }
.sheet .fine { color: var(--muted); font-size: 0.85rem; margin-top: 2em; }
.sheet a { color: var(--accent); }

.bio-era { margin: 4px 0 0; color: var(--muted); letter-spacing: 0.08em; font-size: 0.85rem; }
.bio { font-family: var(--serif); font-size: 1.15rem; line-height: 1.55; margin: 1.2em 0 0; }
.more-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 0;
  border-top: 1px solid var(--edge);
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.5;
}
.more-item:last-child { border-bottom: 1px solid var(--edge); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .feed { scroll-behavior: auto; }
}

@media (hover: hover) and (min-width: 900px) {
  .top { padding: 22px 34px 0; }
  .bottom { left: 50%; right: auto; width: 560px; transform: translateX(-50%); padding-bottom: 28px; }
}

body.on-welcome .bottom { opacity: 0; pointer-events: none; }
.bottom { transition: opacity 200ms ease; }
