/* Quran word-study demo.
   Colour carries exactly two signals, never more:
     - word level  : underline weight/colour  (untouched / hover / opened)
     - sense level : text colour              (neutral / active)
   Tajweed colouring is deliberately absent here (answer 29). */

:root {
  --bg:        #ffffff;
  --bg-raise:  #ffffff;
  --ink:       #000000;
  --ink-soft:  #4a4a4a;
  --ink-faint: #8a8a8a;
  --rule:      #dcdcdc;
  --accent:    #c0392b;   /* the red underline in the sketch */
  --active:    #0090d0;   /* the blue "Praise" in the sketch */
  --shadow:    0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.07);
  --fade:      .28;       /* opacity of branches you are not currently in */
  --ease:      cubic-bezier(.32,.72,0,1);   /* one easing everywhere */
  --dur:       .22s;
  --hairline:  rgba(0,0,0,.08);
}

/* Deliberately one palette: white ground, black ink, whatever the OS prefers.
   Scripture on a page reads as ink on white; a dark theme would be a different
   product decision, not a default. */

* { box-sizing: border-box; }

html, body {
  height: 100%; margin: 0;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, Inter, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

.sr { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }

/* ---------- bars ---------- */

.bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  min-height: 52px;
}
.bar        { border-bottom: 1px solid var(--hairline); }
.bar.bottom { border-bottom: 0; border-top: 1px solid var(--hairline); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.bar-l, .bar-r { display: flex; align-items: center; gap: 8px; }

.ref { font-size: 15px; letter-spacing: .02em; color: var(--ink-soft); }
.progress { font-size: 14px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 0; border-radius: 9px; background: transparent; color: var(--ink-soft);
  cursor: pointer; transition: background .16s, color .16s;
}
.icon-btn:hover { background: var(--bg-raise); color: var(--ink); }
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.icon-btn .spk { fill: currentColor; stroke-width: 1.2; }
.icon-btn .slash { opacity: 0; transition: opacity .16s; }
.icon-btn[aria-pressed="true"] .waves { opacity: 0; }
.icon-btn[aria-pressed="true"] .slash { opacity: 1; }

.text-btn {
  border: 0; background: transparent; color: var(--ink-soft);
  font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: color .16s, background .16s;
}
.text-btn:hover { color: var(--ink); background: rgba(0,0,0,.045); }
.text-btn:active, .icon-btn:active, .next-btn:active, .depth-chip:active, .usage-ref:active { transform: scale(.97); }
button:focus-visible, .depth-chip:focus-visible, input:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--active) 55%, transparent); outline-offset: 2px;
}

.next-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid color-mix(in srgb, var(--active) 28%, var(--rule));
  background: color-mix(in srgb, var(--active) 6%, #fff);
  color: var(--ink);
  font: inherit; font-size: 16px; font-weight: 500;
  padding: 11px 20px; border-radius: 999px; cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.next-btn:hover { transform: translateY(-1px); border-color: var(--ink-faint); }
.next-btn .arrow { font-size: 16px; line-height: 1; }   /* points left: "next" in RTL */

/* ---------- stage ---------- */

.stage { position: relative; flex: 1 1 auto; overflow: hidden; touch-action: none; }

/* ---------- the ayah, pinned ---------- */

.ayah {
  position: relative; z-index: 3;
  padding: 8px 20px 0;
  text-align: right;
  font-family: "Amiri Quran", "Scheherazade New", "Traditional Arabic", serif;
  font-size: clamp(38px, 10vw, 68px);
  line-height: 2.15;
  opacity: 0; transform: translateY(-6px);
  transition: opacity .9s ease, transform .9s ease;
}
.ayah.in { opacity: 1; transform: none; }

.word {
  display: inline-block; position: relative;
  padding: 0 .06em 2px;
  cursor: pointer;
  color: var(--ink);
  border-bottom: 3px solid transparent;
  transition: color .18s, border-color .18s, opacity .3s;
  -webkit-tap-highlight-color: transparent;
}
.word:hover     { color: var(--active); border-bottom-color: color-mix(in srgb, var(--active) 45%, transparent); }
.word.open      { border-bottom-color: var(--accent); }
.word.open.dim  { border-bottom-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.word.dim       { opacity: .5; }

/* empty text slot, so a missing word is obvious rather than invisible */
.word.empty {
  min-width: 2.2em; min-height: 1.1em;
  border: 1px dashed var(--ink-faint); border-radius: 6px;
  opacity: .55; font-size: .42em; line-height: 2.4;
  font-family: Inter, sans-serif; text-align: center; color: var(--ink-faint);
}

/* ---------- the map ---------- */

.viewport { position: absolute; inset: 0; z-index: 2; }
/* width/height must be definite: absolutely-positioned nodes resolve their
   max-width against this box, and a shrink-to-fit .map collapses prose to one word per line */
.map { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform-origin: 0 0; will-change: transform; }

.links { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: visible; }
.links path { fill: none; stroke: var(--active); stroke-width: 1.4; opacity: .7; transition: opacity .3s; }
.links path.dim { opacity: .12; }

.node {
  position: absolute; top: 0; left: 0;
  transform-origin: 50% 0;
  transition: opacity .32s ease;
  animation: pop .28s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(-10px) scale(.94); } }
.node.dim { opacity: var(--fade); }

/* sense - bare text, as in the sketch */
.sense {
  font-size: clamp(25px, 6.5vw, 40px); font-weight: 600; letter-spacing: -.01em;
  color: var(--ink); cursor: pointer; white-space: nowrap;
  padding: 4px 6px; border-radius: 8px;
  transition: color .18s;
  -webkit-tap-highlight-color: transparent;
}
.sense:hover  { color: color-mix(in srgb, var(--active) 60%, var(--ink)); }
.sense.active { color: var(--active); }
.sense.placeholder { color: var(--ink-faint); font-weight: 500; font-style: italic; }

/* example - bordered prose box, as in the sketch */
.example {
  max-width: min(46vw, 300px);
  border: 1.5px solid var(--accent); border-radius: 4px;
  background: var(--bg-raise);
  padding: 16px 18px;
  font-size: 18px; line-height: 1.55; color: var(--ink);
}
.example .ar {
  display: block; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--rule);
  direction: rtl; text-align: right;
  font-family: "Amiri Quran", "Scheherazade New", serif; font-size: 22px; line-height: 1.9;
}
.example .todo { color: var(--ink-faint); font-style: italic; }

/* documentaries */
.docs {
  max-width: min(44vw, 280px);
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--bg-raise); box-shadow: var(--shadow);
  padding: 14px 16px; font-size: 15.5px;
}
.docs h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-faint); font-weight: 600; }
.docs a { display: block; padding: 6px 0; color: var(--active); text-decoration: none; border-bottom: 1px solid var(--rule); }
.docs a:last-child { border-bottom: 0; }
.docs a:hover { text-decoration: underline; }
.docs .src { color: var(--ink-faint); font-size: 12px; }
.docs .dead { display: block; padding: 6px 0; color: var(--ink-faint); border-bottom: 1px solid var(--rule); }

.hint {
  position: absolute; left: 0; right: 0; bottom: 14px; z-index: 3;
  margin: 0; text-align: center; font-size: 14px; color: var(--ink-faint);
  pointer-events: none; transition: opacity .4s;
}
.hint.gone { opacity: 0; }

/* ---------- overlays ---------- */

.reveal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(6px);
  animation: fadein .35s ease both;
}
@keyframes fadein { from { opacity: 0; } }

.reveal-card {
  width: min(560px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--bg-raise); border: 1px solid var(--rule); border-radius: 16px;
  box-shadow: var(--shadow); padding: 26px 24px 18px;
  animation: rise .4s cubic-bezier(.2,.9,.3,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.reveal-eyebrow { margin: 0 0 16px; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-faint); font-weight: 600; }
.reveal-ayah { font-family: "Amiri Quran", "Scheherazade New", serif; font-size: clamp(24px, 6vw, 34px); line-height: 2; margin-bottom: 18px; text-align: right; }
.reveal-text { margin: 0 0 20px; font-size: 20px; line-height: 1.65; }
.reveal-text.todo { color: var(--ink-faint); font-style: italic; font-size: 15px; }
.reveal-recap { border-top: 1px solid var(--rule); padding-top: 14px; }
/* row-reverse puts the Arabic on the right, matching the ayah above it */
.reveal-recap .row { display: flex; flex-direction: row-reverse; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 0; font-size: 16px; }
.reveal-recap .ar { font-family: "Amiri Quran", "Scheherazade New", serif; font-size: 20px; direction: rtl; }
.reveal-recap .en { color: var(--ink-soft); text-align: right; }
.reveal-recap .en .unseen { color: var(--ink-faint); font-style: italic; }
.reveal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 16px; }

.about-body { margin: 0; font-size: 14px; }
.about-body dt { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin-top: 14px; }
.about-body dd { margin: 4px 0 0; color: var(--ink); }
.about-body dd.empty { color: var(--ink-faint); font-style: italic; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ayah number — rendered, never interactive */
.ayah-mark {
  display: inline-block;
  color: var(--ink-faint);
  cursor: default;
  -webkit-user-select: none; user-select: none;
}

/* the hidden attribute must beat the overlay's display:grid */
[hidden] { display: none !important; }

/* ---------- in-depth: chip on the map, prose in a panel ---------- */

.depth-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 17px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--bg-raise);
  font-size: 16px; font-weight: 500; color: var(--ink-soft);
  cursor: pointer; white-space: nowrap;
  transition: color .18s, border-color .18s, transform .18s;
}
.depth-chip:hover { color: var(--ink); border-color: var(--active); transform: translateY(-1px); }
.depth-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--active); }
.depth-chip .count {
  font-variant-numeric: tabular-nums; font-size: 11px;
  padding: 1px 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--active) 16%, transparent); color: var(--active);
}

.depth-word {
  font-family: "Amiri Quran", "Scheherazade New", serif;
  font-size: clamp(26px, 6vw, 38px); line-height: 1.9;
  text-align: right; margin-bottom: 6px;
}

.note {
  border-top: 1px solid var(--rule);
  padding: 18px 0 4px;
}
.note:first-child { border-top: 0; padding-top: 4px; }
.note h3 { margin: 0 0 8px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.note-on {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--active); font-weight: 600;
}
.note-summary { margin: 0 0 14px; font-size: 16px; line-height: 1.6; color: var(--ink-soft); }
.note ul { margin: 0 0 14px; padding-left: 18px; }
.note li { font-size: 16px; line-height: 1.55; margin-bottom: 5px; }
.note blockquote {
  margin: 0; padding: 12px 0 12px 16px;
  border-left: 2px solid var(--accent);
  font-size: 17px; line-height: 1.6; font-style: italic;
}
.note blockquote cite {
  display: block; margin-top: 8px;
  font-style: normal; font-size: 12.5px; color: var(--ink-faint);
}
.note-status {
  margin: 10px 0 0; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint);
}

.reveal-notes { margin-top: 18px; }
.reveal-notes .note:first-child { border-top: 1px solid var(--rule); padding-top: 18px; }

/* A faded meaning is context, not something you are reading right now. Shrinking
   it keeps several open words on screen without squeezing the active branch. */
.sense.dim { font-size: clamp(13px, 2.8vw, 17px); font-weight: 500; }

/* ---------- usage: where this exact word occurs across the Quran ---------- */

.usage-count { margin: 0 0 14px; font-size: 15px; color: var(--ink-soft); }
.usage-list { display: flex; flex-wrap: wrap; gap: 8px; }
.usage-ref {
  border: 1px solid var(--rule); background: var(--bg-raise); color: var(--ink);
  font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  transition: border-color .16s, transform .16s;
}
.usage-ref:hover { border-color: var(--active); transform: translateY(-1px); }
.usage-ref.here { border-color: var(--accent); cursor: default; }
.usage-ref.here:hover { transform: none; }
.usage-ref .here-tag { margin-left: 8px; font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }

/* the word you followed from another ayah - marked so it is found instantly */
.word.trace { color: var(--accent); }
.word.trace:hover { color: var(--active); }
.word.trace.dim { opacity: .65; }

/* ---------- surah info bar, above the ayah ---------- */

.surah-info {
  position: relative; z-index: 3;
  display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap;
  gap: 10px; padding: 10px 20px 0;
}
.si-ar {
  font-family: "Amiri Quran", "Scheherazade New", serif;
  font-size: 26px; line-height: 1.4; color: var(--ink);
}
.si-name { font-size: 15px; font-weight: 600; color: var(--ink); }
.si-chip {
  font-size: 12.5px; font-weight: 600; letter-spacing: .03em;
  padding: 4px 11px; border-radius: 999px; border: 1px solid var(--rule);
  color: var(--ink-soft);
}
.si-chip.makki  { color: #8a5a00; border-color: #e0c185; background: #fdf6e7; }
.si-chip.madani { color: #1c6b3c; border-color: #a8d5b5; background: #eef8f0; }

/* ---------- juz / page / sajdah chips, nav arrows, transliteration ---------- */

.si-chip.sajdah { color: #7a3fa0; border-color: #d3b3e6; background: #f7effc; }

.nav-btn { font-variant-numeric: tabular-nums; font-size: 14px; }

.translit {
  position: relative; z-index: 3;
  padding: 2px 20px 0; text-align: right;
  font-size: 17px; line-height: 1.7; color: var(--ink-soft);
}
.tl-long { text-decoration: underline; text-underline-offset: 3px; }
.tl-el { font-style: italic; color: var(--ink-faint); }  /* silent mid-word letter */
.tl-el.tl-final { color: var(--ink-soft); }   /* the case-ending, dropped at a pause */
.translit { text-align: center; }       /* fallback line spans the whole ayah */

/* per-word transliteration, directly under its Arabic word */
.word .wt {
  display: block;
  font-family: Inter, system-ui, sans-serif;
  font-size: 14px; line-height: 1.2;
  color: var(--ink-soft); text-align: center;
  letter-spacing: 0; margin-top: -2px; padding-bottom: 4px;
}

/* ---------- surah search ---------- */

.search-wrap { position: relative; }
#surah-search {
  width: 190px; font: inherit; font-size: 14px; color: var(--ink);
  padding: 8px 12px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--bg-raise); outline: none;
}
#surah-search:focus { border-color: var(--active); }
.suggest {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  width: 320px; max-height: 330px; overflow-y: auto;
  margin: 0; padding: 6px; list-style: none;
  background: var(--bg-raise); border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: var(--shadow);
}
.suggest li {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.suggest li:hover { background: color-mix(in srgb, var(--active) 8%, transparent); }
.sg-no { color: var(--ink-faint); font-variant-numeric: tabular-nums; min-width: 24px; }
.sg-en { font-weight: 600; }
.sg-mean { color: var(--ink-soft); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-ar { font-family: "Amiri Quran", serif; font-size: 18px; }

/* ---------- tilawah (reading) mode ---------- */

.tilawah-card { width: min(860px, 100%); max-height: 92vh; display: flex; flex-direction: column; }
.t-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
.t-spacer { flex: 1; }
.t-body { overflow-y: auto; padding-top: 6px; }
.t-ayah {
  padding: 16px 10px; border-bottom: 1px solid var(--rule);
  border-radius: 10px; cursor: pointer; transition: background .16s;
}
.t-ayah:hover { background: color-mix(in srgb, var(--active) 6%, transparent); }
.t-ayah.playing { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.t-arabic {
  font-family: "Amiri Quran", "Scheherazade New", serif;
  font-size: clamp(26px, 5vw, 38px); line-height: 2; text-align: right;
}
.t-mark { color: var(--ink-faint); font-size: .7em; }
.t-translit { font-size: 14.5px; color: var(--ink-soft); line-height: 1.6; margin-top: 2px; }

/* the basmalah heads the surah on its own line - present, not clickable */
.basmalah {
  display: block; text-align: center;
  font-size: .62em; line-height: 1.8; color: var(--ink-soft);
  margin-bottom: .1em;
}
.t-basmalah {
  font-family: "Amiri Quran", "Scheherazade New", serif;
  font-size: clamp(22px, 4vw, 30px); line-height: 2;
  text-align: center; color: var(--ink-soft);
  padding: 10px 0 4px; border-bottom: 1px solid var(--rule);
}

/* ---------- editor (localhost only) ---------- */

.ed-status { margin: 8px 0 0; font-size: 13px; color: var(--ink-soft); white-space: pre-wrap; font-family: Consolas, monospace; }
.ed-word { border: 1px solid var(--rule); border-radius: 12px; padding: 14px; margin-top: 14px; }
.ed-word-head { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-bottom: 6px; }
.ed-word-ar { font-family: "Amiri Quran", serif; font-size: 26px; }
.ed-sense { border-top: 1px dashed var(--rule); padding-top: 10px; margin-top: 10px; }
.ed-sense-head { display: flex; align-items: center; gap: 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); margin-bottom: 6px; }
.ed-ok { margin-left: auto; font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; }
.ed-field { display: block; margin: 8px 0; }
.ed-field span { display: block; font-size: 11.5px; color: var(--ink-faint); margin-bottom: 3px; }
.ed-field input, .ed-field textarea {
  width: 100%; font: inherit; font-size: 14.5px; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--bg-raise); outline: none; resize: vertical;
}
.ed-field input:focus, .ed-field textarea:focus { border-color: var(--active); }
.ed-field .ed-ar { font-family: "Amiri Quran", serif; font-size: 20px; text-align: right; }

.ed-note { border-top: 1px dashed var(--rule); padding-top: 10px; margin-top: 10px;
           background: color-mix(in srgb, var(--active) 4%, transparent);
           border-radius: 8px; padding: 10px; }
.ed-word-head .text-btn { border: 1px solid var(--rule); border-radius: 999px; margin-left: auto; }

.ed-topic { display: flex; align-items: center; gap: 8px; padding: 6px 2px; font-size: 14px; cursor: pointer; }

/* ---------- responsive: portrait phones ---------- */
@media (max-width: 560px) {
  .bar { padding: 8px 10px; min-height: 46px; gap: 4px; }
  .bar-l, .bar-r { gap: 4px; }
  .ref { font-size: 12.5px; }
  #home, #tilawah-btn { font-size: 12px; padding: 6px 8px; }
  #surah-search { width: 118px; font-size: 13px; padding: 7px 10px; }
  .suggest { width: min(320px, calc(100vw - 20px)); }
  .next-btn { padding: 9px 14px; font-size: 14px; }
  .text-btn { font-size: 12px; padding: 6px 8px; }
  .progress { font-size: 11.5px; }
  .surah-info { gap: 6px; padding: 8px 12px 0; }
  .si-chip { font-size: 11px; padding: 3px 8px; }
  .si-ar { font-size: 20px; }
  .si-name { font-size: 13px; }
}

/* ---------- responsive: landscape phones (short viewport) ---------- */
@media (max-height: 480px) {
  .bar { min-height: 42px; padding-top: 6px; padding-bottom: 6px; }
  .ayah { font-size: clamp(26px, 9vh, 44px); line-height: 1.9; padding-top: 2px; }
  .surah-info { padding-top: 4px; }
  .word .wt { font-size: 11px; }
  .hint { display: none; }
}

/* ---------- portrait lock on phones ---------- */
/* The web cannot hard-lock orientation outside fullscreen, so a landscape
   phone gets a calm full-screen ask instead of a broken layout. Desktop
   windows (fine pointers) are never affected. */
.rotate-overlay { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate-overlay {
    display: grid; place-items: center;
    position: fixed; inset: 0; z-index: 100;
    background: var(--bg);
  }
}
.rotate-card { text-align: center; color: var(--ink); }
.rotate-card p { margin: 18px 0 4px; font-size: 17px; font-weight: 600; }
.rotate-card span { font-size: 13px; color: var(--ink-faint); }
.rotate-phone {
  width: 34px; height: 58px; margin: 0 auto;
  border: 2.5px solid var(--ink-soft); border-radius: 8px;
  animation: rotate-hint 2.2s var(--ease) infinite;
}
@keyframes rotate-hint {
  0%, 20%  { transform: rotate(90deg); }
  55%, 100% { transform: rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) { .rotate-phone { animation: none; } }
