/* سجدةٌ أنقذتني — een open boek op een houten tafel */

:root {
    --paper: #fffaf6;
    --ink: #33263A;
    --ink-soft: #62525f;
    --rose: #A3485F;
    --sage: #5b7b5f;
    --gold: #e3c27a;
    --line: #ecdcd9;
    --leather: #5c2a36;
    --pw: 360px;   /* breedte van één bladzijde (JS) */
    --ph: 560px;   /* hoogte van een bladzijde (JS) */
    --flip: 0.9s;
    box-sizing: border-box;
}
*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }

html, body { height: 100%; overflow: hidden; }
body {
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background: #3b2418 url("../images/tafel.svg") center / cover no-repeat;
    font-family: "Noto Naskh Arabic", "Amiri", "Traditional Arabic", "Arial", serif;
    -webkit-text-size-adjust: 100%;
    display: flex;
    flex-direction: column;
}
:focus-visible { outline: 2px solid #e8b04c; outline-offset: 3px; border-radius: 6px; }

.candle-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 8% 75%, rgba(255, 182, 92, 0.25), transparent 40%);
    animation: glow 4s ease-in-out infinite alternate;
}
@keyframes glow { from { opacity: .7; } to { opacity: 1; } }

/* Bovenbalk */
.topbar {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: calc(0.4rem + env(safe-area-inset-top, 0px)) 1rem 0.4rem;
    background: rgba(35, 20, 14, 0.7);
    color: #f7e9dc;
}
.brand { display: flex; gap: 0.5rem; align-items: baseline; text-decoration: none; color: inherit; min-width: 0; }
.brand-title { font-family: "Amiri", serif; font-size: 1.25rem; font-weight: 700; white-space: nowrap; }
.brand-sep { opacity: .5; }
.brand-author { opacity: .85; white-space: nowrap; }
.tool {
    font: inherit;
    font-size: 0.95rem;
    color: #f7e9dc;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    padding: 0.25rem 1rem;
    cursor: pointer;
}

/* Tafel */
.desk {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    padding: 0.75rem 0.5rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    overflow: clip;
}

.candle {
    position: fixed;
    left: 1.2vw;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    width: 110px;
    pointer-events: none;
    filter: drop-shadow(0 18px 16px rgba(0, 0, 0, 0.45));
    z-index: 1;
}
.candle svg { width: 100%; height: auto; display: block; overflow: visible; }
.candle .flame { transform-origin: 80px 100px; animation: flicker 2.2s ease-in-out infinite; }
.candle .halo { animation: glow 3s ease-in-out infinite alternate; }
@keyframes flicker {
    0%, 100% { transform: scale(1, 1) rotate(0deg); }
    25% { transform: scale(0.96, 1.05) rotate(-2deg); }
    50% { transform: scale(1.03, 0.95) rotate(1.5deg); }
    75% { transform: scale(0.98, 1.03) rotate(-1deg); }
}

/* ---------- Het boek ---------- */
.book {
    position: relative;
    z-index: 2;
    width: calc(var(--pw) * 2);
    height: var(--ph);
    perspective: 2600px;
    transition: transform var(--flip) ease-in-out;
}
.book.is-single { width: var(--pw); }
.book.is-closed-front { transform: translateX(calc(var(--pw) / 2)); }
.book.is-closed-back { transform: translateX(calc(var(--pw) / -2)); }
.book.is-single.is-closed-front, .book.is-single.is-closed-back { transform: none; }

/* Leren kaft achter de bladzijden */
.leather {
    position: absolute;
    inset: -10px -12px -12px -12px;
    border-radius: 14px;
    background: linear-gradient(90deg, #4b2029, var(--leather) 48%, #3e1a22 50%, var(--leather) 52%, #6b3342);
    box-shadow: 0 30px 60px -10px rgba(0, 0, 0, 0.65), 0 8px 18px rgba(0, 0, 0, 0.35);
    transition: left var(--flip) ease-in-out, right var(--flip) ease-in-out;
}
.book.is-closed-front .leather { right: calc(var(--pw) - 2px); }
.book.is-closed-back .leather { left: calc(var(--pw) - 2px); }
.book.is-single .leather { inset: -8px -16px -10px -8px; background: linear-gradient(90deg, #4b2029, var(--leather) 60%, #3e1a22); }

.slot {
    position: absolute;
    top: 0;
    width: var(--pw);
    height: var(--ph);
}
.slot-right { right: 0; }
.slot-left { left: 0; }
.book.is-single .slot-right { display: none; }

/* Dikte van de papierstapel */
.slot-left.has-face { box-shadow: -2px 2px 0 #eadfd3, -4px 3px 0 #f4ebe1, -6px 4px 0 #e2d4c6; border-radius: 10px 2px 2px 10px; }
.slot-right.has-face { box-shadow: 2px 2px 0 #eadfd3, 4px 3px 0 #f4ebe1, 6px 4px 0 #e2d4c6; border-radius: 2px 10px 10px 2px; }
.book.is-single .slot-left { box-shadow: -2px 2px 0 #eadfd3, -4px 3px 0 #f4ebe1, -6px 4px 0 #e2d4c6; }

.measure { position: absolute; top: 0; left: 0; width: var(--pw); height: var(--ph); visibility: hidden; pointer-events: none; }
.stash { display: none; }
.no-js .stash { display: block; }

/* ---------- Een bladzijde ---------- */
.face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--paper) url("../images/pagina-bloemen.svg") center / 100% 100% no-repeat;
    overflow: hidden;
}
.slot-left .face, .flipper.on-left .face { border-radius: 10px 2px 2px 10px; }
.slot-right .face, .flipper.on-right .face { border-radius: 2px 10px 10px 2px; }
/* Schaduw van de rug in het midden */
.face::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 36px;
    pointer-events: none;
    z-index: 1;
}
.slot-left .face::before, .flipper.on-left .face-front::before { right: 0; background: linear-gradient(270deg, rgba(90, 50, 30, 0.28), transparent); }
.slot-right .face::before, .flipper.on-right .face-front::before { left: 0; background: linear-gradient(90deg, rgba(90, 50, 30, 0.28), transparent); }
.book.is-single .slot-left .face::before { right: 0; left: auto; background: linear-gradient(270deg, rgba(90, 50, 30, 0.3), transparent); }

.face-inner {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 1.1em 1.5em 0.3em;
    font-size: calc(16px * var(--fit, 1));
    line-height: 1.85;
}
.face.is-overflow .face-inner { overflow-y: auto; }

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5em;
    padding-bottom: 0.35em;
    margin-bottom: 0.8em;
    border-bottom: 1px solid var(--line);
    font-size: 0.66em;
    color: var(--ink-soft);
    white-space: nowrap;
    overflow: hidden;
}

.face-foot {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 2.6rem 0.55rem;
    font-size: 13px;
    color: var(--ink-soft);
}
.face-foot > :last-child { justify-self: end; }
.page-number { font-family: "Amiri", serif; font-size: 1.05rem; }

.kind { margin: 0; color: var(--sage); font-size: 0.8em; }
.page-title { font-family: "Amiri", serif; font-size: 1.7em; line-height: 1.4; margin: 0 0 0.45em; }
.page-body p { margin: 0 0 0.15em; }
.page-body.is-poem { text-align: center; font-family: "Amiri", serif; font-size: 1.1em; line-height: 1.9; }
.page-body.is-poem p { white-space: nowrap; }
.page-body.is-poem p:nth-child(even) { margin-bottom: 0.55em; }

.meaning {
    margin-top: 0.9em;
    padding: 0.5em 0.8em;
    border-right: 3px solid var(--sage);
    background: rgba(91, 123, 95, 0.08);
    border-radius: 8px 0 0 8px;
    font-size: 0.88em;
}
.meaning h2 { margin: 0; font-size: 0.9em; color: var(--sage); font-weight: 600; }
.meaning p { margin: 0; color: var(--ink-soft); line-height: 1.85; }

.verse { margin: 0.9em 0 0; text-align: center; }
.verse blockquote { margin: 0; font-family: "Amiri", serif; font-size: 1.25em; line-height: 2; color: var(--rose); }
.verse figcaption { font-size: 0.72em; color: var(--ink-soft); }

.dua {
    margin: 0.8em 0 0;
    text-align: center;
    font-size: 0.9em;
    color: var(--ink);
    background: rgba(163, 72, 95, 0.07);
    border-radius: 999px;
    padding: 0.3em 1em;
}
.dua span:first-child { color: var(--rose); font-weight: 600; }

.quote {
    margin: 0.8em 0 0;
    padding-top: 0.6em;
    border-top: 1px dashed var(--line);
    text-align: center;
    font-family: "Amiri", serif;
    font-weight: 700;
    font-size: 1.02em;
}
.the-end { text-align: center; font-family: "Amiri", serif; color: var(--rose); margin: 0.8em 0 0; }

.ornament { color: var(--rose); font-size: 1.5em; display: block; text-align: center; }

/* Titelpagina */
.title-page { min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 0.3em; }
.title-page-title { font-family: "Amiri", serif; font-size: 3em; line-height: 1.3; margin: 0.3em 0 0; }
.title-page-tag { color: var(--ink-soft); margin: 0 0 1.5em; max-width: 20em; }
.title-page-by { margin: 0; color: var(--sage); font-size: 0.9em; }
.title-page-author { margin: 0 0 0.6em; font-family: "Amiri", serif; font-size: 1.9em; font-weight: 700; color: var(--rose); }

/* Hoofdstukopening */
.chapter-open { min-height: 88%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.chapter-kicker { color: var(--sage); margin: 0; font-size: 1.05em; }
.chapter-title { font-family: "Amiri", serif; font-size: 2.8em; margin: 0.1em 0; line-height: 1.4; }
.chapter-sub { color: var(--ink-soft); font-size: 1.05em; margin: 0 0 0.6em; }

/* Binnenkant van de kaft */
.face--endpaper-front, .face--endpaper-back { background-color: #fbeef0; }
.endpaper { min-height: 100%; display: flex; align-items: center; justify-content: center; }
.basmala { font-family: "Amiri", serif; font-size: 1.8em; color: var(--rose); margin: 0; }

/* Voor- en achterkant */
.face--cover, .face--back {
    background: radial-gradient(circle at 50% 35%, #7a3446, var(--leather) 60%, #3e1a22);
    color: #f7e6d6;
}
.face--cover::before, .face--back::before { display: none; }
.cover { min-height: 100%; padding: 0.4em; display: flex; }
.cover-frame {
    flex: 1;
    border: 2px solid var(--gold);
    outline: 1px solid rgba(227, 194, 122, 0.45);
    outline-offset: -8px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1em;
}
.cover-verse { font-family: "Amiri", serif; color: var(--gold); font-size: 1.15em; margin: 0 0 1em; }
.cover-title { font-family: "Amiri", serif; font-weight: 700; font-size: 3.1em; line-height: 1.35; margin: 0; color: #fff4e6; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); }
.cover-ornament { color: var(--gold); font-size: 1.6em; margin: 0.4em 0; }
.cover-author { font-family: "Amiri", serif; font-size: 1.6em; color: var(--gold); margin: 0 0 1.4em; }
.cover-actions { display: flex; gap: 0.5em; flex-wrap: wrap; justify-content: center; }

.back-kicker { color: var(--gold); font-family: "Amiri", serif; font-size: 1.2em; margin: 0 0 0.6em; }
.back-body p { margin: 0 0 0.1em; line-height: 1.8; }
.cover--back .cover-frame { justify-content: space-evenly; }
.back-poem { font-family: "Amiri", serif; color: var(--gold); font-size: 1.12em; margin: 0.8em 0 0.2em; }
.back-poem p { margin: 0; white-space: nowrap; }
.back-verse { font-family: "Amiri", serif; font-size: 1.1em; margin: 0.6em 0 0; }
.back-verse small { display: block; font-size: 0.65em; opacity: .8; }
.back-sign { margin: 1em 0 0; font-size: 0.8em; opacity: .8; }

/* ---------- Omslaan ---------- */
.flipper {
    position: absolute;
    top: 0;
    width: var(--pw);
    height: var(--ph);
    z-index: 10;
    transform-style: preserve-3d;
}
.flipper.on-left { left: 0; transform-origin: right center; animation: flipToRight var(--flip) cubic-bezier(.45, .05, .35, 1) forwards; }
.flipper.on-right { right: 0; transform-origin: left center; animation: flipToLeft var(--flip) cubic-bezier(.45, .05, .35, 1) forwards; }
.flipper.single-out { left: 0; transform-origin: right center; animation: flipToRight var(--flip) cubic-bezier(.45, .05, .35, 1) forwards; }
.flipper.single-in { left: 0; transform-origin: right center; animation: flipBackIn var(--flip) cubic-bezier(.45, .05, .35, 1) forwards; }
.flip-front, .flip-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.flip-back { transform: rotateY(180deg); }
.flip-front > .face, .flip-back > .face { position: absolute; inset: 0; }
.flip-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgba(60, 30, 20, 0.3), rgba(60, 30, 20, 0)); opacity: 0; animation: shade var(--flip) ease-in-out; z-index: 3; }
.paper-back { position: absolute; inset: 0; background: #f6ede4; border-radius: 2px 10px 10px 2px; }
@keyframes flipToRight { from { transform: rotateY(0deg); } to { transform: rotateY(180deg); } }
@keyframes flipToLeft { from { transform: rotateY(0deg); } to { transform: rotateY(-180deg); } }
@keyframes flipBackIn { from { transform: rotateY(180deg); } to { transform: rotateY(0deg); } }
@keyframes shade { 50% { opacity: 1; } }

.book.is-jumping .slot { animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0.2; } to { opacity: 1; } }

/* Omgekrulde hoekjes */
.corner {
    position: absolute;
    bottom: 0;
    width: 30px;
    height: 30px;
    border: 0;
    padding: 0;
    cursor: pointer;
    z-index: 5;
}
.corner-next { left: 0; background: linear-gradient(45deg, transparent 50%, #efe1d6 50%, #fbf1ea 72%, #e3cfc1); border-radius: 0 10px 0 0; box-shadow: 2px -2px 5px rgba(80, 40, 20, 0.16); }
.corner-prev { right: 0; background: linear-gradient(-45deg, transparent 50%, #efe1d6 50%, #fbf1ea 72%, #e3cfc1); border-radius: 10px 0 0 0; box-shadow: -2px -2px 5px rgba(80, 40, 20, 0.16); }
.slot:not(.has-face) .corner, .slot.no-corner .corner { display: none; }

/* Knoppen */
.btn {
    display: inline-block;
    font: inherit;
    font-size: 0.95rem;
    text-decoration: none;
    padding: 0.4rem 1.2rem;
    border-radius: 999px;
    border: 1px solid var(--rose);
    cursor: pointer;
    line-height: 1.6;
    white-space: nowrap;
}
.btn--primary { background: var(--rose); color: #fff; }
.btn--quiet { background: rgba(255, 250, 246, 0.94); color: var(--rose); }
.btn--gold { background: var(--gold); border-color: var(--gold); color: #3e1a22; font-size: 0.8em; }
.btn--ghost { background: transparent; border-color: var(--gold); color: var(--gold); font-size: 0.8em; }
.link-btn { font: inherit; font-size: 12.5px; border: 0; background: none; color: var(--rose); cursor: pointer; padding: 0.1rem 0; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }

/* Navigatie onder het boek */
.pager {
    width: min(100%, 620px);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.8rem;
    position: relative;
    z-index: 3;
}
.pager .is-disabled { opacity: .4; pointer-events: none; }
.progress { text-align: center; font-size: 0.85rem; color: #f5e3d3; }
.progress-track { height: 4px; background: rgba(255, 255, 255, 0.18); border-radius: 4px; overflow: hidden; margin-top: 0.25rem; }
.progress-fill { height: 100%; width: 0; background: #e8b04c; transition: width .4s; }

/* Fihris */
.toc {
    width: min(92vw, 30rem);
    max-height: 85vh;
    border: 0;
    border-radius: 16px;
    padding: 1.1rem 1.4rem;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.toc::backdrop { background: rgba(20, 10, 6, 0.55); }
.toc-head { display: flex; justify-content: space-between; align-items: center; }
.toc h2 { font-family: "Amiri", serif; font-size: 1.7rem; margin: 0; }
.toc ol { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.toc li { border-bottom: 1px solid var(--line); }
.toc li button { width: 100%; display: flex; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; font: inherit; text-align: right; background: none; border: 0; color: var(--ink); cursor: pointer; }
.toc strong { display: block; font-weight: 600; }
.toc em { display: block; font-style: normal; color: var(--ink-soft); font-size: 0.88rem; }

.toast {
    position: fixed;
    bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    background: #2a1c16;
    color: #fff;
    padding: 0.5rem 1.2rem;
    border-radius: 999px;
}

/* Telefoon en tablet staand: één bladzijde */
@media (max-width: 899px), (orientation: portrait) {
    .candle { width: 38px; left: 6px; bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px)); }
    .candle-glow { background: radial-gradient(circle at 4% 96%, rgba(255, 182, 92, 0.3), transparent 30%); }
    .pager { padding-left: 38px; gap: 0.5rem; }
    .pager .btn { padding: 0.3rem 0.9rem; }
    .desk { gap: 0.6rem; padding-top: 0.6rem; }
}
@media (max-width: 480px) {
    .brand-author, .brand-sep { display: none; }
    .topbar { padding-left: 0.6rem; padding-right: 0.6rem; }
    .face-inner { padding: 0.9em 1.15em 0.2em; }
    .face-foot { padding: 0.15rem 2.3rem 0.45rem; }
}

@media (prefers-reduced-motion: reduce) {
    :root { --flip: 1ms; }
    .candle .flame, .candle .halo, .candle-glow { animation: none; }
}

/* Korte schermen: meer ruimte voor de tekst */
@media (max-height: 720px) and (orientation: portrait) {
    .topbar { padding-top: calc(0.25rem + env(safe-area-inset-top, 0px)); padding-bottom: 0.25rem; }
    .brand-title { font-size: 1.1rem; }
    .desk { gap: 0.45rem; padding-top: 0.45rem; }
    .pager .btn { padding: 0.2rem 0.8rem; font-size: 0.9rem; }
    .face-inner { line-height: 1.75; }
    .quote { display: none; }   /* de zin blijft te kopiëren met «انسخ كحالة» */
}
