@font-face {
  font-family: "Noto Naskh Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("data/fonts/noto-naskh-arabic.woff2") format("woff2");
}

:root {
  /* Sepia paper instead of white. */
  --paper: #f4ead4;
  /* The spread fills the window, keeping the two-page aspect ratio (2 x
     345/550 = 1.2545) plus the side stacks (2 x 0.064) so they are not
     cropped. An open tafsir takes --tafsir-max of the window and the pages
     centre in the rest. */
  --tafsir-max: 1000px;
  --tafsir-gap: 8px;
  --tafsir-side: 0px;
  --spread-h: min(100vh, calc((100vw - var(--tafsir-side)) / 1.3825));
  --spread-w: calc(var(--spread-h) * 345 * 2 / 550);
  /* Stack thickness follows the place in the mushaf: this is a right-to-left
     book, so pages already read sit on the right and pages ahead on the left.
     app.js sets --stack-progress to 0 near page 1 and 1 near the last page. */
  --stack-progress: 0;
  --stack-w-left: calc(
    var(--spread-h) * 0.064 * (1 - var(--stack-progress))
  );
  --stack-w-right: calc(var(--spread-h) * 0.064 * var(--stack-progress));
}

:root.tafsir-open {
  --tafsir-side: min(calc(var(--tafsir-max) + 10px), 100vw);
}

@media (max-width: 700px) {
  :root.tafsir-open {
    --tafsir-side: 0px;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.viewer {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* An open tafsir takes its column and the pages centre in what is left. */
:root.tafsir-open .viewer {
  padding-right: var(--tafsir-side);
}

.spread {
  position: relative;
  display: flex;
  align-items: center;
  /* One shadow around the whole spread: per-page shadows would land on the
     facing page and cut a hard line into the crease. */
  box-shadow: var(--spread-shadow);
}

.spread::before,
.spread::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 0;
  background: repeating-linear-gradient(
    90deg,
    #f7efdd 0 1px,
    #e2d9c2 1px 2px,
    #f2e9d5 2px 3px
  );
  border: 1px solid #cdc2a8;
  border-radius: 0;
  box-shadow: 0 6px 14px rgb(0 0 0 / 24%);
}

.spread::before {
  width: var(--stack-w-left);
  left: calc(-1 * var(--stack-w-left) - 2px);
}

.spread::after {
  width: var(--stack-w-right);
  right: calc(-1 * var(--stack-w-right) - 2px);
}

.page {
  /* White paper margin around the frame. Scales with the page. The frame and
     its content are laid out in absolute units from one shared box. */
  --paper-margin: calc(var(--spread-h) * 0.023);
  --frame-w: calc(var(--spread-h) * 345 / 550 - 2 * var(--paper-margin));
  --frame-h: calc(var(--spread-h) - 2 * var(--paper-margin));
  position: relative;
  z-index: 1;
  height: var(--spread-h);
  aspect-ratio: 345 / 550;
  overflow: hidden;
  background: var(--paper) url("data/frame-color.svg") center / var(--frame-w)
    var(--frame-h) no-repeat;
  box-shadow: var(--page-shadow);
}

/* Soft shadow where the two pages curve into the spine. One overlay centered
   on the fold keeps the shading continuous across both pages, and it lives in
   the white paper margins so it never reaches the text. */
.spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 2;
  width: calc(var(--spread-h) * 0.046);
  transform: translateX(-50%);
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgb(40 28 18 / 0%),
    rgb(40 28 18 / 3%) 20%,
    rgb(40 28 18 / 9%) 35%,
    rgb(40 28 18 / 17%) 44%,
    rgb(40 28 18 / 50%) 50%,
    rgb(40 28 18 / 17%) 56%,
    rgb(40 28 18 / 9%) 65%,
    rgb(40 28 18 / 3%) 80%,
    rgb(40 28 18 / 0%)
  );
}

.page > svg {
  position: absolute;
  left: calc(var(--paper-margin) + var(--frame-w) * 0.0664);
  top: calc(var(--paper-margin) + var(--frame-h) * 0.0504);
  width: calc(var(--frame-w) * 0.8672);
  height: calc(var(--frame-h) * 0.8992);
  z-index: 1;
  display: block;
}



.ornament-cartouche {
  /* Same colour as the paper, so the slot behind the name is invisible. */
  fill: var(--paper);
  stroke: #2f6fa8;
  stroke-width: 0.9;
}

.ornament-cartouche-inner {
  fill: none;
  stroke: #c9a227;
  stroke-width: 0.55;
}

.ornament {
  transition: opacity 140ms ease;
}

.quiz-mode.quiz-hint-labels .ornament-page-number,
.quiz-mode.quiz-hint-labels .ornament-top {
  opacity: 0;
}

.quiz-mode.quiz-show-page-number .ornament-page-number,
.quiz-mode.quiz-show-header .ornament-top {
  opacity: 1;
}



.mushaf-svg {
  overflow: visible;
  fill: #171717;
}

.viewer-aya-highlight {
  display: none;
}

.viewer-aya-highlight.is-selected,
.viewer-aya-highlight.is-quiz-answer,
.viewer-aya-highlight.is-quiz-hint {
  display: block;
}

.viewer-aya-highlight.is-quiz-answer,
.viewer-aya-highlight.is-quiz-hint {
  animation: quiz-fade-in 220ms ease;
}

.viewer-highlight-rect {
  fill: #ffd84d;
}

.viewer-aya-highlight.is-selected .viewer-highlight-rect {
  fill: #eafaf6;
  fill-opacity: 1;
}

.viewer-aya-highlight.is-quiz-answer .viewer-highlight-rect {
  fill: #a9efdc;
}

.viewer-aya-highlight.is-quiz-hint .viewer-highlight-rect {
  fill: #ffe6a3;
}

.viewer-quiz-hint-box {
  fill: #ffe6a3;
}

@keyframes quiz-fade-in {
  from {
    opacity: 0;
  }
}

/* Quiz hints hide the aya text itself instead of painting a mask over it.
   Opacity (not visibility) so hints and the revealed answer fade in. */
[data-surah][data-aya] {
  transition: opacity 220ms ease;
}

.quiz-hint-active [data-surah][data-aya] {
  opacity: 0;
}

.quiz-hint-active [data-surah][data-aya].is-quiz-visible {
  opacity: 1;
}

/* The answer stage hides the ayas that follow the answer, so a second question
   on the same page is not spoiled. */
.is-quiz-later {
  opacity: 0;
}

/* Instant quiz: the words after the hovered one stay hidden until ↓ reveals
   them again. */
.is-instant-later {
  opacity: 0;
}

/* A page fetched mid-question stays blank until its quiz masks are drawn. */
.quiz-page-loading .page > svg {
  visibility: hidden;
}

.quiz-mode.quiz-hint-labels .ornament-surah-start,
.quiz-mode.quiz-hint-labels .ornament-hezb {
  opacity: 0;
}

.quiz-mode.quiz-show-header .ornament-surah-start,
.quiz-mode.quiz-show-header .ornament-hezb {
  opacity: 1;
}

.viewer-hit {
  fill: transparent;
  pointer-events: all;
}

/* The aya number opens its tafsir in every mode. In quiz mode only a number
   the hints have revealed is a target. */
.viewer-aya-hit {
  fill: transparent;
  pointer-events: all;
  cursor: pointer;
}

.quiz-hint-active .viewer-aya-hit {
  pointer-events: none;
}

.quiz-hint-active .viewer-aya-hit.is-quiz-visible {
  pointer-events: all;
}

/* Tafsir choices for the aya number that was clicked. */
.tafsir-menu {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
  padding: 4px;
  border: 1px solid #d9c9a4;
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 8px 20px rgb(0 0 0 / 30%);
  font-size: 0.95rem;
}

.tafsir-menu.is-visible {
  display: flex;
}

.tafsir-option {
  padding: 5px 10px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: #2b2118;
  font: inherit;
  text-align: right;
  white-space: nowrap;
  cursor: pointer;
}

.tafsir-option:hover,
.tafsir-option:focus-visible {
  background: rgb(43 33 24 / 10%);
}

/* The aya's tafsir text, read beside the page. */
.tafsir-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 30;
  display: none;
  flex-direction: column;
  width: min(var(--tafsir-max), calc(100vw - 20px));
  border: 1px solid #d9c9a4;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 30px rgb(0 0 0 / 35%);
  color: #2b2118;
}

.tafsir-panel.is-open {
  display: flex;
}

/* Take whatever the pages leave, up to a readable column. */
:root.tafsir-open .tafsir-panel {
  left: auto;
}

@media (max-width: 700px) {
  /* The tafsir overlays the pages on a narrow window. */
  :root.tafsir-open .viewer {
    justify-content: center;
    padding-left: 0;
  }

  :root.tafsir-open .tafsir-panel {
    left: auto;
  }
}

.tafsir-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgb(43 33 24 / 12%);
}

.tafsir-title {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.tafsir-close {
  border: 0;
  background: none;
  color: #6b5c48;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

/* Previous/next aya buttons beside the tafsir title. */
.tafsir-nav {
  flex: none;
  padding: 0 4px;
  border: 0;
  background: none;
  color: #6b5c48;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.tafsir-nav:hover {
  color: #2b2118;
}

.tafsir-close:hover {
  color: #2b2118;
}

.tafsir-link {
  /* Keeps the aya buttons next to the title and the × at the far edge. */
  margin-inline-start: auto;
  display: flex;
  padding: 2px;
  border-radius: 4px;
  color: #6b5c48;
}

.tafsir-link:hover {
  background: rgb(43 33 24 / 10%);
  color: #2b2118;
}

.tafsir-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px 16px;
  /* Kitab is tafsir.app's face; the bundled Noto Naskh Arabic is the closest
     free one when it is not installed. */
  font-family: Kitab, "Noto Naskh Arabic", "Noto Naskh", serif;
  font-size: 1.55rem;
  line-height: 1.4;
}

.tafsir-body p {
  margin: 0 0 0.85em;
}

/* Quranic quotes, page markers and cross-references, as tafsir.app colours
   them. */
.tafsir-ayah {
  color: #1e6b45;
}

.tafsir-page,
.tafsir-ref {
  color: #8a6a3d;
  font-size: 0.88em;
}

.word-hover-mode .viewer-hit {
  pointer-events: none;
}

.viewer-word-hover {
  fill: #ffe9a8;
}

.viewer-word-mark {
  display: none;
  fill: #f4a09a;
}

.viewer-word-mark.is-marked {
  display: block;
  fill-opacity: 1;
}

.word-hover-mode .mushaf-svg {
  user-select: none;
}

.viewer-word-line-box {
  fill: none;
  stroke: #7ba7f0;
  stroke-width: 0.7;
  stroke-opacity: 1;
}

.viewer-word-line-path {
  fill: none;
  stroke: #7ba7f0;
  stroke-width: 1.2;
  stroke-opacity: 1;
  stroke-linecap: round;
}

.viewer-word-line-delete {
  display: none;
  pointer-events: all;
  cursor: pointer;
}

.viewer-word-line-delete.is-visible {
  display: inline;
}

.viewer-word-line-delete-hit {
  fill: transparent;
}

.viewer-word-line-delete-ring {
  fill: #fffdf8;
  stroke: #7ba7f0;
  stroke-width: 1;
}

.viewer-word-line-delete-mark {
  fill: none;
  stroke: #7ba7f0;
  stroke-width: 1.1;
  stroke-linecap: round;
}

.viewer-word-hit {
  fill: transparent;
  pointer-events: none;
}

.word-hover-mode .viewer-word-hit {
  pointer-events: all;
  cursor: pointer;
}

.quiz-mode .viewer-word-hit {
  pointer-events: all;
  cursor: pointer;
}

.collection-mode .viewer-hit {
  cursor: pointer;
}

.corner-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--control-fg);
  cursor: pointer;
}

.corner-button:hover {
  background: var(--surface-hover);
  color: var(--fg-strong);
}

.corner-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.corner-button svg {
  display: block;
  width: 19px;
  height: 19px;
}

/* Controls float over the mushaf in the top-right corner. */
.hud {
  position: fixed;
  z-index: 5;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(560px, calc(100vw - 24px));
  /* Only the controls take clicks; the rest of the mushaf stays usable. */
  pointer-events: none;
}

.hud__nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.hud__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bar-bg) 86%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 22px rgb(0 0 0 / 28%);
  pointer-events: auto;
}

.hud__bar p {
  margin: 0;
}

.hud__bar p:empty {
  display: none;
}

.collection-status {
  min-height: 1.4em;
  margin: 0;
  color: var(--good-text);
  font-size: 0.85rem;
  line-height: 1.45;
}

.quiz-status {
  min-height: 1.4em;
  margin: 0;
  color: var(--hint);
  font-size: 0.85rem;
  line-height: 1.45;
}

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quiz-left {
  display: inline-flex;
  align-items: center;
  padding: 4px 2px;
  color: var(--muted-dim);
  font-size: 0.85rem;
  white-space: nowrap;
}

.quiz-left[hidden] {
  display: none;
}

.quiz-action {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--control-fg);
  font: inherit;
  cursor: pointer;
}

.quiz-action[hidden] {
  display: none;
}

.quiz-action:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.quiz-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.quiz-action:disabled {
  opacity: 0.4;
  cursor: default;
}

.quiz-action--start {
  border-color: color-mix(in srgb, var(--good) 35%, transparent);
}

.quiz-action--start:hover {
  border-color: color-mix(in srgb, var(--good) 70%, transparent);
}

.quiz-action--good {
  border-color: color-mix(in srgb, var(--good) 45%, transparent);
  color: var(--good);
}

.quiz-action--good:hover {
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 14%, transparent);
}

.quiz-action--bad {
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
  color: var(--bad);
}

.quiz-action--bad:hover {
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 14%, transparent);
}

.quiz-action--show {
  border-color: color-mix(in srgb, var(--info) 45%, transparent);
  color: var(--info);
}

.quiz-action--show:hover {
  border-color: var(--info);
  background: color-mix(in srgb, var(--info) 14%, transparent);
}

.quiz-action--hint {
  border-color: color-mix(in srgb, var(--hint) 45%, transparent);
  color: var(--hint);
}

.quiz-action--hint:hover {
  border-color: var(--hint);
  background: color-mix(in srgb, var(--hint) 14%, transparent);
}

.quiz-action--undo {
  padding: 4px 10px;
  border-color: var(--border);
  color: var(--muted-dim);
  font-size: 0.8rem;
}

.quiz-action--undo:hover {
  border-color: var(--muted);
  color: var(--control-fg);
}

.status {
  min-height: 1.4em;
  margin: 0;
  color: var(--accent-soft);
  font-size: 0.88rem;
}

@media (max-width: 900px) {
  .hud {
    top: 8px;
    right: 8px;
    max-width: calc(100vw - 16px);
  }
}

/* The surah index opens over the mushaf instead of navigating away, so the
   reader keeps its page. */
.index-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 3vh 3vw;
  background: rgb(0 0 0 / 55%);
}

.index-modal[hidden] {
  display: none;
}

.index-modal__page {
  width: min(1900px, 94vw);
  max-height: 92vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: var(--spread-shadow);
}

.index-modal__close {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--control-fg);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.index-modal__close:hover {
  background: var(--surface-hover);
  color: var(--fg-strong);
}
