@font-face {
  font-family: "QEC-UthmanicHafs";
  src: url("https://verses.quran.foundation/fonts/quran/hafs/uthmanic_hafs/UthmanicHafs1Ver18.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #edf3f4;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --ink: #15232c;
  --muted: #5d6f76;
  --line: #cfdadd;
  --line-strong: #91a5aa;
  --green: #0f766e;
  --green-dark: #0d5f5a;
  --gold: #ffd76a;
  --qec-highlight-color: #ffd76a;
  --qec-highlight-text: #120c00;
  --danger: #b83255;
  --page: #fffaf0;
  --shadow: 0 14px 34px rgba(19, 35, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 9px;
  color: white;
  background: var(--green-dark);
  font-size: 14px;
  font-weight: 850;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand p {
  max-width: 210px;
  margin-top: 1px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}

.ui-language {
  display: grid;
  gap: 3px;
  min-width: 88px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.ui-language select {
  height: 30px;
  min-width: 0;
  padding: 3px 24px 3px 8px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 750;
}

.queue-button {
  display: grid;
  min-width: 64px;
  height: 44px;
  place-items: center;
  padding: 5px 10px;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 750;
}

.queue-button span:first-child {
  font-size: 18px;
  line-height: 1;
}

.workspace {
  display: grid;
  gap: 12px;
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 12px 10px calc(18px + env(safe-area-inset-bottom));
}

.mushaf-card,
.control-sheet,
.queue-dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mushaf-card {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.page-toolbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.page-input-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.page-input-wrap input {
  min-width: 0;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--ink);
  background: white;
  font-weight: 700;
}

.page-meta {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.mushaf-stage {
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  padding: 8px;
  background: #e3ebec;
}

.mushaf-page {
  display: grid;
  grid-template-rows: repeat(15, minmax(0, 1fr));
  align-content: stretch;
  width: min(100%, 390px);
  aspect-ratio: 31 / 50;
  padding: 4.2% 4.8%;
  border: 1px solid #d4c4aa;
  border-radius: 8px;
  direction: rtl;
  color: #111827;
  background: var(--page);
  box-shadow: 0 8px 26px rgba(22, 34, 42, 0.14);
  overflow: hidden;
}

.quran-line,
.qec-line {
  position: relative;
  display: flex;
  direction: rtl;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  color: #111827;
  font-family: var(--qec-page-font), "QEC-UthmanicHafs", "Traditional Arabic", serif;
  font-size: var(--quran-font-size, 24px);
  font-kerning: normal;
  font-synthesis: none;
  letter-spacing: 0;
  line-height: 1;
  text-rendering: optimizeLegibility;
  white-space: nowrap;
  word-spacing: 0;
}

.quran-line-empty,
.qec-line-empty {
  visibility: hidden;
}

.quran-line-centered,
.qec-line-centered {
  justify-content: center;
}

.quran-deco-line,
.qec-deco-line {
  justify-content: center;
  color: #24303a;
  font-family: "QEC-UthmanicHafs", "Traditional Arabic", serif;
}

.quran-surah-header,
.qec-surah-header {
  border-top: 1px solid rgba(97, 72, 38, 0.28);
  border-bottom: 1px solid rgba(97, 72, 38, 0.28);
  font-size: calc(var(--quran-font-size, 24px) * 0.66);
  font-weight: 700;
}

.quran-basmala,
.qec-basmala {
  font-size: calc(var(--quran-font-size, 24px) * 0.62);
}

.quran-word,
.qec-word {
  position: relative;
  z-index: 1;
  display: inline-block;
  border-radius: 5px;
  padding: 0 1px;
  color: #111827;
  letter-spacing: 0;
  user-select: none;
  word-spacing: 0;
}

.quran-word {
  cursor: pointer;
  touch-action: none;
}

.quran-word:hover {
  background: rgba(15, 118, 110, 0.13);
}

.quran-word.selected,
.qec-highlight {
  color: var(--qec-highlight-text);
  background: transparent;
  box-shadow: none;
}

.quran-highlight-fill,
.qec-highlight-fill {
  position: absolute;
  z-index: 0;
  border-radius: 5px;
  pointer-events: none;
  background: var(--qec-highlight-color);
}

.control-sheet {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.selection-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.selection-summary div {
  min-width: 0;
}

.eyebrow,
.form-grid label span,
.note-field span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.selection-summary strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-grid label,
.note-field {
  min-width: 0;
}

select,
textarea,
input[type="color"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
}

select {
  height: 42px;
  padding: 7px 9px;
}

input[type="color"] {
  height: 42px;
  padding: 4px;
}

textarea {
  min-height: 70px;
  padding: 9px 10px;
  resize: vertical;
}

.primary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary,
.secondary {
  min-height: 44px;
  font-weight: 800;
}

.primary {
  border-color: var(--green-dark);
  color: white;
  background: var(--green);
}

.secondary {
  color: var(--green-dark);
  background: #eef8f6;
}

.preview-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab.active {
  border-color: var(--green-dark);
  color: var(--green-dark);
  background: rgba(15, 118, 110, 0.09);
  font-weight: 800;
}

.anchor-plan {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.preview {
  display: none;
  max-height: 64vh;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #202326;
}

.preview.active {
  display: block;
}

.preview:empty {
  border-color: transparent;
  padding: 0;
  background: transparent;
}

.qec-card {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px;
  color: #e6ecec;
  font-family: Arial, sans-serif;
}

.qec-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 0 0 10px;
  color: #d7dde0;
  font-size: 12px;
}

.qec-card-meta span {
  border: 1px solid #56716f;
  border-radius: 999px;
  padding: 4px 8px;
  background: #23302f;
}

.qec-task,
.qec-anchor,
.qec-notes {
  max-width: 520px;
  margin: 10px auto;
  color: #e6ecec;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

.qec-anchor {
  padding: 10px;
  border: 1px solid #56716f;
  border-radius: 8px;
  background: #28302f;
  font-weight: 700;
}

.qec-page {
  --qec-page-width: min(100%, 390px);
  --quran-font-size: 22px;
  direction: rtl;
  display: grid;
  grid-template-rows: repeat(15, minmax(0, 1fr));
  align-content: stretch;
  width: var(--qec-page-width);
  aspect-ratio: 31 / 50;
  height: auto;
  margin: 0 auto;
  padding: 4.2% 4.8%;
  border: 1px solid #d4c4aa;
  border-radius: 8px;
  color: #111827;
  background: var(--page);
  overflow: hidden;
}

.qec-word-hidden {
  visibility: hidden;
  pointer-events: none;
}

.queue-dialog {
  width: min(92vw, 440px);
  max-height: min(760px, 86vh);
  padding: 0;
  color: var(--ink);
}

.queue-dialog::backdrop {
  background: rgba(10, 20, 24, 0.38);
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.dialog-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

.queue-list {
  display: grid;
  gap: 8px;
  max-height: 54vh;
  overflow: auto;
  padding: 12px;
}

.queue-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--surface-soft);
}

.queue-item strong {
  font-size: 14px;
}

.queue-item span {
  color: var(--muted);
  font-size: 12px;
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .mushaf-page,
html[dir="rtl"] .quran-line,
html[dir="rtl"] .qec-page,
html[dir="rtl"] .qec-line {
  direction: rtl;
}

html[dir="rtl"] .qec-card[dir="ltr"] {
  direction: ltr;
}

html[dir="rtl"] .qec-card[dir="rtl"] {
  direction: rtl;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.error {
  color: var(--danger);
}

@media (min-width: 860px) {
  .workspace {
    grid-template-columns: minmax(420px, 1fr) 420px;
    align-items: start;
    padding: 16px;
  }

  .app-topbar {
    padding-right: 16px;
    padding-left: 16px;
  }

  .mushaf-card {
    position: sticky;
    top: 82px;
  }

  .mushaf-stage {
    min-height: calc(100vh - 220px);
  }
}

@media (max-width: 420px) {
  .brand p {
    max-width: 150px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  h1 {
    font-size: 16px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .ui-language {
    min-width: 76px;
  }

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

  .ui-language select {
    height: 28px;
    font-size: 11px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .primary-actions {
    grid-template-columns: 1fr;
  }
}
