/* ==========================================================================
   Reader (family-facing). Its own look, separate from the AI Story Studio admin.
   "Lembut": a warm cream page, white cards, one coral accent, dark ink buttons.
   Everything is scoped under .rd-shell. Touch targets are at least 48px; text is large.
   Fonts are served from wwwroot/fonts (the Content-Security-Policy allows only 'self'); both are SIL OFL.
   ========================================================================== */

@font-face { font-family: "Nunito"; font-style: normal; font-weight: 200 1000; font-display: swap; src: url("fonts/nunito-latin-wght.woff2") format("woff2"); }
@font-face { font-family: "Andika"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/andika-latin-400.woff2") format("woff2"); }
@font-face { font-family: "Andika"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/andika-latin-700.woff2") format("woff2"); }

.rd-shell {
    --rd-accent: #e8664a;
    --rd-accent-700: #c2492f;
    --rd-accent-100: #fde7e0;
    --rd-teal: #1f6f6a;
    --rd-teal-100: #dcefed;
    --rd-sun: #ffe7a8;
    --rd-sun-700: #7a5300;
    --rd-leaf: #2a8a5f;
    --rd-leaf-100: #ddf2e7;
    --rd-berry: #b8323f;
    --rd-berry-100: #fbe4e6;
    --rd-ink: #1f2430;
    --rd-ink-soft: #545b6b;
    --rd-paper: #ffffff;
    --rd-page: #fbf7f2;
    --rd-sand: #f1eae0;
    --rd-line: #eae1d4;
    --rd-radius: 1.25rem;
    --rd-radius-lg: 1.75rem;
    --rd-shadow: 0 1px 2px rgba(31, 36, 48, .05), 0 16px 40px -24px rgba(31, 36, 48, .28);
    --rd-font: "Nunito", "Trebuchet MS", system-ui, sans-serif;
    --rd-font-read: "Andika", "Nunito", "Trebuchet MS", sans-serif;

    min-height: 100vh;
    background: var(--rd-page);
    color: var(--rd-ink);
    font-family: var(--rd-font);
    font-size: 1.125rem;
    -webkit-font-smoothing: antialiased;
}

.rd-shell h1, .rd-shell h2, .rd-shell h3 { color: var(--rd-ink); font-family: var(--rd-font); letter-spacing: -.015em; }
.rd-shell a { color: var(--rd-teal); }
.rd-shell :focus-visible { outline: 3px solid var(--rd-teal); outline-offset: 3px; border-radius: .75rem; }
.rd-shell .icon { flex: none; }

/* Top bar ------------------------------------------------------------------ */
.rd-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem 1.5rem; flex-wrap: wrap; max-width: 76rem; margin: 0 auto; padding: 1.1rem clamp(1rem, 3vw, 2.5rem); }
.rd-brand { display: inline-flex; align-items: center; gap: .7rem; font-weight: 900; font-size: 1.35rem; letter-spacing: -.01em; color: var(--rd-ink) !important; text-decoration: none; }
.rd-mark { display: inline-block; flex: none; width: 2.75rem; height: 2.75rem; object-fit: contain; }
.rd-nav { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.rd-nav form { margin: 0; }
.rd-tabs { display: flex; gap: .25rem; padding: .3rem; border-radius: 999px; background: var(--rd-sand); }
.rd-tab { display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; padding: 0 1.15rem; border-radius: 999px; color: var(--rd-ink-soft) !important; font-weight: 700; text-decoration: none; }
.rd-tab:hover { color: var(--rd-ink) !important; }
.rd-tab.active { background: var(--rd-paper); color: var(--rd-ink) !important; font-weight: 800; box-shadow: 0 1px 2px rgba(31, 36, 48, .1); }
.rd-logout { display: inline-flex; align-items: center; gap: .4rem; min-height: 48px; padding: 0 1rem; border-radius: 999px; border: 1px solid var(--rd-line); background: var(--rd-paper); color: var(--rd-ink); font: inherit; font-weight: 700; cursor: pointer; }
.rd-logout:hover { background: var(--rd-sand); }

.rd-main { max-width: 76rem; margin: 0 auto; padding: .5rem clamp(1rem, 3vw, 2.5rem) clamp(1.5rem, 4vw, 3rem); }
.rd-loading { font-size: 1.3rem; text-align: center; padding: 3rem 0; color: var(--rd-ink-soft); }

/* Buttons ------------------------------------------------------------------ */
.rd-btn { display: inline-flex; align-items: center; justify-content: center; gap: .55rem; min-height: 52px; padding: .5rem 1.4rem; border-radius: 999px; border: 2px solid var(--rd-line); background: var(--rd-paper); color: var(--rd-ink) !important; font: inherit; font-weight: 800; text-decoration: none; cursor: pointer; transition: background-color .12s ease, transform .08s ease; }
.rd-btn:hover { background: var(--rd-sand); }
.rd-btn:active { transform: translateY(1px); }
.rd-btn[disabled] { opacity: .5; cursor: not-allowed; }
.rd-btn-primary { background: var(--rd-ink); border-color: var(--rd-ink); color: #fff !important; }
.rd-btn-primary:hover { background: #343b4d; }
.rd-btn-danger { color: var(--rd-berry) !important; border-color: var(--rd-berry-100); }
.rd-btn-danger:hover { background: var(--rd-berry-100); }
.rd-btn-sm { min-height: 44px; padding: .3rem 1rem; font-size: 1rem; }
.rd-link-btn { border: 0; background: none; padding: .25rem; color: var(--rd-teal); font: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; min-height: 44px; }
.rd-actions { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; margin: 1.25rem 0; }
.rd-hint { color: var(--rd-ink-soft); font-size: 1rem; }
.rd-small-link { font-size: 1rem; font-weight: 800; }
.rd-error { color: var(--rd-berry); font-weight: 800; }
.rd-eyebrow { font-size: .85rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--rd-teal); }

/* Home: who is reading ----------------------------------------------------- */
.rd-welcome { text-align: center; max-width: 52rem; margin: clamp(1rem, 4vw, 2.5rem) auto 0; padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1rem, 4vw, 3rem); border-radius: var(--rd-radius-lg); background: var(--rd-paper); box-shadow: var(--rd-shadow); }
.rd-welcome h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); font-weight: 900; margin-bottom: .75rem; }
.rd-lead { font-size: clamp(1.15rem, 2.5vw, 1.35rem); max-width: 40rem; margin: 0 auto; color: var(--rd-ink-soft); }
.rd-profiles { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(.75rem, 3vw, 1.5rem); margin: 2rem 0; }
.rd-profile { display: flex; flex-direction: column; align-items: center; gap: .7rem; padding: 1.25rem 1rem; min-width: 9.5rem; border-radius: var(--rd-radius); border: 2px solid var(--rd-line); text-decoration: none; color: var(--rd-ink) !important; transition: transform .12s ease, border-color .12s ease; }
.rd-profile:hover { transform: translateY(-3px); border-color: var(--rd-accent); }
.rd-profile-name { font-size: 1.35rem; font-weight: 900; }
.rd-avatar { display: inline-grid; place-items: center; width: clamp(5.5rem, 16vw, 7rem); height: clamp(5.5rem, 16vw, 7rem); border-radius: 50%; background: var(--rd-accent-100); font-size: clamp(2.8rem, 8vw, 3.75rem); line-height: 1; }
.rd-avatar.sm { width: 3.5rem; height: 3.5rem; font-size: 1.9rem; flex: none; }

/* Library ------------------------------------------------------------------ */
.rd-continue { display: grid; grid-template-columns: minmax(0, 22rem) minmax(0, 1fr); gap: clamp(1.25rem, 3vw, 2rem); align-items: center; padding: 1.25rem; margin-bottom: clamp(1.5rem, 4vw, 2.25rem); border-radius: var(--rd-radius-lg); background: var(--rd-paper); box-shadow: var(--rd-shadow); }
.rd-continue-cover { display: block; aspect-ratio: 3 / 2; border-radius: var(--rd-radius); overflow: hidden; background: var(--rd-sand); }
.rd-continue-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rd-continue-body { display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
.rd-continue-body h2 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.5rem); font-weight: 900; line-height: 1.1; }
.rd-continue-body .rd-actions { justify-content: flex-start; margin: .5rem 0 0; }
.rd-meter { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; color: var(--rd-ink-soft); font-weight: 700; font-size: 1.05rem; }
.rd-bar { display: block; width: min(14rem, 100%); height: 10px; border-radius: 999px; background: var(--rd-sand); overflow: hidden; }
.rd-bar > span, .rd-cover-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--rd-accent); }

.rd-library-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.rd-library-title { display: flex; flex-direction: column; flex: 1; min-width: 10rem; }
.rd-library-head h1 { font-size: clamp(1.5rem, 3.5vw, 1.9rem); font-weight: 900; margin: 0; }
.rd-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.rd-chip { display: inline-flex; align-items: center; min-height: 44px; padding: 0 1.1rem; border-radius: 999px; border: 1px solid var(--rd-line); background: var(--rd-paper); color: var(--rd-ink) !important; font-weight: 700; font-size: 1rem; text-decoration: none; }
.rd-chip:hover { border-color: var(--rd-ink-soft); }
.rd-chip.active { background: var(--rd-ink); border-color: var(--rd-ink); color: #fff !important; font-weight: 800; }

.rd-shelf { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); gap: clamp(1rem, 2.5vw, 1.5rem); }
.rd-card { display: flex; flex-direction: column; gap: .3rem; height: 100%; text-decoration: none; color: var(--rd-ink) !important; }
.rd-cover { position: relative; display: block; aspect-ratio: 3 / 2; margin-bottom: .45rem; border-radius: var(--rd-radius); overflow: hidden; background: var(--rd-sand); transition: transform .15s ease, box-shadow .15s ease; }
.rd-card:hover .rd-cover { transform: translateY(-3px); box-shadow: var(--rd-shadow); }
.rd-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rd-cover-blank { display: grid; place-items: center; height: 100%; color: var(--rd-ink-soft); }
.rd-badge { position: absolute; top: .6rem; left: .6rem; display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .75rem; border-radius: 999px; background: var(--rd-paper); font-size: .875rem; font-weight: 800; }
.rd-badge.done { background: var(--rd-sun); color: var(--rd-sun-700); }
.rd-badge.new { color: var(--rd-teal); }
.rd-badge.locked { background: var(--rd-ink); color: #fff; }
.rd-cover-bar { position: absolute; left: .6rem; right: .6rem; bottom: .6rem; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .8); overflow: hidden; }
.rd-card-title { font-size: 1.2rem; font-weight: 800; line-height: 1.25; }
.rd-card-meta { color: var(--rd-ink-soft); font-size: .95rem; font-weight: 600; }
.rd-empty { text-align: center; padding: 3rem 1rem; font-size: 1.25rem; color: var(--rd-ink-soft); }
.rd-empty > span { display: block; font-size: 4rem; }
.rd-empty > .icon { display: block; margin: 0 auto .75rem; }

@media (max-width: 700px) {
    .rd-continue { grid-template-columns: 1fr; }
    .rd-shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rd-card-title { font-size: 1.05rem; }
    .rd-card-meta { font-size: .85rem; }
}

/* Book ---------------------------------------------------------------------
   A storybook: a hard cover, a picture on the left page and the words on the right, with the stack of pages thinning
   on one side and growing on the other as the child reads. reader-book.js turns the pages. Phones show one page at a
   time, picture above words. The background takes a soft tint from the picture (--rd-mood, set by reader-book.js). */
.rd-shell { background: var(--rd-mood, var(--rd-page)); transition: background-color 1s ease; }
.rd-glass { background: rgba(255, 255, 255, .74); -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4); border: 1px solid rgba(255, 255, 255, .9); box-shadow: 0 18px 40px -24px rgba(31, 36, 48, .45); }
.rd-book { position: relative; outline: none; }
.rd-book > :not(.rd-blob) { position: relative; z-index: 1; }
.rd-blob { position: fixed; z-index: 0; border-radius: 50%; filter: blur(80px); opacity: .5; pointer-events: none; background: var(--rd-mood-strong, var(--rd-sand)); transition: background-color 1s ease; }
.rd-blob-a { width: 34rem; height: 34rem; left: -14rem; bottom: -12rem; }
.rd-blob-b { width: 30rem; height: 30rem; right: -12rem; top: 30%; }

.rd-book-bar { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.rd-back { display: inline-flex; align-items: center; gap: .4rem; min-height: 48px; padding: 0 1.1rem 0 .75rem; border-radius: 999px; font-weight: 800; text-decoration: none; color: var(--rd-ink) !important; flex: none; }
.rd-back:hover { background: var(--rd-paper); }
.rd-book-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rd-book-title { margin: 0; font-size: clamp(1.15rem, 2.5vw, 1.55rem); font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-book-sub { color: var(--rd-ink-soft); font-size: .95rem; font-weight: 700; }
.rd-book-progress { display: inline-flex; align-items: center; gap: .9rem; min-height: 48px; padding: 0 1.1rem; border-radius: 999px; flex: none; }
.rd-dots { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 5px; width: clamp(6rem, 18vw, 14rem); }
.rd-dots span { height: 6px; border-radius: 999px; background: rgba(31, 36, 48, .14); transition: background-color .4s ease; }
.rd-dots span.read { background: var(--rd-accent); }
.rd-dots span.current { background: var(--rd-ink); }
.rd-page-count { font-weight: 900; color: var(--rd-ink); white-space: nowrap; }
.rd-icon-btn { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--rd-line); background: var(--rd-paper); color: var(--rd-ink); cursor: pointer; flex: none; }
.rd-icon-btn:hover { background: var(--rd-paper); }
.rd-icon-btn[aria-expanded="true"] { background: var(--rd-ink); border-color: var(--rd-ink); color: #fff; }

.rd-settings { display: grid; padding: .5rem 1.25rem 1rem; margin-bottom: 1.25rem; border-radius: var(--rd-radius); }
.rd-settings-heading { margin: 1rem 0 .25rem; font-size: .8rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--rd-teal); }
.rd-row { display: grid; grid-template-columns: minmax(0, 17rem) minmax(0, 1fr); align-items: center; gap: .5rem 1rem; min-height: 56px; padding: .4rem 0; border-top: 1px solid var(--rd-line); cursor: default; }
.rd-settings-heading + .rd-row { border-top: 0; }
label.rd-row { cursor: pointer; }
.rd-row > :last-child { justify-self: end; }
.rd-row-label { font-weight: 800; }
.rd-row-child .rd-row-label { padding-left: 1.25rem; color: var(--rd-ink-soft); }
.rd-row-child .rd-row-label::before { content: "\21B3\00A0"; }
.rd-switch { appearance: none; position: relative; width: 52px; height: 30px; margin: 0; border-radius: 999px; background: #c9c3b8; cursor: pointer; transition: background-color .15s ease; }
.rd-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--rd-paper); box-shadow: 0 1px 2px rgba(31, 36, 48, .25); transition: transform .15s ease; }
.rd-switch:checked { background: var(--rd-teal); }
.rd-switch:checked::after { transform: translateX(22px); }
.rd-switch:focus-visible { outline: 3px solid var(--rd-teal); outline-offset: 2px; }
@media (max-width: 600px) {
    .rd-row:not(label) { grid-template-columns: minmax(0, 1fr); }
    .rd-row:not(label) > :last-child { justify-self: start; }
}
.rd-seg { display: inline-flex; padding: .25rem; border-radius: 999px; background: var(--rd-sand); }
.rd-seg button { min-height: 44px; padding: .3rem 1rem; border: 0; border-radius: 999px; background: transparent; font: inherit; font-weight: 700; color: var(--rd-ink-soft); cursor: pointer; }
.rd-seg button.active { background: var(--rd-paper); color: var(--rd-ink); font-weight: 800; box-shadow: 0 1px 2px rgba(31, 36, 48, .12); }
.rd-toggle { display: inline-flex; align-items: center; gap: .55rem; min-height: 44px; font-weight: 700; cursor: pointer; }
.rd-toggle input { width: 1.4rem; height: 1.4rem; accent-color: var(--rd-teal); }
.rd-swatches { display: inline-flex; gap: .5rem; }
.rd-swatch { width: 44px; height: 44px; border-radius: 999px; border: 3px solid var(--rd-paper); background: var(--swatch); box-shadow: 0 0 0 1px var(--rd-line); cursor: pointer; }
.rd-swatch.active { box-shadow: 0 0 0 3px var(--rd-teal); }
.rd-note { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem; padding: .35rem 1.1rem; margin-bottom: 1.25rem; border-radius: 999px; background: var(--rd-teal-100); color: var(--rd-ink); font-weight: 700; }

/* The volume: cover boards, ribbon and pages. */
.rd-stage { display: flex; justify-content: center; padding-bottom: .75rem; }
.rd-volume { --rd-spread: 0; position: relative; isolation: isolate; width: 100%; max-width: 34rem; padding: 8px 14px 8px 8px; border-radius: 8px 24px 24px 8px; background: var(--rd-board, #174f4b); box-shadow: 0 34px 60px -30px rgba(23, 40, 40, .7); transition: transform .8s cubic-bezier(.45, .05, .2, 1), background-color .6s ease; }
.rd-paper { background-color: #fffaf0; background-image: radial-gradient(rgba(120, 90, 40, .05) 1px, transparent 1.2px); background-size: 7px 7px; }
.rd-spread { display: grid; grid-template-columns: minmax(0, 1fr); border-radius: 4px 18px 18px 4px; overflow: hidden; box-shadow: 2px 1px 0 #efe4cf, 4px 2px 0 #ddcfb3, 6px 3px 0 #efe4cf; }
.rd-leaf-left, .rd-leaf-right { position: relative; min-width: 0; }
.rd-leaf-left[hidden] { display: none; }
.rd-picture { position: relative; aspect-ratio: 3 / 2; overflow: hidden; background: var(--rd-sand); display: grid; place-items: center; }
.rd-picture-fill { display: none; }
.rd-picture-main { width: 100%; height: 100%; object-fit: cover; display: block; position: relative; }
.rd-picture-blank { font-size: 4rem; opacity: .5; }
.rd-folio { position: absolute; z-index: 3; left: 1rem; top: 1rem; padding: .15rem .8rem; border-radius: 999px; font-size: .95rem; font-weight: 900; }
.rd-leaf-right { padding: clamp(1.25rem, 4vw, 2rem) clamp(1.25rem, 4vw, 2rem) clamp(1.5rem, 4vw, 2.25rem); }
.rd-page-label { display: block; margin-bottom: .6rem; color: var(--rd-accent-700); font-size: .85rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.rd-words { min-width: 0; }
.rd-text { margin: 0; font-family: var(--rd-font-read); font-size: clamp(1.7rem, 6vw, 2.6rem); line-height: 1.6; letter-spacing: .01em; font-weight: 700; word-spacing: .12em; }
.rd-text .syl-word { display: inline-block; padding: 0 .06em; border-radius: .5rem; transition: background-color .2s ease, transform .2s ease; }
.rd-text .syllable-text .syl-word.clickable:hover { background: var(--rd-sand); }
.rd-text .syllable-text .syl-word.selected { background: var(--rd-sun); }
.rd-text .syllable-text .syl-word.ra-active { background: #ffe08a; box-shadow: 0 0 0 .14em #ffe08a; transform: translateY(-2px); }
.rd-text .syllable-text .syl.ra-active { background: #ffe08a; border-radius: .35rem; }
.rd-focus { display: inline-flex; align-items: center; gap: 1rem; margin-top: 1.25rem; padding: .5rem 1.25rem; border-radius: var(--rd-radius); background: var(--rd-paper); border: 1px solid var(--rd-line); font-family: var(--rd-font-read); font-size: clamp(2rem, 6vw, 3rem); font-weight: 700; }
.rd-focus .syl + .syl { margin-left: .25em; }

/* The cover, shown before the book is opened. */
.rd-book-cover { position: relative; display: block; width: 100%; min-height: 26rem; height: 100%; margin: 0; padding: 0; border: 0; border-radius: 4px 18px 18px 4px; overflow: hidden; background: var(--rd-teal); color: #fff; font: inherit; text-align: left; cursor: pointer; }
.rd-leaf-right:has(.rd-book-cover) { padding: 0; }
.rd-book-cover-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.rd-book-cover::before { content: ""; position: absolute; inset: 0; z-index: 1; background: linear-gradient(to bottom, rgba(16, 40, 52, .62), rgba(16, 40, 52, 0) 55%), linear-gradient(to right, rgba(0, 0, 0, .3), rgba(255, 255, 255, .15) 3%, rgba(0, 0, 0, 0) 6%); }
.rd-book-cover-title { position: absolute; z-index: 2; top: 2rem; left: 2.25rem; right: 1.75rem; font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 900; line-height: 1.05; letter-spacing: -.02em; text-shadow: 0 4px 18px rgba(0, 0, 0, .3); }
.rd-book-cover-open { position: absolute; z-index: 2; right: 1.5rem; bottom: 1.5rem; display: inline-flex; align-items: center; gap: .4rem; min-height: 52px; padding: 0 1.25rem; border-radius: 999px; background: #fff; color: var(--rd-ink); font-weight: 900; box-shadow: 0 12px 26px -12px rgba(0, 0, 0, .5); animation: rd-bob 2.4s ease-in-out infinite; }
@keyframes rd-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* The end of the story, on the last spread. */
.rd-end-art { display: grid; place-items: center; aspect-ratio: 3 / 2; height: 100%; background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .55) 0 30%, transparent 31%), var(--rd-sun); }
.rd-end-star { display: inline-grid; place-items: center; font-size: clamp(5rem, 14vw, 8rem); line-height: 1; animation: rd-pop .6s ease-out; }
.rd-end h2 { margin: 0 0 .5rem; font-size: clamp(2.5rem, 6vw, 4rem); font-weight: 900; line-height: 1; }
.rd-end .rd-lead { margin: 0; }
.rd-end .rd-actions { justify-content: flex-start; }

/* Turning: copies of the old pages laid over the new ones while a leaf turns (see reader-book.js). */
.rd-turn-layer { position: absolute; inset: 0; z-index: 5; pointer-events: none; perspective: 2600px; }
.rd-flip-under { z-index: 1; overflow: hidden; }
.rd-flip { z-index: 3; transform-style: preserve-3d; animation-name: rd-flip-next; animation-timing-function: cubic-bezier(.45, .05, .2, 1); animation-fill-mode: forwards; }
.rd-flip-prev { animation-name: rd-flip-prev; }
.rd-flip-in { animation-name: rd-flip-in; }
.rd-flip-face { position: absolute; inset: 0; overflow: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden; box-shadow: 0 0 40px rgba(40, 25, 5, .28); animation-duration: inherit; }
.rd-flip-back { transform: rotateY(180deg); }
.rd-flip-blank { background-color: #fffaf0; background-image: radial-gradient(rgba(120, 90, 40, .05) 1px, transparent 1.2px); background-size: 7px 7px; }
.rd-flip-shade { position: absolute; inset: 0; pointer-events: none; opacity: 0; animation-duration: inherit; animation-fill-mode: forwards; background: linear-gradient(to right, rgba(40, 25, 5, .5), rgba(40, 25, 5, .06) 50%, rgba(255, 255, 255, .3)); }
.rd-flip-back .rd-flip-shade { background: linear-gradient(to left, rgba(40, 25, 5, .5), rgba(40, 25, 5, .06) 50%, rgba(255, 255, 255, .3)); }
.rd-flip-next > .rd-flip-face:not(.rd-flip-back) .rd-flip-shade, .rd-flip-prev > .rd-flip-face:not(.rd-flip-back) .rd-flip-shade { animation-name: rd-shade-up; }
.rd-flip-next > .rd-flip-back .rd-flip-shade, .rd-flip-prev > .rd-flip-back .rd-flip-shade, .rd-flip-in > .rd-flip-face .rd-flip-shade { animation-name: rd-shade-down; }
.rd-flip-cast { z-index: 2; animation: rd-cast-out ease-in forwards; animation-duration: inherit; }
.rd-flip-cast-right { background: linear-gradient(to right, rgba(40, 25, 5, .42), rgba(40, 25, 5, 0) 78%); }
.rd-flip-cast-left { background: linear-gradient(to left, rgba(40, 25, 5, .42), rgba(40, 25, 5, 0) 78%); }
@keyframes rd-flip-next { 0% { transform: rotateY(0deg); } 50% { transform: rotateY(-90deg) skewY(-2.5deg); } 100% { transform: rotateY(-180deg); } }
@keyframes rd-flip-prev { 0% { transform: rotateY(0deg); } 50% { transform: rotateY(90deg) skewY(2.5deg); } 100% { transform: rotateY(180deg); } }
@keyframes rd-flip-in { 0% { transform: rotateY(-180deg); } 50% { transform: rotateY(-90deg) skewY(2.5deg); } 100% { transform: rotateY(0deg); } }
@keyframes rd-shade-up { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes rd-shade-down { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes rd-cast-out { 0% { opacity: 1; } 100% { opacity: 0; } }

/* The folded corners turn the page too. */
.rd-corner { position: absolute; bottom: 8px; z-index: 6; width: 72px; height: 72px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.rd-corner span { position: absolute; bottom: 0; width: 32px; height: 32px; transition: width .25s ease, height .25s ease; }
.rd-corner-next { right: 14px; }
.rd-corner-next span { right: 0; border-radius: 0 0 18px 0; background: linear-gradient(315deg, transparent 0 49%, #e9dcc2 50%, #fffaf0 100%); box-shadow: -4px -4px 10px rgba(60, 38, 8, .22); }
.rd-corner-prev { left: 8px; display: none; }
.rd-corner-prev span { left: 0; border-radius: 0 0 0 18px; background: linear-gradient(45deg, transparent 0 49%, #e9dcc2 50%, #fffaf0 100%); box-shadow: 4px -4px 10px rgba(60, 38, 8, .22); }
.rd-corner:hover span { width: 52px; height: 52px; }
.rd-ribbon { display: none; }

@media (min-width: 900px) {
    /* Tablets in landscape and computers: the open book, picture on the left page and words on the right. */
    .rd-volume { --rd-spread: 1; max-width: 72rem; padding: 14px; border-radius: 22px; background: transparent; box-shadow: none; }
    .rd-volume::before, .rd-volume::after { content: ""; position: absolute; z-index: -1; top: 0; bottom: 0; width: 50%; background: var(--rd-board, #174f4b); box-shadow: 0 40px 70px -30px rgba(23, 40, 40, .7), inset 0 0 0 2px rgba(255, 255, 255, .07); transition: opacity .5s ease, background-color .6s ease; }
    .rd-volume::before { left: 0; border-radius: 22px 4px 4px 22px; }
    .rd-volume::after { right: 0; border-radius: 4px 22px 22px 4px; }
    .rd-volume.rd-closed { transform: translateX(-25%); }
    .rd-volume.rd-closed::before { opacity: 0; }
    .rd-spread { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: min(34rem, 72vh); overflow: visible; border-radius: 0; box-shadow: none; }
    .rd-leaf-left { border-radius: 16px 3px 3px 16px; box-shadow: var(--rd-edge); }
    .rd-leaf-right { grid-column: 2; border-radius: 3px 16px 16px 3px; box-shadow: var(--rd-edge); display: flex; flex-direction: column; justify-content: center; padding: clamp(2rem, 4vw, 3.5rem) clamp(2rem, 4vw, 3.5rem) clamp(2rem, 4vw, 3.5rem) clamp(2.5rem, 4.5vw, 4rem); }
    .rd-leaf-left::after, .rd-leaf-right::before { content: ""; position: absolute; top: 0; bottom: 0; width: 4.5rem; z-index: 2; pointer-events: none; }
    .rd-leaf-left::after { right: 0; background: linear-gradient(to left, rgba(20, 12, 0, .3), rgba(20, 12, 0, .07) 40%, rgba(20, 12, 0, 0)); }
    .rd-leaf-right::before { left: 0; background: linear-gradient(to right, rgba(60, 38, 8, .2), rgba(60, 38, 8, .05) 40%, rgba(60, 38, 8, 0)); }
    .rd-leaf-left { overflow: hidden; }
    .rd-picture { position: absolute; inset: 0; aspect-ratio: auto; border-radius: inherit; }
    .rd-picture-fill { display: block; position: absolute; inset: -10%; width: 120%; height: 120%; object-fit: cover; filter: blur(22px) saturate(1.2); opacity: .9; }
    .rd-picture-main { height: auto; aspect-ratio: 3 / 2; object-fit: contain; box-shadow: 0 18px 40px -22px rgba(0, 0, 0, .55); }
    .rd-end-art { position: absolute; inset: 0; aspect-ratio: auto; border-radius: inherit; }
    .rd-text { font-size: clamp(1.9rem, 3vw, 2.75rem); }
    .rd-book-cover { position: absolute; inset: 0; min-height: 0; border-radius: inherit; }
    .rd-corner-prev { display: block; left: 14px; }
    .rd-corner-next { right: 14px; bottom: 14px; }
    .rd-corner-prev { bottom: 14px; }
    .rd-ribbon { display: block; position: absolute; z-index: -2; right: 13%; bottom: -78px; width: 26px; height: 110px; background: var(--rd-accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); transition: opacity .5s ease; }
    .rd-closed .rd-ribbon { opacity: 0; }
}

/* The controls float under the book. */
.rd-controls { display: flex; align-items: center; justify-content: center; gap: clamp(.5rem, 2vw, 1rem); width: fit-content; max-width: 100%; box-sizing: border-box; margin: clamp(1.75rem, 4vw, 2.5rem) auto 0; padding: .5rem; border-radius: 999px; }
.rd-turn { display: inline-grid; place-items: center; width: clamp(56px, 12vw, 64px); height: clamp(56px, 12vw, 64px); border-radius: 50%; border: 1px solid var(--rd-line); background: var(--rd-paper); color: var(--rd-ink); cursor: pointer; transition: transform .08s ease, background-color .12s ease; flex: none; }
.rd-turn:hover { background: var(--rd-sand); }
.rd-turn:active { transform: scale(.96); }
.rd-turn-next { background: #ff4f7b; border-color: #ff4f7b; color: #fff; }
.rd-turn-next:hover { background: #e83a67; }
.rd-turn[disabled] { opacity: .35; cursor: not-allowed; }
.rd-play-group { display: flex; align-items: center; justify-content: center; gap: .5rem; flex-wrap: wrap; text-align: center; min-width: 0; }
/* Dengar: a sunset gradient that glows while the story plays. White text stays above 4.5:1 on the darkest stops it sits on. */
.rd-play { display: inline-flex; align-items: center; justify-content: center; gap: .7rem; min-width: 13rem; min-height: 64px; padding: 0 1.9rem 0 1rem; border-radius: 999px; border: 0; background: linear-gradient(135deg, #e8622a 0%, #e0335f 55%, #a83bc0 100%); box-shadow: 0 14px 28px -12px rgba(224, 51, 95, .75), inset 0 2px 0 rgba(255, 255, 255, .3); color: #fff; font: inherit; font-size: 1.3rem; font-weight: 900; cursor: pointer; transition: transform .15s ease, filter .2s ease; }
.rd-play:hover { transform: translateY(-2px); filter: brightness(1.05); }
.rd-play:active { transform: scale(.97); }
.rd-play.on { animation: rd-glow 1.6s ease-in-out infinite; }
.rd-play-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .25); }
@keyframes rd-glow { 0%, 100% { filter: saturate(1); } 50% { filter: saturate(1.35) brightness(1.06); } }
.rd-wave { display: inline-flex; align-items: flex-end; gap: 3px; height: 18px; }
.rd-wave i { display: block; width: 4px; height: 5px; border-radius: 2px; background: currentColor; opacity: .85; }
.rd-wave.on i { animation: rd-wave .9s ease-in-out infinite; }
.rd-wave.on i:nth-child(2) { animation-delay: .15s; }
.rd-wave.on i:nth-child(3) { animation-delay: .3s; }
.rd-wave.on i:nth-child(4) { animation-delay: .45s; }
@keyframes rd-wave { 0%, 100% { height: 5px; } 50% { height: 18px; } }

/* The end and the questions ------------------------------------------------- */
.rd-questions { text-align: left; max-width: 46rem; margin: 2.5rem auto 0; padding: clamp(1rem, 3vw, 1.75rem); border-radius: var(--rd-radius-lg); }
.rd-questions h2 { font-size: clamp(1.4rem, 3.5vw, 1.8rem); text-align: center; }
.rd-questions > .rd-hint { text-align: center; }
.rd-questions ol { padding-left: 1.5rem; }
.rd-question { margin-bottom: 1rem; padding: 1.1rem 1.25rem; border-radius: var(--rd-radius); background: var(--rd-page); border: 1px solid var(--rd-line); }
.rd-question::marker { font-weight: 900; font-size: 1.3rem; }
.rd-question-text { font-size: clamp(1.25rem, 3.5vw, 1.5rem); font-weight: 800; margin-bottom: .75rem; }
.rd-answer { font-size: 1.15rem; padding: .6rem .9rem; border-radius: 1rem; background: var(--rd-paper); }
.rd-answer-label { font-weight: 900; color: var(--rd-leaf); }
.rd-marks { display: flex; flex-wrap: wrap; gap: .6rem; }
.rd-marks button { display: inline-flex; align-items: center; gap: .4rem; min-height: 52px; padding: .4rem 1.2rem; border-radius: 999px; border: 2px solid var(--rd-line); background: var(--rd-paper); font: inherit; font-weight: 800; cursor: pointer; }
.rd-marks button.active { background: var(--rd-leaf); border-color: var(--rd-leaf); color: #fff; }

@keyframes rd-pop { 0% { transform: scale(.3) rotate(-20deg); opacity: 0; } 70% { transform: scale(1.12) rotate(6deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }

/* Parents ------------------------------------------------------------------- */
.rd-gate { max-width: 28rem; margin: 2rem auto; text-align: center; padding: 2rem; border-radius: var(--rd-radius-lg); background: var(--rd-paper); box-shadow: var(--rd-shadow); }
.rd-gate-form { display: flex; flex-direction: column; gap: .75rem; align-items: center; font-size: 1.3rem; font-weight: 800; }
.rd-gate-form input { width: 8rem; min-height: 52px; text-align: center; font: inherit; font-size: 1.5rem; border-radius: 1rem; border: 2px solid var(--rd-line); }
.rd-parents { max-width: 52rem; margin: 0 auto; font-size: 1.05rem; }
.rd-parents > h1 { font-size: clamp(1.8rem, 4vw, 2.3rem); font-weight: 900; margin: .5rem 0 1.25rem; }
.rd-panel { padding: clamp(1.1rem, 3vw, 1.75rem); margin-bottom: 1.25rem; border-radius: var(--rd-radius-lg); background: var(--rd-paper); box-shadow: var(--rd-shadow); }
.rd-panel h2 { font-size: 1.35rem; font-weight: 900; }
.rd-child-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.rd-child-list > li { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; padding: .9rem 0; border-bottom: 1px solid var(--rd-line); }
.rd-child-info { display: flex; flex-direction: column; flex: 1; min-width: 8rem; font-weight: 800; }
.rd-child-info span { color: var(--rd-ink-soft); font-weight: 600; }
.rd-child-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.rd-confirm, .rd-progress { flex-basis: 100%; padding: 1rem; border-radius: 1rem; }
.rd-confirm { background: var(--rd-berry-100); }
.rd-progress { background: var(--rd-page); overflow-x: auto; }
.rd-progress table { width: 100%; border-collapse: collapse; }
.rd-progress th, .rd-progress td { padding: .45rem .6rem; text-align: left; border-bottom: 1px solid var(--rd-line); }
.rd-child-form { display: flex; flex-direction: column; gap: .4rem; padding: 1.1rem; border-radius: 1rem; background: var(--rd-page); }
.rd-child-form h3 { font-size: 1.2rem; font-weight: 900; }
.rd-child-form label { font-weight: 700; margin-top: .5rem; }
.rd-child-form input[type="text"], .rd-child-form input:not([type]), .rd-child-form select { min-height: 48px; padding: .4rem .8rem; border-radius: .75rem; border: 2px solid var(--rd-line); font: inherit; background: #fff; max-width: 24rem; }
.rd-child-form fieldset { border: 0; padding: 0; margin: .5rem 0 0; }
.rd-child-form legend { font-size: 1rem; font-weight: 700; }
.rd-avatar-picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.rd-avatar-choice { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--rd-line); background: #fff; font-size: 1.8rem; cursor: pointer; }
.rd-avatar-choice.active { border-color: var(--rd-accent); background: var(--rd-accent-100); }
.rd-consent { margin-top: .75rem; padding: 1rem; border-radius: 1rem; background: var(--rd-teal-100); font-size: 1rem; }
.rd-plain-list { padding-left: 1.25rem; }
.rd-parents .rd-actions { justify-content: flex-start; }

/* Blazor's "something went wrong" bar, hidden until Blazor shows it. The admin styles its own copy in MainLayout. */
#blazor-error-ui { display: none; position: fixed; left: 0; bottom: 0; width: 100%; z-index: 1000; box-sizing: border-box; padding: .75rem 3rem .75rem 1.25rem; background: #fff4d1; box-shadow: 0 -1px 2px rgba(0, 0, 0, .2); font-weight: 700; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .6rem; }

@media (max-width: 600px) {
    .rd-back-label, .rd-logout span { display: none; }
    .rd-back { padding: 0 .75rem; }
    .rd-play span { display: none; }
    .rd-play { min-width: 0; padding: 0 1rem; }
    .rd-dots { display: none; }
    .rd-book-progress { padding: 0 .9rem; }
}

@media (prefers-reduced-motion: reduce) {
    .rd-shell *, .rd-shell *::before, .rd-shell *::after { animation: none !important; transition: none !important; }
}

/* Subscriptions ---------------------------------------------------------------- */
.rd-locked .rd-hint { font-size: 1rem; }
.rd-locked .rd-actions, .rd-payment-result .rd-actions { justify-content: center; }
.rd-payment-result h1 { margin: .5rem 0; }
.rd-sub-status { display: grid; gap: .3rem; padding: .9rem 1.1rem; margin-bottom: 1rem; border-radius: 1rem; background: var(--rd-sun); }
.rd-sub-status.active { background: var(--rd-leaf-100); }
.rd-plans { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.rd-plan { display: grid; gap: .5rem; align-content: start; padding: 1.25rem; border: 2px solid var(--rd-line); border-radius: var(--rd-radius); background: var(--rd-page); }
.rd-plan .rd-btn { justify-self: start; }
.rd-price { font-size: 1.6rem; font-weight: 900; }
.rd-price small { font-size: 1rem; font-weight: 600; color: var(--rd-ink-soft); }
.rd-orders summary { cursor: pointer; font-weight: 800; min-height: 48px; display: flex; align-items: center; }
.rd-orders table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.rd-orders th, .rd-orders td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--rd-line); }
.rd-practice { max-width: 32rem; margin: 2rem auto; text-align: center; }
.rd-practice .rd-actions { justify-content: center; }
.rd-practice-flag { display: inline-block; padding: .2rem .8rem; border-radius: 999px; background: var(--rd-berry-100); color: var(--rd-berry); font-weight: 800; font-size: .9rem; }
.rd-nowrap { white-space: nowrap; }
