/* ============================================
   READNEXT
   A quiet digital bookshelf: warm paper, soft ink, cloth-bound covers.
   Calm on purpose. No streaks, no stats, no dashboard energy.
   ============================================ */

:root {
  --rn-paper: #F5EFE4;
  --rn-paper-deep: #ECE3D3;
  --rn-card: #FBF7F0;
  --rn-ink: #2B2420;
  --rn-soft: #5E534B;
  --rn-muted: #8C8077;
  --rn-line: rgba(43, 36, 32, 0.14);
  --rn-accent: #B5573B;
  --rn-accent-deep: #97452D;
  --rn-sage: #6F8B6A;
  --rn-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --rn-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --rn-shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 8px 24px rgba(43, 36, 32, 0.07);
  --rn-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.17 0 0 0 0 0.14 0 0 0 0 0.12 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --rn-paper: #1F1B18;
    --rn-paper-deep: #2A2420;
    --rn-card: #29231F;
    --rn-ink: #F1E9DC;
    --rn-soft: #CBBFB1;
    --rn-muted: #9A8E82;
    --rn-line: rgba(241, 233, 220, 0.14);
    --rn-accent: #D9795B;
    --rn-accent-deep: #E48E71;
    --rn-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
  /* The accent is lighter in the dark, so its buttons take dark text. */
  .rn-btn:not(.rn-btn--ghost) { color: #1F1B18; }
}

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

body {
  font-family: var(--rn-sans);
  color: var(--rn-soft);
  background: var(--rn-paper) var(--rn-grain);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; }

.rn-visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.rn-page {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 1.25rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Top --- */
.rn-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 0;
}

.rn-back { font-size: 0.85rem; color: var(--rn-muted); text-decoration: none; }
.rn-back:hover { color: var(--rn-ink); }

.rn-brand {
  font-family: var(--rn-serif);
  font-size: 1.3rem;
  font-weight: 600;
  font-style: italic;
  color: var(--rn-ink);
}

.rn-main { flex: 1; }

/* --- Hero --- */
.rn-hero { text-align: center; padding: clamp(2rem, 7vw, 4rem) 0 1.75rem; }

.rn-title {
  font-family: var(--rn-serif);
  font-weight: 500;
  font-size: clamp(2.3rem, 7vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--rn-ink);
  margin-bottom: 1rem;
}

.rn-lede {
  font-family: var(--rn-serif);
  font-size: clamp(1.1rem, 2.4vw, 1.3rem);
  line-height: 1.5;
  max-width: 34rem;
  margin: 0 auto;
}

.rn-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--rn-accent);
  margin-bottom: 0.4rem;
}

.rn-h2 {
  font-family: var(--rn-serif);
  font-weight: 500;
  font-size: 1.6rem;
  color: var(--rn-ink);
}

/* --- Buttons --- */
.rn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 11px 20px;
  border: 1px solid var(--rn-accent);
  border-radius: 999px;
  background: var(--rn-accent);
  color: #FFF8F0;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.rn-btn:hover { background: var(--rn-accent-deep); border-color: var(--rn-accent-deep); }
.rn-btn:active { transform: translateY(1px); }

.rn-btn--ghost { background: transparent; color: var(--rn-ink); border-color: var(--rn-line); }
.rn-btn--ghost:hover { background: var(--rn-paper-deep); border-color: var(--rn-line); }

.rn-btn--small { padding: 8px 15px; font-size: 0.875rem; }

.rn-btn--big {
  font-family: var(--rn-serif);
  font-size: clamp(1.15rem, 3vw, 1.35rem);
  font-weight: 500;
  font-style: italic;
  padding: 16px 32px;
  box-shadow: var(--rn-shadow);
}

.rn-btn:focus-visible, .rn-link:focus-visible, .rn-tab:focus-visible,
.rn-toast-undo:focus-visible, .rn-field input:focus-visible {
  outline: 2px solid var(--rn-accent);
  outline-offset: 3px;
}

.rn-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }

/* --- Covers --- */
.rn-cover {
  --cover: #B5573B;
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: 3px 8px 8px 3px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.22) 0, rgba(0,0,0,0.05) 7%, rgba(255,255,255,0.08) 9%, rgba(0,0,0,0) 12%),
    var(--rn-grain),
    var(--cover);
  color: #FBF4E8;
  box-shadow: 0 2px 4px rgba(43,36,32,0.15), 0 10px 22px rgba(43,36,32,0.18);
  overflow: hidden;
}

/* A thin gilt rule near the top and bottom, like a stamped cloth cover. */
.rn-cover::before, .rn-cover::after {
  content: '';
  position: absolute;
  left: 16%;
  right: 8%;
  height: 1px;
  background: rgba(251, 244, 232, 0.45);
}
.rn-cover::before { top: 9%; }
.rn-cover::after { bottom: 9%; }

.rn-cover-title {
  font-family: var(--rn-serif);
  font-weight: 500;
  line-height: 1.1;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rn-cover-author {
  font-family: var(--rn-serif);
  font-style: italic;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fixed padding: percentages would resolve against the surrounding card. */
.rn-cover--lg { width: 150px; height: 220px; padding: 34px 14px 26px 26px; }
.rn-cover--lg .rn-cover-title { font-size: 1.2rem; -webkit-line-clamp: 5; }
.rn-cover--lg .rn-cover-author { font-size: 0.8rem; }

.rn-cover--md { width: 92px; height: 136px; padding: 20px 9px 15px 16px; }
.rn-cover--md .rn-cover-title { font-size: 0.82rem; -webkit-line-clamp: 4; }
.rn-cover--md .rn-cover-author { font-size: 0.62rem; }

/* --- Byline --- */
.rn-book-title {
  font-family: var(--rn-serif);
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--rn-ink);
  overflow-wrap: anywhere;
}

.rn-book-author { font-family: var(--rn-serif); font-style: italic; font-size: 1.02rem; }
.rn-book-note { font-size: 0.85rem; color: var(--rn-muted); margin-top: 0.3rem; }
.rn-book-note::before { content: 'Found via: '; }

/* --- Now reading --- */
.rn-now { margin: 0 auto 2rem; }

.rn-now-card {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  background: var(--rn-card);
  border: 1px solid var(--rn-line);
  border-radius: 18px;
  padding: 1.35rem 1.5rem;
  box-shadow: var(--rn-shadow);
}

.rn-now-body { min-width: 0; }

/* --- Pick --- */
.rn-pick { text-align: center; margin-bottom: 3rem; }
.rn-pick-result { margin-top: 1.75rem; }

.rn-pick-card {
  display: flex;
  gap: 2rem;
  align-items: center;
  text-align: left;
  max-width: 560px;
  margin: 0 auto;
  background: var(--rn-card);
  border: 1px solid var(--rn-line);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: var(--rn-shadow);
}

.rn-pick-card.is-new { animation: rn-arrive 0.45s ease both; }
.rn-pick-card.is-new .rn-cover { animation: rn-lift 0.55s cubic-bezier(.3,1.4,.5,1) both; }

@keyframes rn-arrive { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rn-lift { from { transform: translateY(14px) rotate(-3deg); } to { transform: none; } }

.rn-pick-body { min-width: 0; }
.rn-pick-body .rn-book-title { font-size: 1.6rem; }

.rn-pick-empty {
  max-width: 460px;
  margin: 0 auto;
  font-family: var(--rn-serif);
  font-size: 1.1rem;
  font-style: italic;
  color: var(--rn-muted);
}

/* --- Panels --- */
.rn-panel {
  background: var(--rn-card);
  border: 1px solid var(--rn-line);
  border-radius: 20px;
  padding: 1.6rem;
  margin-bottom: 1.5rem;
}

/* --- Add form --- */
.rn-add .rn-h2 { margin-bottom: 1rem; }

.rn-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem 1rem;
}

.rn-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.rn-field--wide { grid-column: 1 / -1; }
.rn-field label { font-size: 0.85rem; font-weight: 600; color: var(--rn-ink); }
.rn-field label span { font-weight: 400; color: var(--rn-muted); }

.rn-field input {
  font: inherit;
  font-size: 1rem;
  color: var(--rn-ink);
  background: var(--rn-paper);
  border: 1px solid var(--rn-line);
  border-radius: 12px;
  padding: 11px 14px;
  width: 100%;
}

.rn-field input::placeholder { color: var(--rn-muted); opacity: 0.8; }

.rn-form-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.rn-field textarea {
  font: inherit;
  font-size: 0.98rem;
  line-height: 1.55;
  color: var(--rn-ink);
  background: var(--rn-paper);
  border: 1px solid var(--rn-line);
  border-radius: 12px;
  padding: 11px 14px;
  width: 100%;
  resize: vertical;
}

.rn-field textarea::placeholder { color: var(--rn-muted); opacity: 0.8; }
.rn-field textarea:focus-visible { outline: 2px solid var(--rn-accent); outline-offset: 3px; }
.rn-hint { font-size: 0.82rem; color: var(--rn-muted); }

/* Bulk add: folded away under the single-book form. */
.rn-bulk { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--rn-line); }
.rn-bulk summary {
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--rn-accent);
  list-style: none;
}
.rn-bulk summary::-webkit-details-marker { display: none; }
.rn-bulk summary::before { content: '+ '; }
.rn-bulk[open] summary::before { content: '− '; }
.rn-bulk summary:focus-visible { outline: 2px solid var(--rn-accent); outline-offset: 3px; border-radius: 4px; }
.rn-bulk-form { margin-top: 1rem; }
.rn-form-status { font-size: 0.9rem; color: var(--rn-sage); }
.rn-form-status.is-error { color: var(--rn-accent); }

/* --- Shelf --- */
.rn-shelf-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.rn-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--rn-paper-deep);
  border-radius: 999px;
  padding: 4px;
}

.rn-tab {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--rn-soft);
  cursor: pointer;
}

.rn-tab span { font-weight: 500; color: var(--rn-muted); margin-left: 0.2rem; }
.rn-tab.is-on { background: var(--rn-card); color: var(--rn-ink); box-shadow: 0 1px 3px rgba(43,36,32,0.12); }

.rn-list { list-style: none; }

.rn-row {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--rn-line);
}

.rn-row:first-child { border-top: 0; }

.rn-spine {
  --cover: #B5573B;
  flex-shrink: 0;
  width: 12px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(0,0,0,0.18), rgba(0,0,0,0) 60%), var(--cover);
}

.rn-row-body { min-width: 0; flex: 1; }
.rn-row .rn-book-title { font-size: 1.15rem; }

.rn-chip {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rn-sage);
}

.rn-row-actions { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin-top: 0.5rem; }

.rn-link {
  border: 0;
  background: none;
  padding: 2px 0;
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--rn-accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s ease;
}

.rn-link:hover { text-decoration-color: currentColor; }
.rn-link--quiet { color: var(--rn-muted); font-weight: 500; }

.rn-empty {
  padding: 1.25rem 0 0.5rem;
  font-family: var(--rn-serif);
  font-size: 1.08rem;
  font-style: italic;
  color: var(--rn-muted);
}

.rn-empty .rn-btn { margin-top: 1rem; font-family: var(--rn-sans); font-style: normal; }

/* --- Curated lists --- */
.rn-select {
  font: inherit;
  font-size: 0.9rem;
  color: var(--rn-ink);
  background: var(--rn-paper);
  border: 1px solid var(--rn-line);
  border-radius: 999px;
  padding: 7px 14px;
}

.rn-lists-blurb { font-family: var(--rn-serif); font-style: italic; font-size: 1.05rem; margin: -0.35rem 0 1rem; }

.rn-list-books {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 1.25rem;
}

.rn-list-book {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rn-line);
  min-width: 0;
}

.rn-list-book .rn-spine { align-self: stretch; width: 8px; }
.rn-list-book-text { flex: 1; min-width: 0; }
.rn-list-book-title { font-family: var(--rn-serif); font-size: 1.02rem; font-weight: 500; color: var(--rn-ink); line-height: 1.25; overflow-wrap: anywhere; }
.rn-list-book-author { font-family: var(--rn-serif); font-style: italic; font-size: 0.88rem; }

.rn-add-one {
  flex-shrink: 0;
  border: 1px solid var(--rn-accent);
  background: transparent;
  color: var(--rn-accent);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.rn-add-one:hover { background: var(--rn-accent); color: #FFF8F0; }
.rn-add-one:disabled { border-color: transparent; background: transparent; color: var(--rn-sage); cursor: default; }
.rn-add-one:focus-visible, .rn-select:focus-visible { outline: 2px solid var(--rn-accent); outline-offset: 3px; }

.rn-lists-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.rn-lists-foot [hidden] { display: none; }

@media (max-width: 600px) {
  .rn-list-books { grid-template-columns: 1fr; }
}

@media (prefers-color-scheme: dark) {
  .rn-add-one:hover { color: #1F1B18; }
}

/* --- Toast --- */
.rn-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: calc(100% - 2rem);
  background: var(--rn-ink);
  color: var(--rn-paper);
  border-radius: 999px;
  padding: 10px 12px 10px 20px;
  font-size: 0.9rem;
  box-shadow: var(--rn-shadow);
  z-index: 10;
}

.rn-toast[hidden] { display: none; }
.rn-toast-undo {
  border: 0;
  background: transparent;
  color: var(--rn-paper);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px 8px;
  cursor: pointer;
}

/* --- Footer --- */
.rn-footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--rn-muted);
  padding: 2rem 0 5rem;
}

/* --- Small screens --- */
@media (max-width: 600px) {
  .rn-pick-card { flex-direction: column; text-align: center; padding: 1.5rem 1.25rem; gap: 1.25rem; }
  .rn-pick-card .rn-actions { justify-content: center; }
  .rn-now-card { padding: 1.1rem; gap: 1rem; }
  .rn-now-card .rn-cover--md { width: 76px; height: 112px; padding: 16px 7px 12px 13px; }
  .rn-now-card .rn-cover--md .rn-cover-title { font-size: 0.7rem; }
  .rn-form { grid-template-columns: 1fr; }
  .rn-panel { padding: 1.25rem; }
  .rn-shelf-head { flex-direction: column; align-items: stretch; }
  .rn-tabs { justify-content: space-between; }
  .rn-tab { flex: 1; padding: 7px 6px; font-size: 0.84rem; }
}

@media (prefers-reduced-motion: reduce) {
  .rn-pick-card.is-new, .rn-pick-card.is-new .rn-cover { animation: none; }
  .rn-btn { transition: none; }
}
