/* Layout: én smal kolonne som en notesbog i hånden, fast fanebjælke nederst.
   Farver: blækblå tekst på lys salvie, granatæble som accent, oliven for "besvaret",
   og en broderet tatreez-kant som eneste pynt. */
:root {
  --bg: #F1F3EF;
  --surface: #FFFFFF;
  --surface-2: #E6EAE3;
  --ink: #1D2433;
  --muted: #5B6375;
  --line: #D3D9CF;
  --accent: #9B2A4A;        /* granatæble */
  --accent-ink: #FFFFFF;
  --accent-soft: #F3DDE4;
  --olive: #56662A;
  --olive-soft: #E1E8CC;
  --gold: #B7822A;
  --rec: #C0392B;

  --f-ui: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-display: "Literata", Georgia, "Times New Roman", serif;
  --f-ar: "Noto Naskh Arabic", "Geeza Pro", "Arabic Typesetting", serif;
  --f-ar-display: "Reem Kufi", "Noto Naskh Arabic", "Geeza Pro", sans-serif;

  --r: 14px;
  --shadow: 0 1px 2px rgba(29, 36, 51, .06), 0 6px 20px rgba(29, 36, 51, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181F; --surface: #1C222B; --surface-2: #252C37; --ink: #ECEAE4; --muted: #A0A7B5;
    --line: #313946; --accent: #E2789A; --accent-ink: #1A0E13; --accent-soft: #3A2430;
    --olive: #B3C27A; --olive-soft: #2D3320; --gold: #D9A752; --rec: #F0645A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14181F; --surface: #1C222B; --surface-2: #252C37; --ink: #ECEAE4; --muted: #A0A7B5;
  --line: #313946; --accent: #E2789A; --accent-ink: #1A0E13; --accent-soft: #3A2430;
  --olive: #B3C27A; --olive-soft: #2D3320; --gold: #D9A752; --rec: #F0645A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--f-ui);
  padding-top: env(safe-area-inset-top, 0px);
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[lang="ar"] { font-family: var(--f-ar); }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

/* ---------- top ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding-block: 16px 8px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-da { font-family: var(--f-display); font-size: 1.35rem; font-weight: 600; letter-spacing: -.01em; }
.brand-ar { font-family: var(--f-ar-display); font-size: 1.2rem; color: var(--accent); }


/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.tab {
  border: 0; background: none; cursor: pointer; padding: 8px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: .78rem; font-weight: 700;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- generic ---------- */
main { outline: none; display: flex; flex-direction: column; gap: 16px; padding-top: 8px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; text-wrap: balance; margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; text-decoration: none;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); padding-inline: 10px; }
.btn.quiet:hover { color: var(--ink); }
.btn.danger { color: var(--rec); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.row > .btn.big { flex: 1 1 140px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: .92rem; }
input[type="text"], input[type="email"], input[type="password"], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 10px 12px; font-weight: 400; font-size: 1rem;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
textarea[dir="rtl"], input[dir="rtl"] { font-family: var(--f-ar); font-size: 1.15rem; line-height: 2; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.chip.done { background: var(--olive-soft); color: var(--olive); }
.chip.part { background: var(--accent-soft); color: var(--accent); }

/* ---------- question card ---------- */
.qcard {
  position: relative; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  padding: 28px 20px 20px; display: flex; flex-direction: column; gap: 14px; overflow: hidden;
}
/* Tatreez-kant: små korssting i guld og granatæble */
.qcard::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 10px;
  background:
    linear-gradient(45deg, transparent 40%, var(--accent) 40% 60%, transparent 60%) 0 0 / 10px 10px,
    linear-gradient(-45deg, transparent 40%, var(--accent) 40% 60%, transparent 60%) 0 0 / 10px 10px,
    linear-gradient(45deg, transparent 40%, var(--gold) 40% 60%, transparent 60%) 5px 0 / 10px 10px,
    linear-gradient(-45deg, transparent 40%, var(--gold) 40% 60%, transparent 60%) 5px 0 / 10px 10px;
  opacity: .75;
}
.q-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; }
.q-ar {
  font-family: var(--f-ar); font-size: clamp(1.7rem, 6.6vw, 2.25rem); line-height: 2.05;
  font-weight: 500; text-align: right; margin: 0;
}
.q-da { font-family: var(--f-display); font-size: 1.15rem; line-height: 1.45; margin: 0; }
.q-ask {
  border-top: 1px dashed var(--line); padding-top: 12px; font-size: .95rem; color: var(--muted);
}
.q-ask b { color: var(--ink); }
.q-quote { margin: 12px 0 0; font-family: var(--f-display); font-style: italic; font-size: .92rem; color: var(--muted); }
.q-edit { margin-top: 12px; }
.q-nav { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- sync status ---------- */
.sync {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 700;
  color: var(--muted); padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sync.ok { color: var(--olive); background: var(--olive-soft); }
.sync.saving { color: var(--muted); }
.sync.offline { color: var(--gold); }
.sync:empty { display: none; }

/* ---------- parent switch ---------- */
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.who-card {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px;
  text-align: left; cursor: pointer; padding: 12px 14px 10px; border-radius: var(--r);
  background: var(--surface); border: 2px solid var(--line); min-width: 0;
}
.who-card[aria-checked="true"] { border-color: var(--accent); box-shadow: var(--shadow); }
.who-name { font-family: var(--f-display); font-weight: 600; font-size: 1.2rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-ar { font-family: var(--f-ar-display); color: var(--accent); font-size: 1rem; }
.who-count { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.who-card .progress { grid-column: 1 / -1; margin-top: 4px; }
.who-card[aria-checked="false"] .who-ar { color: var(--muted); }

/* ---------- record zone ---------- */
.reczone {
  display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--line); flex-wrap: wrap;
}
.recbtn {
  width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer; flex: none;
  background: var(--rec); color: #fff; display: grid; place-items: center;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--rec) 18%, transparent);
}
.recbtn svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.recbtn.on svg { fill: currentColor; }
.recbtn.on { animation: ring 1.4s ease-in-out infinite; }
.recbtn[disabled] { opacity: .45; cursor: not-allowed; }
@keyframes ring { 50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--rec) 10%, transparent); } }
@media (prefers-reduced-motion: reduce) { .recbtn.on { animation: none; } }
.rec-info { flex: 1 1 120px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rec-info b { font-size: 1.1rem; }

.code-panel { margin-top: 10vh; text-align: left; }
.code-ar { font-family: var(--f-ar-display); font-size: 2.4rem; color: var(--accent); line-height: 1.2; }
.code-panel input[type="email"], .code-panel input[type="password"] { font-size: 1.05rem; min-height: 52px; }
.auth-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-size: .95rem; }
.auth-switch { margin-top: 14px; }
.linkbtn { background: none; border: 0; padding: 6px 2px; min-height: 44px; font: inherit; color: var(--accent); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.small-h { font-size: 1rem; margin: 16px 0 6px; }
.people { list-style: none; margin: 0 0 12px; padding: 0; }
.people li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 4px 8px; min-height: 48px; border-bottom: 1px solid var(--line); }
.people li > span:first-child { overflow-wrap: anywhere; }
.small-btn { min-height: 44px; }
.qlist li button.is-current { background: var(--accent-soft); }

/* ---------- recording ---------- */
.recbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--r);
  background: var(--surface); border: 2px solid var(--rec);
}
.recdot { width: 14px; height: 14px; border-radius: 50%; background: var(--rec); flex: none; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .recdot { animation: none; } }
.rectime { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.2rem; }
.meter { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 40px; }
.meter i { display: block; height: 100%; width: 0; background: var(--rec); transition: width .08s linear; }

.live {
  font-family: var(--f-ar); font-size: 1.15rem; line-height: 2; direction: rtl; text-align: right;
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-height: 2.4em;
}
.live .interim { color: var(--muted); }

.clips { display: flex; flex-direction: column; gap: 8px; }
.clip { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; border-radius: 10px; background: var(--surface-2); }
.clip audio { flex: 1 1 200px; min-width: 0; height: 40px; }
.clip .when { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

details.more { border-top: 1px solid var(--line); padding-top: 8px; }
details.more summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 6px 0; }

/* ---------- chapters ---------- */
.chap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.chap > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; display: grid;
  grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center;
}
.chap > summary::-webkit-details-marker { display: none; }
.chap-num { font-family: var(--f-ar-display); font-size: 1.5rem; color: var(--gold); width: 1.6em; text-align: center; }
.chap-titles { min-width: 0; }
.chap-titles .ar { font-family: var(--f-ar); color: var(--muted); font-size: .95rem; }
.progress { height: 4px; background: var(--surface-2); grid-column: 1 / -1; border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--olive); }
.qlist { list-style: none; margin: 0; padding: 0 8px 8px; }
.qlist li button {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer; padding: 10px 8px;
  display: flex; gap: 10px; align-items: flex-start; border-radius: 8px;
}
.qlist li button:hover { background: var(--surface-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; margin-top: 7px; }
.dot.done { background: var(--olive); border-color: var(--olive); }
.dot.part { border-color: var(--accent); }
.dot.skip { border-style: dashed; }

/* ---------- book preview ---------- */
.book-preview { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; }
.bk-entry { display: flex; flex-direction: column; gap: 6px; }
.bk-q { font-weight: 700; font-family: var(--f-display); }
.bk-q-ar { font-family: var(--f-ar); direction: rtl; text-align: right; color: var(--muted); line-height: 2; }
.bk-a { font-family: var(--f-display); line-height: 1.65; white-space: pre-wrap; }
.bk-a-ar { font-family: var(--f-ar); font-size: 1.15rem; line-height: 2.1; direction: rtl; text-align: right; white-space: pre-wrap; }
.bk-chap { font-family: var(--f-display); font-size: 1.3rem; border-bottom: 1px solid var(--line); padding-bottom: 6px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bk-chap .ar { font-family: var(--f-ar-display); color: var(--accent); }
.raw-tag { font-size: .75rem; color: var(--gold); font-weight: 700; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 700; box-shadow: var(--shadow); width: max-content; max-width: calc(100% - 32px); text-align: center;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 10px;
}
.toast[hidden] { display: none; }
.toast-btn { min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 1px solid currentColor; background: transparent; color: inherit; font: inherit; font-weight: 700; cursor: pointer; }
.dict-note { flex-basis: 100%; margin: 4px 0 0; }

.print-root { display: none; }

/* =================== PRINT: selve bogen =================== */
@media print {
  @page { size: A5; margin: 18mm 16mm 20mm; }
  :root { --ink: #1D2433; --muted: #5B6375; --accent: #9B2A4A; --gold: #B7822A; --line: #D3D9CF; color-scheme: light; }
  body { background: #fff; color: #1D2433; font-size: 10.5pt; padding: 0; }
  .app, .toast { display: none !important; }
  .print-root { display: block; }

  .pb-cover { height: 170mm; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 10mm; page-break-after: always; }
  .pb-cover .stitch { width: 60mm; height: 4mm; background:
    linear-gradient(45deg, transparent 40%, #9B2A4A 40% 60%, transparent 60%) 0 0 / 4mm 4mm,
    linear-gradient(-45deg, transparent 40%, #9B2A4A 40% 60%, transparent 60%) 0 0 / 4mm 4mm;
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pb-title { font-family: var(--f-display); font-size: 28pt; font-weight: 600; line-height: 1.15; }
  .pb-title-ar { font-family: var(--f-ar-display); font-size: 26pt; color: #9B2A4A; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pb-sub { font-family: var(--f-display); font-style: italic; color: #5B6375; }

  .pb-toc { page-break-after: always; }
  .pb-toc h2 { font-family: var(--f-display); font-size: 16pt; margin-bottom: 6mm; }
  .pb-toc ol { padding-left: 6mm; line-height: 2; font-family: var(--f-display); }

  .pb-chapter { page-break-before: always; }
  .pb-chapter-head { text-align: center; margin: 20mm 0 12mm; }
  .pb-chapter-num { font-family: var(--f-ar-display); color: #B7822A; font-size: 22pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pb-chapter-da { font-family: var(--f-display); font-size: 20pt; font-weight: 600; }
  .pb-chapter-ar { font-family: var(--f-ar-display); font-size: 17pt; color: #9B2A4A; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .pb-entry { margin-bottom: 8mm; break-inside: avoid-page; }
  .pb-q { font-family: var(--f-display); font-weight: 600; font-size: 11.5pt; margin-bottom: 1.5mm; }
  .pb-q-ar { font-family: var(--f-ar); direction: rtl; text-align: right; font-weight: 500; font-size: 12.5pt; line-height: 2; margin-bottom: 1.5mm; }
  .pb-a { font-family: var(--f-display); line-height: 1.6; white-space: pre-wrap; text-align: justify; hyphens: auto; }
  .pb-a-ar { font-family: var(--f-ar); direction: rtl; text-align: right; font-size: 12pt; line-height: 2.1; white-space: pre-wrap; margin-top: 2mm; }
  .pb-rule { width: 12mm; height: 0; border-top: 1px solid #B7822A; margin: 0 auto 8mm; }

  .pb-end { page-break-before: always; text-align: center; padding-top: 60mm; font-family: var(--f-display); font-style: italic; color: #5B6375; }
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rec-info .meter { flex: none; width: 100%; }
