@font-face {
  font-family: "Jameel Noori Nastaleeq";
  src:
    url("./fonts/JameelNooriNastaleeq-subset.woff2") format("woff2"),
    url("./fonts/JameelNooriNastaleeq.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #17333a;
  --muted: #5d7478;
  --teal: #07505a;
  --deep: #043943;
  --gold: #e6aa25;
  --cream: #fff8df;
  --paper: #fffdf6;
  --mist: #dff1ee;
  --line: rgba(7, 80, 90, 0.16);
  --shadow: 0 30px 90px rgba(4, 57, 67, 0.16);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgba(230, 170, 37, 0.22), transparent 28rem),
    radial-gradient(circle at 82% 8%, rgba(7, 80, 90, 0.18), transparent 30rem),
    linear-gradient(135deg, #fff8df, #eff8f4 48%, #fffdf6);
  font-family: "Jameel Noori Nastaleeq", serif;
}

button {
  font: inherit;
}

.urdu {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
  font-family: "Jameel Noori Nastaleeq", serif;
}

.ebook-shell {
  display: grid;
  grid-template-rows: 1fr auto;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: clamp(10px, 2vw, 22px);
  gap: 12px;
}

.book-stage {
  min-height: 0;
  display: grid;
  place-items: center;
}

.book-page {
  position: relative;
  display: grid;
  grid-template-columns: minmax(260px, 0.96fr) minmax(320px, 1.04fr);
  gap: clamp(18px, 3vw, 42px);
  width: min(1280px, 100%);
  height: min(760px, 100%);
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: clamp(26px, 4vw, 48px);
  background:
    linear-gradient(90deg, rgba(255,255,255,.2), transparent 48%),
    var(--paper);
  box-shadow: var(--shadow);
  overflow: hidden;
  isolation: isolate;
}

.book-page::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(230, 170, 37, 0.28);
  border-radius: clamp(18px, 3vw, 34px);
  pointer-events: none;
  z-index: 1;
}

.book-page::after {
  content: "";
  position: absolute;
  right: -12%;
  bottom: -28%;
  width: 56%;
  height: 56%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(223,241,238,.82), rgba(223,241,238,0) 65%);
  z-index: -1;
}

.page-art {
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(7,80,90,.10), rgba(230,170,37,.10)),
    var(--page-art, linear-gradient(135deg, #f6d28b, #9fd1c8));
  background-size: cover;
  background-position: center;
  border-radius: 0 42px 42px 0;
  margin: clamp(12px, 2vw, 24px) 0 clamp(12px, 2vw, 24px) clamp(12px, 2vw, 24px);
}

.page-content {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: clamp(28px, 5vw, 70px) clamp(22px, 4vw, 58px);
  scrollbar-width: thin;
  scrollbar-color: rgba(7, 80, 90, 0.34) transparent;
}

.page-content::-webkit-scrollbar {
  width: 8px;
}

.page-content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(7, 80, 90, 0.28);
}

.book-page.is-cover .page-content,
.book-page[data-page-type="chapter-title"] .page-content {
  justify-content: center;
}

.page-logo {
  width: clamp(76px, 9vw, 128px);
  height: auto;
  object-fit: contain;
  align-self: flex-start;
  margin-bottom: clamp(8px, 2vh, 18px);
}

.page-kicker {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: clamp(20px, 2.2vw, 30px);
  line-height: 1.8;
}

.page-title {
  margin: 0;
  color: var(--teal);
  font-size: clamp(38px, 5.6vw, 76px);
  line-height: 1.45;
  font-weight: 400;
}

.page-title[hidden] {
  display: none;
}

.page-text {
  margin-top: clamp(10px, 2vh, 20px);
  color: var(--ink);
  font-size: clamp(21px, 2.45vw, 30px);
  line-height: 1.95;
  overflow: visible;
}

.page-text p {
  margin: 0 0 .6em;
}

.page-text ul {
  margin: 0;
  padding-inline-start: 1.2em;
}

.start-button,
.control-button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  color: var(--deep);
  background: #fff;
  box-shadow: 0 12px 30px rgba(4, 57, 67, 0.12);
}

.start-button {
  display: none;
  align-self: flex-start;
  margin-top: 22px;
  padding: 14px 28px;
  font-size: clamp(22px, 2.3vw, 30px);
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--deep));
}

.book-page.is-cover .start-button {
  display: inline-flex;
}

.reader-controls {
  display: grid;
  grid-template-columns: auto auto auto minmax(120px, 360px) auto auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.control-button {
  min-width: 54px;
  min-height: 50px;
  padding: 8px 18px;
  font-size: 22px;
}

.control-button.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--deep));
}

.control-button:disabled {
  opacity: .38;
  cursor: not-allowed;
}

.page-status {
  display: grid;
  gap: 8px;
  color: var(--deep);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  direction: ltr;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(7, 80, 90, 0.14);
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--teal));
  transition: width .28s ease;
}

.toc-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(4, 57, 67, 0.38);
  backdrop-filter: blur(12px);
}

.toc-overlay.open {
  display: grid;
}

.toc-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(760px, 90vh);
  overflow: auto;
  border-radius: 32px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 28px;
}

.toc-panel img {
  width: 94px;
}

.toc-panel h2 {
  margin: 16px 0;
  color: var(--teal);
  font-size: 42px;
  font-weight: 400;
}

.toc-close {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: var(--teal);
  cursor: pointer;
  font-size: 28px;
}

.toc-list {
  display: grid;
  gap: 10px;
}

.toc-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  padding: 12px 16px;
  color: var(--ink);
  cursor: pointer;
  font-family: "Jameel Noori Nastaleeq", serif;
  font-size: 24px;
  text-align: right;
}

@media (max-width: 900px) {
  .ebook-shell {
    height: 100dvh;
    padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  }

  .book-page {
    grid-template-columns: 1fr;
    grid-template-rows: 34% 1fr;
  }

  .page-art {
    margin: 12px 12px 0;
    border-radius: 32px;
  }

  .page-content {
    justify-content: start;
    padding: 18px 24px 28px;
  }

  .page-logo {
    display: none;
  }

  .reader-controls {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(4, minmax(64px, auto));
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 10px 12px;
    border: 1px solid rgba(7, 80, 90, 0.12);
    border-radius: 28px;
    background: rgba(255, 253, 246, 0.94);
    box-shadow: 0 18px 40px rgba(4, 57, 67, 0.18);
    backdrop-filter: blur(16px);
  }

  .page-status {
    grid-column: 1 / -1;
    grid-row: 1;
    justify-self: center;
    width: min(360px, 100%);
  }

  #fullscreenButton {
    display: none;
  }

  #homeButton {
    grid-column: 1;
    grid-row: 2;
  }

  #prevButton {
    grid-column: 2;
    grid-row: 2;
  }

  #tocButton {
    grid-column: 3;
    grid-row: 2;
  }

  #nextButton {
    grid-column: 4;
    grid-row: 2;
  }
}

@media (max-width: 540px) {
  .ebook-shell {
    padding: 8px 8px calc(112px + env(safe-area-inset-bottom, 0px));
  }

  .book-page {
    border-radius: 24px;
    grid-template-rows: 30% 1fr;
  }

  .book-page::before {
    inset: 10px;
    border-radius: 18px;
  }

  .page-title {
    font-size: clamp(34px, 11vw, 46px);
  }

  .page-text {
    font-size: clamp(22px, 7vw, 26px);
    line-height: 2.05;
  }

  .control-button {
    min-width: 62px;
    min-height: 46px;
    padding: 8px 12px;
    font-size: 18px;
  }

  #homeButton {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 24px;
  }
}
