@font-face {
  font-family: Hafs;
  src: url('hafs.woff2') format('woff2');
  font-display: block;
}

:root {
  color-scheme: light;
  font: 16px/1.6 'Noto Sans Arabic', Tahoma, Arial, sans-serif;
  color: #192722;
  background: #f1f3ef;
  --ink: #192722;
  --quiet: #50625a;
  --border: #d6dfd6;
  --accent: #215c48;
  --hover-ink: #21664f;
  --hover-bg: #dcefe2;
  --selected-ink: #fffdf6;
  --selected-bg: #25614b;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }

.topbar {
  background: #fafbf7;
  border-block-end: 1px solid var(--border);
}

.topbar-inner {
  margin: auto;
  width: min(1088px, calc(100% - 2rem));
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

h1 { font-size: 1.25rem; font-weight: 730; margin: 0; }
.reader-nav, .surah-nav, form, .page-controls { display: flex; align-items: center; gap: .5rem; }
.reader-nav { gap: 1.4rem; }
form { gap: .65rem; }
label { font-size: .9rem; font-weight: 650; }
.page-total { color: var(--quiet); font-size: .875rem; }
input, select, button { font: inherit; border: 1px solid var(--border); border-radius: 7px; }
input { text-align: center; width: 4rem; height: 2.5rem; color: var(--ink); background: white; }
select { height: 2.5rem; width: 8.5rem; padding-inline: .45rem; background: white; color: var(--ink); }
button { padding: .25rem .85rem; min-height: 2.5rem; color: white; background: var(--accent); cursor: pointer; }
button:hover { background: #174737; }
:focus-visible { outline: 2px solid #427f69; outline-offset: 3px; }

.status { margin: .75rem auto 0; width: min(1088px, calc(100% - 2rem)); color: #903a28; }
.desk {
  width: min(1088px, calc(100% - 2rem));
  margin: clamp(.875rem, 2.2vw, 1.65rem) auto 2rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(285px, 345px);
  align-items: start;
  gap: clamp(1rem, 2.7vw, 1.75rem);
}

.paper {
  position: relative;
  background: #fffef8;
  border: 1px solid #d8ded0;
  box-shadow: 0 5px 18px #22352b0b;
  padding: 0 clamp(.7rem, 3.2vw, 2rem) 1.1rem;
  border-radius: 8px;
  min-width: 0;
}

.page-heading {
  min-height: 2.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  color: var(--quiet);
  border-block-end: 1px solid #e1e4d7;
  margin-block-end: .55rem;
  font-size: .85rem;
}

.mushaf {
  --quran-size: 30px;
  font-family: Hafs, 'Noto Naskh Arabic', serif;
  font-size: var(--quran-size);
  min-height: 330px;
  cursor: default;
  user-select: none;
}

.quran-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .17em;
  height: 1.52em;
  white-space: nowrap;
}

.quran-line.centered { justify-content: center; gap: .32em; }
.quran-token { flex: none; line-height: 1.36; }
.quran-line.surah-title {
  justify-content: center;
  height: 1.35em;
  background: #f2f4e9;
  color: #245443;
  border-block: 1px solid #dbe4d4;
}
.surah-title span { font: 650 .93rem/1.1 'Noto Sans Arabic', Tahoma, sans-serif; }
.surah-title.surah-target { background: var(--hover-bg); border-color: #91b19d; }
.quran-line.basmala { justify-content: center; }
.mushaf.opening { min-height: 0; padding: .55em 0 1em; }
.mushaf.opening .quran-line { height: 1.56em; }

.paper.has-spot, .paper.has-spot .mushaf { cursor: pointer; }
#ink-feedback { pointer-events: none; position: absolute; inset: 0; overflow: hidden; }
.ink-fragment { position: absolute; overflow: hidden; background: var(--hover-bg); color: var(--hover-ink); }
.ink-fragment.selected { background: var(--selected-bg); color: var(--selected-ink); z-index: 1; }
.ink-fragment span { position: absolute; white-space: pre; font-family: Hafs, serif; line-height: 1.36; }
::highlight(tajwid-hover) { color: var(--hover-ink); background: var(--hover-bg); }
::highlight(tajwid-selected) { color: var(--selected-ink); background: var(--selected-bg); }

.answers {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: #fafbf7;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.answer-heading {
  display: flex; align-items: center; justify-content: space-between;
  border-block-end: 1px solid var(--border); background: #fafbf7;
}
.answers h2 {
  font-size: 1rem;
  padding: .9rem 1.15rem .8rem;
  margin: 0;
}
#dismiss { display: none; }
footer { margin: 0 auto 1rem; width: min(1088px, calc(100% - 2rem)); color: var(--quiet); font-size: .75rem; }
footer a { color: inherit; }
#offline-status:not(:empty) { margin-inline-end: .7rem; }
#answer-content { padding: .95rem 1.15rem 1.15rem; }
.instruction { color: var(--quiet); margin: 0; }
.spot-summary { border-block-end: 1px solid var(--border); padding-block-end: .65rem; }
.spot-label { color: var(--quiet); font-size: .85rem; margin: 0; }
.spot-quote { font: 1.7rem/1.65 Hafs, 'Noto Naskh Arabic', serif; margin: 0; color: #1e5844; }
.spot-quote mark { color: #fffdf6; background: #25614b; }
.subject + .subject { border-block-start: 1px solid var(--border); }
.subject { padding: .75rem 0 .6rem; }
.subject:last-child { padding-block-end: 0; }
.subject h3 { color: #215c48; font-size: .94rem; margin: 0 0 .4rem; line-height: 1.7; }
.answer { margin-block: .25rem .45rem; line-height: 1.95; }
.answer-mode { font-weight: 700; }
.evidence { color: var(--quiet); margin: .25rem 0 .45rem; font-size: .875rem; line-height: 1.8; }

@media (max-width: 830px) {
  .desk { grid-template-columns: minmax(0, 1fr); max-width: 670px; }
  .answers { position: static; max-height: none; }
  body.show-answer .answers {
    position: fixed; inset: auto 0 0; max-height: 44vh; max-height: 44dvh;
    z-index: 3; border-radius: 12px 12px 0 0; box-shadow: 0 -3px 16px #193c291c;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.show-answer { padding-bottom: 45vh; }
  body.show-answer .answer-heading { position: sticky; top: 0; }
  body.show-answer #dismiss { display: block; margin-inline-end: .7rem; min-height: 2.2rem; }
  .topbar-inner { width: min(670px, calc(100% - 2rem)); }
}
@media (max-width: 620px) {
  .topbar-inner { display: grid; gap: .3rem; padding-block: .6rem; }
  .reader-nav { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1rem; align-items: end; }
  #page-form, .surah-nav { display: grid; gap: .15rem; }
  .surah-nav select { width: 100%; min-width: 0; }
  .page-total { display: none; }
  h1 { font-size: 1.05rem; }
}
.offline-save {
  background: transparent; color: var(--accent); min-height: 2rem; font-size: inherit;
  border: 0; padding: 0; text-decoration: underline;
}
.offline-save:hover { background: transparent; }
.sources { max-width: 42rem; margin: 3rem auto; padding: 0 1.25rem; }
.sources a { color: var(--accent); }
