:root {
    --pink: #ff2d8b;
    --pink-dark: #e6006f;
    --purple: #7c3aed;
    --purple-dark: #5b21b6;
    --blue: #2563eb;
    --cyan: #06b6d4;
    --lime: #84cc16;
    --orange: #f97316;
    --yellow: #facc15;
    --mint: #2dd4bf;

    --color-primary: var(--purple);
    --color-primary-dark: var(--purple-dark);
    --color-accent: var(--cyan);
    --color-accent-warm: var(--orange);
    --color-success: #22c55e;
    --color-danger: #f43f5e;
    --color-warning: var(--yellow);
    --color-surface: #ffffff;
    --color-text: #1a1033;
    --color-text-muted: #5b4d7a;
    --color-bg-page: #818CF8;
    --color-border: rgba(255, 255, 255, 0.65);

    --radius: 20px;
    --radius-lg: 28px;
    --radius-xl: 36px;
    --shadow: 0 12px 32px rgba(124, 58, 237, 0.18);
    --shadow-lg: 0 20px 50px rgba(255, 45, 139, 0.22);
    --shadow-glow: 0 0 40px rgba(6, 182, 212, 0.35);
    --font: 'Outfit', system-ui, sans-serif;
    --font-display: 'Fredoka', system-ui, sans-serif;

    --text-base: 1.5rem;
    --text-lg: 1.75rem;
    --text-xl: 2rem;
    --text-2xl: 2.5rem;
    --text-3xl: 3.25rem;

    --topic-space: #6366f1;
    --topic-body: #ec4899;
    --topic-plants: #22c55e;
    --topic-animals: #f59e0b;
    --topic-weather: #38bdf8;
    --topic-germs: #a855f7;
    --topic-earth-science: #0ea5e9;
    --topic-engineering: #f97316;
    --topic-physical-science: #eab308;

    --content-max-width: 100%;
    --page-gutter: 200px;
    --page-gutter-mobile: 16px;
    --page-inner-padding: 64px;
    --page-inner-padding-mobile: 16px;
    --pdf-page-max-width: 980px;
}

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

html {
    scroll-behavior: smooth;
    background: var(--color-bg-page);
}

body {
    font-family: var(--font);
    font-size: var(--text-base);
    color: var(--color-text);
    line-height: 1.7;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-page);
    position: relative;
    overflow-x: hidden;
}

body::before {
    display: none;
}

@keyframes skyShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes twinkle {
    from { opacity: 0.25; transform: translateY(0); }
    to { opacity: 0.55; transform: translateY(-8px); }
}

@keyframes floatUp {
    from { transform: translateY(0) rotate(0deg); }
    to { transform: translateY(-14px) rotate(6deg); }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-6deg) scale(1.1); }
    50% { transform: rotate(8deg) scale(1.15); }
}

@keyframes signBounce {
    0%, 100% { transform: rotate(-8deg) translateY(0); }
    50% { transform: rotate(-8deg) translateY(-6px); }
}

@keyframes drift {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(12px); }
}

/* —— Ambient background (full bleed, soft — no emoji walls) —— */
.fun-bg {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-glow-minimal {
    background: transparent;
}

.fun-bg-minimal .bg-glow {
    opacity: 1;
}

.bg-glow {
    position: absolute;
    inset: 0;
    background: transparent;
}

.bg-fill {
    position: absolute;
    inset: -5%;
    background: transparent;
    opacity: 0.95;
}

.bg-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(42px);
    opacity: 0.88;
    animation: blobDrift 22s ease-in-out infinite;
}

.bg-blob-1 {
    width: min(70vw, 720px);
    height: min(70vw, 720px);
    top: -15%;
    left: -12%;
    background: rgba(255, 45, 139, 0.35);
    animation-duration: 24s;
}

.bg-blob-2 {
    width: min(65vw, 680px);
    height: min(65vw, 680px);
    top: 30%;
    right: -15%;
    background: rgba(37, 99, 235, 0.32);
    animation-duration: 28s;
    animation-delay: -6s;
}

.bg-blob-3 {
    width: min(60vw, 620px);
    height: min(60vw, 620px);
    bottom: -18%;
    left: 5%;
    background: rgba(6, 182, 212, 0.3);
    animation-duration: 26s;
    animation-delay: -12s;
}

.bg-blob-4 {
    width: min(55vw, 560px);
    height: min(55vw, 560px);
    top: 8%;
    right: 10%;
    background: rgba(132, 204, 22, 0.28);
    animation-duration: 30s;
    animation-delay: -4s;
}

.bg-blob-5 {
    width: min(50vw, 500px);
    height: min(50vw, 500px);
    bottom: 20%;
    right: 25%;
    background: rgba(168, 85, 247, 0.3);
    animation-duration: 32s;
    animation-delay: -8s;
}

.bg-blob-6 {
    width: min(58vw, 580px);
    height: min(58vw, 580px);
    top: 42%;
    left: 28%;
    background: rgba(236, 72, 153, 0.28);
    animation-duration: 27s;
    animation-delay: -10s;
}

.bg-blob-7 {
    width: min(48vw, 480px);
    height: min(48vw, 480px);
    top: 55%;
    left: -8%;
    background: rgba(250, 204, 21, 0.26);
    animation-duration: 29s;
    animation-delay: -14s;
}

.bg-blob-8 {
    width: min(52vw, 520px);
    height: min(52vw, 520px);
    top: 18%;
    left: 42%;
    background: rgba(14, 165, 233, 0.24);
    animation-duration: 31s;
    animation-delay: -5s;
}

.bg-waves {
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 200' preserveAspectRatio='none'%3E%3Cpath fill='rgba(255,255,255,0.14)' d='M0,96L60,101.3C120,107,240,117,360,112C480,107,600,85,720,80C840,75,960,85,1080,96C1200,107,1320,117,1380,122.7L1440,128L1440,200L0,200Z'/%3E%3C/svg%3E");
    background-size: 100% 28%;
    background-repeat: repeat-x;
    background-position: 0 100%;
    opacity: 0.9;
    animation: waveSlide 28s linear infinite;
}

.bg-waves-2 {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 200' preserveAspectRatio='none'%3E%3Cpath fill='rgba(255,255,255,0.1)' d='M0,64L48,74.7C96,85,192,107,288,112C384,117,480,107,576,90.7C672,75,768,53,864,58.7C960,64,1056,96,1152,101.3C1248,107,1344,85,1392,74.7L1440,64L1440,200L0,200Z'/%3E%3C/svg%3E");
    background-size: 120% 22%;
    background-position: 0 60%;
    opacity: 0.85;
    animation: waveSlide2 36s linear infinite;
}

@keyframes waveSlide2 {
    0% { background-position: 0 60%; }
    100% { background-position: -1440px 60%; }
}

.bg-rings {
    position: absolute;
    inset: 0;
    background: transparent;
    opacity: 0.65;
}

.bg-shapes {
    position: absolute;
    inset: 0;
}

.bg-shape {
    position: absolute;
    animation: shapeFloat 10s ease-in-out infinite;
    animation-delay: calc(var(--si) * 0.4s);
}

.bg-shape-ring {
    border: 3px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.15);
}

.bg-shape-diamond {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    animation-name: diamondFloat;
}

.bg-shape-plus::before,
.bg-shape-plus::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 3px;
}

.bg-shape-plus::before {
    width: 100%;
    height: 22%;
    top: 39%;
    left: 0;
}

.bg-shape-plus::after {
    width: 22%;
    height: 100%;
    left: 39%;
    top: 0;
}

.bg-shape-star::before {
    content: '★';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: inherit;
    color: rgba(255, 255, 255, 0.55);
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.4);
    line-height: 1;
}

@keyframes waveSlide {
    0% { background-position: 0 100%; }
    100% { background-position: 1440px 100%; }
}

@keyframes shapeFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(6deg); }
}

@keyframes diamondFloat {
    0%, 100% { transform: rotate(45deg) translateY(0); }
    50% { transform: rotate(45deg) translateY(-8px); }
}

.bg-icon-field {
    position: absolute;
    inset: 0;
}

.bg-field-icon {
    position: absolute;
    line-height: 1;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.1));
    user-select: none;
    pointer-events: none;
}

.bg-mesh,
.bg-pattern,
.bg-sparkles {
    display: none;
}

.bg-icons {
    position: absolute;
    inset: 0;
}

.bg-icon {
    position: absolute;
    line-height: 1;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.12));
    animation: iconFloat 8s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.35s);
    user-select: none;
}

@keyframes iconFloat {
    0%, 100% {
        transform: translateY(0) rotate(-6deg);
    }
    50% {
        transform: translateY(-10px) rotate(5deg);
    }
}

@keyframes blobDrift {
    0%, 100% {
        transform: translate(0, 0) scale(1);
    }
    33% {
        transform: translate(2%, 3%) scale(1.04);
    }
    66% {
        transform: translate(-2%, 1%) scale(0.98);
    }
}

body::after {
    display: none;
}

a {
    color: var(--purple);
    text-decoration: none;
    transition: color 0.2s ease, transform 0.2s ease;
}

a:hover {
    color: var(--pink);
}

img {
    max-width: 100%;
    display: block;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 20px;
    position: relative;
    z-index: 1;
    width: 100%;
}

main.page-main.container {
    padding: 16px var(--page-gutter) 32px;
    max-width: 100%;
}

/* —— Public site shell (same look as home) —— */
.public-page {
    font-size: 1.35rem;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.public-page .logo {
    font-size: 1.75rem;
}

.public-page .logo-tagline {
    font-size: clamp(0.62rem, 0.9vw, 0.72rem);
    margin-top: 0;
    line-height: 1.1;
}

.public-page .nav-links a {
    font-size: 0.95rem;
    padding: 4px 10px;
}

.public-page .nav-user-name {
    font-size: 1.05rem;
    max-width: 140px;
}

.public-page .site-header .container {
    padding: 2px var(--page-gutter);
}

.public-page main.page-main.page-main-compact {
    background: rgba(255, 255, 255, 0.93);
    border-radius: var(--radius-lg);
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.08);
    min-height: calc(100dvh - 58px);
    flex: 1;
    margin-left: var(--page-gutter);
    margin-right: var(--page-gutter);
    width: auto;
    max-width: none;
    padding: 32px var(--page-inner-padding) 40px;
}

.public-page main.page-main.page-main-compact > .section-title-compact,
.public-page main.page-main.page-main-compact > .story-grid-compact,
.public-page main.page-main.page-main-compact > .empty-state-compact,
.public-page main.page-main.page-main-compact > .alert,
.public-page main.page-main.page-main-compact > .page-section,
.public-page main.page-main.page-main-compact > .page-header {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.public-page .section-title,
.public-page .section-title-compact {
    color: var(--purple-dark);
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.35rem);
    margin-bottom: 8px;
    text-align: left;
}

.public-page .story-grid-compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    align-items: stretch;
}

@media (max-width: 900px) {
    .public-page .story-grid-compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .public-page main.page-main.container {
        padding-left: var(--page-gutter-mobile);
        padding-right: var(--page-gutter-mobile);
    }

    .public-page main.page-main.page-main-compact {
        margin-left: var(--page-gutter-mobile);
        margin-right: var(--page-gutter-mobile);
        padding: 28px var(--page-inner-padding-mobile) 36px;
    }

    .explore-library-page main.page-main.page-main-compact {
        padding: 28px calc(var(--page-inner-padding-mobile) + 8px) 36px;
    }

    .public-page .story-grid-compact {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 900px) {
    .public-page .site-header .container {
        padding: 2px var(--page-gutter);
    }
}

/* —— Site-wide full-bleed content panels —— */
.page-content-panel,
.page-section,
.page-header,
.page-main > .story-grid,
.page-main > .story-grid-compact,
.page-main > .section-title,
.page-main > .section-title-compact,
.page-main > .empty-state,
.page-main > .empty-state-compact,
.page-main > .alert,
.page-main > .filters-bar {
    background: rgba(255, 255, 255, 0.93);
    border-radius: var(--radius-lg);
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.08);
    width: 100%;
}

.page-section {
    padding: 16px 20px;
}

.page-section .form-panel {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.page-section .form-panel:not(.login-panel) {
    max-width: none;
}

.page-main > .story-grid,
.page-main > .story-grid-compact {
    padding: 16px 18px;
}

.page-main > .section-title,
.page-main > .section-title-compact,
.page-main > .empty-state,
.page-main > .empty-state-compact,
.page-main > .alert,
.page-main > .filters-bar {
    padding: 16px 18px;
}

.explore-library-page .page-main-compact > .section-title-compact,
.explore-library-page .page-main-compact > .my-library-tip,
.explore-library-page .page-main-compact > .explore-search-panel,
.explore-library-page .page-main-compact > .story-grid-compact,
.explore-library-page .page-main-compact > .empty-state-compact,
.explore-library-page .page-main-compact > .explore-locked-state,
.explore-library-page .page-main-compact > .alert {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

/* —— Header —— */
.site-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.1);
    position: sticky;
    top: 0;
    z-index: 200;
    flex-shrink: 0;
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 46px;
    flex-wrap: nowrap;
    padding: 2px 0;
}

.site-brand {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex-shrink: 0;
    min-width: 0;
    line-height: 1;
}

.logo-tagline {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
    line-height: 1.1;
    padding: 0;
}

.logo {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 0;
}

.site-logo-img {
    display: block;
    height: 46px;
    width: auto;
    max-width: min(220px, 42vw);
    object-fit: contain;
}

.public-page .site-logo-img {
    height: 48px;
}

.admin-header .site-logo-img {
    height: 58px;
    max-width: 300px;
}

.logo-icon {
    color: var(--purple);
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.logo-icon svg {
    width: 1.25em;
    height: 1.25em;
}

.logo:hover {
    transform: scale(1.02);
    color: var(--color-text);
}

.nav-links {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
    min-width: 0;
}

.nav-links a {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--color-text);
    padding: 4px 9px;
    border-radius: 999px;
    background: transparent;
    border: 2px solid transparent;
    white-space: nowrap;
}

.nav-links a:not(.nav-login-btn):not(.nav-cart):hover {
    background: #ffffff;
    color: var(--color-text) !important;
    border-color: var(--purple);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.18);
}

.nav-auth {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 2px;
    padding-left: 6px;
    border-left: 2px solid rgba(124, 58, 237, 0.15);
    flex-shrink: 0;
}

.nav-user-name {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--purple-dark);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-login-btn {
    flex-shrink: 0;
}

/* Sign up / Log in — white fill, purple outline (.nav-links a overrides .btn-*) */
.nav-links a.nav-login-btn.btn-primary,
.nav-links a.nav-login-btn.btn-outline {
    background: #ffffff !important;
    color: var(--color-text) !important;
    border: 2px solid var(--purple) !important;
    box-shadow: none;
    font-weight: 800;
    text-shadow: none;
}

.nav-links a.nav-login-btn.btn-primary:hover,
.nav-links a.nav-login-btn.btn-outline:hover {
    background: #ffffff !important;
    color: var(--color-text) !important;
    border-color: var(--purple-dark) !important;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.18);
    transform: translateY(-2px);
}

.admin-header .nav-links a.nav-login-btn.btn-primary,
.admin-header .nav-links a.nav-login-btn.btn-outline {
    background: #ffffff !important;
    color: var(--color-text) !important;
    border: 2px solid var(--purple) !important;
    box-shadow: none;
    text-shadow: none;
}

.admin-header .nav-links a.nav-login-btn.btn-primary:hover,
.admin-header .nav-links a.nav-login-btn.btn-outline:hover {
    background: #ffffff !important;
    color: var(--color-text) !important;
    border-color: var(--purple-dark) !important;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.18);
}

.nav-admin-link {
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-text-muted);
    padding: 8px 12px;
    border-radius: 999px;
}

.nav-admin-link:hover {
    color: var(--purple) !important;
    background: rgba(124, 58, 237, 0.1);
}

.login-panel {
    max-width: 100%;
    margin: 0;
}

.public-page.auth-page main.page-main.page-main-compact.auth-main {
    min-height: min(560px, calc(100dvh - 140px));
    flex: 1 0 auto;
    max-width: 760px;
    margin-top: 24px;
    margin-bottom: 32px;
    margin-left: auto;
    margin-right: auto;
    width: calc(100% - 2 * var(--page-gutter));
    padding: 40px 44px 48px;
}

@media (max-width: 640px) {
    .public-page.auth-page main.page-main.page-main-compact.auth-main {
        min-height: auto;
        margin-top: 16px;
        margin-bottom: 24px;
        width: calc(100% - 2 * var(--page-gutter-mobile));
        padding: 28px var(--page-inner-padding-mobile) 32px;
    }
}

.auth-card {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.auth-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(2rem, 4vw, 2.65rem);
    color: var(--purple-dark);
    line-height: 1.15;
}

.auth-lead {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    line-height: 1.5;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form .form-group:last-of-type {
    margin-bottom: 24px;
}

.auth-form .form-control {
    padding: 18px 22px;
    font-size: 1.1rem;
}

.auth-form .btn-primary {
    padding: 16px 24px;
    font-size: 1.15rem;
}

.auth-switch {
    margin: 0;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 1.05rem;
    line-height: 1.55;
}

.btn-block {
    width: 100%;
}

.public-page.auth-page main.page-main.page-main-compact:not(.auth-main) {
    max-width: none;
    margin-left: auto;
    margin-right: auto;
    width: calc(100% - 2 * var(--page-gutter));
}

@media (max-width: 640px) {
    .public-page.auth-page main.page-main.page-main-compact:not(.auth-main) {
        margin-left: auto;
        margin-right: auto;
        width: calc(100% - 2 * var(--page-gutter-mobile));
    }
}

.public-page.auth-page .btn-primary {
    background: #ffffff !important;
    color: var(--color-text) !important;
    border: 2px solid var(--purple) !important;
    box-shadow: none;
    text-shadow: none;
}

.public-page.auth-page .btn-primary:hover {
    background: #ffffff !important;
    color: var(--color-text) !important;
    border-color: var(--purple-dark) !important;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.18);
}

.login-switch {
    margin-top: 24px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--text-lg);
}

.setup-list {
    margin: 0 0 24px;
    padding-left: 1.25rem;
    line-height: 1.7;
}

main,
.page-main {
    padding: 10px 0 16px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    width: 100%;
}

.page-main-compact {
    padding-top: 10px;
    padding-bottom: 14px;
    gap: 12px;
}

.stories-section {
    width: 100%;
}

.section-title-compact {
    font-size: 1.35rem;
    margin-bottom: 10px;
    text-align: left;
}

.page-main-compact > .section-title-compact {
    color: var(--purple-dark);
    text-shadow: none;
}

.page-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.page-header {
    text-align: center;
    width: 100%;
    margin: 0 auto;
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.93);
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.95);
}

.page-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, var(--text-3xl));
    font-weight: 700;
    color: var(--purple-dark);
    line-height: 1.2;
    margin-bottom: 16px;
}

.page-title-sub {
    font-size: clamp(1.75rem, 4vw, var(--text-2xl));
    margin-bottom: 0;
}

.page-header .page-lead {
    color: var(--color-text-muted);
    text-align: center;
    margin: 0 auto;
    max-width: 620px;
    font-size: var(--text-lg);
    line-height: 1.65;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    line-height: 1.2;
    color: var(--color-text);
}

.section-title {
    font-size: clamp(2rem, 5vw, var(--text-2xl));
    margin-bottom: 24px;
    color: var(--purple-dark);
    text-align: center;
}

.page-lead {
    color: var(--color-text-muted);
    font-size: var(--text-lg);
    font-weight: 500;
    line-height: 1.65;
}

/* —— Hero —— */
.hero {
    background: rgba(255, 255, 255, 0.98);
    color: var(--color-text);
    border-radius: var(--radius-xl);
    padding: 64px 48px;
    text-align: center;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    margin-bottom: 0;
    border: 4px solid white;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 280px;
    height: 280px;
    background: rgba(255, 45, 139, 0.12);
    border-radius: 50%;
}

.hero::after {
    content: '';
    position: absolute;
    bottom: -40%;
    left: -10%;
    width: 240px;
    height: 240px;
    background: rgba(6, 182, 212, 0.14);
    border-radius: 50%;
}

.hero > * {
    position: relative;
    z-index: 1;
}

.hero h1 {
    font-size: clamp(2.75rem, 7vw, var(--text-3xl));
    margin-bottom: 12px;
    color: var(--purple-dark);
}

.hero .headline {
    font-size: clamp(1.75rem, 4.5vw, 2.35rem);
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--purple-dark);
}

.hero .subtitle {
    font-size: var(--text-lg);
    color: var(--color-text-muted);
    max-width: 560px;
    margin: 0 auto 28px;
    font-weight: 500;
}

.hero-compact {
    padding: 16px 24px;
    border-width: 2px;
    border-radius: var(--radius-lg);
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 20px;
    text-align: center;
}

.hero-compact::before,
.hero-compact::after {
    display: none;
}

.hero-compact h1 {
    font-size: 1.65rem;
    margin-bottom: 0;
}

.hero-compact .headline {
    font-size: 1rem;
    margin-bottom: 0;
    flex: 1 1 auto;
}

.hero-compact .btn {
    margin: 0;
}

/* —— Buttons —— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 1.25rem;
    border: 3px solid transparent;
    cursor: pointer;
    font-family: var(--font-display);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-4px) scale(1.03);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-primary {
    background: var(--purple);
    color: white !important;
    box-shadow: 0 8px 28px rgba(124, 58, 237, 0.35);
    border-color: rgba(255, 255, 255, 0.5);
}

.btn-primary:hover {
    background: var(--purple-dark);
    box-shadow: 0 12px 36px rgba(91, 33, 182, 0.4);
    color: white !important;
}

.btn-outline {
    background: white;
    color: var(--purple) !important;
    border-color: var(--purple);
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.15);
}

.btn-outline:hover {
    background: #f5f3ff;
    color: var(--purple-dark) !important;
}

.btn-success {
    background: var(--color-success);
    color: #064e3b !important;
    border-color: white;
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.35);
}

.btn-danger {
    background: var(--color-danger);
    color: white !important;
    box-shadow: 0 6px 20px rgba(244, 63, 94, 0.35);
}

.btn-warning {
    background: var(--orange);
    color: #7c2d12 !important;
    box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35);
}

.btn-sm {
    padding: 10px 18px;
    font-size: 0.9rem;
}

/* —— Badges —— */
.badge-free {
    display: inline-block;
    background: #4ade80;
    color: #14532d;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 6px 12px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border: 2px solid white;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
}

.badge-format-pdf {
    display: inline-block;
    background: #a78bfa;
    color: #4c1d95;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 6px 12px;
    border-radius: 999px;
    margin-left: 6px;
    text-transform: uppercase;
    border: 2px solid white;
}

.badge-price {
    display: inline;
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    color: #000;
    font-size: 0.95rem;
    font-weight: 700;
}

.badge-owned {
    display: inline-block;
    background: var(--blue);
    color: white;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 6px 12px;
    border-radius: 999px;
    border: 2px solid white;
}

.story-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.story-card-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.story-card-badges .badge-free,
.story-card-badges .badge-format-pdf {
    background: #757575;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.55);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.btn-view-more {
    background: var(--purple);
    color: white !important;
    border: 2px solid white;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
    font-weight: 800;
    text-decoration: none;
}

.btn-view-more:hover {
    transform: translateY(-1px);
    color: white !important;
    box-shadow: 0 6px 18px rgba(124, 58, 237, 0.45);
}

.nav-cart {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: #f5f3ff;
    border: 2px solid rgba(124, 58, 237, 0.2);
    text-decoration: none;
    margin-right: 8px;
    flex-shrink: 0;
}

.nav-cart:hover {
    border-color: var(--purple);
    background: #ede9fe;
}

.nav-cart-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.nav-cart-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--pink);
    color: white;
    font-size: 0.72rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

.cart-panel {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    border: 4px solid white;
    box-shadow: var(--shadow-lg);
    padding: 24px;
}

.cart-list {
    list-style: none;
    margin: 0 0 24px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cart-item {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 16px;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 2px dashed rgba(124, 58, 237, 0.15);
}

.cart-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.cart-item-cover {
    width: 80px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-lg);
    border: 2px solid white;
    box-shadow: var(--shadow);
}

.cart-item-info h3 {
    font-size: var(--text-lg);
    color: var(--color-text);
    margin-bottom: 4px;
}

.cart-item-price {
    font-weight: 800;
    color: var(--purple-dark);
    font-size: 1.1rem;
}

.cart-summary {
    text-align: center;
    padding-top: 8px;
}

.cart-total {
    font-size: var(--text-xl);
    margin-bottom: 16px;
    color: var(--purple-dark);
}

.cart-note {
    margin-top: 12px;
    font-size: 0.95rem;
    color: var(--color-text-muted);
}

.cart-owned-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cart-owned-list a {
    font-weight: 700;
}

.cart-owned-grid {
    margin-top: 16px;
}

.cart-owned-item .cart-item-info h3 a {
    color: var(--color-text);
    text-decoration: none;
}

.cart-owned-item .cart-item-info h3 a:hover {
    text-decoration: underline;
}

.cart-owned-actions,
.book-owned-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.book-owned-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

.book-purchase-cta {
    background: #f5f3ff;
    border-radius: var(--radius-lg);
    padding: 16px;
    border: 2px dashed rgba(124, 58, 237, 0.25);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1.1rem;
}

/* —— Story cards —— */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 28px;
}

.story-grid-latest {
    grid-template-columns: repeat(3, minmax(280px, 340px));
    justify-content: center;
}

.latest-stories-section .page-header-compact {
    text-align: center;
}

@media (max-width: 960px) {
    .story-grid-latest {
        grid-template-columns: repeat(2, minmax(280px, 340px));
    }
}

@media (max-width: 640px) {
    .story-grid-latest {
        grid-template-columns: minmax(280px, 1fr);
    }
}

.story-grid-compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    align-items: stretch;
}

@media (max-width: 900px) {
    .story-grid-compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 18px;
    }
}

/* Compact grid uses full-size story cards — no shrinking */
.story-card-compact:hover {
    transform: translateY(-8px) rotate(-0.5deg);
}

.empty-state-compact {
    padding: 20px;
}

.site-footer-compact {
    padding: 12px 0;
    font-size: 0.85rem;
}

.site-footer-promo {
    margin: 0 0 6px;
}

/* Explore library */
.explore-library-page .container {
    max-width: 100%;
}

.explore-library-page main.page-main.page-main-compact {
    margin-left: var(--page-gutter);
    margin-right: var(--page-gutter);
    padding: 36px calc(var(--page-inner-padding) + 16px) 44px;
}

.explore-library-page .page-main-compact {
    position: relative;
    z-index: 1;
    gap: 14px;
}

.explore-library-page .section-title-compact {
    margin-bottom: 4px;
}

.explore-search-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 8px;
}

.explore-search-form {
    margin-bottom: 0;
    align-items: stretch;
}

.explore-search-input {
    min-width: 0;
    margin-bottom: 0;
}

.explore-search-btn {
    white-space: nowrap;
}

.explore-topic-chips {
    margin-top: 2px;
}

.explore-results-meta {
    margin: 0;
    font-size: var(--text-base);
    color: var(--purple-dark);
    font-weight: 600;
}

.explore-locked-state {
    text-align: center;
    padding: 48px 24px;
    margin-top: 12px;
}

.explore-locked-message {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.35rem, 2.5vw, 1.75rem);
    font-weight: 700;
    color: var(--purple-dark);
    line-height: 1.5;
}

.explore-locked-message a {
    color: var(--purple);
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.explore-locked-message a:hover {
    color: var(--purple-dark);
}

.explore-library-page .story-card-compact .story-card-img {
    width: 100%;
    height: 230px;
    object-fit: cover;
    object-position: center center;
    flex-shrink: 0;
}

.explore-library-page .story-card-compact .story-card-content {
    padding: 18px 20px 22px;
    gap: 10px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.explore-library-page .story-card-compact .story-card-desc {
    font-size: clamp(1.25rem, 1.85vw, 1.55rem);
    line-height: 1.5;
    flex: 1 1 auto;
    min-height: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.explore-library-page .story-card-compact .story-card-title {
    font-size: clamp(1.85rem, 3.2vw, 2.75rem);
    line-height: 1.3;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    font-weight: 700;
    color: var(--color-text);
    flex-shrink: 0;
}

.explore-library-page .story-card-compact .story-card-meta {
    font-size: 1.2rem;
    font-weight: 600;
    flex-shrink: 0;
}

.explore-library-page .story-card-compact .story-card-bottom {
    margin-top: auto;
}

.explore-library-page .story-card-compact .story-card-bottom .story-card-footer {
    margin-top: 0;
    padding-top: 8px;
}

.explore-library-page .site-footer-compact {
    padding: 10px 0 14px;
    font-size: 1rem;
}

@media (max-width: 900px) {
    .explore-library-page .story-card-compact .story-card-img {
        height: 210px;
    }
}

.story-card {
    background: rgba(255, 255, 255, 0.99);
    border-radius: var(--radius-xl);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow);
    border: 4px solid white;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 560px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.story-card-media,
.home-story-cover-wrap,
.book-cover-wrap {
    position: relative;
    flex-shrink: 0;
}

.story-favorite-form {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    margin: 0;
}

.story-favorite-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    color: #94a3b8;
    transition: transform 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.story-favorite-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
    color: #ef4444;
}

.story-favorite-btn.is-favorited {
    color: #ef4444;
    background: rgba(255, 255, 255, 0.98);
}

.story-favorite-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.my-library-tip {
    margin: 0 0 20px;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    background: rgba(254, 226, 226, 0.55);
    border: 2px solid rgba(239, 68, 68, 0.22);
    color: var(--purple-dark);
    font-size: 1.05rem;
    line-height: 1.5;
}

.my-library-tip-heart {
    color: #ef4444;
    font-size: 1.15em;
    vertical-align: -0.05em;
}

.my-library-empty p + p {
    margin-top: 10px;
}

.story-card:hover {
    transform: translateY(-10px) rotate(-0.5deg);
    box-shadow: var(--shadow-lg);
}

.story-card-img {
    width: 100%;
    height: 240px;
    object-fit: cover;
    background: #e9d5ff;
    border-bottom: 4px solid white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.story-card-content {
    padding: 22px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 10px;
    min-width: 0;
    min-height: 0;
}

.story-card-title {
    font-size: clamp(1.75rem, 3vw, 2.6rem);
    color: var(--color-text);
    flex-shrink: 0;
    line-height: 1.3;
    margin: 0;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    font-weight: 700;
}

.story-card-meta {
    color: var(--color-text-muted);
    font-size: 1.15rem;
    font-weight: 600;
    flex-shrink: 0;
}

.story-card-desc {
    font-size: clamp(1.2rem, 1.75vw, 1.5rem);
    color: var(--color-text-muted);
    flex: 1 1 auto;
    line-height: 1.5;
    margin: 0;
    min-height: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.story-card-bottom {
    margin-top: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.story-card-bottom .story-card-footer {
    margin-top: 0;
    padding-top: 8px;
}

.story-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    padding-top: 12px;
    flex-shrink: 0;
    border-top: 2px dashed rgba(124, 58, 237, 0.15);
}

.category-btn {
    background-color: #334155;
    color: #FFFFFF;
    border: 2px solid #CBD5E1;
}

.category-btn:hover {
    background-color: #475569;
    color: #FFFFFF;
}

.topic-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.topic-tag {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 6px 12px;
    border-radius: 999px;
    box-shadow: none;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* —— Filters —— */
.filters-bar {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    padding: 32px;
    box-shadow: var(--shadow);
    margin-bottom: 0;
    border: 4px solid white;
    backdrop-filter: blur(12px);
}

.search-form {
    display: flex;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.search-form input[type="search"] {
    flex: 1;
    min-width: 200px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.filter-chip {
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 1.05rem;
    background: #f3e8ff;
    color: var(--purple-dark);
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.filter-chip:hover {
    border-color: var(--pink);
    transform: translateY(-2px);
    color: var(--pink) !important;
}

.filter-chip.active {
    background: var(--purple);
    color: white !important;
    border-color: white;
    box-shadow: 0 6px 20px rgba(255, 45, 139, 0.4);
}

/* —— Forms —— */
.form-panel {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
    border: 4px solid white;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}

.form-group label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    margin-bottom: 0;
    cursor: pointer;
}

.form-group label.checkbox-label input {
    width: auto;
    margin: 0;
}

.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    font-weight: 800;
    margin-bottom: 10px;
    color: var(--purple-dark);
    font-family: var(--font-display);
    font-size: var(--text-lg);
}

.form-control {
    width: 100%;
    padding: 16px 20px;
    border: 3px solid #e9d5ff;
    border-radius: var(--radius);
    font-size: var(--text-base);
    font-family: inherit;
    background: #faf5ff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--pink);
    background: white;
    box-shadow: 0 0 0 4px rgba(255, 45, 139, 0.2);
}

textarea.form-control {
    min-height: 150px;
    resize: vertical;
}

input[type="file"].form-control {
    padding: 12px;
    background: white;
}

/* —— Alerts —— */
.alert {
    padding: 16px 20px;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: var(--text-base);
    margin-bottom: 22px;
    border: 3px solid white;
}

.alert-success {
    background: #bbf7d0;
    color: #14532d;
}

.alert-error {
    background: #fecdd3;
    color: #9f1239;
}

.empty-state {
    text-align: center;
    padding: 56px 28px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-xl);
    color: var(--color-text-muted);
    border: 4px solid white;
    box-shadow: var(--shadow);
    font-size: 1.1rem;
}

.empty-state .btn {
    margin-top: 16px;
}

/* —— Stats & tables —— */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 18px;
    margin-bottom: 0;
}

.stat-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 4px solid white;
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
}

.stat-card:nth-child(1) { border-top: 6px solid var(--pink); }
.stat-card:nth-child(2) { border-top: 6px solid var(--lime); }
.stat-card:nth-child(3) { border-top: 6px solid var(--cyan); }
.stat-card:nth-child(4) { border-top: 6px solid var(--orange); }
.stat-card:nth-child(5) { border-top: 6px solid var(--purple); }

.stat-num {
    font-family: var(--font-display);
    font-size: 2.75rem;
    font-weight: 700;
    color: var(--purple-dark);
}

.stat-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.table-panel {
    background: rgba(255, 255, 255, 0.97);
    border-radius: var(--radius-xl);
    overflow-x: auto;
    box-shadow: var(--shadow);
    border: 4px solid white;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 16px 20px;
    text-align: left;
    border-bottom: 2px solid #f3e8ff;
    font-size: 1.15rem;
}

th {
    background: #fae8ff;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--purple-dark);
    font-weight: 800;
}

tr:hover td {
    background: #faf5ff;
}

.status-tag {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: capitalize;
    border: 2px solid white;
}

.status-approved { background: #bbf7d0; color: #166534; }
.status-under_review { background: #fef08a; color: #854d0e; }
.status-rejected { background: #fecaca; color: #991b1b; }
.status-draft { background: #e2e8f0; color: #475569; }
.status-needs_edits { background: #fed7aa; color: #9a3412; }
.status-open { background: #fecaca; color: #991b1b; }
.status-reviewed { background: #fef08a; color: #854d0e; }
.status-resolved { background: #bbf7d0; color: #166534; }
.status-dismissed { background: #e2e8f0; color: #475569; }

/* —— Book reader —— */
.book-header {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 36px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 0;
    border: 4px solid white;
    text-align: left;
}

.book-header h1 {
    font-family: var(--font-display);
    font-size: clamp(1.85rem, 4vw, var(--text-3xl));
    color: var(--color-text);
    margin-bottom: 12px;
    text-align: left;
}

.book-cover {
    width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 32px rgba(124, 58, 237, 0.25);
    border: 4px solid white;
}

.story-page {
    background: rgba(255, 255, 255, 0.97);
    border-radius: var(--radius-xl);
    padding: 36px 40px;
    margin-bottom: 0;
    box-shadow: var(--shadow);
    border: 4px solid white;
    border-left: 8px solid var(--cyan);
}

.story-page-num {
    font-size: 0.88rem;
    font-weight: 800;
    color: white;
    background: var(--purple);
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.story-page p {
    font-size: var(--text-xl);
    margin-bottom: 18px;
    color: var(--color-text);
    line-height: 1.8;
}

.science-box {
    background: var(--purple);
    color: white;
    border-radius: var(--radius-xl);
    padding: 36px;
    margin: 36px 0;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border: 4px solid rgba(255, 255, 255, 0.5);
    position: relative;
    overflow: hidden;
}

.science-box::before {
    content: '🔬';
    position: absolute;
    top: -8px;
    right: 16px;
    font-size: 4rem;
    opacity: 0.2;
}

.science-box h2 {
    color: var(--yellow);
    margin-bottom: 14px;
    font-size: var(--text-2xl);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.science-box p {
    font-size: var(--text-lg);
    font-weight: 500;
    line-height: 1.8;
}

.book-header .story-card-meta,
.book-header p {
    font-size: var(--text-lg);
    line-height: 1.65;
}

.book-header .topic-tags {
    justify-content: flex-start;
    margin-bottom: 12px;
}

.book-meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 12px;
}

.book-meta-row .book-meta-item {
    margin: 0;
    flex-shrink: 0;
}

.book-meta-row .story-card-meta {
    font-size: var(--text-lg);
    line-height: 1.4;
    font-weight: 600;
}

.book-meta-row .book-meta-note {
    font-size: 1rem;
    color: var(--color-text-muted);
    font-weight: 600;
}

.book-meta-row .book-rating-summary {
    margin: 0;
    display: inline-flex;
    align-items: center;
}

.book-meta-row .book-rating-line {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.book-meta-row .book-rating-text {
    font-size: 1rem;
    white-space: nowrap;
}

.pdf-viewer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: center;
    margin-top: 36px;
    margin-bottom: 20px;
}

.btn-download-pdf {
    background: var(--purple) !important;
    border-color: var(--purple-dark) !important;
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.35);
}

.btn-download-pdf:hover {
    background: var(--purple-dark) !important;
    box-shadow: 0 8px 28px rgba(91, 33, 182, 0.45);
}

.pdf-viewer-wrap {
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    border: none;
    overflow: visible;
    position: relative;
}

.pdf-viewer-layout {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
    width: 100%;
    max-width: calc(var(--pdf-page-max-width, 980px) + 200px);
    margin: 0 auto;
}

.pdf-viewer-column {
    flex: 1 1 var(--pdf-page-max-width, 980px);
    min-width: 0;
    max-width: var(--pdf-page-max-width, 980px);
    width: 100%;
}

.pdf-viewer-sidebar {
    display: none;
    flex: 0 0 168px;
    position: sticky;
    top: 96px;
    align-self: flex-start;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    min-height: 120px;
    padding-top: min(42vh, 360px);
}

.pdf-viewer-sidebar.has-quiz-cta {
    display: flex;
}

@media (max-width: 1100px) {
    .pdf-viewer-layout {
        flex-direction: column;
        align-items: center;
        max-width: var(--pdf-page-max-width, 980px);
    }

    .pdf-viewer-sidebar {
        flex: none;
        width: 100%;
        max-width: var(--pdf-page-max-width, 980px);
        position: static;
        padding-top: 0;
        min-height: 0;
        align-items: center;
    }
}

.read-aloud-player {
    position: sticky;
    bottom: 0;
    z-index: 30;
    margin-top: 16px;
    padding: 12px 14px 14px;
    border-radius: 16px;
    border: 2px solid #ddd6fe;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -4px 24px rgba(91, 33, 182, 0.12), 0 8px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(8px);
}

.read-aloud-player[hidden] {
    display: none !important;
}

.read-aloud-player.is-unavailable {
    opacity: 0.72;
}

.read-aloud-player-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

.read-aloud-player-track {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.read-aloud-seek {
    width: 100%;
    height: 8px;
    margin: 0;
    accent-color: var(--purple);
    cursor: pointer;
}

.read-aloud-seek:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.read-aloud-player-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
    color: #5b21b6;
}

.read-aloud-player-page,
.read-aloud-player-time {
    white-space: nowrap;
}

.read-aloud-player-time {
    color: #64748b;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
    .read-aloud-player {
        padding: 10px 10px 12px;
    }

    .read-aloud-player-main {
        flex-wrap: wrap;
        gap: 10px;
    }

    .read-aloud-player-track {
        order: 3;
        flex-basis: 100%;
    }

    .read-aloud-btn-label {
        display: none;
    }

    .read-aloud-player-meta {
        font-size: 0.78rem;
    }
}

.pdf-reader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0;
    background: transparent;
    min-height: 120px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.pdf-page-frame {
    position: relative;
    width: 100%;
    max-width: var(--pdf-page-max-width, 980px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    border-radius: 10px;
    transition: box-shadow 0.2s ease, outline-color 0.2s ease;
}

.pdf-page-frame.is-reading-aloud {
    outline: 3px solid var(--purple);
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(124, 58, 237, 0.15);
}

.read-aloud-pages-clickable .pdf-page-frame {
    cursor: pointer;
}

.read-aloud-pages-clickable .pdf-page-frame:hover {
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.18);
}

.read-aloud-btn-speed {
    min-width: 52px;
    padding: 8px 10px;
    font-variant-numeric: tabular-nums;
    background: #fff;
}

.pdf-page-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 6px 4px 8px;
    min-height: 44px;
}

.read-aloud-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.read-aloud-controls-story {
    position: sticky;
    top: 12px;
    z-index: 3;
}

.read-aloud-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    min-width: 44px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 2px solid #c4b5fd;
    background: #f5f3ff;
    color: var(--purple-dark);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.12);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.read-aloud-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.18);
}

.read-aloud-btn:focus-visible {
    outline: 3px solid var(--purple);
    outline-offset: 2px;
}

.read-aloud-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.read-aloud-btn.is-playing {
    background: #ddd6fe;
    border-color: var(--purple);
}

.read-aloud-btn.is-paused {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
}

.read-aloud-btn.is-loading {
    opacity: 0.85;
    cursor: wait;
}

.read-aloud-btn.is-error {
    background: #fee2e2;
    border-color: #f87171;
    color: #991b1b;
}

.read-aloud-btn.is-unavailable {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #64748b;
}

.read-aloud-btn-stop {
    padding: 8px 12px;
    background: #fff;
}

.read-aloud-btn-icon {
    font-size: 1.05rem;
    line-height: 1;
}

.read-aloud-btn-label {
    line-height: 1.2;
}

@media (max-width: 640px) {
    .read-aloud-btn {
        font-size: 0.88rem;
        padding: 8px 12px;
    }

    .pdf-page-toolbar {
        justify-content: center;
    }
}

.pdf-page-canvas {
    display: block;
    max-width: 100%;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.pdf-reader-loading {
    text-align: center;
    padding: 32px 12px;
    color: var(--color-text-muted);
    font-weight: 600;
    margin: 0;
}

.book-content-pdf {
    padding: 0;
    gap: 28px;
    overflow: visible;
}

.book-header .book-meta-row + p {
    margin-top: 16px;
    margin-bottom: 0;
}

.book-content-pdf .pdf-viewer-fallback {
    padding: 0;
    font-size: 0.95rem;
}

.pdf-viewer-fallback {
    text-align: center;
    margin: 0;
    padding: 0;
    font-weight: 600;
}

.pdf-viewer-fallback a {
    color: var(--pink);
    font-weight: 800;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 28px;
}

/* —— Admin —— */
.admin-header {
    background: #312e81;
    border-bottom: 4px solid var(--pink);
}

.admin-header .logo {
    color: white;
    background: none;
    -webkit-text-fill-color: white;
    filter: none;
}

.admin-header .logo-icon {
    color: #c4b5fd;
}

.admin-header .nav-links a {
    color: #e9d5ff;
}

.admin-header .nav-links a:hover {
    color: white !important;
    background: rgba(255, 45, 139, 0.5);
    border-color: rgba(255, 255, 255, 0.3);
}

.admin-badge {
    font-size: 0.68rem;
    background: var(--pink);
    color: white;
    padding: 4px 10px;
    border-radius: 999px;
    margin-left: 8px;
    vertical-align: middle;
    border: 2px solid white;
}

.review-card {
    background: rgba(255, 255, 255, 0.97);
    border-radius: var(--radius-xl);
    padding: 32px;
    margin-bottom: 0;
    box-shadow: var(--shadow);
    border: 4px solid white;
    border-left: 8px solid var(--orange);
}

.review-card h3 {
    color: var(--purple-dark);
    font-size: 1.3rem;
}

.review-meta {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin-bottom: 14px;
}

.review-preview {
    background: #faf5ff;
    border-radius: var(--radius);
    padding: 18px;
    margin: 14px 0;
    font-size: 0.95rem;
    color: var(--color-text-muted);
    max-height: 120px;
    overflow: hidden;
    border: 2px dashed #e9d5ff;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inline-form {
    display: inline;
    margin: 0;
}

.form-hint {
    color: var(--color-text-muted);
    font-size: 1rem;
}

.admin-cover-preview {
    display: block;
    width: 120px;
    height: auto;
    border-radius: 8px;
    border: 2px solid rgba(124, 58, 237, 0.18);
    margin-top: 8px;
}

.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

/* —— Footer & utilities —— */
.site-footer {
    text-align: center;
    padding: 32px 24px;
    color: rgba(255, 255, 255, 0.95);
    font-size: var(--text-base);
    font-weight: 600;
    text-shadow: 0 2px 8px rgba(26, 16, 51, 0.3);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.site-footer-copyright {
    margin: 0;
}

.mt-2 { margin-top: 16px; }
.mt-4 { margin-top: 32px; }
.mb-2 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 32px; }

.page-header-compact {
    padding: 32px 36px 28px;
}

.page-main > .alert {
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.page-section .review-card + .review-card {
    margin-top: 24px;
}

.book-content {
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 16px 32px 48px;
}

.book-recommendations {
    width: 100%;
    margin-top: 40px;
    padding-top: 32px;
    border-top: 2px dashed rgba(124, 58, 237, 0.15);
}

.book-recommendations .section-subtitle {
    margin-bottom: 18px;
    text-align: center;
}

.story-grid-recommended {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    width: 100%;
    align-items: stretch;
}

@media (max-width: 900px) {
    .story-grid-recommended {
        grid-template-columns: 1fr;
    }
}

.book-content .panel-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
}

.book-content .panel-section .section-subtitle,
.book-content .panel-section .page-lead,
.book-content .panel-section .empty-state-inline {
    width: 100%;
    text-align: center;
}

.book-content .review-form {
    margin-left: auto;
    margin-right: auto;
    align-items: center;
    width: 100%;
}

.book-content .review-form .form-label {
    align-self: stretch;
    text-align: left;
}

.book-content .star-rating-fieldset {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.book-content .star-rating-fieldset legend {
    text-align: center;
}

.book-content .star-rating-input {
    justify-content: center;
}

.book-content .review-form .form-control {
    width: 100%;
}

.book-content .review-form .btn {
    align-self: center;
}

.book-content .reviews-list {
    max-width: 640px;
    width: 100%;
}

.book-content > .alert {
    max-width: 640px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.book-content .page-actions {
    justify-content: center;
    width: 100%;
    margin-top: 12px;
    margin-bottom: 0;
    padding: 16px 24px 32px;
}

.report-story-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 0;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
}

.report-story-link:hover {
    color: var(--color-text);
    text-decoration: underline;
}

.report-story-flag {
    color: #ef4444;
    font-size: 1.1rem;
    line-height: 1;
}

@media (max-width: 768px) {
    .public-page .site-header .container {
        padding-left: var(--page-gutter-mobile);
        padding-right: var(--page-gutter-mobile);
    }

    .bg-blob {
        filter: blur(48px);
        opacity: 0.45;
    }

    .bg-pattern {
        background-size: 24px 24px;
        opacity: 0.3;
    }

    body {
        font-size: 1.3rem;
    }

    .book-header {
        grid-template-columns: 1fr;
    }

    .book-cover {
        max-width: 220px;
        margin: 0 auto;
    }

    .nav-links {
        flex-wrap: wrap;
        overflow: visible;
        justify-content: flex-end;
        width: auto;
    }

    .story-grid-compact {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .hero-compact {
        padding: 12px 16px;
    }

    .hero {
        padding: 40px 24px;
    }

    main.page-main.container {
        padding: 32px var(--page-gutter-mobile) 56px;
        gap: 28px;
    }

    .public-page main.page-main.page-main-compact {
        margin-left: var(--page-gutter-mobile);
        margin-right: var(--page-gutter-mobile);
        padding: 28px var(--page-inner-padding-mobile) 36px;
    }

    .page-header {
        padding: 32px 24px 28px;
    }

    .page-header-compact {
        padding: 24px 20px 20px;
    }

    .form-panel {
        padding: 28px 22px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body,
    body::after,
    .bg-blob,
    .bg-icon,
    .bg-field-icon,
    .bg-shape,
    .bg-waves {
        animation: none;
    }

    .btn:hover,
    .story-card:hover {
        transform: none;
    }
}

/* —— AI Authoring Tool —— */
.ai-workflow-panel {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    border: 3px solid white;
    box-shadow: var(--shadow-lg);
    padding: 22px;
}

.ai-step-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.ai-step-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: #f3f4f6;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.9rem;
}

.ai-step-item.ai-step-active {
    background: var(--purple);
    color: white;
}

.ai-step-item.ai-step-done {
    background: #ede9fe;
    color: var(--purple-dark);
}

.ai-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    font-size: 0.8rem;
}

.ai-step-item.ai-step-done .ai-step-num {
    background: rgba(91, 33, 182, 0.15);
}

.ai-step-connector {
    width: 32px;
    height: 2px;
    background: rgba(124, 58, 237, 0.25);
    margin: 0 4px;
}

.ai-workflow-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.ai-workflow-stage {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 2px solid rgba(124, 58, 237, 0.08);
}

.ai-workflow-stage:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.ai-stage-hidden {
    display: none;
}

.ai-workflow-textarea {
    width: 100%;
    min-height: 120px;
    resize: vertical;
    font-family: var(--font);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 12px;
}

.ai-idea-input {
    min-height: 88px;
}

.ai-stage-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}

.ai-authoring-page .ai-page-header {
    text-align: center;
    margin-bottom: 8px;
}

.ai-page-title {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    color: var(--color-text);
    margin-bottom: 8px;
}

.ai-page-lead {
    color: var(--color-text-muted);
    font-size: 1rem;
    max-width: 960px;
    margin: 0 auto;
}

.ai-layout {
    display: block;
}

.ai-chat-panel-main {
    width: 100%;
    margin: 0 auto;
}

.ai-chat-panel {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    border: 3px solid white;
    box-shadow: var(--shadow-lg);
    padding: 18px;
    display: flex;
    flex-direction: column;
}

.ai-panel-title {
    font-size: 1.1rem;
    color: var(--purple-dark);
    margin-bottom: 6px;
}

.ai-panel-hint {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.ai-prompt-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 70vh;
    overflow-y: auto;
}

.ai-prompt-card {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    text-align: left;
    width: 100%;
    padding: 10px 12px;
    border: 2px solid rgba(124, 58, 237, 0.15);
    border-radius: var(--radius-lg);
    background: #faf5ff;
    cursor: pointer;
    font-family: var(--font);
    transition: border-color 0.2s, transform 0.2s;
}

.ai-prompt-card:hover {
    border-color: var(--purple);
    transform: translateY(-2px);
}

.ai-prompt-icon {
    font-size: 1.4rem;
    line-height: 1;
}

.ai-prompt-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.ai-prompt-card-body strong {
    color: var(--purple-dark);
    font-size: 0.95rem;
}

.ai-chat-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.ai-chat-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-template-form-wrap {
    background: #f5f3ff;
    border-radius: var(--radius-lg);
    padding: 14px;
    margin-bottom: 12px;
    border: 2px dashed rgba(124, 58, 237, 0.25);
}

.ai-template-form-title {
    font-size: 1rem;
    color: var(--purple-dark);
    margin-bottom: 10px;
}

.ai-template-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ai-messages {
    min-height: 420px;
    max-height: min(62vh, 680px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
    background: #f8fafc;
    border-radius: var(--radius-lg);
    border: 2px solid rgba(124, 58, 237, 0.1);
    margin-bottom: 12px;
}

.ai-message {
    padding: 0;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 88%;
}

.ai-message-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 6px;
    opacity: 0.75;
}

.ai-message-body p {
    margin: 0 0 0.65em;
}

.ai-message-body p:last-child {
    margin-bottom: 0;
}

.ai-message-body h3,
.ai-message-body h4 {
    margin: 0.4em 0 0.5em;
    font-size: 1rem;
}

.ai-message-body ul {
    margin: 0.4em 0 0.8em 1.2em;
    padding: 0;
}

.ai-message-user {
    align-self: flex-end;
    background: none;
    color: inherit;
}

.ai-message-user .ai-message-label {
    text-align: right;
    color: rgba(255, 255, 255, 0.85);
}

.ai-message-user .ai-message-body {
    padding: 12px 14px;
    background: var(--purple);
    color: white;
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}

.ai-message-assistant {
    align-self: flex-start;
    background: none;
    border: none;
    color: inherit;
}

.ai-message-assistant .ai-message-body {
    padding: 12px 14px;
    background: white;
    border: 2px solid rgba(124, 58, 237, 0.12);
    color: var(--color-text);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}

.ai-typing .ai-typing-dots {
    display: inline-flex;
    gap: 6px;
    padding: 12px 14px;
    background: white;
    border: 2px solid rgba(124, 58, 237, 0.12);
    border-radius: var(--radius-lg);
}

.ai-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--purple);
    animation: aiTypingBounce 1.2s infinite ease-in-out;
}

.ai-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes aiTypingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    40% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

.ai-chat-form {
    flex-shrink: 0;
}

.ai-input-wrap {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding: 10px 12px;
    background: #fff;
    border: 2px solid rgba(124, 58, 237, 0.18);
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 16px rgba(91, 110, 225, 0.08);
}

.ai-input-wrap textarea {
    flex: 1;
    min-height: 44px;
    max-height: 160px;
    resize: none;
    border: none;
    box-shadow: none;
    padding: 10px 4px;
    background: transparent;
}

.ai-input-wrap textarea:focus {
    outline: none;
    box-shadow: none;
}

.ai-send-btn {
    flex-shrink: 0;
    border-radius: 999px;
    min-width: 72px;
}

.ai-examples {
    margin-top: 10px;
    font-size: 0.88rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.ai-starters-details {
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.ai-starters-details summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--purple-dark);
    margin-bottom: 8px;
}

.ai-starter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 4px;
}

.ai-starter-chip {
    border: 2px solid rgba(124, 58, 237, 0.2);
    background: #f5f3ff;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    color: var(--purple-dark);
}

.ai-starter-chip:hover {
    border-color: var(--purple);
    background: #ede9fe;
}

.ai-setup-alert a {
    color: #7c3aed;
    font-weight: 700;
}

.ai-setup-alert small {
    display: block;
    margin-top: 8px;
}

.ai-export-progress {
    margin-top: 10px;
}

.ai-export-progress-track {
    height: 8px;
    background: rgba(124, 58, 237, 0.12);
    border-radius: 999px;
    overflow: hidden;
}

.ai-export-progress-bar {
    height: 100%;
    width: 0;
    background: var(--purple);
    border-radius: 999px;
    transition: width 0.35s ease;
}

.ai-status {
    font-size: 0.88rem;
    color: var(--color-text-muted);
    margin-top: 8px;
    min-height: 1.2em;
}

.ai-status-error {
    color: #b91c1c;
    font-weight: 600;
}

@media (max-width: 900px) {
    .ai-messages {
        max-height: 52vh;
        min-height: 320px;
    }

    .ai-message {
        max-width: 94%;
    }
}

/* —— Homepage (layout only; chrome is .public-page) —— */
.home-page {
    --content-max-width: 100%;
}

@media (min-width: 900px) {
    .home-page {
        min-height: 100dvh;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .home-page main.page-main.container {
        padding: 4px var(--page-gutter) 12px;
        flex: 1;
        min-height: 0;
        overflow: visible;
        display: flex;
        flex-direction: column;
    }

    .home-main {
        overflow: visible;
        padding: 2px 0 0;
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .home-shell {
        flex: 1;
        min-height: 0;
        overflow: visible;
        gap: 12px;
    }

    .home-topics {
        padding: 4px 8px;
        flex-shrink: 0;
    }

    .home-topic-grid {
        gap: 4px;
    }

    .home-topic-tile {
        padding: 5px 6px;
        font-size: 0.72rem;
    }

    .home-topic-icon-glyph {
        font-size: 0.95rem;
    }

    .home-latest {
        flex: none;
        overflow: visible;
        padding: 16px 20px 20px;
    }

    .home-latest-rows {
        overflow: visible;
        gap: 28px;
    }

    .home-top-picks {
        padding: 14px 16px 16px;
        margin: 0;
    }

    .home-story-grid {
        gap: 24px;
    }

    .home-page .site-footer-compact {
        padding: 4px 12px 6px;
        font-size: 0.72rem;
    }
}

.home-page .container {
    max-width: 100%;
    padding: 0 var(--page-gutter);
}

.home-page .site-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: none;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.1);
    position: sticky;
    top: 0;
    padding: 0;
    flex-shrink: 0;
}

.home-main {
    padding: 8px 0 16px;
    gap: 0;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.home-shell {
    width: 100%;
    min-height: calc(100dvh - 58px);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.home-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: nowrap;
    background: rgba(255, 255, 255, 0.93);
    border-radius: var(--radius-lg);
    padding: 10px 18px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.08);
    flex-shrink: 0;
}

.home-hero-text {
    text-align: left;
    min-width: 0;
}

.home-hero h1 {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 5.5vw, 4rem);
    margin-bottom: 6px;
    color: var(--purple-dark);
}

.home-hero-tagline {
    font-size: clamp(1.35rem, 2.5vw, 1.85rem);
    font-weight: 600;
    color: var(--purple-dark);
    margin-bottom: 0;
}

.btn-home-cta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    font-size: 1.35rem;
    font-weight: 800;
    color: white;
    text-decoration: none;
    border-radius: 999px;
    border: 2px solid white;
    background: var(--purple);
    box-shadow: 0 6px 18px rgba(124, 58, 237, 0.3);
}

.btn-home-cta:hover {
    transform: translateY(-2px);
    color: white;
}

.home-section-title {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.35rem);
    color: var(--purple-dark);
    margin-bottom: 10px;
}

.home-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.home-section-head .home-section-title {
    margin-bottom: 0;
}

.home-view-all {
    color: var(--purple);
    font-weight: 700;
    font-size: 1.25rem;
    text-decoration: none;
}

.home-view-all:hover {
    text-decoration: underline;
}

.home-topics {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--radius-lg);
    padding: 6px 10px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.08);
}

.home-topics .home-section-title,
.home-topics-title {
    margin-bottom: 0;
}

.home-topic-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}

.home-topic-tile {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 800;
    font-size: clamp(0.85rem, 1.1vw, 1rem);
    min-height: 0;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.home-topic-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.65em;
    height: 1.65em;
    flex-shrink: 0;
    background: transparent;
    border-radius: 0;
}

.home-topic-icon-glyph {
    display: block;
    font-size: 1.1rem;
    line-height: 1;
    filter: brightness(0) invert(1);
}

.home-topic-label {
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
}

.home-topic-tile:hover {
    transform: translateY(-1px);
}

.home-latest {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
    background: rgba(255, 255, 255, 0.93);
    border-radius: var(--radius-lg);
    padding: 16px 20px 20px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.08);
}

.home-latest-rows {
    display: flex;
    flex-direction: column;
    gap: 28px;
    width: 100%;
}

.home-story-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
    width: 100%;
    align-items: stretch;
}

.home-story-grid--row,
.home-story-grid--picks {
    grid-auto-rows: 1fr;
}

.home-story-grid--picks .home-story-card {
    border-color: #ddd6fe;
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.12);
}

.home-top-picks {
    margin: 4px 0;
    padding: 14px 16px 16px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(245, 243, 255, 0.95) 0%, rgba(237, 233, 254, 0.85) 100%);
    border: 2px dashed rgba(124, 58, 237, 0.18);
}

.home-top-picks-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 14px;
    margin-bottom: 12px;
}

.home-top-picks-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.15rem, 2vw, 1.45rem);
    font-weight: 800;
    color: var(--color-primary);
}

.home-top-picks-title::before {
    content: '⭐ ';
}

.home-top-picks-lead {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.home-story-card {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid #f3e8ff;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.08);
    display: flex;
    flex-direction: row;
    align-items: stretch;
    height: 100%;
    min-height: 300px;
}

.home-story-card:hover {
    box-shadow: 0 8px 22px rgba(124, 58, 237, 0.14);
    border-color: #e9d5ff;
}

.home-story-cover-wrap {
    flex: 0 0 38%;
    min-width: 0;
    align-self: stretch;
}

.home-story-cover-link {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    line-height: 0;
}

.home-story-img {
    width: 100%;
    height: 100%;
    min-height: 160px;
    object-fit: cover;
    background: #e9d5ff;
}

.home-story-body {
    flex: 1;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    min-height: 0;
}

.home-story-tag {
    align-self: flex-start;
    font-size: 0.95rem;
    padding: 5px 12px;
    flex-shrink: 0;
}

.home-story-title {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.6rem);
    font-weight: 700;
    line-height: 1.3;
    margin: 0;
    min-width: 0;
    width: 100%;
    color: var(--color-text);
    text-decoration: none;
    display: block;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    flex-shrink: 0;
}

.home-story-title:hover {
    color: var(--color-text);
    text-decoration: underline;
}

.home-story-desc {
    font-size: clamp(1.15rem, 1.7vw, 1.4rem);
    color: var(--color-text-muted);
    line-height: 1.4;
    margin: 0;
    flex: 1 1 auto;
    min-height: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.home-story-card-footer {
    margin-top: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.home-story-meta {
    display: flex;
    justify-content: flex-start;
    gap: 14px;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.home-story-actions {
    flex-shrink: 0;
    margin-top: 0;
}

.home-story-actions .story-card-footer {
    margin-top: 0;
    padding-top: 8px;
    border-top: 2px dashed rgba(124, 58, 237, 0.12);
}

.home-story-actions .btn-sm {
    padding: 10px 18px;
    font-size: 1.05rem;
}

.home-story-actions .story-card-badges .badge-free,
.home-story-actions .story-card-badges .badge-owned,
.home-story-actions .story-card-badges .badge-format-pdf {
    font-size: 0.95rem;
    padding: 5px 12px;
}

.home-story-actions .story-card-badges .badge-price {
    font-size: 1rem;
    padding: 0;
}

.home-empty {
    padding: 16px;
    background: #f5f3ff;
    border-radius: 14px;
}

.home-topics,
.home-latest {
    width: 100%;
}

@media (min-width: 900px) {
    .home-topics-title {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .home-hero h1 {
        font-size: clamp(2rem, 4vw, 3rem);
        margin-bottom: 2px;
    }

    .home-hero-tagline {
        font-size: clamp(1.1rem, 2vw, 1.45rem);
    }

    .btn-home-cta {
        padding: 10px 22px;
        font-size: 1.15rem;
    }

    .home-section-title {
        font-size: clamp(1.35rem, 2.2vw, 1.75rem);
    }

    .home-view-all {
        font-size: 1.05rem;
    }

    .home-story-actions .story-card-footer {
        padding-top: 6px;
        margin-top: 0;
    }

    .home-story-actions .btn-sm {
        padding: 8px 14px;
        font-size: 0.95rem;
    }
}

@media (max-width: 899px) {
    .home-page {
        height: auto;
        overflow: visible;
    }

    .home-main,
    .home-shell,
    .home-latest {
        overflow: visible;
    }

    .home-topics {
        padding: 10px 12px;
    }

    .home-topics-title {
        margin-bottom: 8px;
        font-size: clamp(1.35rem, 2.5vw, 1.75rem);
    }

    .home-topic-tile {
        flex-direction: column;
        padding: 10px 8px;
        min-height: 72px;
        font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    }

    .home-topic-icon-glyph {
        font-size: 1.75rem;
    }
}

@media (max-width: 1100px) {
    .home-topic-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .home-story-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }
}

@media (max-width: 640px) {
    .home-page .container {
        padding: 0 var(--page-gutter-mobile);
    }

    .home-shell {
        gap: 10px;
        min-height: auto;
    }

    .home-hero {
        padding: 12px 14px;
        flex-direction: column;
        align-items: flex-start;
    }

    .home-topic-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .home-story-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .home-story-card {
        flex-direction: column;
    }

    .home-story-cover-link {
        flex: none;
        height: 180px;
    }
}

/* —— Book ratings & reviews —— */
.stars-display {
    display: inline-flex;
    gap: 1px;
    line-height: 1;
    letter-spacing: 0;
}

.star {
    font-size: 1rem;
}

.star-filled {
    color: #f59e0b;
}

.star-empty {
    color: #d1d5db;
}

.story-card-rating {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.story-card-rating .stars-display .star {
    font-size: 0.85rem;
}

.story-card-rating .rating-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text);
}

.story-card-rating-empty .rating-label {
    font-weight: 600;
    color: var(--color-text-muted);
}

.book-rating-summary {
    margin: 8px 0 4px;
}

.book-rating-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.book-rating-stars .star {
    font-size: 1.25rem;
}

.book-rating-text {
    font-size: 1.1rem;
    color: var(--color-text-muted);
}

.panel-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 2px dashed rgba(124, 58, 237, 0.15);
}

.section-subtitle {
    font-family: var(--font-display);
    font-size: clamp(1.35rem, 2vw, 1.75rem);
    color: var(--purple-dark);
    margin-bottom: 12px;
}

.review-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 640px;
}

.star-rating-fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

.star-rating-fieldset legend {
    font-weight: 700;
    font-size: 1.05rem;
    margin-bottom: 8px;
}

.star-rating-input {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    gap: 4px;
    width: fit-content;
}

.star-rating-choice {
    cursor: pointer;
    display: inline-flex;
}

.star-rating-choice input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.star-choice-icon {
    font-size: 2rem;
    color: #d1d5db;
    line-height: 1;
    transition: color 0.15s ease;
}

.star-rating-input .star-rating-choice input:checked + .star-choice-icon,
.star-rating-input .star-rating-choice:has(input:checked) ~ .star-rating-choice .star-choice-icon {
    color: #f59e0b;
}

.star-rating-input .star-rating-choice:hover .star-choice-icon,
.star-rating-input .star-rating-choice:hover ~ .star-rating-choice .star-choice-icon {
    color: #fbbf24;
}

.reviews-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 0;
    padding: 0;
}

.review-item {
    background: #faf5ff;
    border-radius: 14px;
    padding: 14px 16px;
    border: 2px solid #f3e8ff;
}

.review-item-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.review-item-author {
    font-weight: 700;
    color: var(--purple-dark);
}

.review-item-text {
    margin: 0;
    line-height: 1.5;
    color: var(--color-text);
}

.review-item-text-muted {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.empty-state-inline {
    color: var(--color-text-muted);
    margin: 0;
}

.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;
}

/* —— Sales dashboards —— */
.sales-page .sales-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.sales-stat-card {
    background: #ffffff;
    border: 1px solid #E5E7EB;
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.sales-stat-num {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 700;
    color: #111827;
    line-height: 1.2;
    margin-bottom: 6px;
}

.sales-stat-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #64748B;
    line-height: 1.35;
}

.sales-section {
    margin-top: 28px;
}

.sales-section-title {
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 2.5vw, 1.5rem);
    color: #111827;
    margin-bottom: 14px;
}

.sales-table td,
.sales-table th {
    font-size: 0.92rem;
}

.sales-rating {
    font-weight: 700;
    color: #111827;
    white-space: nowrap;
}

.sales-rating-count {
    font-weight: 600;
    color: #64748B;
}

.sales-rating-empty {
    color: #94A3B8;
    font-size: 0.88rem;
}

.sales-footnote {
    margin-top: 20px;
    font-size: 0.88rem;
    color: #64748B;
}

.story-quiz-mount {
    margin-top: 24px;
}

.story-quiz-cta {
    display: flex;
    justify-content: center;
    padding: 0;
    max-width: none;
    margin: 0;
    pointer-events: auto;
}

.pdf-viewer-sidebar .story-quiz-cta {
    width: 100%;
}

.pdf-viewer-sidebar .story-quiz-cta[hidden] {
    display: none !important;
}

.story-page.has-story-quiz-cta .story-quiz-cta {
    position: absolute;
    left: 50%;
    bottom: 56px;
    transform: translateX(-50%);
    z-index: 4;
    width: calc(100% - 48px);
    max-width: 420px;
}

.story-quiz-cta .story-quiz-start {
    width: 100%;
    min-width: 0;
    font-size: var(--text-lg);
    box-shadow: var(--shadow-lg);
}

.story-page.has-story-quiz-cta {
    position: relative;
    padding-bottom: 72px;
}

.story-quiz {
    background: #fff;
    border-radius: var(--radius-xl);
    border: 4px solid rgba(124, 58, 237, 0.18);
    box-shadow: var(--shadow-lg);
    padding: 28px 24px 24px;
    max-width: var(--pdf-page-max-width, 980px);
    margin: 24px auto 0;
}

.story-quiz-header h2 {
    margin: 0 0 8px;
    font-size: var(--text-2xl);
    color: var(--purple);
}

.story-quiz-intro {
    margin: 0 0 8px;
    color: var(--color-text-muted);
    font-size: var(--text-base);
    line-height: 1.5;
}

.story-quiz-lead {
    margin: 0 0 16px;
    color: var(--color-text-muted);
    font-size: var(--text-lg);
    line-height: 1.5;
}

.story-quiz-meta {
    margin: 0 0 18px;
    font-weight: 700;
    color: var(--purple);
}

.story-quiz-progress {
    height: 8px;
    border-radius: 999px;
    background: rgba(124, 58, 237, 0.12);
    overflow: hidden;
    margin-bottom: 10px;
}

.story-quiz-progress-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--purple), var(--cyan));
    border-radius: inherit;
    transition: width 0.25s ease;
}

.story-quiz-question {
    border: 0;
    margin: 0;
    padding: 0;
}

.story-quiz-prompt {
    font-size: var(--text-xl);
    font-weight: 700;
    line-height: 1.45;
    margin-bottom: 16px;
    color: var(--color-text);
}

.story-quiz-choices {
    display: grid;
    gap: 10px;
}

.story-quiz-choice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    border: 2px solid rgba(124, 58, 237, 0.14);
    background: rgba(124, 58, 237, 0.04);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
    min-width: 0;
}

.story-quiz-choice:hover {
    border-color: rgba(124, 58, 237, 0.35);
    background: rgba(124, 58, 237, 0.08);
}

.story-quiz-choice input {
    margin-top: 4px;
    accent-color: var(--purple);
    flex-shrink: 0;
}

.story-quiz-choice-text {
    flex: 1;
    min-width: 0;
    font-size: var(--text-lg);
    line-height: 1.45;
    overflow-wrap: anywhere;
    word-break: normal;
}

.story-quiz-choice.is-correct {
    border-color: #16a34a;
    background: rgba(22, 163, 74, 0.1);
}

.story-quiz-choice.is-correct .story-quiz-choice-text::after {
    content: ' ✓';
    color: #16a34a;
    font-weight: 800;
    margin-left: 6px;
}

.story-quiz-tick {
    display: inline-block;
    margin-left: 6px;
    color: #16a34a;
    font-size: 1.35em;
    font-weight: 800;
    line-height: 1;
}

.story-quiz-choice.is-incorrect {
    border-color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
}

.story-quiz-feedback {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    font-size: var(--text-lg);
    line-height: 1.5;
}

.story-quiz-feedback.is-correct {
    background: rgba(22, 163, 74, 0.12);
    color: #166534;
}

.story-quiz-feedback.is-incorrect {
    background: rgba(220, 38, 38, 0.08);
    color: #991b1b;
}

.story-quiz-actions {
    margin-top: 18px;
    display: flex;
    gap: 10px;
}

.story-quiz-score {
    font-size: 2rem;
    font-weight: 800;
    color: var(--purple);
    margin: 0 0 8px;
}

.story-quiz-empty {
    text-align: center;
    color: var(--color-text-muted);
}

.story-quiz-confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.story-quiz-balloons {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
    overflow: hidden;
}

.story-quiz-balloon {
    position: absolute;
    bottom: -40px;
    animation: story-quiz-balloon-rise 3.8s ease-in forwards;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
}

@keyframes story-quiz-balloon-rise {
    0% {
        transform: translateY(0) translateX(0) scale(0.8);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    100% {
        transform: translateY(-110vh) translateX(-12px) scale(1.05);
        opacity: 0.95;
    }
}

.book-content-pdf .story-quiz-mount {
    width: 100%;
}

@media (max-width: 640px) {
    .story-quiz {
        padding: 20px 16px 18px;
    }

    .story-quiz-prompt {
        font-size: var(--text-lg);
    }

    .story-quiz-actions {
        flex-wrap: wrap;
    }

    .story-quiz-actions .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* —— Tablet & mobile responsive —— */
@media (max-width: 899px) {
    :root {
        --page-gutter: 24px;
        --page-inner-padding: 20px;
    }

    .container {
        padding-left: var(--page-gutter-mobile);
        padding-right: var(--page-gutter-mobile);
    }

    main.page-main.container {
        padding-left: var(--page-gutter-mobile);
        padding-right: var(--page-gutter-mobile);
    }

    .public-page main.page-main.page-main-compact,
    .explore-library-page main.page-main.page-main-compact {
        margin-left: 0;
        margin-right: 0;
        padding: 24px var(--page-inner-padding-mobile) 32px;
    }

    .home-page .container {
        padding-left: var(--page-gutter-mobile);
        padding-right: var(--page-gutter-mobile);
    }

    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        padding: 0;
        border: 2px solid var(--purple);
        border-radius: 10px;
        background: #fff;
        cursor: pointer;
        flex-shrink: 0;
        margin-left: auto;
    }

    .nav-toggle-lines,
    .nav-toggle-lines::before,
    .nav-toggle-lines::after {
        display: block;
        width: 20px;
        height: 2px;
        background: var(--purple-dark);
        border-radius: 2px;
        position: relative;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .nav-toggle-lines::before,
    .nav-toggle-lines::after {
        content: '';
        position: absolute;
        left: 0;
    }

    .nav-toggle-lines::before {
        top: -6px;
    }

    .nav-toggle-lines::after {
        top: 6px;
    }

    .site-header.is-nav-open .nav-toggle-lines {
        background: transparent;
    }

    .site-header.is-nav-open .nav-toggle-lines::before {
        top: 0;
        transform: rotate(45deg);
    }

    .site-header.is-nav-open .nav-toggle-lines::after {
        top: 0;
        transform: rotate(-45deg);
    }

    .logo-tagline {
        display: none;
    }

    .nav-container {
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
        padding: 8px 0;
    }

    .site-brand {
        flex: 1;
        min-width: 0;
    }

    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        order: 4;
        padding: 10px 0 4px;
        border-top: 2px solid rgba(124, 58, 237, 0.12);
        overflow: visible;
    }

    .site-header.is-nav-open .nav-links {
        display: flex;
    }

    .nav-links a {
        white-space: normal;
        padding: 10px 12px;
        font-size: 1rem;
        border-radius: 10px;
    }

    .nav-auth {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        margin: 8px 0 0;
        padding: 10px 0 0;
        border-left: none;
        border-top: 2px dashed rgba(124, 58, 237, 0.15);
        gap: 8px;
    }

    .nav-user-name {
        max-width: none;
        text-align: center;
    }

    .nav-login-btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    .book-header {
        grid-template-columns: 1fr;
        padding: 24px 20px;
        gap: 20px;
    }

    .book-cover {
        max-width: 220px;
        margin: 0 auto;
    }

    .book-meta-row {
        flex-wrap: wrap;
    }

    .book-meta-row .book-rating-line {
        flex-wrap: wrap;
    }

    .book-meta-row .book-rating-text {
        white-space: normal;
    }

    .story-page {
        padding: 24px 18px;
    }

    .story-page p {
        font-size: 1.25rem;
        line-height: 1.65;
    }

    .science-box {
        padding: 22px 18px;
        margin: 24px 0;
    }

    .book-content {
        padding: 12px var(--page-inner-padding-mobile) 32px;
    }

    .home-story-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .home-story-card {
        flex-direction: column;
        min-height: 0;
    }

    .home-story-cover-wrap {
        flex: none;
    }

    .home-story-cover-link {
        height: 200px;
    }

    .home-story-img {
        min-height: 200px;
        height: 200px;
    }

    .home-story-title {
        font-size: clamp(1.35rem, 5vw, 1.75rem);
    }

    .home-story-desc {
        font-size: 1rem;
    }

    .home-story-actions .story-card-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .home-topic-label {
        white-space: normal;
        text-align: center;
        line-height: 1.2;
    }

    .home-topic-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .story-grid-compact {
        grid-template-columns: 1fr;
    }

    .story-card {
        min-height: 0;
    }

    .explore-library-page .story-card-compact .story-card-title {
        font-size: clamp(1.25rem, 4vw, 1.75rem);
    }

    .explore-library-page .story-card-compact .story-card-desc {
        font-size: 1rem;
    }

    .explore-search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .explore-search-form .btn {
        width: 100%;
    }

    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form input {
        min-width: 0;
        width: 100%;
    }

    .search-form .btn {
        width: 100%;
    }

    .filter-chips {
        gap: 8px;
    }

    .home-section-head {
        flex-wrap: wrap;
        gap: 8px;
    }
}

@media (min-width: 900px) {
    .nav-toggle {
        display: none;
    }
}

@media (max-width: 640px) {
    .home-topic-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .home-latest {
        padding: 12px 14px 16px;
    }

    .home-top-picks {
        padding: 12px 14px;
    }

    .site-logo-img {
        height: 40px;
    }

    body {
        font-size: 1rem;
    }
}
