@import url("https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Outfit:wght@400;500;600;700&family=Tajawal:wght@400;500;700&display=swap");

:root {
  /* Warm cream page + beige reading band */
  --paper: #faf6ef;
  --paper-2: #f2e8d5;
  --paper-cream: #faf3e3;
  --ink: #2c2825;
  --ink-soft: #635e56;
  --line: #e2d4c2;
  --accent: #5c4a3a;
  --accent-light: #eaddc7;
  --accent-name: #6b5344;
  --pop: #a85d2c;
  --shadow: 0 14px 36px rgba(44, 40, 37, 0.07);
  --font-ui: "Outfit", system-ui, sans-serif;
  --font-reading: "Lora", "Georgia", serif;
  --radius: 12px;
  --radius-sm: 10px;
  --reader-inset: clamp(14px, 3.5vw, 40px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body.reader {
  margin: 0;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.reader.has-content-zoom {
  overflow-y: auto;
  overflow-x: auto;
  max-height: none;
}

body.reader .reader-flow.is-content-zoomed {
  overflow-y: visible;
  overflow-x: visible;
  flex: 0 0 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

html:fullscreen {
  height: 100%;
  background: var(--paper);
}

html:-webkit-full-screen {
  height: 100%;
  background: var(--paper);
}

html:fullscreen body.reader {
  height: 100%;
  min-height: 100%;
  max-height: 100%;
}

/* Slide-style fullscreen: no top chrome (exit with Esc or move pointer to screen top). */
html:fullscreen body.reader .reader-top,
html:-webkit-full-screen body.reader .reader-top {
  display: none !important;
}

html:fullscreen body.reader .reader-progress,
html:-webkit-full-screen body.reader .reader-progress {
  display: none !important;
}

.focus-veil {
  position: fixed;
  inset: 0;
  background: rgba(20, 19, 18, 0.04);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 50;
}

body.focus-mode .focus-veil {
  opacity: 1;
}

/* ——— Top bar ——— */
.reader-top {
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px clamp(12px, 3vw, 28px);
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: rgba(250, 246, 239, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.reader-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-width: 0;
}

.reader-logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.15;
}

.reader-logo-ar {
  margin: 2px 0 0;
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-soft);
  direction: rtl;
  unicode-bidi: isolate;
  text-align: right;
}

.reader-logo:hover {
  color: var(--accent);
}

.reader-top__tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
  padding-top: 2px;
}

.reader-fs-btn {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.reader-fs-btn:hover {
  border-color: #c9c3b8;
  color: var(--ink);
  background: var(--paper);
}

.reader-pager {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pager-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.pager-link:hover {
  background: var(--paper-2);
  color: var(--ink);
  border-color: var(--line);
}

.pager-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  font-size: 13px;
  font-weight: 700;
  color: var(--paper);
  background: var(--accent);
  border-radius: 10px;
}

/* ——— Progress ——— */
.reader-progress {
  flex-shrink: 0;
  height: 3px;
  background: var(--line);
}

#reading-progress {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--pop);
  transition: width 0.12s ease-out;
}

/* ——— Main column (exactly fills space under header; no page scroll) ——— */
.reader-flow {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ——— Article shell: passage is full width; title row is inset ——— */
.reader-article {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 2px 0 0;
  width: 100%;
  max-width: none;
  overflow: visible;
}

.reader-article-stack {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  margin: 0;
  overflow: hidden;
}

.reader-article-stack > :not(.reader-passage-wrap) {
  flex-shrink: 0;
}

body.is-ready .reader-article {
  animation: reader-in 0.55s ease both;
}

@keyframes reader-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.reader-eyebrow {
  margin: 0 0 2px;
  padding-inline: var(--reader-inset);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.reader-eyebrow-ar {
  margin: 0 0 4px;
  padding-inline: var(--reader-inset);
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.35;
  color: var(--ink-soft);
}

.reader-h1 {
  margin: 0;
  padding-inline: var(--reader-inset);
  font-size: clamp(1.5rem, 3.6vw, 2.15rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--ink);
}

.reader-h1-ar {
  margin: 2px 0 0;
  padding-inline: var(--reader-inset);
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: clamp(1rem, 2.5vw, 1.28rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--accent-name);
}

.reader-lede {
  margin: 5px 0 0;
  padding-inline: var(--reader-inset);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.42;
  color: var(--ink-soft);
  max-width: none;
}

.reader-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  padding-inline: var(--reader-inset);
}

.reader-tools button {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.reader-tools button:hover {
  border-color: #c9c3b8;
  color: var(--ink);
}

.reader-tools button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

/* ——— Passage: full page width, maximum vertical space ——— */
.reader-passage-wrap {
  flex: 1 1 0%;
  min-height: 0;
  width: 100%;
  margin-top: clamp(4px, 0.9vh, 10px);
  padding: clamp(10px, 1.6vh, 20px) var(--reader-inset);
  background: linear-gradient(180deg, var(--paper-cream) 0%, var(--paper-2) 100%);
  border: none;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.focus-mode .reader-top .reader-pager,
body.focus-mode .reader-logo {
  opacity: 0.45;
}

body.focus-mode .reader-logo-ar,
body.focus-mode .reader-eyebrow-ar,
body.focus-mode .reader-h1-ar {
  display: none;
}

body.focus-mode .reader-eyebrow,
body.focus-mode .reader-lede {
  display: none;
}

body.focus-mode .reader-h1 {
  font-size: clamp(1.35rem, 3vw, 1.6rem);
  margin-bottom: 4px;
}

body.focus-mode .reader-tools {
  margin-top: 14px;
}

body.focus-mode .reader-passage-wrap {
  background: linear-gradient(180deg, #faf0df 0%, #ebe0cc 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.reading-scroll {
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
  width: 100%;
}

.reading-text {
  margin: 0;
  font-family: var(--font-reading);
  font-size: clamp(1.18rem, 1.95vw, 1.38rem);
  line-height: 1.68;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink);
  font-synthesis: none;
}

body.focus-mode .reading-text {
  font-size: clamp(1.22rem, 2.1vw, 1.42rem);
  line-height: 1.72;
}

.reading-text p {
  margin: 0 0 1em;
}

.reading-text p:last-child {
  margin-bottom: 0;
}

.name {
  color: var(--accent-name);
  font-weight: 600;
}

.vocab {
  background: linear-gradient(transparent 58%, var(--accent-light) 58%);
  border-radius: 3px;
  padding: 0 0.08em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.interactive-word {
  position: relative;
  cursor: pointer;
}

.interactive-word:hover {
  box-shadow: 0 2px 0 0 rgba(168, 93, 44, 0.45);
}

.interactive-word::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%) translateY(3px);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  max-width: min(260px, 72vw);
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 9px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
  z-index: 60;
}

.interactive-word:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sentence {
  border-radius: 3px;
  padding: 0.06em 0.04em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background-color 0.14s ease, opacity 0.14s ease;
}

.reading-text.is-interacting .sentence {
  opacity: 0.34;
}

.reading-text.is-interacting .sentence.is-active {
  opacity: 1;
  background: rgba(168, 93, 44, 0.12);
}

body.teacher-highlight-mode .interactive-word {
  cursor: crosshair;
}

.interactive-word.manual-highlight {
  background: #fef08a;
  box-shadow: none;
}

/* ——— Translation ——— */
.reader-trans {
  flex-shrink: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 6px var(--reader-inset) 6px;
}

.translation-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.translation-toggle:hover {
  border-color: #b8b0a3;
  background: var(--paper-2);
}

.translation-toggle::after {
  content: "＋";
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-soft);
}

.translation-toggle[aria-expanded="true"]::after {
  content: "−";
}

.translation-panel {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition:
    max-height 0.3s ease,
    opacity 0.22s ease,
    margin 0.22s ease,
    padding 0.22s ease,
    border-color 0.22s ease;
}

.translation-panel.is-open {
  max-height: min(24vh, 200px);
  opacity: 1;
  margin-top: 8px;
  padding: 10px 12px;
  border-color: var(--line);
  background: var(--paper-cream);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.translation-panel p {
  margin: 0;
  font-size: 15px;
  line-height: 1.85;
  color: var(--ink-soft);
  font-family: "Tajawal", system-ui, sans-serif;
}

.reader-foot {
  flex-shrink: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 6px var(--reader-inset) calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-soft);
}

.reader-foot a {
  color: var(--pop);
  text-decoration: none;
  font-weight: 600;
}

.reader-foot a:hover {
  text-decoration: underline;
}

@media (max-width: 520px) {
  .reader-top {
    flex-wrap: wrap;
  }

  .reader-top__tools {
    width: 100%;
    justify-content: space-between;
  }

  .reader-tools {
    width: 100%;
  }

  .reader-tools button {
    flex: 1;
    text-align: center;
  }
}
