.reader-shell {
  --reader-gutter: clamp(1rem, 4vw, 2.75rem);
  width: min(100%, 60rem);
  margin-inline: auto;
  padding: 1.25rem var(--reader-gutter) max(1.5rem, env(safe-area-inset-bottom));
}
.reader-shell h1 {
  margin: .3rem 0 1.35rem;
  font-size: clamp(2.45rem, 7vw, 3.8rem);
}
.location {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: .7rem 1rem;
  padding: 1rem 1.1rem;
  background: #eef1e8;
  border: 1px solid #d7dfd2;
  border-radius: 1rem;
}
.field, #jump { display: block; min-width: 0; flex: 1 1 7rem; }
#surah-field { flex-grow: 1.5; }
.field > span {
  display: block;
  color: var(--quiet);
  font-size: .78rem;
  font-weight: 650;
  margin: 0 0 .25rem .1rem;
}
.location select, .page-entry input, .page-entry button {
  min-width: 0;
  min-height: 44px;
  border: 1px solid #b8c6b7;
  border-radius: .55rem;
  color: var(--ink);
  background: #fffef9;
  font: inherit;
  font-size: 1rem;
}
.location select { width: 100%; padding-inline: .55rem .25rem; }
.page-entry { display: flex; gap: .3rem; }
.page-entry input { width: 100%; text-align: center; padding: .3rem; }
.page-entry button { padding: .35rem .75rem; color: white; background: var(--green); border-color: var(--green); cursor: pointer; }
#saved-location {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .3rem .5rem;
  padding: .55rem .15rem 0;
  color: var(--quiet);
  font-size: .87rem;
}
#resume { min-height: 44px; border: 0; background: transparent; color: var(--green); text-decoration: underline; text-underline-offset: .2rem; font-weight: 650; cursor: pointer; }
.page-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .25rem .5rem;
  margin: 1.4rem 0 .18rem;
}
.page-top h2 { font: 650 clamp(1.05rem, 3.5vw, 1.3rem)/1.4 system-ui, sans-serif; color: var(--green); letter-spacing: -.025em; }
.page-top h2:focus:not(:focus-visible) { outline: none; }
.save-place, .display-controls button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  gap: .45rem;
  color: var(--green);
  font: 600 .91rem/1.3 system-ui, sans-serif;
  cursor: pointer;
}
.save-place { padding: .5rem .8rem; background: #fdfdf9; border: 1px solid #c1cfc0; border-radius: .65rem; }
.save-place[data-saved="true"] { background: #eaf1e8; }
.bookmark-icon {
  display: inline-block;
  flex: none;
  width: .75rem;
  height: 1rem;
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%, 0 0, 16% 13%, 16% 78%, 50% 59%, 84% 78%, 84% 13%, 16% 13%);
}
[data-saved="true"] .bookmark-icon, #saved-location .bookmark-icon { clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%); }
.display-controls { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; margin: .15rem 0 .3rem; }
.display-controls button { background: transparent; border: 0; min-width: 44px; font-size: .83rem; padding: .3rem .5rem; }
.display-controls button:first-child { padding-left: .1rem; }
.display-controls button[aria-pressed="true"] { text-decoration: underline; text-underline-offset: .18em; }
.zoom-icon { box-sizing: border-box; width: .83rem; height: .83rem; border: 1.5px solid currentColor; border-radius: 50%; position: relative; margin-right: .15rem; }
.zoom-icon::after { content: ''; position: absolute; height: .38rem; width: 1.5px; background: currentColor; transform: rotate(-42deg); top: 80%; left: 96%; }
.focus-icon {
  width: .95rem; height: .95rem;
  background: linear-gradient(currentColor,currentColor) left top, linear-gradient(currentColor,currentColor) left top, linear-gradient(currentColor,currentColor) right bottom, linear-gradient(currentColor,currentColor) right bottom;
  background-size: 1.5px .42rem, .42rem 1.5px, 1.5px .42rem, .42rem 1.5px;
  background-repeat: no-repeat;
}
.sheet-view { width: 100%; overflow-x: auto; overscroll-behavior-x: contain; background: white; box-shadow: 0 0 0 1px #d6d1c5, 0 .55rem 1.5rem #2635260c; }
#sheet { width: 100%; }
#sheet canvas { width: 100%; height: auto; display: block; }
.sheet-view:not(.enlarged) { touch-action: pan-y pinch-zoom; }
.sheet-view.enlarged #sheet { width: 165%; }
.paging { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: center; gap: .5rem; margin-top: 1rem; }
.paging button { gap: .3rem; }
#next { background: var(--green); color: white; border-color: var(--green); }
#position, .page-bottom p { color: var(--quiet); font-size: .83rem; }
.page-bottom { margin-top: 1rem; display: flex; flex-wrap: wrap; gap: .35rem .75rem; align-items: center; }
.reader-feedback:empty { margin: 0; }
.reader-feedback, #load-status, #image-status { color: var(--green); margin: .65rem 0; }
.reader-source { display: flex; align-items: baseline; gap: .4em; color: var(--quiet); font-size: .75rem; padding-top: 1rem; margin-top: 1.35rem; border-top: 1px solid var(--line); }
.source-dot { color: var(--gold); }
.reader-source a { color: inherit; padding-block: .5rem; text-decoration-color: #b8c3b8; }
.focus-view .sitebar, .focus-view .reader-intro, .focus-view #location, .focus-view #book-info { display: none; }
.focus-view .reader-shell { padding-top: max(.5rem, env(safe-area-inset-top)); }
.focus-view .page-top { margin-top: 0; }
@media (max-width: 540px) {
  .reader-shell { padding-top: .4rem; }
  .location { gap: .5rem .65rem; padding: .75rem; }
  .location { display: grid; grid-template-columns: 1fr 1fr; }
  .location:has(#surah-field:not([hidden])) { grid-template-columns: minmax(4.5rem,.75fr) minmax(0,1.16fr) minmax(5.1rem,1fr); }
  .page-entry button { padding-inline: .6rem; }
  .page-top { margin-top: 1rem; }
}
@media (max-width: 360px) {
  .reader-shell { --reader-gutter: .75rem; }
  .paging { gap: .3rem; }
  .paging button { padding-inline: .35rem; }
}
@media screen and (max-width: 800px) {
  .sheet-view {
    width: auto;
    margin-left: calc(max(2px, env(safe-area-inset-left)) - var(--reader-gutter));
    margin-right: calc(max(2px, env(safe-area-inset-right)) - var(--reader-gutter));
  }
}
@media print {
  .reader-shell { padding: 0; }
  .reader-intro, .location, .display-controls, #book-info, .page-top, .paging, .page-bottom, .reader-feedback { display: none; }
  .sheet-view { width: 100%; margin: 0; overflow: visible; box-shadow: none; }
  .sheet-view.enlarged #sheet { width: 100%; }
}

/* Turn the outgoing page toward the binding of a right-to-left mushaf. */
.sheet-view { position: relative; }
.page-turn-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  --hinge: right;
  --tilt: 86deg;
  --shade: to right;
}
.page-turn-layer[data-direction="backward"] {
  --hinge: left;
  --tilt: -86deg;
  --shade: to left;
}
.page-turn-leaf {
  position: relative;
  transform-origin: var(--hinge) center;
  backface-visibility: hidden;
  animation: mushaf-page-turn 390ms cubic-bezier(.45,.05,.50,1) both;
  box-shadow: 0 0 .65rem #45371e42;
}
.page-turn-leaf canvas { display: block; width: 100%; height: auto; }
.page-turn-leaf::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(var(--shade), transparent 12%, #f9e2a50c 48%, #60491c26 93%, transparent);
}
@keyframes mushaf-page-turn {
  from { transform: perspective(200vmax) rotateY(0deg); opacity: 1; }
  82% { opacity: 1; }
  to { transform: perspective(200vmax) rotateY(var(--tilt)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .page-turn-leaf { animation-duration: 1ms; }
}
@media print {
  .page-turn-layer { display: none; }
}
