:root {
  color-scheme: light dark;
  --bg: #f7f6f3;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #5d5d5d;
  --line: #e0ddd6;
  --accent: #1f6f4a;
  --accent-ink: #ffffff;
  --danger: #a12a1f;
  --warn: #8a6100;
  --warn-bg: #fdf3da;
  --link: #9a3412;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1c1b;
    --ink: #ececea;
    --muted: #a5a29b;
    --line: #333331;
    --accent: #58b184;
    --accent-ink: #0d1a13;
    --danger: #f0847a;
    --warn: #e5bd68;
    --warn-bg: #2b2415;
    --link: #f2a27a;
  }
}

* { box-sizing: border-box; }
/* `display: flex` on .overlay would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}
main { max-width: 900px; margin: 0 auto; padding: 16px; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.bar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.bar-right { display: flex; align-items: center; gap: 10px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }

label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
input[type="password"], input[type="text"] {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px;
}
input[type="file"] { width: 100%; font: inherit; color: var(--ink); }
input:focus-visible, button:focus-visible, li:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

button {
  font: inherit; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { padding: 6px 12px; font-size: 14px; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}

.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.ok { color: var(--accent); font-size: 14px; margin: 8px 0 0; }
.log { font-size: 14px; color: var(--muted); margin-top: 10px; }
.log div { padding: 3px 0; }
.log .bad { color: var(--danger); }

.uploads { list-style: none; margin: 0; padding: 0; }
.uploads li {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line);
}
.uploads li:first-child { border-top: 0; }
.uploads input[type="checkbox"] { margin-top: 5px; width: 18px; height: 18px; flex: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; word-break: break-word; }
.row-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.row-actions { display: flex; gap: 8px; flex: none; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; margin-inline-start: 6px;
}
.badge.blocked { background: var(--danger); color: #fff; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; }

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center; z-index: 10;
}
.sheet {
  background: var(--surface); width: min(900px, 100%); max-height: 92vh;
  border-radius: var(--radius) var(--radius) 0 0; display: flex; flex-direction: column;
}
@media (min-width: 700px) {
  .overlay { align-items: center; }
  .sheet { border-radius: var(--radius); }
}
.sheet-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.sheet-bar h2 { margin: 0; font-size: 16px; }
.sheet-body { overflow-y: auto; padding: 16px; }

.verse { border-top: 1px solid var(--line); padding: 14px 0; }
.verse:first-child { border-top: 0; }
.verse-no { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.arabic {
  direction: rtl; text-align: right; font-size: 26px; line-height: 2.1;
  font-family: "Scheherazade New", "Geeza Pro", "Traditional Arabic", serif;
}
.translation { margin-top: 10px; }
.linked { color: var(--link); cursor: pointer; border-bottom: 1px dotted currentColor; }
.word-detail {
  margin-top: 10px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px; white-space: pre-wrap;
}
.issues { margin: 0; padding: 0; list-style: none; font-size: 14px; }
.issues li { padding: 5px 0; border-top: 1px solid var(--line); }
.issues li:first-child { border-top: 0; }
.issue-code { font-weight: 600; }
.issue-blocking .issue-code { color: var(--danger); }

/* --- editorial alignment ------------------------------------------------- */
.editor-hint {
  background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor;
  border-radius: 8px; padding: 9px 12px; font-size: 14px; margin: 0 0 14px;
}
.progress { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.progress b { color: var(--ink); }

/* Each linked word carries its own hue, the same one in Arabic and in the meal. */
.linked { color: hsl(var(--w, 20) 72% var(--word-l, 68%)); }
@media (prefers-color-scheme: light) { :root { --word-l: 33%; } }
.arabic .linked { cursor: pointer; border-bottom: 2px dotted currentColor; font-weight: 600; }
.arabic .linked.picked { background: color-mix(in srgb, currentColor 22%, transparent); border-radius: 4px; }
.arabic .linked.todo { border-bottom-style: solid; }
.translation .linked { border-bottom: 2px dotted currentColor; font-weight: 600; }
.translation.picking { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 6px; }
.verse-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.verse-tools button { padding: 4px 10px; font-size: 13px; }
.word-detail .quote-add { margin-top: 8px; }
.summary-line { font-size: 14px; color: var(--accent); margin-top: 6px; }

/* --- Faz 2: tabs, publication, history --- */
.tabs { display: flex; gap: 6px; margin: 0 0 14px; flex-wrap: wrap; }
.tab { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.report { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.report dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 8px; }
.report dt { color: var(--muted); }
.report dd { margin: 0; font-variant-numeric: tabular-nums; }
.report .failed { color: var(--danger); }
.confirm { margin: 12px 0; padding: 10px 12px; border-radius: var(--radius); background: var(--warn-bg); }
.confirm ul { margin: 6px 0 10px; padding-left: 20px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.row-note { font-size: 13px; color: var(--danger); }
.active-pill { background: var(--accent); color: var(--accent-ink); }
.inline { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.inline input { flex: 1 1 220px; }

/* --- Faz 3: surah catalogue and lesson editor --- */
.surahs { list-style: none; margin: 10px 0 0; padding: 0; }
.surahs > li { border-top: 1px solid var(--line); }
.surah-row { width: 100%; text-align: left; background: none; border: 0; padding: 10px 4px; color: var(--ink);
  display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; cursor: pointer; }
.surah-row .num { width: 2.2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.surah-row .name { font-weight: 600; min-width: 8em; }
.surah-row .meta { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.surah-row.empty { opacity: .55; }
.lesson-list { list-style: none; margin: 0 0 10px 2.6em; padding: 0; }
.lesson-list button { background: none; border: 0; padding: 5px 0; color: var(--link); cursor: pointer; text-align: left; }
.badge.site { background: var(--accent); color: var(--accent-ink); }
.pending-list { margin: 6px 0 12px; padding-left: 18px; font-size: 14px; }
.pending-list .failed { color: var(--danger); }
.word-detail textarea { width: 100%; min-height: 110px; margin: 6px 0; font: inherit; }
.new-word { margin-top: 8px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); }
.new-word textarea { width: 100%; min-height: 80px; font: inherit; margin: 6px 0; }
.danger-zone { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }

/* --- Faz 4a: suggestions --- */
.suggest { margin: 10px 0 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.suggest h3 { margin: 0 0 6px; font-size: 16px; }
.suggest ul { list-style: none; margin: 8px 0; padding: 0; max-height: 360px; overflow: auto; }
.suggest li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px dotted var(--line); }
.suggest li .ar { font-family: "Lateef", serif; font-size: 20px; direction: rtl; }
.suggest .job { font-size: 14px; color: var(--muted); }
.suggest .notes { font-size: 14px; color: var(--warn); margin: 4px 0 0; padding-left: 18px; }
.badge.check { background: var(--warn-bg); color: var(--warn); }
