:root {
  --p: 560px;
  --flip-duur: 950ms;
  --papier: #fbf6ec;
  --inkt: #3b2f27;
  --accent: #c8775a;
  --zacht: #8a7563;
  --achtergrond: #f3e8d6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  color: var(--inkt);
  font-family: "Literata", Georgia, "Times New Roman", serif;
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(255, 255, 255, .75), transparent 60%),
    radial-gradient(900px 600px at 85% 90%, rgba(232, 196, 160, .45), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='%23b79b80' fill-opacity='.11'%3E%3Cg transform='translate(30 40) rotate(-20)'%3E%3Cellipse cx='0' cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-7' cy='-4' r='2.6'/%3E%3Ccircle cx='-2.5' cy='-8' r='2.6'/%3E%3Ccircle cx='2.5' cy='-8' r='2.6'/%3E%3Ccircle cx='7' cy='-4' r='2.6'/%3E%3C/g%3E%3Cg transform='translate(115 115) rotate(25)'%3E%3Cellipse cx='0' cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-7' cy='-4' r='2.6'/%3E%3Ccircle cx='-2.5' cy='-8' r='2.6'/%3E%3Ccircle cx='2.5' cy='-8' r='2.6'/%3E%3Ccircle cx='7' cy='-4' r='2.6'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
    var(--achtergrond);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Kop ---------- */

.kop {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 18px 4px;
}

.kop-titel {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.kop-naam {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(18px, 2.4vw, 26px);
  letter-spacing: .01em;
}

.kop-sub {
  font-style: italic;
  color: var(--zacht);
  font-size: clamp(13px, 1.5vw, 16px);
}

.kop-knoppen { display: flex; gap: 8px; }

/* ---------- Knoppen ---------- */

.knop {
  appearance: none;
  border: 1px solid rgba(59, 47, 39, .14);
  background: rgba(255, 252, 246, .8);
  color: var(--inkt);
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(80, 55, 30, .08), 0 4px 12px rgba(80, 55, 30, .06);
  transition: background .2s, transform .15s, opacity .2s;
}
.knop:hover { background: #fff; }
.knop:active { transform: scale(.96); }
.knop:disabled { opacity: .35; cursor: default; transform: none; }
.knop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.knop.rond {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.knop.rond.groot { width: 46px; height: 46px; }
.knop svg { width: 20px; height: 20px; fill: currentColor; }
.knop.groot svg { width: 24px; height: 24px; }

#knop-geluid .uit { display: none; }
#knop-geluid[aria-pressed="false"] .aan { display: none; }
#knop-geluid[aria-pressed="false"] .uit { display: inline; }

/* ---------- Podium & boek ---------- */

.podium {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.podium.boven { align-items: flex-start; padding-top: 10px; }

.boek-houder {
  position: relative;
  width: calc(var(--p) * 2);
  height: var(--p);
  transition: transform var(--flip-duur) cubic-bezier(.45, .05, .25, 1);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.boek-houder.dicht-voor { transform: translateX(-25%); }
.boek-houder.dicht-achter { transform: translateX(25%); }

.boek {
  position: absolute;
  inset: 0;
  perspective: calc(var(--p) * 3.2);
  perspective-origin: 50% 40%;
  cursor: pointer;
}

.onder-schaduw {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 3px;
  box-shadow:
    0 calc(var(--p) * .03) calc(var(--p) * .07) rgba(70, 45, 20, .28),
    0 2px 6px rgba(70, 45, 20, .18);
  transition: left var(--flip-duur) cubic-bezier(.45, .05, .25, 1), right var(--flip-duur) cubic-bezier(.45, .05, .25, 1);
}
.dicht-voor .onder-schaduw { left: 50%; }
.dicht-achter .onder-schaduw { right: 50%; }

/* Paginaranden: dikte van het boek aan beide kanten */
.stapel {
  position: absolute;
  top: 1.2%;
  bottom: 1.2%;
  width: 0;
  background:
    repeating-linear-gradient(to right, #efe6d6 0 1px, #fffaf1 1px 2px);
  box-shadow: 0 2px 6px rgba(70, 45, 20, .2);
  transition: width var(--flip-duur) ease;
}
.stapel-links { right: 100%; border-radius: 3px 0 0 3px; }
.stapel-rechts { left: 100%; border-radius: 0 3px 3px 0; }

/* ---------- Bladen ---------- */

.blad {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--flip-duur) cubic-bezier(.45, .05, .25, 1);
  will-change: transform;
}

.blad.om { transform: rotateY(-180deg); }

.zijde {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--papier);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.zijde.achter { transform: rotateY(180deg); }

.zijde img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

/* Rugschaduw (vouw in het midden) */
.zijde::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.zijde.voor::after {
  background: linear-gradient(to right,
    rgba(60, 38, 18, .30) 0%,
    rgba(60, 38, 18, .12) 2.5%,
    rgba(255, 255, 255, .06) 5%,
    transparent 10%);
}
.zijde.achter::after {
  background: linear-gradient(to left,
    rgba(60, 38, 18, .30) 0%,
    rgba(60, 38, 18, .12) 2.5%,
    rgba(255, 255, 255, .06) 5%,
    transparent 10%);
}
.zijde.omslag::after {
  background: linear-gradient(to right,
    rgba(40, 25, 10, .25) 0%,
    rgba(255, 255, 255, .22) 1.2%,
    rgba(40, 25, 10, .10) 2.6%,
    transparent 5%);
}
.zijde.omslag.achter::after {
  background: linear-gradient(to left,
    rgba(40, 25, 10, .25) 0%,
    rgba(255, 255, 255, .22) 1.2%,
    rgba(40, 25, 10, .10) 2.6%,
    transparent 5%);
}
/* Licht/schaduw tijdens het omslaan */
.schaduw {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 6;
}
.voor .schaduw { background: linear-gradient(to left, rgba(30, 18, 8, .38), rgba(30, 18, 8, .10) 55%, rgba(255, 255, 255, .08)); }
.achter .schaduw { background: linear-gradient(to right, rgba(30, 18, 8, .38), rgba(30, 18, 8, .10) 55%, rgba(255, 255, 255, .08)); }

.blad.vooruit .voor .schaduw { animation: schaduw-in var(--flip-duur) ease-in forwards; }
.blad.vooruit .achter .schaduw { animation: schaduw-uit var(--flip-duur) ease-out forwards; }
.blad.terug .achter .schaduw { animation: schaduw-in var(--flip-duur) ease-in forwards; }
.blad.terug .voor .schaduw { animation: schaduw-uit var(--flip-duur) ease-out forwards; }

@keyframes schaduw-in {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 1; }
}
@keyframes schaduw-uit {
  0% { opacity: 1; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

.stil.boek-houder,
.stil .blad,
.stil .stapel,
.stil .onder-schaduw { transition: none !important; }

/* ---------- Tekst op de pagina ---------- */

.tekst {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: var(--inkt);
  font-family: "Literata", Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.36;
  text-align: left;
  text-shadow:
    0 0 .25em rgba(255, 251, 243, .95),
    0 0 .6em rgba(255, 251, 243, .7);
  pointer-events: none;
}
.tekst.v-boven { justify-content: flex-start; }
.tekst.v-onder { justify-content: flex-end; }
.tekst.u-midden { text-align: center; }
.tekst.u-rechts { text-align: right; }

.tekst .inhoud { position: relative; width: 100%; }

.tekst p {
  margin: 0 0 .22em;
  text-wrap: pretty;
}
.tekst p:last-child { margin-bottom: 0; }

.tekst.sluier .inhoud::before {
  content: "";
  position: absolute;
  inset: -.55em -.85em;
  z-index: -1;
  border-radius: 1.4em;
  background: rgba(252, 247, 237, .80);
  filter: blur(.45em);
}

.tekst.donker {
  color: #fbf1e1;
  text-shadow: 0 0 .3em rgba(30, 20, 14, .8);
}
.tekst.donker.sluier .inhoud::before { background: rgba(38, 27, 20, .55); }

.tekst .liedje {
  font-style: italic;
  padding-left: .8em;
  border-left: 2px solid rgba(200, 119, 90, .55);
  margin: .3em 0;
}

.titel-groot {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 400;
  font-size: 2.5em;
  line-height: 1.05;
  letter-spacing: .005em;
}
.titel-onder {
  margin: .25em 0 0 !important;
  font-size: 1em;
  font-style: italic;
}
.titel-auteur {
  margin: 0 !important;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05em;
  letter-spacing: .06em;
}
.titel-auteur.klein { margin-top: .9em !important; font-size: .7em; letter-spacing: .1em; }
.einde {
  margin: 0 !important;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.9em;
  font-style: italic;
}

/* Tekst te klein voor dit scherm: tonen onder het boek */
.zijde.tekst-onder .tekst.verhaal { visibility: hidden; }

/* ---------- Leestekst onder het boek ---------- */

.leestekst {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(var(--p) * 2), calc(100% - 24px));
  overflow: auto;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(255, 252, 246, .93);
  box-shadow: 0 6px 24px rgba(70, 45, 20, .15);
  font-size: 16px;
  line-height: 1.5;
  z-index: 50;
  touch-action: pan-y;
}
.leestekst p { margin: 0 0 .35em; }
.leestekst p:last-child { margin-bottom: 0; }
.leestekst .liedje { font-style: italic; padding-left: .8em; border-left: 2px solid rgba(200, 119, 90, .55); }
.leestekst hr { border: 0; border-top: 1px dashed rgba(59, 47, 39, .2); margin: .6em 0; }
.leestekst-greep { display: none; }
.leestekst-inhoud { min-height: 0; }

/* ---------- Bediening ---------- */

.bediening {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 14px max(12px, env(safe-area-inset-bottom));
}

.voortgang {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 170px;
}

.teller {
  font-size: 14px;
  color: var(--zacht);
  font-variant-numeric: tabular-nums;
}

.stippen { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; max-width: 360px; }
.stip {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(59, 47, 39, .18);
  cursor: pointer;
  transition: background .25s, transform .25s;
}
.stip:hover { background: rgba(59, 47, 39, .4); }
.stip.actief { background: var(--accent); transform: scale(1.35); }
/* ---------- Hint & laden ---------- */

.hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(59, 47, 39, .78);
  color: #fff8ee;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s;
  z-index: 60;
}
.hint.zichtbaar { opacity: 1; }

.laden {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--achtergrond);
  z-index: 100;
  transition: opacity .6s;
}
.laden.weg { opacity: 0; pointer-events: none; }
.pootje { font-size: 34px; animation: hup 1s ease-in-out infinite; }
@keyframes hup {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50% { transform: translateY(-10px) rotate(8deg); }
}

.draai-tip {
  display: none;
  position: relative;
  flex: none;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(59, 47, 39, .08);
  font-size: 13px;
  font-style: italic;
  color: var(--zacht);
  text-align: center;
}

/* Enkele pagina (telefoon rechtop) */
.enkele {
  display: none;
  position: relative;
  flex: none;
  width: var(--p);
  height: var(--p);
  border-radius: 3px;
  overflow: hidden;
  background: var(--papier);
  box-shadow:
    0 calc(var(--p) * .03) calc(var(--p) * .07) rgba(70, 45, 20, .28),
    0 2px 6px rgba(70, 45, 20, .18);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.enkele .zijde { position: absolute; inset: 0; }
.enkele .zijde.blad-links::after {
  background: linear-gradient(to left,
    rgba(60, 38, 18, .22) 0%,
    rgba(60, 38, 18, .08) 2.5%,
    transparent 8%);
}
.enkele .zijde.blad-rechts::after,
.enkele .zijde.omslag::after {
  background: linear-gradient(to right,
    rgba(60, 38, 18, .22) 0%,
    rgba(60, 38, 18, .08) 2.5%,
    transparent 8%);
}

@media (prefers-reduced-motion: reduce) {
  :root { --flip-duur: 1ms; }
}

/* ---------- Telefoon, rechtop: één grote pagina ---------- */

body.pagina-modus .boek-houder { display: none; }
body.pagina-modus .enkele { display: block; }
body.pagina-modus .podium {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 4px;
}
body.pagina-modus .podium.boven { justify-content: flex-start; }
body.pagina-modus .leestekst {
  position: relative;
  left: auto;
  transform: none;
  width: min(var(--p), calc(100% - 8px));
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  top: auto;
  bottom: auto;
  font-size: 17px;
  line-height: 1.55;
}
body.pagina-modus .draai-tip { display: block; }
body.pagina-modus .podium.boven .draai-tip { display: none; }
body.pagina-modus .hint {
  bottom: auto;
  top: calc(8px + var(--p) - 52px);
  white-space: normal;
  max-width: 90%;
  text-align: center;
}

/* ---------- Telefoon, liggend: boek vult het scherm ---------- */

body.liggend {
  display: block;
}
body.liggend .kop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  padding: max(4px, env(safe-area-inset-top)) 12px 4px;
  background: linear-gradient(to bottom, rgba(243, 232, 214, .88), rgba(243, 232, 214, 0));
  pointer-events: none;
}
body.liggend .kop-titel { display: none; }
body.liggend .kop-knoppen {
  margin-left: auto;
  pointer-events: auto;
}
body.liggend .podium {
  position: fixed;
  inset: 0;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.liggend .bediening {
  position: fixed;
  left: 0;
  right: 0;
  top: max(6px, env(safe-area-inset-top));
  bottom: auto;
  z-index: 40;
  justify-content: center;
  padding: 0 12px;
  background: none;
  pointer-events: none;
}
body.liggend .bediening .knop,
body.liggend .teller { pointer-events: auto; }
body.liggend #knop-vorige,
body.liggend #knop-volgende {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 45;
  background: rgba(255, 252, 246, .86);
}
body.liggend #knop-vorige { left: max(6px, env(safe-area-inset-left)); }
body.liggend #knop-volgende { right: max(6px, env(safe-area-inset-right)); }
body.liggend .teller {
  background: rgba(59, 47, 39, .62);
  color: #fff8ee;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
body.liggend .stippen,
body.liggend .draai-tip { display: none; }
body.liggend .leestekst {
  position: fixed;
  left: 50%;
  right: auto;
  top: auto;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100% - 24px));
  max-height: min(70dvh, 320px);
  transform: translateX(-50%) translateY(calc(100% - 44px));
  transition: transform .35s cubic-bezier(.45, .05, .25, 1);
  padding: 0 18px max(16px, env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  font-size: 17px;
  line-height: 1.55;
  z-index: 55;
  overflow: hidden;
}
body.liggend .leestekst-inhoud {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding-bottom: 4px;
}
body.liggend .leestekst.open { transform: translateX(-50%) translateY(0); }
body.liggend .leestekst-greep {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 8px 0 10px;
  border: 0;
  background: none;
  color: var(--zacht);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
body.liggend .leestekst-greep-streep {
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(59, 47, 39, .22);
}
body.liggend .hint {
  bottom: 52px;
  white-space: normal;
  max-width: 80%;
  text-align: center;
}

/* Compacte chrome op smalle of lage schermen */
@media (max-width: 720px), (max-height: 560px) {
  .kop-sub { display: none; }
  .knop:not(.rond) { display: none; }
  .stippen { display: none; }
  .voortgang { min-width: 0; }
  .bediening { gap: 16px; }
  .hint { white-space: normal; width: max-content; max-width: 90%; text-align: center; }
}
@media (max-width: 720px) {
  .kop {
    padding: max(6px, env(safe-area-inset-top)) 12px 2px;
  }
  .kop-naam { font-size: 17px; }
  .bediening { padding: 4px 12px max(10px, env(safe-area-inset-bottom)); }
}
