/* ==========================================================================
   Hikayati — public site & story reader
   Mobile first. Logical properties throughout so RTL (Arabic) and LTR share one stylesheet.
   ========================================================================== */

/* ---------- fonts (self-hosted, SIL OFL) ---------- */
@font-face {
    font-family: "Hk Read";
    src: url("/fonts/naskh-arabic.woff2") format("woff2");
    font-weight: 400 700;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41;
}
@font-face {
    font-family: "Hk UI";
    src: url("/fonts/kufi-arabic.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41;
}
@font-face {
    font-family: "Hk Read";
    src: url("/fonts/nunito-latin.woff2") format("woff2");
    font-weight: 200 1000;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Hk Read";
    src: url("/fonts/nunito-latin-ext.woff2") format("woff2");
    font-weight: 200 1000;
    font-display: swap;
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Hk UI";
    src: url("/fonts/nunito-latin.woff2") format("woff2");
    font-weight: 200 1000;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Hk UI";
    src: url("/fonts/nunito-latin-ext.woff2") format("woff2");
    font-weight: 200 1000;
    font-display: swap;
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- tokens ---------- */
:root {
    color-scheme: light;
    --bg: #fff8ef;
    --paper: #fffaf3;
    --surface: #ffffff;
    --surface-2: #f6f0ff;
    --ink: #2b2240;
    --muted: #6a6180;
    --line: #ebe2f5;
    --primary: #5b3cc4;
    --primary-ink: #ffffff;
    --primary-soft: #ece6ff;
    --accent: #ff9f43;
    --accent-soft: #fff0df;
    --ok: #1f8a5b;
    --danger: #c62f45;
    --whatsapp: #128c4a;
    --shadow: 0 1px 2px rgb(43 34 64 / 6%), 0 8px 24px rgb(43 34 64 / 8%);
    --shadow-lg: 0 12px 40px rgb(43 34 64 / 18%);
    --radius: 18px;
    --header-block: 69px;   /* the sticky site header */
    --font-ui: "Hk UI", system-ui, -apple-system, "Segoe UI", Roboto, "Geeza Pro", Tahoma, sans-serif;
    --font-read: "Hk Read", "Geeza Pro", Georgia, "Times New Roman", serif;
    --read-size: 1.25rem;
    --read-leading: 1.8;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #15111f;
    --paper: #17131f;
    --surface: #221b31;
    --surface-2: #2b2340;
    --ink: #f1ecfb;
    --muted: #b6abcd;
    --line: #372d4f;
    --primary: #a993ff;
    --primary-ink: #1b1530;
    --primary-soft: #33295a;
    --accent: #ffb36b;
    --accent-soft: #3a2a1d;
    --ok: #5fd39e;
    --danger: #ff7d8f;
    --whatsapp: #3ccf7d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 35%);
    --shadow-lg: 0 12px 40px rgb(0 0 0 / 55%);
}
/* Reader text size steps, chosen in the reader settings (stored on <html data-size>). */
:root[data-size="0"] { --read-size: 1rem; }
:root[data-size="1"] { --read-size: 1.125rem; }
:root[data-size="2"] { --read-size: 1.25rem; }
:root[data-size="3"] { --read-size: 1.4rem; }
:root[data-size="4"] { --read-size: 1.6rem; }
:root[data-size="5"] { --read-size: 1.85rem; }
:lang(ar) { --read-leading: 2; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 1rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
img { max-width: 100%; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.3; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.needs-js { display: none !important; }
html.js .needs-js { display: revert !important; }
html.js .needs-js[hidden] { display: none !important; }
.muted { color: var(--muted); }
.icon { inline-size: 1.4em; block-size: 1.4em; flex: none; }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }
.skip-link { position: absolute; inset-inline-start: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 14px; border-radius: 10px; }
.skip-link:focus { inset-inline-start: 8px; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0;
    font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
    background: var(--surface-2); color: var(--ink);
    white-space: nowrap;
    transition: transform .1s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-whatsapp { background: var(--whatsapp); color: #fff; }
.btn-block { inline-size: 100%; }
.icon-btn {
    display: inline-grid; place-items: center; inline-size: 44px; block-size: 44px; flex: none;
    border-radius: 50%; border: 0; background: transparent; color: var(--ink); cursor: pointer;
    list-style: none; text-decoration: none;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--surface-2); }
summary.icon-btn::-webkit-details-marker { display: none; }

/* ---------- header / footer ---------- */
.site-header {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand img { border-radius: 12px; }
.brand-text { display: grid; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 800; font-size: 1.2rem; }
.brand-tag { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.site-main { padding: 8px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); max-width: 1180px; margin: 0 auto; }
.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }

/* language menu (works without JS thanks to <details>) */
.lang-menu { position: relative; }
/* closed: a compact code button (AR / EN / SV / NL / DE), at least 44x44 px */
.lang-menu > summary {
    display: inline-flex; align-items: center; justify-content: center; gap: 2px; min-height: 44px; min-width: 44px; padding: 0 8px 0 12px;
    border-radius: 999px; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--line);
    cursor: pointer; list-style: none; font-weight: 800; font-size: .92rem;
}
.lang-code { letter-spacing: .03em; }
.lang-caret { inline-size: 18px; block-size: 18px; opacity: .65; }
.lang-item-code { display: inline-block; min-inline-size: 2.2em; font-size: .82em; font-weight: 800; color: var(--muted); }
.lang-menu > summary::-webkit-details-marker { display: none; }
.lang-list {
    position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 40;
    min-inline-size: 180px; margin: 0; padding: 6px; list-style: none;
    background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
}
.lang-list form { margin: 0; }
.lang-list button { inline-size: 100%; text-align: start; border: 0; background: none; font: inherit; cursor: pointer; }
.lang-list a, .lang-list button { display: block; padding: 10px 14px; border-radius: 10px; text-decoration: none; color: var(--ink); font-weight: 600; }
.lang-list a:hover, .lang-list a:focus-visible, .lang-list button:hover, .lang-list button:focus-visible { background: var(--surface-2); }
.lang-list [aria-current="true"] { background: var(--primary-soft); color: var(--primary); }

.offline-banner { background: var(--accent-soft); color: var(--ink); text-align: center; padding: 8px 16px; font-size: .9rem; }
.ios-hint {
    position: fixed; inset-inline: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 60;
    display: flex; gap: 12px; align-items: center; justify-content: space-between;
    padding: 14px 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.ios-hint p { margin: 0; }
.hint-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-glyph { vertical-align: -0.3em; color: #0a84ff; }
@media (min-width: 640px) { .ios-hint { inset-inline: auto 16px; max-inline-size: 420px; } }

/* ---------- library ---------- */
.visually-hidden { position: absolute !important; inline-size: 1px; block-size: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

/*
 * Three views, chosen with the buttons above the results and stored in localStorage['hk.libraryView'];
 * theme.js sets <html data-library-view> before the first paint. Without JavaScript the compact grid is shown.
 *   grid    (default) small cards: whole cover, title (2 lines), age + minutes
 *   list    one row per story: small cover, title, age, minutes
 *   gallery the large cards: whole cover, title, short summary, all details
 * Every view shows the same stories; covers are never cropped (object-fit: contain in a reserved box).
 */
.story-grid {
    list-style: none; margin: 10px 0 0; padding: 0;
    display: grid; gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr));
}
@media (min-width: 640px) { .story-grid { gap: 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
@media (min-width: 1000px) { .story-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.story-card {
    display: flex; flex-direction: column; overflow: hidden; block-size: 100%;
    background: var(--surface); color: var(--ink); text-decoration: none;
    border-radius: var(--radius); box-shadow: var(--shadow);
    transition: transform .15s ease, box-shadow .15s ease;
}
.story-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
/* Whole illustration, never cropped, letterboxed in a fixed 4:3 box so every card has the same size. */
.card-media { position: relative; overflow: hidden; background: var(--surface-2); aspect-ratio: 4 / 3; }
.card-media img { position: absolute; inset: 0; display: block; inline-size: 100%; block-size: 100%; object-fit: contain; }
.card-body { padding: 10px 12px 0; }
.card-meta { margin-block-start: auto; }
.card-body h2 {
    margin: 0; font-size: 1rem; line-height: 1.3;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.card-body p {
    margin: 6px 0 0; color: var(--muted); font-family: var(--font-read); font-size: 1.02rem;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
}
.card-meta { padding: 8px 12px 12px; display: grid; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chips li { font-size: .82rem; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.chips .chip-saved { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.card-note { margin: 0; font-size: .85rem; color: var(--muted); }
.card-language { margin: 0; justify-self: start; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .78rem; font-weight: 700; }
.chips .chip-resume { background: var(--primary-soft); color: var(--primary); }

/* grid (default): only title, age and minutes; the rest stays in the DOM for screen readers and the story page */
.story-grid .card-body p, .story-grid .chip-detail, .story-grid .card-note, .story-grid .card-cta { display: none; }
.story-grid .chips li { font-size: .78rem; padding: 2px 8px; }
.story-grid .chip-audio-text { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* list: one compact row per story */
:root[data-library-view="list"] .story-grid { grid-template-columns: 1fr; gap: 10px; }
:root[data-library-view="list"] .story-card {
    display: grid; grid-template-columns: 96px minmax(0, 1fr); grid-template-areas: "media body" "media meta";
    align-items: start; column-gap: 12px; padding: 8px; padding-inline-end: 56px; block-size: auto;
}
:root[data-library-view="list"] .card-media { grid-area: media; border-radius: 10px; }
:root[data-library-view="list"] .card-body { grid-area: body; padding: 2px 0 0; }
:root[data-library-view="list"] .card-meta { grid-area: meta; padding: 6px 0 0; }
:root[data-library-view="list"] .story-card:not(:has(.card-media)) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "body" "meta"; }
@media (min-width: 640px) {
    :root[data-library-view="list"] .story-card { grid-template-columns: 120px minmax(0, 1fr); }
    :root[data-library-view="list"] .card-body p { display: -webkit-box; -webkit-line-clamp: 1; line-clamp: 1; font-size: .95rem; margin-top: 2px; }
}

/* gallery: the large cards (full cover, short summary, details) */
:root[data-library-view="gallery"] .story-grid { gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
:root[data-library-view="gallery"] .card-media { aspect-ratio: auto; display: block; }
:root[data-library-view="gallery"] .card-media img {
    position: static; inline-size: auto; block-size: auto; max-inline-size: 100%;
    margin-inline: auto; max-block-size: min(85vw, 380px);
}
:root[data-library-view="gallery"] .card-body { padding: 14px 18px 0; }
:root[data-library-view="gallery"] .card-body h2 { font-size: 1.25rem; }
:root[data-library-view="gallery"] .card-body p { display: -webkit-box; }
:root[data-library-view="gallery"] .card-meta { padding: 12px 18px 18px; gap: 10px; }
:root[data-library-view="gallery"] .chip-detail { display: revert; }
:root[data-library-view="gallery"] .card-note { display: block; }
:root[data-library-view="gallery"] .card-cta { display: inline-flex; }
:root[data-library-view="gallery"] .story-grid .chips li { font-size: .82rem; padding: 3px 10px; }
:root[data-library-view="gallery"] .chip-audio-text { position: static; inline-size: auto; block-size: auto; overflow: visible; clip: auto; }

/* favourites: heart over the card (a button can't live inside the card link) */
.story-item { position: relative; display: flex; flex-direction: column; }
.story-item > .story-card { flex: 1 1 auto; }
.fav-btn {
    display: inline-grid; place-items: center; inline-size: 44px; block-size: 44px; flex: none;
    border: 0; border-radius: 50%; cursor: pointer; background: transparent; color: var(--ink);
}
.fav-btn .heart-on { display: none; }
.fav-btn[aria-pressed="true"] { color: #e0245e; }
.fav-btn[aria-pressed="true"] .heart-on { display: block; }
.fav-btn[aria-pressed="true"] .heart-off { display: none; }
.card-fav {
    position: absolute; top: 6px; inset-inline-end: 6px;
    background: color-mix(in srgb, var(--surface) 88%, transparent); box-shadow: var(--shadow);
}
.card-fav:hover, .card-fav:focus-visible { background: var(--surface); }

/* library filters (a plain GET form: works without JavaScript) and the view buttons on one control row */
.library-controls {
    position: sticky; top: calc(var(--header-block) + env(safe-area-inset-top)); z-index: 27;
    display: flex; align-items: flex-start; gap: 8px;
    margin: 0 -16px; padding: 8px 16px;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
/* The open filters float over the stories, whatever their number: the sticky row itself never grows. */
.filters { position: relative; }
.filters[open] .filter-form {
    position: absolute; inset-block-start: calc(100% + 6px); inset-inline-start: 0; z-index: 29;
    inline-size: min(620px, calc(100vw - 32px)); max-block-size: calc(100vh - 92px - env(safe-area-inset-top)); max-block-size: calc(100dvh - 92px - env(safe-area-inset-top));
    overflow-y: auto; overscroll-behavior: contain;
    padding: 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-lg);
}
/* Phones: the brand row scrolls away, only the filter and view row stays. */
@media (max-width: 700px), (max-height: 500px) {
    body:has(.library-controls) .site-header { position: relative; top: auto; }
    .library-controls { top: env(safe-area-inset-top); }
}
.filters { flex: 1 1 auto; min-inline-size: 0; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters > summary {
    display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 16px;
    cursor: pointer; list-style: none; font-weight: 800;
}
.filters > summary > span:first-of-type { min-inline-size: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view-switch { flex: none; padding: 4px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); white-space: nowrap; }
.view-btn {
    display: inline-grid; place-items: center; inline-size: 44px; block-size: 44px; vertical-align: middle;
    border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer;
}
.view-btn .icon { inline-size: 22px; block-size: 22px; }
.view-btn:hover { background: var(--surface-2); color: var(--ink); }
.view-btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary-ink) 35%, transparent); }
.active-filters { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.active-filters[hidden], .active-filters li[hidden] { display: none; }
.filter-chip {
    display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border: 0; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary); font: inherit; font-size: .9rem; font-weight: 700; text-decoration: none; cursor: pointer;
}
.filter-chip-clear { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.filters > summary::-webkit-details-marker { display: none; }
.filter-count { display: inline-grid; place-items: center; min-inline-size: 24px; block-size: 24px; padding: 0 6px; border-radius: 999px; background: var(--primary); color: var(--primary-ink); font-size: .8rem; }
.filter-form {
    display: grid; gap: 12px; padding: 4px 18px 18px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr));
}
.filter-form .field-wide { grid-column: 1 / -1; }
.filter-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.result-count { margin: 10px 0 0; color: var(--muted); font-weight: 700; font-size: .92rem; min-height: 1px; }
.result-count:empty { margin: 0; }
.saved-offline { margin: 12px 0; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.saved-offline h2 { margin: 0 0 6px; font-size: 1rem; color: var(--ok); }
.saved-offline ul { margin: 0; padding-inline-start: 20px; display: grid; gap: 4px; }
.saved-offline a { display: inline-block; min-block-size: 32px; padding-block: 4px; font-weight: 700; }
/* Count and page size on one line (wraps on narrow phones). */
.result-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin: 10px 0 0; }
.result-bar .result-count { margin: 0; }
.result-range { font-weight: 600; }
.page-size { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .9rem; font-weight: 700; color: var(--muted); }
.page-size select {
    font: inherit; font-weight: 800; color: var(--ink); background: var(--paper);
    border: 1.5px solid var(--line); border-radius: 12px; min-block-size: 44px; padding: 0 10px;
}
.page-size select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
html.js .page-size-apply { display: none; }

/* Page numbers (library and admin): touch-sized, wraps instead of overflowing, arrows follow the reading direction. */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin: 20px 0 8px; }
.pager-pages { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
.pager-page, .pager-step {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    min-inline-size: 44px; min-block-size: 44px; padding: 0 12px; border-radius: 12px;
    border: 0; background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line);
    font: inherit; font-weight: 800; text-decoration: none; cursor: pointer; font-variant-numeric: tabular-nums;
}
a.pager-page:hover, a.pager-step:hover, button.pager-page:hover, button.pager-step:hover { background: var(--surface-2); }
.pager-page[aria-current="page"] { background: var(--primary); color: var(--primary-ink); box-shadow: none; cursor: default; }
.pager-step[aria-disabled="true"] { opacity: .4; cursor: default; }
.pager-gap { min-inline-size: 20px; text-align: center; color: var(--muted); font-weight: 800; align-self: center; }
@media (max-width: 380px) {
    .pager-step span { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .pager-step { padding: 0; }
}
.card-cta { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-weight: 800; }

/* ---------- message pages / auth ---------- */
.message-page { text-align: center; max-width: 520px; margin: 48px auto; }
.message-icon { font-size: 3rem; }
.auth-card { max-width: 420px; margin: 32px auto; padding: 24px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-card h1 { margin-top: 0; font-size: 1.5rem; }
.form-stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 700; font-size: .92rem; }
.field input, .field select, .field textarea {
    font: inherit; color: var(--ink); background: var(--paper);
    border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px; inline-size: 100%;
}
.field textarea { font-family: var(--font-read); line-height: 1.7; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.check, .radio { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input, .radio input { inline-size: 20px; block-size: 20px; accent-color: var(--primary); flex: none; }
.alert { padding: 12px 16px; border-radius: 12px; }
.alert ul { margin: 0; padding-inline-start: 18px; }
.alert-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert-ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.help { color: var(--muted); font-size: .85rem; }

/* ==========================================================================
   Story reader
   The reader is a fixed, full-viewport column: top bar · stage · ONE nav bar.
   Only the text panel scrolls; the illustration stays in view.
   ========================================================================== */
.reader {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    background: var(--paper);
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow: hidden;
}
.reader-bar { flex: none; display: flex; align-items: center; gap: 2px; padding: 6px 8px; }
.reader-title { flex: 1; min-width: 0; margin: 0 6px; font-size: 1rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notice { flex: none; margin: 0 12px 6px; padding: 8px 12px; border-radius: 12px; background: var(--accent-soft); font-size: .9rem; }
.notice-warn { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.notice-inline { margin: 0 0 1em; }

.popover { position: relative; }
.popover > summary { list-style: none; }
.popover-panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 50;
    inline-size: min(330px, calc(100vw - 24px));
    max-block-size: min(70vh, 560px); overflow: auto; overscroll-behavior: contain;
    display: grid; gap: 12px; padding: 16px;
    background: var(--surface); color: var(--ink);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.popover-title { margin: 0; font-weight: 800; }
.share-url { inline-size: 100%; font: inherit; font-size: .85rem; direction: ltr; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--paper); color: var(--muted); }
.setting { display: grid; gap: 8px; border: 0; margin: 0; padding: 0; }
.setting-label { font-weight: 700; font-size: .9rem; color: var(--muted); padding: 0; }
.setting-status { font-size: .88rem; color: var(--ok); }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.segmented button {
    min-height: 44px; border-radius: 12px; border: 0; cursor: pointer;
    font: inherit; font-weight: 800; background: var(--surface-2); color: var(--ink);
}
.segmented button[aria-checked="true"] { background: var(--primary); color: var(--primary-ink); }
.voices .radio span small { color: var(--muted); }

.reader-stage { position: relative; flex: 1 1 auto; min-height: 0; }
.scene { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* Portrait: illustration on top, sized to its own aspect ratio (no letterbox bands), text scrolls below. */
.scene-figure {
    flex: none; margin: 0; padding: 4px 12px 6px;
    display: flex; justify-content: center; align-items: center;
}
.scene-figure img {
    display: block;
    inline-size: auto; block-size: auto;
    max-inline-size: 100%;
    max-block-size: 42vh;
    max-block-size: 42dvh;
    object-fit: contain;
    border-radius: 16px;
    box-shadow: var(--shadow);
    background: var(--surface-2);
    cursor: zoom-in;
    touch-action: pan-y;
}
.scene-text {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding: 6px 20px 28px;
    font-family: var(--font-read); font-size: var(--read-size); line-height: var(--read-leading);
    scrollbar-gutter: stable;
}
.scene-text > * { max-inline-size: 42em; margin-inline: auto; }
.scene-text:focus-visible { outline-offset: -3px; }
.scene-title { font-family: var(--font-ui); font-size: 1.15em; margin: .3em auto .6em; color: var(--primary); outline: none; }
.scene-text p { margin-block: 0 .85em; }
/* Following the narration: the whole word and its paragraph; the colours keep the text readable in both themes. */
.w { border-radius: .2em; transition: background-color .08s linear; }
.word-active { background: color-mix(in srgb, var(--accent) 45%, transparent); box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.scene-text p.block-active { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); border-radius: .35em; box-shadow: 0 0 0 .3em color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.follow-resume {
    position: fixed; inset-inline: 0; margin-inline: auto; inline-size: fit-content; max-inline-size: calc(100vw - 32px);
    bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
    min-block-size: 44px; padding: 0 18px; border: 0; border-radius: 999px; cursor: pointer;
    background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 800; box-shadow: var(--shadow-lg);
}
.follow-resume[hidden] { display: none; }
.scene-question {
    margin-block: 1.4em .6em; padding: 14px 16px; border-radius: 16px;
    background: var(--primary-soft); font-size: .95em;
}
.scene-question strong { display: block; font-family: var(--font-ui); font-size: .8em; color: var(--primary); margin-bottom: 4px; }
.scene-question p { margin: 0; }
/* Clickable sound words inside the text ("Muuuuuu!"): a real <button>, so keyboard and screen readers work. */
.sound-word {
    display: inline; font: inherit; color: var(--primary); font-weight: 800; cursor: pointer;
    padding: 0 .3em; margin: 0 .05em; border: 0; border-radius: .5em;
    background: var(--primary-soft); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--primary) 45%, transparent);
    -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.sound-word:hover { background: color-mix(in srgb, var(--primary) 22%, var(--surface)); }
.sound-word[aria-pressed="true"] { background: var(--accent); color: #2b1a05; }
.sound-icon { font-size: .8em; margin-inline-end: .2em; }
html:not(.js) .sound-word { cursor: default; box-shadow: none; }
html:not(.js) .sound-icon { display: none; }
.the-end { text-align: center; padding-top: .6em; font-family: var(--font-ui); font-size: 1rem; }

/* Tap the illustration to see it large; tap again to return to the text. */
.scene.zoomed .scene-text { display: none; }
.scene.zoomed .scene-figure { flex: 1 1 auto; min-height: 0; }
.scene.zoomed .scene-figure img { max-block-size: 100%; cursor: zoom-out; }

.scene.no-image .scene-text { padding-top: 16px; }

/* Short portrait screens (small phones, iPhone SE): give the text more room. */
@media (orientation: portrait) and (max-height: 700px) {
    .scene-figure img { max-block-size: 36vh; max-block-size: 36dvh; }
}

/* Landscape phones, tablets and desktops: illustration and text side by side. */
@media (min-aspect-ratio: 5/4) {
    .scene { flex-direction: row; }
    .scene-figure { flex: 0 0 52%; block-size: 100%; padding: 8px 12px 12px; }
    .scene-figure img { max-block-size: 100%; }
    .scene-text { flex: 1 1 0; block-size: 100%; padding: 12px 24px 28px; }
    .scene.zoomed .scene-figure { flex-basis: 100%; }
}
@media (min-aspect-ratio: 5/4) and (min-width: 1200px) {
    .scene-figure { flex-basis: 56%; padding: 12px 24px 20px; }
}

/* The single navigation bar. */
.reader-nav {
    position: relative; flex: none;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
    padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: var(--surface);
    box-shadow: 0 -1px 0 var(--line);
}
.progress { position: absolute; inset-inline: 0; top: 0; block-size: 3px; background: var(--line); }
.progress span { display: block; block-size: 100%; background: var(--accent); transition: width .25s ease; }
.nav-btn {
    display: inline-flex; align-items: center; gap: 4px;
    min-block-size: 52px; min-inline-size: 52px; padding: 0 16px;
    border-radius: 999px; text-decoration: none; font-weight: 800; font-size: 1.02rem;
    color: var(--ink); background: var(--surface-2); justify-self: start;
    user-select: none; -webkit-user-select: none;
}
.nav-btn.nav-next { justify-self: end; background: var(--primary); color: var(--primary-ink); }
.nav-btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.nav-center { display: flex; align-items: center; gap: 10px; }
.counter { font-weight: 800; color: var(--muted); font-size: .95rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.listen-btn {
    display: inline-grid; place-items: center; inline-size: 52px; block-size: 52px; border-radius: 50%;
    border: 0; cursor: pointer; background: var(--accent); color: #2b1a05;
}
.listen-btn .pause { display: none; }
.listen-btn[aria-pressed="true"] .play { display: none; }
.listen-btn[aria-pressed="true"] .pause { display: block; }

@media (max-width: 520px) {
    .brand-tag { display: none; }
    .site-header .btn { padding: 0 12px; min-height: 40px; font-size: .9rem; }
    .lang-menu > summary { padding: 0 6px 0 10px; }
}
/* phones: less empty space above the stories */
@media (max-width: 640px) {
    .filters > summary { padding: 0 14px; }
}
@media (max-width: 380px) {
    .nav-btn { padding: 0 12px; font-size: .95rem; }
    .scene-text { padding-inline: 16px; }
}

.toast {
    position: fixed; inset-inline: 0; margin-inline: auto; inline-size: fit-content; max-inline-size: calc(100vw - 32px);
    bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 70;
    padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 700;
    box-shadow: var(--shadow-lg);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
