/* ============================================================
   Her Shelf — a private reading record.
   Visual source material: library binding cloth, manila circulation
   cards, and rubber date stamps. The stamped date slip is the one
   loud element; everything else stays quiet.
   ============================================================ */

:root {
  --ground:    #16302A;   /* buckram binding cloth */
  --ground-lo: #102420;
  --ground-hi: #1E3D35;
  --card:      #E8E0CE;   /* manila card stock */
  --card-hi:   #F1EBDF;
  --ink:       #17211E;   /* text on manila — 10.7:1 */
  --ink-soft:  #5A5347;   /* 4.6:1 on manila */
  --buckram:   #1B4D3E;   /* chart bars — 7.3:1 on manila */
  --oxblood:   #8C2F39;   /* stamp ink — 6.2:1 on manila */
  --gold:      #C89A3C;   /* accent, DARK GROUND ONLY (2:1 on manila) */
  --rule:      rgba(23, 33, 30, 0.18);
  --rule-lo:   rgba(232, 224, 206, 0.16);

  --display: "Fraunces", Georgia, serif;
  --body:    "Spectral", Georgia, serif;
  --stamp:   "Courier Prime", ui-monospace, "Courier New", monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --tap: 48px;              /* minimum touch target */
  --sheet-max: 34rem;
}

/* Scroll container: body owns scrolling, never the root. */
html { height: 100%; overflow: hidden; }
body {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
  margin: 0;
  background: var(--ground);
  color: var(--card);
  font: 400 18px/1.6 var(--body);
  -webkit-text-size-adjust: 100%;
}
*, *::before, *::after { box-sizing: inherit; }

:where(button, a, input, textarea, select):focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 3px;
}

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- sign in ---------- */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}
.gate__inner { width: min(24rem, 100%); text-align: center; }
.gate__mark {
  font: 400 clamp(2.4rem, 9vw, 3.4rem)/1 var(--display);
  font-variation-settings: "SOFT" 40, "WONK" 1;
  color: var(--card);
  margin: 0 0 .35rem;
}
.gate__sub {
  font: 400 .95rem/1.5 var(--stamp);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 2rem;
}
.gate form { display: grid; gap: .85rem; }

/* ---------- shell ---------- */

.shell { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--ground-lo);
  border-bottom: 1px solid var(--rule-lo);
}
.topbar__row {
  max-width: 72rem; margin: 0 auto;
  padding: .7rem 1rem .55rem;
  display: flex; align-items: baseline; gap: 1rem;
}
.wordmark {
  font: 400 1.5rem/1 var(--display);
  font-variation-settings: "SOFT" 40, "WONK" 1;
  margin: 0; color: var(--card);
}
.wordmark span { color: var(--gold); }
.count {
  font: 400 .78rem/1 var(--stamp);
  letter-spacing: .08em; color: rgba(232,224,206,.55);
  margin-left: auto; white-space: nowrap;
}

.tabs {
  display: flex; gap: .25rem;
  max-width: 72rem; margin: 0 auto; width: 100%;
  padding: 0 .6rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: none;
  font: 500 .95rem/1 var(--ui);
  color: rgba(232,224,206,.62);
  padding: .7rem .8rem .8rem;
  min-height: var(--tap);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap; flex: 0 0 auto;
}
.tab__n {
  font: 400 .72rem/1 var(--stamp);
  color: rgba(232,224,206,.45); margin-left: .3rem;
}
.tab[aria-selected="true"] .tab__n { color: var(--gold); }
.tab[aria-selected="true"] { color: var(--card); border-bottom-color: var(--gold); }

.view { max-width: 72rem; margin: 0 auto; width: 100%; padding: 1.1rem 1rem 4rem; }

/* ---------- controls ---------- */

.search {
  position: relative; margin-bottom: .85rem;
}
.search input {
  width: 100%; min-height: var(--tap);
  padding: .6rem .9rem .6rem 2.6rem;
  font: 400 1.05rem/1.4 var(--body);
  color: var(--ink); background: var(--card);
  border: 1px solid transparent; border-radius: 4px;
}
.search input::placeholder { color: var(--ink-soft); }
.search__icon {
  position: absolute; left: .85rem; top: 50%; transform: translateY(-50%);
  color: var(--ink-soft); pointer-events: none; font-size: 1.05rem;
}

.filters { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .55rem; }
.chip {
  appearance: none; cursor: pointer;
  font: 500 .88rem/1 var(--ui);
  color: rgba(232,224,206,.75);
  background: transparent;
  border: 1px solid var(--rule-lo);
  border-radius: 999px;
  padding: .55rem .85rem; min-height: 40px;
}
.chip[aria-pressed="true"] {
  background: var(--gold); border-color: var(--gold); color: var(--ground-lo);
  font-weight: 600;
}

.sortrow {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: 1.1rem;
  font: 400 .85rem/1 var(--ui); color: rgba(232,224,206,.6);
}
.sortrow select {
  font: 500 .88rem/1 var(--ui);
  color: var(--card); background: var(--ground-hi);
  border: 1px solid var(--rule-lo); border-radius: 4px;
  padding: .5rem .6rem; min-height: 40px; cursor: pointer;
}
.sortrow .spacer { margin-left: auto; }

/* ---------- shelf grid ---------- */

.grid {
  display: grid;
  /* 140px keeps two roomy columns on a phone, so a card's five stars each get
     ~38px of width -- enough to rate accurately without opening the book. */
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1.3rem .85rem;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); }
}

.book { display: flex; flex-direction: column; gap: .4rem; }

/* The cover/title area opens the book; the stars below are separate controls,
   so they can't be nested inside one another. */
.book__open {
  appearance: none; border: 0; background: none; padding: 0;
  text-align: left; cursor: pointer; color: inherit;
  display: flex; flex-direction: column; gap: .45rem;
}
.book__cover {
  position: relative;
  aspect-ratio: 2 / 3;
  background: var(--ground-hi);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.35), inset 0 0 0 1px rgba(232,224,206,.08);
}
.book__cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book__fallback {
  position: absolute; inset: 0;
  display: grid; align-content: center; gap: .3rem;
  padding: .6rem; text-align: center;
  background: linear-gradient(160deg, var(--ground-hi), var(--ground-lo));
}
.book__fallback b {
  font: 400 .82rem/1.25 var(--display); color: var(--card);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.book__fallback i {
  font: 400 .68rem/1.2 var(--stamp); font-style: normal;
  color: rgba(232,224,206,.5);
}
.book__meta { display: flex; flex-direction: column; gap: .1rem; }
.book__title {
  font: 400 .88rem/1.3 var(--body); color: var(--card);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book__author {
  font: 400 .76rem/1.3 var(--body); color: rgba(232,224,206,.55);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book__when {
  font: 400 .68rem/1.3 var(--stamp);
  letter-spacing: .04em; text-transform: uppercase;
  color: rgba(232,224,206,.42);
}
.book__when b { color: var(--oxblood); font-weight: 700; }

/* Inline rating: five stars per card for rating a stack in one pass. */
.book__rate {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 1px;
}
.book__star {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 0; height: 40px;
  font-size: 1.35rem; line-height: 1;
  color: rgba(232,224,206,.20);
  transition: color .12s ease, transform .12s ease;
}
.book__star[data-on="1"] { color: var(--gold); }
.book__star:active { transform: scale(.88); }
.book__rate:hover .book__star { color: rgba(232,224,206,.32); }
.book__rate .book__star.hot { color: var(--gold); }
.book__star--pressed { animation: press .28s ease; }

.book__done {
  appearance: none; cursor: pointer;
  width: 100%; min-height: 40px;
  font: 600 .82rem/1 var(--ui);
  color: var(--card); background: transparent;
  border: 1px solid var(--rule-lo); border-radius: 4px;
  padding: .55rem .4rem;
}
.book__done:hover { background: var(--ground-hi); }
.book__done:disabled { opacity: .5; cursor: default; }

.empty {
  padding: 3rem 1rem; text-align: center;
  color: rgba(232,224,206,.6);
}
.empty b { display: block; font: 400 1.3rem/1.3 var(--display); color: var(--card); margin-bottom: .4rem; }

/* ---------- sheet (book detail / add) ---------- */

.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 18, 15, .72);
  display: grid; align-items: end; justify-items: center;
}
@media (min-width: 640px) { .scrim { align-items: center; padding: 2rem 1rem; } }

.sheet {
  width: min(var(--sheet-max), 100%);
  max-height: 92vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card); color: var(--ink);
  border-radius: 10px 10px 0 0;
  padding: 1.1rem 1.15rem 1.6rem;
}
@media (min-width: 640px) { .sheet { border-radius: 6px; } }

.sheet__bar { display: flex; justify-content: flex-end; margin: -.35rem -.35rem .2rem 0; }
.iconbtn {
  appearance: none; border: 0; background: none; cursor: pointer;
  width: var(--tap); height: var(--tap);
  font-size: 1.5rem; line-height: 1; color: var(--ink-soft);
  border-radius: 4px;
}

.sheet__head { display: flex; gap: .9rem; margin-bottom: 1.1rem; }
.sheet__cover {
  width: 92px; flex: 0 0 92px; aspect-ratio: 2/3;
  border-radius: 2px; overflow: hidden; background: var(--ground-hi);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.sheet__cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet__title {
  font: 400 1.45rem/1.18 var(--display);
  font-variation-settings: "SOFT" 40, "WONK" 1;
  margin: 0 0 .2rem; color: var(--ink);
}
.sheet__author { font: 400 1rem/1.35 var(--body); color: var(--ink-soft); margin: 0; }
.sheet__pub { font: 400 .78rem/1.4 var(--stamp); color: var(--ink-soft); margin: .45rem 0 0; }

/* --- the signature: a stamped date-due slip --- */
.slip {
  border: 1px solid var(--rule);
  border-radius: 2px;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0 26px,
      var(--rule) 26px 27px
    ),
    var(--card-hi);
  padding: .5rem .7rem .6rem;
  margin: 0 0 1.15rem;
}
.slip__label {
  font: 400 .66rem/1 var(--stamp);
  letter-spacing: .19em; text-transform: uppercase;
  color: var(--ink-soft);
  padding-bottom: .45rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: .5rem;
}
.slip__dates { display: flex; flex-wrap: wrap; gap: .45rem .6rem; }
.stamp {
  font: 700 .78rem/1 var(--stamp);
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--oxblood);
  border: 2px solid var(--oxblood);
  border-radius: 2px;
  padding: .34rem .5rem;
  opacity: .88;
  /* rotation is set per-stamp inline so it stays stable across renders */
}
.slip__note {
  font: 400 .74rem/1.4 var(--stamp);
  color: var(--ink-soft); margin-top: .55rem;
}

/* --- rating --- */
.field { margin-bottom: 1.15rem; }
.field__label {
  display: block;
  font: 400 .72rem/1 var(--stamp);
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: .5rem;
}
.stars { display: flex; gap: .1rem; align-items: center; }
.star {
  appearance: none; border: 0; background: none; cursor: pointer;
  width: 52px; height: 52px; padding: 0;
  font-size: 2rem; line-height: 1;
  color: rgba(23,33,30,.22);
  transition: transform .12s ease, color .12s ease;
}
.star[data-on="1"] { color: var(--oxblood); }
.star:active { transform: scale(.92); }
.star--pressed { animation: press .28s ease; }
@keyframes press {
  0% { transform: scale(1); }
  45% { transform: scale(1.22) rotate(-4deg); }
  100% { transform: scale(1); }
}
.stars__clear {
  appearance: none; border: 0; background: none; cursor: pointer;
  font: 400 .8rem/1 var(--ui); color: var(--ink-soft);
  text-decoration: underline; margin-left: .5rem; min-height: 44px; padding: 0 .3rem;
}

textarea, .textinput {
  width: 100%;
  font: 400 1rem/1.5 var(--body);
  color: var(--ink); background: var(--card-hi);
  border: 1px solid var(--rule); border-radius: 4px;
  padding: .65rem .75rem;
  resize: vertical;
}
textarea { min-height: 5.5rem; }
.textinput { min-height: var(--tap); }

.saved {
  font: 400 .78rem/1 var(--stamp); color: var(--buckram);
  opacity: 0; transition: opacity .25s ease; margin-left: .5rem;
}
.saved.on { opacity: 1; }

/* --- buttons --- */
.btn {
  appearance: none; cursor: pointer;
  font: 600 1rem/1 var(--ui);
  min-height: var(--tap);
  padding: .8rem 1.1rem;
  border-radius: 4px;
  border: 1px solid transparent;
  /* anchors styled as buttons must not keep link decoration */
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  text-align: center;
}
.btn--primary { background: var(--buckram); color: var(--card-hi); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn--gold { background: var(--gold); color: var(--ground-lo); }
.btn--danger { background: transparent; color: var(--oxblood); border-color: rgba(140,47,57,.4); }
.btn--wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn--onground { background: transparent; color: var(--card); border-color: var(--rule-lo); }

.sheet__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.sheet__actions .btn { flex: 1 1 auto; }

/* ---------- ideas (recommendations) ---------- */

.ideas__head {
  display: flex; align-items: center; gap: .8rem;
  flex-wrap: wrap; margin-bottom: 1.1rem;
}
.ideas__when {
  font: 400 .78rem/1.5 var(--stamp);
  color: rgba(232,224,206,.42);
  display: flex; flex-direction: column; gap: .1rem;
}
.ideas__basis { color: rgba(232,224,206,.68); }

.idea {
  display: flex; gap: .9rem;
  background: var(--card); color: var(--ink);
  border-radius: 5px; padding: .85rem;
  margin-bottom: .7rem;
}
.idea__cover {
  width: 66px; flex: 0 0 66px; aspect-ratio: 2/3;
  border-radius: 2px; overflow: hidden; background: var(--ground-hi);
}
.idea__cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.idea__body { flex: 1; min-width: 0; }
.idea__title { font: 400 1.12rem/1.25 var(--display); margin: 0 0 .1rem; }
.idea__author { font: 400 .88rem/1.3 var(--body); color: var(--ink-soft); margin: 0 0 .45rem; }
.idea__why {
  font: 400 .93rem/1.45 var(--body); margin: 0 0 .7rem;
  padding-left: .6rem; border-left: 2px solid var(--oxblood);
}
.idea__actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.idea__actions .btn { font-size: .88rem; padding: .6rem .8rem; min-height: 44px; }

.spinner {
  display: inline-block; width: 1em; height: 1em;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -.12em; margin-right: .45rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- stats ---------- */

.statgrid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 1.4rem; }
.stat {
  background: var(--ground-hi); border: 1px solid var(--rule-lo);
  border-radius: 5px; padding: .85rem .95rem;
}
.stat__n {
  font: 400 2.1rem/1 var(--display);
  font-variation-settings: "SOFT" 40, "WONK" 1;
  color: var(--gold); display: block;
}
.stat__l {
  font: 400 .72rem/1.3 var(--stamp);
  letter-spacing: .11em; text-transform: uppercase;
  color: rgba(232,224,206,.6); margin-top: .3rem; display: block;
}

.panel {
  background: var(--card); color: var(--ink);
  border-radius: 6px; padding: 1rem 1.05rem 1.15rem;
  margin-bottom: 1rem;
}
.panel h3 {
  font: 400 1.15rem/1.2 var(--display);
  margin: 0 0 .15rem; color: var(--ink);
}
.panel__sub {
  font: 400 .78rem/1.4 var(--stamp);
  color: var(--ink-soft); margin: 0 0 .9rem;
}

/* Bars: one hue (buckram, 7.3:1 on manila), 4px rounded data-end,
   2px surface gap, recessive axis. Single series — no legend needed. */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 132px; }
.bars__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: .3rem; }
.bars__bar {
  background: var(--buckram);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: opacity .15s ease;
}
.bars__col:hover .bars__bar { opacity: .78; }
.bars__n { font: 400 .68rem/1 var(--stamp); color: var(--ink-soft); text-align: center; }
.bars__axis { display: flex; gap: 2px; border-top: 1px solid var(--rule); padding-top: .35rem; margin-top: .1rem; }
.bars__tick { flex: 1; font: 400 .68rem/1 var(--stamp); color: var(--ink-soft); text-align: center; }

.hbar { display: grid; grid-template-columns: minmax(0,9rem) 1fr auto; gap: .6rem; align-items: center; margin-bottom: .35rem; }
.hbar__name { font: 400 .88rem/1.3 var(--body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar__track { background: rgba(23,33,30,.09); border-radius: 4px; height: 16px; }
.hbar__fill { background: var(--buckram); height: 100%; border-radius: 4px; }
.hbar__n { font: 400 .8rem/1 var(--stamp); color: var(--ink-soft); min-width: 2.2rem; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  z-index: 90; background: var(--card); color: var(--ink);
  border-radius: 4px; padding: .7rem 1rem;
  font: 500 .92rem/1.3 var(--ui);
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  max-width: min(28rem, calc(100vw - 2rem));
}
.toast--bad { background: var(--oxblood); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- the ask: what to base recommendations on ---------- */

.asker {
  background: var(--ground-hi);
  border: 1px solid var(--rule-lo);
  border-radius: 6px;
  padding: 1rem 1.05rem 1.1rem;
  margin-bottom: 1.4rem;
}
.asker__row {
  display: flex; align-items: center; gap: .75rem;
  flex-wrap: wrap; margin-bottom: .6rem;
}
.asker__row--slider { margin-top: 1.2rem; margin-bottom: .4rem; }
.asker__pick { font-size: .9rem; padding: .55rem .8rem; min-height: 42px; }
.asker__value {
  font: 400 .95rem/1 var(--body);
  color: var(--gold); margin-left: auto;
}
.asker__ends {
  display: flex; justify-content: space-between;
  font: 400 .7rem/1.3 var(--stamp);
  color: rgba(232,224,206,.45);
  margin: .1rem 0 1.1rem;
}
.asker .btn--wide { margin-top: .2rem; }

/* A slider an older reader can actually grab: tall track, large thumb. */
#adventure {
  -webkit-appearance: none; appearance: none;
  width: 100%; background: transparent; margin: .5rem 0 0;
  height: 44px; cursor: pointer;
}
#adventure::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right, var(--oxblood), var(--gold));
}
#adventure::-moz-range-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right, var(--oxblood), var(--gold));
}
#adventure::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--ground-lo);
  margin-top: -12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
#adventure::-moz-range-thumb {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--ground-lo);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}

.seedchips { display: flex; flex-wrap: wrap; gap: .35rem; }
.seedchip {
  display: inline-flex; align-items: center; gap: .4rem;
  font: 400 .82rem/1 var(--body);
  background: var(--ground-lo); color: var(--card);
  border: 1px solid var(--rule-lo); border-radius: 999px;
  padding: .4rem .5rem .4rem .7rem;
}
.seedchip button {
  appearance: none; border: 0; background: none; cursor: pointer;
  color: rgba(232,224,206,.6); font-size: 1.1rem; line-height: 1;
  width: 26px; height: 26px; border-radius: 50%;
}
.seedchip button:hover { color: var(--card); }

/* ---------- book picker ---------- */

.seedlist { max-height: 46vh; overflow-y: auto; margin-top: .7rem; }
.seedrow {
  display: flex; align-items: center; gap: .7rem; width: 100%;
  appearance: none; border: 0; background: none; cursor: pointer;
  text-align: left; color: var(--ink);
  padding: .5rem .4rem; border-bottom: 1px solid var(--rule);
  min-height: var(--tap);
}
.seedrow:hover { background: var(--card-hi); }
.seedrow__box {
  flex: 0 0 24px; width: 24px; height: 24px; border-radius: 4px;
  border: 2px solid rgba(23,33,30,.3);
  display: grid; place-items: center;
  font-size: .9rem; color: transparent;
}
.seedrow[aria-pressed="true"] .seedrow__box {
  background: var(--buckram); border-color: var(--buckram); color: var(--card-hi);
}
.seedrow__t { font: 400 .95rem/1.3 var(--body); }
.seedrow__a { font: 400 .8rem/1.3 var(--body); color: var(--ink-soft); }
.seedrow__r { margin-left: auto; font-size: .8rem; color: var(--oxblood); white-space: nowrap; }
