/*
  Madinah Mushaf page — same proportion as the Store app / printed page.

  Page  510.236 × 729.448
  Frame 390.973 × 600.732 at y=64.36  (pages 3–604)
  Opening frame 283.275 × 398.981 at y=165.233 (pages 1–2)

  The page is contained in the viewport (never stretched). Side mint-green
  on a wide window is the app chrome, not extra padding inside the Mushaf.
*/

:root {
  --stage-bg: #eef1ee;
  --paper: #fcfbf7;
  --crimson: #8b2e2e;
  --ink: #141414;
  --frame-gold: #c4a15a;
  --overlay-bg: #f7f5ef;
  --page-w: 510.236;
  --page-h: 729.448;
}

* { box-sizing: border-box; }

html,
body,
#stage {
  height: 100%;
  margin: 0;
  background: var(--stage-bg);
}

body {
  overflow: hidden;
  font-family: "Amiri", "Traditional Arabic", "Scheherazade New", serif;
}

#stage {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#page {
  position: relative;
  aspect-ratio: 510.236 / 729.448;
  width: min(100vw, calc(100vh * 510.236 / 729.448));
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  background: var(--stage-bg);
  overflow: hidden;
  container-type: size;
  container-name: mushaf;
}

/* ---------------------------------------------------------------- header */

.page-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 8.825%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 11.7%;
  direction: ltr;
  color: var(--crimson);
  font-family: "Amiri", "Traditional Arabic", "Scheherazade New", serif;
  z-index: 6;
}

#surahName,
#juzName {
  font-size: 3.15cqh;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1;
}

#bookBtn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--crimson);
  cursor: pointer;
  width: 3.1cqh;
  height: 3.1cqh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#bookBtn svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------------------------------------------------------------- frame */

#frame {
  position: absolute;
  top: 8.825%;
  left: 11.686%;
  width: 76.627%;
  height: 82.352%;
  z-index: 2;
  pointer-events: none;
}

#page[data-opening="1"] #frame {
  top: 22.657%;
  left: 22.244%;
  width: 55.517%;
  height: 54.696%;
}

#frame svg {
  width: 100%;
  height: 100%;
  display: block;
}

#frame svg path {
  fill-rule: evenodd;
}

/* ---------------------------------------------------------------- lines */

#lines {
  position: absolute;
  z-index: 1;
  /* evenodd frame hole on the 510×729 page */
  top: 12.42%;
  bottom: 12.4%;
  left: 16.57%;
  right: 16.6%;
  background: var(--paper);
  direction: rtl;
  display: grid;
  grid-template-rows: repeat(15, minmax(0, 1fr));
  color: var(--ink);
  letter-spacing: 0;
  word-spacing: 0;
  /* fallback only; JS fitPageLines sets the real size from line width */
  font-size: 3.85cqh;
  padding: 0.5% 1.2%;
  overflow: hidden;
}

#page[data-opening="1"] #lines {
  top: 29.2%;
  bottom: 29.4%;
  left: 30.8%;
  right: 30.8%;
  background: var(--paper);
  font-size: 3.55cqh;
  padding: 1.2% 2%;
  border-radius: 50%;
}

.line {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  line-height: 1;
}

.line__text {
  white-space: nowrap;
  line-height: 1;
}

.line--center {
  justify-content: center;
}

.line--surah {
  font-family: "Amiri", "Traditional Arabic", "Scheherazade New", serif;
  font-size: 0.78em;
  font-weight: 700;
  color: #1f4a3a;
}

.line--basmala {
  font-family: QCF2BSML, serif;
  font-size: 1.05em;
}

.w {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- footer */

.page-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8.823%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Amiri", "Traditional Arabic", "Scheherazade New", serif;
  z-index: 6;
}

#pageNum {
  background: none;
  border: none;
  color: var(--crimson);
  font-size: 2.9cqh;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 2px 10px;
}

#pageInput {
  width: 4.5em;
  text-align: center;
  font-size: 2.9cqh;
  font-weight: 700;
  font-family: inherit;
  color: var(--crimson);
  border: 1px solid var(--crimson);
  border-radius: 4px;
  padding: 2px 6px;
  background: var(--paper);
}

#pageInput[hidden] {
  display: none;
}

/* ---------------------------------------------------------------- error */

#error {
  position: absolute;
  top: 12.85%;
  bottom: 12.8%;
  left: 18.5%;
  right: 18.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(252, 251, 247, 0.94);
  color: var(--crimson);
  font-size: 2.2cqh;
  text-align: center;
  z-index: 5;
}

#error[hidden] {
  display: none;
}

#retry {
  font-family: inherit;
  font-size: 0.9em;
  color: var(--paper);
  background: var(--crimson);
  border: none;
  border-radius: 6px;
  padding: 6px 18px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- overlay */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 15, 0.4);
  display: flex;
  direction: ltr;
  justify-content: flex-end;
  z-index: 20;
}

#overlay[hidden] {
  display: none;
}

#overlayPanel {
  width: min(360px, 86vw);
  height: 100%;
  background: var(--overlay-bg);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25);
  overflow-y: auto;
  padding: 14px 10px 30px;
  direction: rtl;
}

#overlayPanel h2 {
  color: var(--crimson);
  font-size: 1rem;
  margin: 18px 8px 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #ddd7c8;
  cursor: pointer;
}

#overlayPanel button[data-page] {
  display: block;
  width: 100%;
  text-align: right;
  background: none;
  border: none;
  padding: 9px 10px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
  border-radius: 6px;
}

#overlayPanel button[data-page]:hover {
  background: #e9e5d8;
}
