@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/plex-arabic-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/plex-arabic-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/plex-arabic-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/plex-arabic-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/plex-sans-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/plex-sans-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F;
}
@font-face {
  font-family: Amiri;
  src: url("../fonts/amiri-arabic-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: Amiri;
  src: url("../fonts/amiri-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F;
}

:root[data-theme="day"] {
  color-scheme: light;
  --bg: #F3F6F4;
  --surface: #FFFFFF;
  --recess: #E7EEEA;
  --ink: #17211C;
  --text-secondary: #3E4A45;
  --accent: #0E5850;
  --accent-text: #0E5850;
  --on-accent: #F4FBF8;
  --accent-press: #0C4A44;
  --danger: #7A2824;
  --success: #1E5C32;
  --warning: #6E450E;
  --border: #5C6B65;
  --hairline: #D5DDD8;
  --ring: #0E5850;
}
:root[data-theme="ink"] {
  color-scheme: light;
  --bg: #E7E1D6;
  --surface: #F6F1E8;
  --recess: #D9D0C2;
  --ink: #1A140F;
  --text-secondary: #4A4036;
  --accent: #0E5850;
  --accent-text: #0E5850;
  --on-accent: #F4FBF8;
  --accent-press: #0C4A44;
  --danger: #7A2824;
  --success: #1E5C32;
  --warning: #6E450E;
  --border: #6A5E50;
  --hairline: #C9BEB0;
  --ring: #0E5850;
}
:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #141816;
  --surface: #1C221F;
  --recess: #101412;
  --ink: #E6E2D6;
  --text-secondary: #C2BEB2;
  --accent: #0E5850;
  --accent-text: #7EB8AD;
  --on-accent: #F4FBF8;
  --accent-press: #0C4A44;
  --danger: #F0B4AE;
  --success: #9DCFB0;
  --warning: #E6C98A;
  --border: #8AA39C;
  --hairline: #2C3833;
  --ring: #7EB8AD;
}
@media (prefers-contrast: more) {
  :root[data-theme="day"] {
    --bg: #FFFFFF;
    --ink: #0E1411;
    --accent: #0A3F39;
    --accent-text: #0A3F39;
    --ring: #0A3F39;
  }
  :root[data-theme="night"] {
    --bg: #0C0E0D;
    --ink: #F7F4EC;
    --accent: #0E5850;
    --accent-text: #A8D4CC;
    --on-accent: #F4FBF8;
    --ring: #A8D4CC;
    --border: #B7D0C8;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
[data-along="1"] { background: var(--accent); color: var(--on-accent); }
.tour-target { outline: 3px solid var(--accent); outline-offset: 3px; }
:root[data-glass="1"] .bar,
:root[data-glass="1"] .sheet-enter { background: color-mix(in srgb, var(--bg) 82%, transparent); }
:root[data-glass="0"] .bar,
:root[data-glass="0"] .sheet-enter { background: var(--bg); }
.overlay-box { position: absolute; border: 2px solid var(--accent); color: var(--ink); font-size: 12px; }
.scan-figure { position: relative; }
html {
  letter-spacing: 0;
}
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}
body {
  font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, "Segoe UI", Tahoma, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  letter-spacing: 0;
  text-align: start;
}
button, input, textarea {
  font: inherit;
  letter-spacing: 0;
  color: inherit;
}
button {
  cursor: pointer;
}
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
}
.brand {
  margin: 0;
  font-weight: 600;
  font-size: 17px;
  margin-inline-end: auto;
}
.bar-actions { display: flex; gap: 8px; }
.status, .note, .banner {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.status { font-weight: 600; }
.status svg, .banner svg, .note svg {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  display: block;
}
.status[data-status="saved"] { color: var(--success); }
.status[data-status="failed"] { color: var(--danger); }
.status[data-status="not-durable"], .banner.warn { color: var(--warning); }
.meta, .note {
  margin: 8px 20px 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.45;
}
.note { font-size: 15px; min-height: 0; }
.note:empty, .meta:empty { display: none; }

main {
  width: min(48rem, calc(100% - 32px));
  margin: 24px auto 48px;
}
.view h1, .view h2 {
  font-weight: 600;
  font-size: 24px;
  line-height: 1.35;
  margin: 0 0 8px;
}
.lede {
  max-width: 38rem;
  margin: 0 0 20px;
}
.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.hit {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
}
.filled {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  transition: background-color 80ms linear;
}
.filled:active { background: var(--accent-press); }
.quiet { background: transparent; }
.danger { color: var(--danger); border-color: var(--danger); }
.actions, .pager, .dialog-actions, .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.pager { margin-top: 12px; }
.pager span { font-size: 15px; }

.lecture, .formal, .colloquial, .quote, .scope, .banner, .stage-body, .stage-heading {
  letter-spacing: 0;
}
.lecture {
  font-family: Amiri, "IBM Plex Sans Arabic", "Noto Naskh Arabic", serif;
  font-size: 19px;
  line-height: 1.9;
  max-width: 38rem;
  white-space: pre-wrap;
  margin: 12px 0;
}
.latin {
  font-family: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, sans-serif;
  unicode-bidi: isolate;
}
.quote {
  margin: 12px 0;
  padding: 0 0 0 0;
  padding-inline-start: 12px;
  border-inline-start: 2px solid var(--border);
  max-width: 38rem;
}
.formal {
  max-width: 38rem;
  font-size: 17px;
  line-height: 1.7;
}
.formal p, .colloquial p { margin: 0 0 8px; }
.scope { font-weight: 600; max-width: 38rem; }
.banner {
  max-width: 38rem;
  margin: 0 0 12px;
}
.colloquial, .enrich {
  max-width: 38rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
}
.subhead {
  margin: 16px 0 8px;
  font-size: 15px;
  font-weight: 600;
}

.pdf-frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--hairline);
}
.pdf-frame canvas { display: block; width: 100%; height: auto; }
.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  opacity: 1;
  z-index: 2;
}
.textLayer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
  letter-spacing: 0;
}
.textLayer ::selection { background: rgba(14, 88, 80, 0.28); }
.figure {
  margin: 0;
  background: var(--recess);
  border: 1px solid var(--hairline);
}
.figure img { width: 100%; height: auto; display: block; }
audio, video { width: min(100%, 28rem); min-height: 44px; }
video {
  width: min(100%, 38rem);
  max-height: 70vh;
  height: auto;
  background: var(--recess);
  border: 1px solid var(--hairline);
}
.kept {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 38rem;
}

.source-list { list-style: none; padding: 0; margin: 16px 0; }
.source-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
}
.row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: transparent;
  border: 0;
  min-height: 44px;
  padding: 4px 0;
  text-align: start;
}
.row span { font-size: 13px; color: var(--text-secondary); }
.field { display: flex; flex-direction: column; gap: 6px; width: min(100%, 38rem); }
textarea, input[type="text"] {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
textarea { min-height: 7rem; line-height: 1.6; }
.examples { width: min(100%, 28rem); }
.pending {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  max-width: 38rem;
}

.board-stage { max-width: 38rem; }
.stage-body {
  font-family: Amiri, "IBM Plex Sans Arabic", serif;
  font-size: 19px;
  line-height: 1.9;
  margin: 8px 0 12px;
  letter-spacing: 0;
}
.stage-heading {
  margin: 8px 0 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0;
  max-width: 38rem;
}
.view[data-view="board"] .board-sheet {
  margin-bottom: 12px;
}
.ink-wrap { margin: 0; }
.board-sheet {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 10px 4px;
}
#ink {
  width: 100%;
  height: 420px;
  background: transparent;
  border: 0;
  border-radius: 0;
  touch-action: none;
  display: block;
  cursor: grab;
}
.linkish {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.compare { display: flex; flex-direction: column; gap: 16px; }
.compare article { max-width: 38rem; }
.compare h3 { margin: 0 0 6px; font-size: 17px; }

.later-tools {
  max-width: 38rem;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.later-tool {
  background: var(--recess);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 12px;
}
.later-tool h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
}
.later-tool p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
}
.later-tool[aria-disabled="true"] {
  color: var(--text-secondary);
}

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 20px;
  max-width: 28rem;
}
dialog::backdrop { background: rgba(20, 24, 22, 0.45); }
dialog h2 { margin: 0 0 8px; font-size: 24px; }

.sheet-enter { animation: from-leading 200ms ease-out; }
@keyframes from-leading {
  from { transform: translateX(2rem); }
  to { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet-enter { animation: none; }
  .filled { transition: none; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
@media (min-width: 768px) {
  .lecture, .stage-body { font-size: 21px; }
  .stage-heading { font-size: 18px; }
  #ink { height: 520px; }
}
@media (max-width: 420px) {
  main { width: calc(100% - 24px); }
  .bar { padding-inline: 12px; }
}

/* ---------- Settings: text size, lecture font, motion, privacy, focus ---------- */
:root { --scale: 1; }
:root[data-text="s"] { --scale: 0.92; }
:root[data-text="l"] { --scale: 1.12; }
:root[data-text="xl"] { --scale: 1.26; }
body { font-size: calc(17px * var(--scale)); }
.lecture, .stage-body { font-size: calc(19px * var(--scale)); }
:root[data-lecture-font="plex"] .lecture,
:root[data-lecture-font="plex"] .stage-body {
  font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, sans-serif;
}
:root[data-lecture-font="system"] .lecture,
:root[data-lecture-font="system"] .stage-body {
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Times New Roman", serif;
}
:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
:root[data-private="1"] .lecture,
:root[data-private="1"] .pdf-frame,
:root[data-private="1"] .figure,
:root[data-private="1"] .quote,
:root[data-private="1"] [data-active-name],
:root[data-private="1"] .source-list .row {
  filter: blur(7px);
}
:root[data-focus="1"] #quota,
:root[data-focus="1"] .study-nav,
:root[data-focus="1"] [data-no-3d],
:root[data-focus="1"] [data-pen-note],
:root[data-focus="1"] .brand { display: none; }

/* ---------- Study surfaces ---------- */
.study-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  margin: 16px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  max-width: 38rem;
}
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 0 0 16px; }
input[type="search"], input[type="date"] {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font-family: inherit;
}
.hit-list, .study-list, .session-list { list-style: none; padding: 0; margin: 12px 0; max-width: 38rem; }
.hit-list li, .study-list li, .session-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.session-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.snippet { margin: 4px 0; font-family: Amiri, "IBM Plex Sans Arabic", serif; font-size: calc(18px * var(--scale)); line-height: 1.8; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; padding: 0 2px; border-radius: 3px; }
.note-text { margin: 6px 0; max-width: 38rem; white-space: pre-wrap; }
.passage-notes { max-width: 38rem; }
.passage-notes:empty { display: none; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 2px 10px;
}
.tag svg { width: 16px; height: 16px; }
.card-front { font-weight: 600; font-size: calc(19px * var(--scale)); margin: 8px 0; max-width: 38rem; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.setting { border: 0; padding: 0; margin: 0 0 16px; }
.setting legend { font-weight: 600; margin-bottom: 4px; }
label.setting { flex-wrap: wrap; }
label.setting .meta { flex-basis: 100%; margin: 0 28px 0 0; }
.quiz-item { border: 1px solid var(--hairline); border-radius: 10px; margin: 0 0 12px; padding: 8px 12px; max-width: 38rem; }
.quiz-item legend { font-weight: 600; padding: 0 4px; }
.verdict { display: flex; align-items: center; gap: 6px; margin: 4px 0 0; }
.verdict svg { width: 20px; height: 20px; }
.verdict.ok { color: var(--success); }
.verdict.no { color: var(--danger); }
.assistant-quote { max-width: 38rem; margin-bottom: 8px; }

/* ---------- Living board: pen tray, timeline, writing sync ---------- */
.pen-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin: 0 0 8px;
}
.tray-group { display: flex; flex-wrap: wrap; gap: 6px; }
/* Selected tool: outline and weight, not a second filled action. */
.tray-btn[aria-checked="true"] {
  background: var(--recess);
  color: var(--accent-text);
  border: 2px solid var(--accent-text);
  font-weight: 600;
}
.bar-actions { flex-wrap: wrap; }
.bar-actions .hit { padding-inline: 10px; white-space: nowrap; }
.tray-btn:disabled { opacity: 0.45; cursor: default; }
.swatch::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-inline-end: 6px;
  vertical-align: -1px;
  border: 1px solid var(--border);
}
.swatch-ink::before { background: var(--ink); }
.swatch-accent::before { background: var(--accent-text); }
.swatch-warn::before { background: var(--warning); }
.pen-tray [data-ink-warn] { margin: 0; color: var(--warning); }
#ink[data-tool="pen"], #ink[data-tool="highlighter"] { cursor: crosshair; }
#ink[data-tool="eraser"] { cursor: cell; }
.timeline {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 0 0 8px;
}
.timeline-step {
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text-secondary);
}
.timeline-step.is-current {
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
.timeline-step:disabled { opacity: 0.55; cursor: default; }
.stage-body .word { transition: opacity 120ms linear; }
.stage-body .word.is-pending { opacity: 0.18; }
.board-files { margin: 12px 0; max-width: 38rem; }
.board-files summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--accent-text); text-decoration: underline; }
body {
  background:
    radial-gradient(circle at 12% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 42%),
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--warning) 12%, transparent), transparent 36%),
    var(--bg);
}
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 30%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 28%),
    radial-gradient(circle at 80% 70%, color-mix(in srgb, var(--ink) 8%, transparent), transparent 32%);
  animation: drift 48s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-2%, 1.5%, 0); }
}
:root[data-theme="night"] body {
  background:
    radial-gradient(circle at 0% 0%, #1e3a34, transparent 46%),
    radial-gradient(circle at 100% 100%, #243028, transparent 40%),
    var(--bg);
}
.hit {
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.hit:hover { background: var(--recess); }
.filled:hover { background: var(--accent-press); }
.hit:active { transform: translateY(1px); }
.view[data-view="empty"] {
  padding: 28px 22px 32px;
  border: 1px solid var(--hairline);
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.empty-mark { width: 48px; height: 48px; color: var(--accent-text); }
.stage-svg { width: min(100%, 36rem); height: auto; margin: 8px 0 12px; }
.stage-svg .flow { stroke-dasharray: 8 6; animation: flow 2.4s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -42; } }
.is-now { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.suggest { max-width: 38rem; }
.region-box { outline: 2px dashed var(--accent); }
@media (max-width: 719px) {
  main { width: min(100% - 20px, 40rem); margin-top: 16px; }
  .bar { padding-inline: 12px; }
  .lecture { font-size: 18px; }
}
@media (min-width: 720px) and (max-width: 1099px) {
  main { width: min(44rem, calc(100% - 48px)); }
  .view[data-view="board"] { padding-inline: 8px; }
}
@media (min-width: 1100px) {
  main { width: min(68rem, calc(100% - 80px)); }
  .view[data-view="board"] .stage-svg { width: min(100%, 44rem); }
  .lecture { max-width: 46rem; }
}
@media (prefers-reduced-motion: reduce) {
  .stage-body .word.is-pending { opacity: 1; }
}
:root[data-motion="reduce"] .stage-body .word.is-pending { opacity: 1; }
@media (min-width: 768px) {
  .lecture, .stage-body { font-size: calc(21px * var(--scale)); }
}
