/* Nova's Book Nook — cozy reading styles.
   Three reading lights: candlelight (warm dark), parchment, daylight. */

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

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, "Segoe UI", system-ui, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }

/* ---------- shelf ---------- */
body {
  font-family: var(--serif);
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(255, 190, 100, .12), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
  color: #e8d9bd;
}
/* Nova's shelf colors — she picks one in /customize (accent, deep, ink) */
body.accent-amber {
  --accent: #ffce7a; --accent-deep: #e0a94a; --accent-ink: #4a2e00;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(255, 190, 100, .12), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
}
body.accent-pink {
  --accent: #f7a8c4; --accent-deep: #e582ab; --accent-ink: #5c1834;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(247, 168, 196, .16), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
}
body.accent-sky {
  --accent: #9cc9ec; --accent-deep: #6fa8d6; --accent-ink: #163a5c;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(156, 201, 236, .16), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
}
body.accent-lilac {
  --accent: #cdb0ef; --accent-deep: #a988dd; --accent-ink: #3c1f63;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(205, 176, 239, .16), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
}
body.accent-mint {
  --accent: #9fddc0; --accent-deep: #6fc29b; --accent-ink: #12432e;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(159, 221, 192, .15), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
}
body.accent-peach {
  --accent: #ffb380; --accent-deep: #e8944f; --accent-ink: #5c2a0c;
  background:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(255, 179, 128, .16), transparent),
    linear-gradient(180deg, #221408 0%, #171009 60%, #100b06 100%);
}
.nook-head { text-align: center; padding: 44px 16px 8px; }
.nook-head h1 {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  font-weight: 600; letter-spacing: -.01em; color: #f3e3c2;
}
.nook-sub { margin-top: 6px; font-style: italic; opacity: .65; }
.make-it-yours-link {
  display: inline-block; margin-top: 14px;
  font-family: var(--sans); font-size: .76rem; font-weight: 800;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-ink, #4a2e00);
  background: linear-gradient(135deg, var(--accent, #ffd98a), var(--accent-deep, #f5b84a));
  border: 1px solid rgba(255, 255, 255, .5);
  padding: 7px 16px; border-radius: 999px; text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
  transition: transform .15s ease;
}
.make-it-yours-link:hover { transform: scale(1.06); }

/* Nova's avatar chip (reader top bar) */
.avatar {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; flex: 0 0 auto;
  background: rgba(128, 128, 128, .16);
  border: 1.5px solid var(--accent, #ffce7a);
  border-radius: 50%; font-size: 18px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.avatar.tiny {
  width: 30px; height: 30px; font-size: 15px;
  vertical-align: -4px; margin-left: 8px;
}
.avatar.big { width: 56px; height: 56px; font-size: 32px; flex: 0 0 auto; }

/* ---------- make it yours (customize page) ---------- */
.make-it-yours { max-width: 520px; margin: 0 auto; padding: 26px 18px 60px; }
.back-link {
  font-family: var(--sans); font-size: .85rem; font-weight: 700;
  color: #e8d9bd; opacity: .7; text-decoration: none;
}
.back-link:hover { opacity: 1; }
.m-card {
  background: linear-gradient(165deg, #2b1c0e, #1a1108);
  border: 1px solid rgba(232, 201, 143, .25); border-radius: 22px;
  padding: 30px 26px; margin-top: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.m-card h1 { font-size: 1.5rem; color: var(--accent, #f3e3c2); }
.m-hi {
  display: flex; align-items: center; gap: 14px; margin-top: 14px;
  font-style: italic; opacity: .85; line-height: 1.4;
}
.m-card h2 {
  font-family: var(--sans); font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
  color: #c9a86a; margin: 26px 0 12px;
}
.swatches, .avatars { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
  transition: transform .15s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.picked {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .35), 0 4px 12px rgba(0, 0, 0, .4);
}
.av {
  width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid rgba(232, 201, 143, .35);
  background: rgba(255, 255, 255, .06);
  font-size: 26px; line-height: 1; cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.av:hover { transform: scale(1.12); background: rgba(255, 255, 255, .14); }
.av.picked {
  border-color: var(--accent, #ffce7a);
  background: rgba(255, 255, 255, .16);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .3);
}
.m-done {
  margin-top: 24px; font-weight: 700;
  color: var(--accent, #ffce7a);
}

.shelf { max-width: 1060px; margin: 0 auto; padding: 18px 20px 30px; }
.shelf h2 {
  font-family: var(--sans); font-size: .82rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .14em;
  color: var(--accent, #c9a86a); margin: 22px 4px 14px;
}
.shelf h2 .star {
  color: var(--accent, #ffce7a); letter-spacing: 0; margin-right: 6px;
  animation: twinkle 2.6s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: .55; transform: scale(.92); }
  50% { opacity: 1; transform: scale(1.12); }
}

/* "New" badge on fresh arrivals (Just-arrived row + shelf grid) */
.new-badge {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  font-family: var(--sans); font-size: .62rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-ink, #4a2e00);
  background: linear-gradient(135deg, var(--accent, #ffd98a), var(--accent-deep, #f5b84a));
  border: 1px solid rgba(255, 255, 255, .55);
  padding: 3px 8px; border-radius: 999px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .45);
  animation: badge-pop .5s ease both;
}
@keyframes badge-pop {
  from { transform: scale(.4) rotate(-8deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.cont-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 148px;
  gap: 14px; overflow-x: auto; padding-bottom: 10px;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
}
.cont-card {
  position: relative; scroll-snap-align: start; text-decoration: none; color: inherit;
}
.cont-card img {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block;
  border-radius: 10px; box-shadow: 0 10px 24px rgba(0,0,0,.55), 0 0 0 1px rgba(232,201,143,.25);
}
.cont-title {
  display: block; margin-top: 8px; font-size: .85rem; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cont-pct {
  position: absolute; top: 8px; left: 8px;
  background: rgba(20,12,4,.85); color: #ffce7a;
  font-family: var(--sans); font-size: .68rem; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
}

.cover-grid {
  display: grid; gap: 22px 18px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.book { position: relative; text-decoration: none; color: inherit; }
.book img {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,.5), 0 0 0 1px rgba(232,201,143,.18);
  transition: transform .18s ease, box-shadow .18s ease;
}
@media (hover: hover) {
  .book:hover img { transform: translateY(-4px) rotate(-.5deg); box-shadow: 0 16px 32px rgba(0,0,0,.6), 0 0 0 1px rgba(255,206,122,.45); }
}
.book:active img { transform: scale(.97); }
.book-title {
  display: block; margin-top: 9px; font-size: .92rem; line-height: 1.28;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-author {
  display: block; margin-top: 3px; font-size: .78rem; font-style: italic; opacity: .55;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nook-foot {
  text-align: center; padding: 26px 16px 34px;
  font-style: italic; font-size: .88rem; opacity: .5;
}

/* ---------- gate ---------- */
.gate-page {
  display: grid; place-items: center; min-height: 100vh;
}
.gate { padding: 24px; }
.gate-card {
  position: relative; overflow: hidden;
  background: linear-gradient(165deg, #2b1c0e, #1a1108);
  border: 1px solid rgba(232,201,143,.25); border-radius: 22px;
  padding: 42px 38px; max-width: 360px; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.gate-glow {
  position: absolute; inset: -40% -20% auto; height: 70%;
  background: radial-gradient(ellipse at center, rgba(255,190,100,.14), transparent 70%);
  pointer-events: none;
}
.gate-card h1 { font-size: 1.55rem; font-weight: 600; color: #f3e3c2; }
.gate-sub { margin-top: 8px; font-style: italic; opacity: .6; }
.gate-error { margin-top: 14px; color: #ffb37a; font-size: .92rem; }
.gate-card form { margin-top: 24px; display: grid; gap: 12px; }
.gate-card label {
  font-family: var(--sans); font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em; text-align: left; opacity: .7;
}
.gate-card input {
  font-family: var(--sans); font-size: 1.05rem;
  background: rgba(0,0,0,.35); color: #f3e3c2;
  border: 1.5px solid rgba(232,201,143,.3); border-radius: 12px;
  padding: 13px 15px; outline: none;
}
.gate-card input:focus { border-color: #ffce7a; }
.gate-card button {
  font-family: var(--sans); font-weight: 700; font-size: 1rem;
  background: linear-gradient(135deg, #b07a3a, #8a5a26); color: #fff4dd;
  border: none; border-radius: 12px; padding: 13px; cursor: pointer;
}
.gate-card button:hover { filter: brightness(1.12); }

/* ---------- reader themes ---------- */
.reader-page { transition: background .35s ease, color .35s ease; }
.theme-candlelight {
  background:
    radial-gradient(ellipse 90% 50% at 50% -10%, rgba(255,180,90,.10), transparent),
    linear-gradient(180deg, #211507, #150e05);
  color: #e6d3ae;
}
.theme-parchment {
  background: linear-gradient(180deg, #f6eeda, #efe4c8);
  color: #46351f;
}
.theme-daylight {
  background: #fbfbf8; color: #2b2b28;
}

.reader-top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 14px 10px;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, currentColor 4%, transparent);
  background-color: var(--topbar, rgba(0,0,0,.18));
  border-bottom: 1px solid rgba(128,128,128,.18);
}
.theme-candlelight .reader-top { --topbar: rgba(23,15,6,.82); }
.theme-parchment .reader-top { --topbar: rgba(246,238,218,.9); }
.theme-daylight .reader-top { --topbar: rgba(251,251,248,.92); }
.back {
  font-family: var(--sans); font-size: .88rem; font-weight: 700;
  color: inherit; text-decoration: none; opacity: .75; white-space: nowrap;
}
.back:hover { opacity: 1; }
.book-name {
  flex: 1; min-width: 0; text-align: center;
  font-style: italic; font-size: .95rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .8;
}
.controls { display: flex; gap: 6px; }
.controls button, .reader-bottom button {
  font-family: var(--sans); font-size: .82rem; font-weight: 700;
  color: inherit; cursor: pointer;
  background: transparent; border: 1.5px solid currentColor;
  border-radius: 10px; padding: 6px 11px; opacity: .8;
}
.controls button:hover, .reader-bottom button:hover { opacity: 1; }
#themeName { font-size: .74rem; text-transform: capitalize; }

/* tiny reading-goal ring — quiet, ignorable, fills toward 20 min/day */
.read-timer {
  position: relative; width: 32px; height: 32px;
  flex: 0 0 auto; opacity: .85; margin-right: 2px;
}
.read-timer .rt-svg { width: 32px; height: 32px; display: block; transform: rotate(-90deg); }
.read-timer .rt-track {
  fill: none; stroke: currentColor; stroke-width: 3; opacity: .16;
}
.read-timer .rt-fill {
  fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 97.39; stroke-dashoffset: 97.39;
  transition: stroke-dashoffset .6s ease;
}
.read-timer .rt-min {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--sans); font-size: .58rem; font-weight: 800;
}
.reader-page.rt-done .read-timer .rt-fill {
  stroke: #e8b34b; filter: drop-shadow(0 0 4px rgba(232,179,75,.7));
}
.reader-page.rt-done .read-timer .rt-min { color: #e8b34b; }

.toc {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: grid; place-items: center;
}
.toc.hidden { display: none; }
.toc ol {
  list-style: none; max-height: 72vh; overflow-y: auto;
  background: var(--tocbg, #241708); color: inherit;
  border-radius: 16px; padding: 18px 8px; width: min(480px, 88vw);
  box-shadow: 0 30px 70px rgba(0,0,0,.5);
}
.theme-parchment .toc ol { --tocbg: #f6eeda; }
.theme-daylight .toc ol { --tocbg: #fbfbf8; }
.toc a {
  display: block; color: inherit; text-decoration: none;
  font-family: var(--sans); font-size: .92rem;
  padding: 9px 14px; border-radius: 8px; line-height: 1.35;
}
.toc a:hover { background: rgba(128,128,128,.15); }
.toc a.active { font-weight: 800; }

/* ---------- page-flip reader ----------
   The reader is a fixed-height app shell: top bar, page viewport (flex:1),
   bottom bar. Each chapter is laid out by the browser into viewport-wide
   CSS columns — every column is a real page, and turning pans the flow
   under a paper sheet that folds over in 3D (a genuine page flip). */
.reader-page {
  overflow: hidden; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#reader {
  height: 100vh; height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
}
.reader-page .reader-top { position: relative; }
.reader-page .reader-bottom { position: relative; }

.page-viewport {
  flex: 1; min-height: 0; position: relative;
  overflow: hidden;
  perspective: 1800px;
  padding: 0 max(14px, calc((100vw - 760px) / 2));
  touch-action: pan-y; /* horizontal drags belong to the page turn, not scrolling */
}

/* two-page spread on landscape tablets — a real open book */
.page-viewport.spread { padding: 0 10px; }
.page-viewport.spread::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 28px; transform: translateX(-50%); z-index: 5; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.30), transparent 72%);
}
.page-viewport.spread .flip-sheet { width: 50%; left: auto; right: 0; }
.page-viewport.spread .flip-sheet.to-next { transform-origin: left center; }
.page-viewport.spread .flip-sheet.to-prev { width: 50%; left: 0; right: auto; transform-origin: right center; }

.chapter-content {
  height: 100%; overflow: hidden;
  column-fill: auto;
  font-size: var(--fs, 22px); line-height: 1.62;
  will-change: transform;
}
.ch-title {
  font-size: clamp(1.3rem, 4vw, 1.85rem); font-weight: 600;
  line-height: 1.25; margin: 10px 0 20px; padding-right: 6px;
  letter-spacing: -.01em;
}
.chapter-content p { margin: 0 0 1em; text-wrap: pretty; }
.chapter-content h1, .chapter-content h2, .chapter-content h3 {
  font-weight: 600; line-height: 1.3; margin: 1.4em 0 .6em;
}
.chapter-content img {
  max-width: 100%; max-height: 62vh; max-height: 62dvh; height: auto; display: block; margin: 1.2em auto;
  border-radius: 6px;
}
.chapter-content blockquote {
  margin: 1.2em 1.4em; padding-left: 1em;
  border-left: 3px solid rgba(128,128,128,.4); font-style: italic;
}
.chapter-content table { border-collapse: collapse; margin: 1.2em 0; width: 100%; }
.chapter-content td, .chapter-content th {
  border: 1px solid rgba(128,128,128,.35); padding: 6px 10px; font-size: .92em;
}
.loading { text-align: center; opacity: .55; font-style: italic; padding: 48px 0; }

/* the paper sheet that folds over a page turn (per-theme paper color) */
.flip-sheet {
  position: absolute; inset: 0; z-index: 6;
  display: none;
  backface-visibility: hidden;
  transition: transform .6s cubic-bezier(.3,.1,.25,1);
  box-shadow: -6px 0 18px rgba(0,0,0,.35);
}
.flip-sheet.visible { display: block; }
.flip-sheet.to-next { transform-origin: left center; }
.flip-sheet.to-next.flipping { transform: rotateY(-180deg); }
.flip-sheet.to-prev { transform-origin: right center; }
.flip-sheet.to-prev.flipping { transform: rotateY(180deg); }
.theme-candlelight .flip-sheet {
  background:
    linear-gradient(90deg, rgba(0,0,0,.28), transparent 16%, transparent 84%, rgba(0,0,0,.38)),
    #241708;
}
.theme-parchment .flip-sheet {
  background:
    linear-gradient(90deg, rgba(90,62,20,.16), transparent 16%, transparent 84%, rgba(90,62,20,.28)),
    #f6eeda;
}
.theme-daylight .flip-sheet {
  background:
    linear-gradient(90deg, rgba(0,0,0,.05), transparent 16%, transparent 84%, rgba(0,0,0,.12)),
    #fbfbf8;
}

.reader-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  backdrop-filter: blur(10px);
  background-color: var(--topbar, rgba(0,0,0,.18));
  border-top: 1px solid rgba(128,128,128,.18);
}
.reader-bottom button {
  font-size: 1.15rem; min-width: 54px; min-height: 44px;
  border-radius: 14px; display: grid; place-items: center;
  touch-action: manipulation;
}
.reader-top button { touch-action: manipulation; }
.page-meta {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 0;
}
#posLabel { font-family: var(--sans); font-size: .8rem; opacity: .65; }
.page-progress {
  width: min(340px, 70vw); height: 7px; border-radius: 99px;
  background: rgba(128,128,128,.22); overflow: hidden;
}
.page-progress span {
  display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, #e8b34b, #c98a2e);
  transition: width .35s ease;
}

@media (max-width: 560px) {
  .page-viewport { padding: 0 10px; }
  .book-name { display: none; }
  .reader-top { justify-content: space-between; }
  .reader-bottom button { min-width: 48px; }
}
