/* ==========================================================================
   Pages at Dawn - motion, effects and brand extras
   Loaded after site.css on every public page.
   Everything animated is switched off under prefers-reduced-motion.
   ========================================================================== */

/* ---------- page entrance ---------- */
@keyframes pageIn { from { opacity: 0; } to { opacity: 1; } }
main { animation: pageIn .5s cubic-bezier(.2,.7,.2,1) both; }

/* ---------- theme toggle (sun <-> moon) ---------- */
.theme-toggle {
    position: relative; width: 40px; height: 40px; border-radius: 50%; flex: none;
    background: transparent; border: 1px solid var(--line); color: var(--text); cursor: pointer;
    display: inline-grid; place-items: center; overflow: hidden;
    transition: border-color .2s, background .2s, transform .2s;
}
.theme-toggle:hover { border-color: var(--lamp); background: rgba(229,187,108,.1); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle svg { grid-area: 1 / 1; width: 20px; height: 20px; transition: transform .55s cubic-bezier(.2,.8,.2,1), opacity .35s; }
.theme-toggle .i-sun { color: var(--lamp-text); transform: rotate(-90deg) scale(.3); opacity: 0; }
.theme-toggle .i-moon { color: var(--lamp-text); transform: none; opacity: 1; }
html[data-theme="light"] .theme-toggle .i-sun { transform: none; opacity: 1; }
html[data-theme="light"] .theme-toggle .i-moon { transform: rotate(90deg) scale(.3); opacity: 0; }
.nav-account .theme-toggle { order: -1; }

/* ---------- scroll line + header state ---------- */
.scroll-line { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
.scroll-line i { display: block; height: 100%; background: linear-gradient(90deg, var(--dawn), var(--lamp)); transform: scaleX(0); transform-origin: 0 50%; }
.site-header { transition: box-shadow .3s, background .3s; }
.site-header.is-scrolled { box-shadow: 0 10px 30px -18px var(--shadow-1); }
.nav-search { position: relative; }
.nav-search kbd {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none;
    font: 600 .7rem var(--font-ui); color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 .4em; line-height: 1.5;
}
.site-nav ul a { position: relative; border-bottom: 0 !important; }
.site-nav ul a::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; background: var(--lamp);
    transform: scaleX(0); transform-origin: 0 50%; transition: transform .3s cubic-bezier(.2,.7,.2,1);
}
.site-nav ul a:hover::after, .site-nav ul a[aria-current="page"]::after { transform: scaleX(1); }

/* ---------- scroll reveal (only when JS is present) ---------- */
.js-reveal .rv { opacity: 0; transform: scale(.97); transition: opacity .6s ease, transform .6s ease; transition-delay: calc(var(--d, 0) * 70ms); }
.js-reveal .rv.in { opacity: 1; transform: none; }

/* ---------- buttons: ripple + glow ---------- */
.btn { position: relative; overflow: hidden; }
.btn-primary { box-shadow: 0 8px 24px -12px rgba(229,187,108,.7); }
.btn-primary:hover { box-shadow: 0 12px 30px -10px rgba(229,187,108,.85); }
.btn .ripple { position: absolute; border-radius: 50%; background: currentColor; opacity: .25; transform: scale(0); pointer-events: none; animation: ripple .6s ease-out forwards; }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

/* ---------- hero ---------- */
.hero-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.hero-kicker {
    display: inline-flex; align-items: center; gap: .55rem; padding: .35em .9em; margin-bottom: 1.2rem;
    border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; color: var(--muted);
    background: color-mix(in srgb, var(--ink-1) 70%, transparent); backdrop-filter: blur(8px);
    animation: pageIn .8s .1s both;
}
.hero-kicker .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lamp); box-shadow: 0 0 0 0 rgba(229,187,108,.6); animation: pulse 2.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px rgba(229,187,108,0); } 100% { box-shadow: 0 0 0 0 rgba(229,187,108,0); } }
.split-words .w { display: inline-block; opacity: 0; animation: wordIn .9s cubic-bezier(.2,.7,.2,1) forwards; animation-delay: calc(var(--i) * 80ms + 250ms); }
@keyframes wordIn { to { opacity: 1; } }
.hero .lede, .hero-actions { animation: pageIn .9s .75s cubic-bezier(.2,.7,.2,1) both; }
.hero-actions { animation-delay: .95s; }
.hero-book::before {
    content: ''; position: absolute; inset: 8% -12% -4%; z-index: -1; border-radius: 50%;
    background: radial-gradient(closest-side, rgba(229,187,108,.35), transparent 70%); filter: blur(24px);
}
.hero-book { position: relative; }
.hero::before { transition: opacity .6s; }
html[data-theme="light"] .hero::before { background: radial-gradient(closest-side, rgba(244,184,92,.7) 0%, rgba(228,140,104,.34) 34%, rgba(228,140,104,.08) 62%, transparent 75%); }
.streak-chip { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .85rem; color: var(--lamp-text); }
.streak-chip svg { width: 16px; height: 16px; color: var(--dawn); }

/* ---------- tiles: tilt, shine, spotlight ---------- */
.tile-cover::after {
    content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .25s;
    background: radial-gradient(circle at var(--sx, 50%) var(--sy, 0%), rgba(255,255,255,.26), transparent 55%);
}
.tile:hover .tile-cover::after { opacity: 1; }
.tile-cover.is-tilting { transition: box-shadow .25s; }
.tile-title { transition: color .2s; }
.tile:hover .tile-title { color: var(--lamp-text-strong); }

[data-spot] { position: relative; overflow: hidden; }
[data-spot]::after {
    content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s;
    background: radial-gradient(360px circle at var(--mx, 50%) var(--my, 50%), rgba(229,187,108,.13), transparent 65%);
}
[data-spot]:hover::after { opacity: 1; }
.continue-card, .plan, .stat { transition: border-color .2s, transform .25s; }

/* ---------- stats strip ---------- */
.stats-strip { border-block: 1px solid var(--line); background: var(--ink-1); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); text-align: center; }
.stats-grid > div { padding: 1.6rem 1rem; position: relative; }
.stats-grid > div + div::before { content: ''; position: absolute; left: 0; top: 24%; bottom: 24%; width: 1px; background: var(--line); }
.stats-grid strong { display: block; font-family: var(--font-display); font-size: clamp(1.7rem, 4vw, 2.4rem); color: var(--lamp-text); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats-grid span { color: var(--muted); font-size: .88rem; }

/* ---------- ranked rail (Most read) ---------- */
.rail { display: flex; gap: 1.4rem; overflow-x: auto; padding: .5rem .25rem 1.4rem; scroll-snap-type: x proximity; counter-reset: rank; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.rail .tile { flex: 0 0 176px; scroll-snap-align: start; counter-increment: rank; position: relative; padding-left: 1.2rem; }
.rail .tile::before {
    content: counter(rank); position: absolute; left: -.2rem; bottom: 3.4rem; z-index: 2; pointer-events: none;
    font: 700 4.6rem/1 var(--font-display); color: transparent; -webkit-text-stroke: 2px var(--lamp); opacity: .9;
    text-shadow: 0 6px 22px var(--shadow-1);
}
.rail .tile-cover { margin-left: .9rem; }
.rail .tile-title, .rail .tile-meta { margin-left: .9rem; }

/* ---------- feature cards ---------- */
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1.25rem; }
.feature { padding: 1.6rem; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--ink-1); transition: border-color .25s, transform .3s; }
.feature:hover { border-color: rgba(229,187,108,.5); }
.feature .ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; margin-bottom: 1rem; background: rgba(229,187,108,.14); color: var(--lamp-text); }
.feature .ico svg { width: 24px; height: 24px; }
.feature h3 { font-size: 1.12rem; margin-bottom: .35em; }
.feature p { color: var(--muted); font-size: .94rem; margin: 0; }

/* ---------- genre marquee ---------- */
.marquee { padding: 0 1.25rem; }
.marquee-track { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; max-width: 1100px; margin: 0 auto; }
.marquee-track [aria-hidden="true"] { display: none; }

/* ---------- back to top ---------- */
.to-top {
    position: fixed; right: 20px; bottom: 20px; z-index: 120; width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--ink-1); color: var(--lamp-text); display: grid; place-items: center; box-shadow: 0 10px 30px -10px var(--shadow-1);
    opacity: 0; transform: translateY(14px) scale(.9); pointer-events: none; transition: opacity .3s, transform .3s;
}
.to-top.is-on { opacity: 1; transform: none; pointer-events: auto; }
.to-top svg { grid-area: 1 / 1; }
.to-top .ring { width: 48px; height: 48px; transform: rotate(-90deg); }
.to-top .ring circle { fill: none; stroke-width: 2.5; }
.to-top .ring .bg { stroke: var(--line); }
.to-top .ring .fg { stroke: var(--lamp); stroke-linecap: round; stroke-dasharray: 125.7; stroke-dashoffset: 125.7; }
.to-top .arrow { width: 18px; height: 18px; }

/* ---------- footer horizon ---------- */
.site-footer { position: relative; margin-top: 5rem; }
.horizon { position: absolute; left: 0; right: 0; top: -58px; height: 58px; pointer-events: none; color: var(--ink-1); }
.horizon svg { width: 100%; height: 100%; display: block; }
.horizon .sun { fill: var(--lamp); opacity: .9; }
.footer-tools { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

/* ---------- search palette ---------- */
.palette { position: fixed; inset: 0; z-index: 5000; display: grid; align-items: start; justify-items: center; padding: 12vh 1rem 1rem; background: color-mix(in srgb, var(--ink-0) 70%, transparent); backdrop-filter: blur(8px); animation: fadeIn .2s both; }
.palette[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.palette-box { width: min(620px, 100%); background: var(--ink-1); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; box-shadow: 0 40px 80px -20px var(--shadow-2); animation: popIn .28s cubic-bezier(.2,.8,.2,1) both; }
@keyframes popIn { from { opacity: 0; transform: translateY(-14px) scale(.97); } }
.palette-box input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 1.1rem 1.3rem; font-size: 1.05rem; background: transparent; }
.palette-box input:focus { box-shadow: none; }
.palette-list { max-height: 52vh; overflow-y: auto; padding: .4rem; }
.palette-list .label { padding: .6rem .9rem .3rem; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.palette-item { display: flex; align-items: center; gap: .9rem; padding: .6rem .9rem; border-radius: 10px; cursor: pointer; }
.palette-item[aria-selected="true"], .palette-item:hover { background: var(--ink-2); }
.palette-item .pi-cover { width: 34px; flex: none; aspect-ratio: 2/3; border-radius: 4px; background: var(--ink-3) center / cover; }
.palette-item .pi-ico { width: 34px; height: 34px; flex: none; border-radius: 9px; display: grid; place-items: center; background: var(--ink-2); color: var(--lamp-text); }
.palette-item .pi-ico svg { width: 18px; height: 18px; }
.palette-item strong { display: block; font-weight: 600; font-size: .96rem; }
.palette-item small { color: var(--muted); }
.palette-empty { padding: 1.4rem; text-align: center; color: var(--muted); }
.palette-foot { display: flex; gap: 1rem; padding: .6rem 1.1rem; border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted); }
.palette-foot kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 .35em; }

/* ---------- toast + misc motion ---------- */
.toast { animation: toastIn .35s cubic-bezier(.2,.8,.2,1) both; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 16px); } }
.chapter-row { transition: background .2s, padding-left .25s; }
.pill { transition: border-color .2s, background .2s, color .2s, transform .2s; }
.owned-note::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ---------- reading streak + week chart ---------- */
.week { display: flex; align-items: flex-end; gap: .55rem; height: 92px; margin-top: .5rem; }
.week .d { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: .4rem; height: 100%; font-size: .72rem; color: var(--muted); }
.week .bar { width: 100%; max-width: 30px; border-radius: 6px 6px 3px 3px; background: var(--line); height: 6px; transform-origin: bottom; }
.week .on .bar { background: linear-gradient(180deg, var(--lamp), var(--dawn)); height: var(--h, 40px); animation: grow .9s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--i) * 70ms); }
.week .today { color: var(--lamp-text); font-weight: 700; }
@keyframes grow { from { height: 6px; } }

/* ---------- story page extras ---------- */
.facts .reading-time { display: inline-flex; align-items: center; gap: .35rem; }
.facts svg { width: 15px; height: 15px; }
.share-btn { display: inline-flex; align-items: center; gap: .5rem; }
.share-btn svg { width: 16px; height: 16px; }
.story-progress { max-width: 520px; margin-top: 1.25rem; }
.story-progress .bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.story-progress .bar i { display: block; height: 100%; width: var(--p, 0%); background: linear-gradient(90deg, var(--dawn), var(--lamp)); border-radius: inherit; animation: fillIn 1.2s cubic-bezier(.2,.8,.2,1) both; }
@keyframes fillIn { from { width: 0; } }
.story-progress small { color: var(--muted); }
.story-cover { transition: transform .5s cubic-bezier(.2,.8,.2,1); }

/* ---------- 404 ---------- */
.lost { text-align: center; padding: clamp(3rem, 10vw, 7rem) 0; }
.lost svg { width: min(360px, 80%); height: auto; margin-bottom: 1rem; overflow: visible; }
.lost .sun404 { animation: rise404 3s cubic-bezier(.2,.8,.2,1) both; fill: var(--lamp); }
@keyframes rise404 { from { transform: translateY(60px); opacity: 0; } }
.lost .star404 { fill: var(--lamp-text); animation: twinkle 3s ease-in-out infinite; }
.lost .star404:nth-child(2n) { animation-delay: 1s; }
@keyframes twinkle { 50% { opacity: .2; } }

/* ---------- view transition: circular theme reveal ---------- */
html.vt-theme::view-transition-old(root), html.vt-theme::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.vt-theme::view-transition-new(root) { z-index: 9999; }
html.vt-theme .site-header { view-transition-name: none; }
html.theme-anim *, html.theme-anim *::before, html.theme-anim *::after { transition: background-color .45s, color .45s, border-color .45s, fill .45s, stroke .45s !important; }

@media (max-width: 880px) {
    .nav-search kbd { display: none; }
    .nav-account .theme-toggle { order: 0; }
}

@media (prefers-reduced-motion: reduce) {
    main, .hero-kicker, .hero .lede, .hero-actions, .toast { animation: none !important; }
    .split-words .w { opacity: 1; transform: none; animation: none; }
    .js-reveal .rv { opacity: 1; transform: none; transition: none; }
    .hero-kicker .dot { animation: none; }
    .week .on .bar, .story-progress .bar i { animation: none; }
}

/* covers fade in once loaded (only when JS is running) */
.js-reveal img.cover { opacity: 0; transition: opacity .6s; }
.js-reveal img.cover.is-loaded { opacity: 1; }

[hidden] { display: none !important; }

/* sunrise behind the footer hills */
.horizon { overflow: hidden; }
.horizon .sun-dot {
    position: absolute; left: 50%; bottom: 14px; width: 70px; height: 70px; margin-left: -35px; border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, var(--lamp-strong), var(--dawn));
    box-shadow: 0 0 70px 14px rgba(229,187,108,.4);
}
.horizon svg { position: relative; }

/* stability */
html { scrollbar-gutter: stable; }

/* ---------- simple, layout-safe effects (nothing here moves its own box) ---------- */
.hero::before { animation: glow 7s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .75; } to { opacity: 1; } }
.tile-cover img, .story-cover img { transition: transform .6s ease, filter .4s; }
.tile:hover .tile-cover img { transform: scale(1.06); filter: brightness(1.06); }
.btn { transition: background-color .25s, color .25s, border-color .25s, box-shadow .25s; }
.btn-primary:hover { box-shadow: 0 0 0 4px rgba(229,187,108,.25), 0 12px 30px -10px rgba(229,187,108,.85); }
.card, .plan, .stat, .continue-card, .feature { transition: border-color .3s, box-shadow .3s, background-color .3s; }
.card:hover, .plan:hover, .stat:hover, .continue-card:hover, .feature:hover { box-shadow: 0 14px 34px -22px var(--shadow-1); border-color: rgba(229,187,108,.45); }
.pill:hover { background: rgba(229,187,108,.14); border-color: var(--lamp); }
.chapter-row:hover { background: rgba(229,187,108,.08); }
.stats-grid strong { transition: color .3s; }
@media (prefers-reduced-motion: reduce) { .hero::before { animation: none; } .tile:hover .tile-cover img { transform: none; } }

/* library: books you can read */
.own-item { position: relative; }
.own-tag { display: inline-block; margin-top: .35rem; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: .15em .6em; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.own-owned { color: var(--ok); border-color: currentColor; }
.own-pass, .own-yours { color: var(--lamp-text); border-color: currentColor; }
.more-row { text-align: center; margin-top: 1.75rem; }
