@font-face {
  font-family: "Qalam Majeed";
  src: url("../fonts/qalam_majeed.ttf") format("truetype");
  font-display: swap;
}

:root {
  --navy: #0b3d4a;
  --navy-deep: #072a33;
  --cyan: #1aa6b7;
  --cyan-soft: #e6f7f9;
  --teal: #00695c;
  --text: #12262c;
  --muted: #5a727a;
  --line: rgba(11, 61, 74, 0.12);
  --surface: #f4fafb;
  --card: #ffffff;
  --danger: #b42318;
  --shadow: 0 -8px 32px rgba(7, 42, 51, 0.18);
  --ayah-base: 1.875rem;
  --tr-base: 1rem;
  --scale: 1;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(26, 166, 183, 0.18), transparent 55%),
    linear-gradient(180deg, #eaf6f8 0%, var(--surface) 40%, #eef4f5 100%);
  color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}
body { padding-bottom: var(--safe-bottom); }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  padding: 0.75rem 1rem 0.85rem;
  box-shadow: 0 4px 18px rgba(7, 42, 51, 0.28);
}
.topbar-row { display: flex; align-items: center; gap: 0.5rem; }
.topbar-titles { flex: 1; min-width: 0; }
.topbar-titles h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 0.25rem; }

.icon-btn {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 999px;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.2); }
.icon-btn.sm { width: 2rem; height: 2rem; font-size: 1.25rem; }
.icon-btn.active { background: var(--cyan); color: #fff; }
.icon-btn.ghost-dark {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line);
}

.search-row {
  margin-top: 0.7rem;
  display: flex;
  gap: 0.45rem;
  align-items: center;
}
.search-row input[type="search"],
#bookmark-search,
#note-input {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  outline: none;
}
.search-nav {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  color: #fff;
  font-size: 0.78rem;
  white-space: nowrap;
}
/* Tombol tampil/sembunyi pemilih Surat / Ayat */
.jump-toggle {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.42rem 0.7rem;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.jump-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
}
.jump-toggle[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.22);
}
.jump-toggle-chevron {
  display: inline-block;
  transition: transform 0.18s ease;
  font-size: 0.75rem;
  opacity: 0.9;
}
.jump-toggle[aria-expanded="true"] .jump-toggle-chevron {
  transform: rotate(180deg);
}
/* Pemilih Surat / Ayat di bawah pencarian */
.jump-picker {
  display: grid;
  grid-template-columns: 1.55fr 0.7fr;
  gap: 0.55rem;
  margin-top: 0.45rem;
  padding: 0.55rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.jump-picker.hidden {
  display: none;
}
.jump-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.jump-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--navy);
  margin: 0 0 0.25rem 0.1rem;
}
.jump-filter {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
  background: #fff;
  color: var(--text);
  outline: none;
  margin-bottom: 0.35rem;
}
.jump-filter:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(26, 166, 183, 0.18);
}
.jump-list {
  height: 8.6rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    #000 12%,
    #000 88%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    #000 12%,
    #000 88%,
    transparent 100%
  );
}
.jump-item {
  appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.35;
  padding: 0.38rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.jump-col-aya .jump-item {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.jump-item:hover {
  background: rgba(11, 61, 74, 0.06);
}
.jump-item.is-selected {
  background: rgba(11, 61, 74, 0.1);
  font-weight: 700;
  color: var(--navy);
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}
.chip {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}
.chip:hover { background: rgba(255, 255, 255, 0.22); }
.chip.accent { background: var(--cyan); }

.main { padding: 0.85rem 0.85rem 5rem; }

.surah-list { display: flex; flex-direction: column; gap: 0.55rem; }
.surah-item {
  display: grid;
  grid-template-columns: 2.6rem 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.85rem 0.9rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  width: 100%;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.surah-item:hover {
  border-color: rgba(26, 166, 183, 0.45);
  box-shadow: 0 4px 14px rgba(11, 61, 74, 0.08);
}
.surah-item.hit {
  border-color: rgba(26, 166, 183, 0.4);
  background: #eef9fb;
}

.ayah-hit-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  text-align: left;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(26, 166, 183, 0.35);
  border-radius: 14px;
  background: #e8f6f8;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.ayah-hit-item:hover {
  border-color: rgba(26, 166, 183, 0.55);
  box-shadow: 0 4px 14px rgba(11, 61, 74, 0.08);
}
.ayah-hit-item strong {
  font-size: 0.95rem;
  color: var(--navy);
}
.ayah-hit-sub {
  font-size: 0.8rem;
  color: var(--muted);
}
.ayah-hit-preview {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.surah-no {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 12px;
  background: var(--cyan-soft);
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}
.surah-meta strong { display: block; font-size: 1rem; }
.surah-meta span {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.surah-ar {
  font-family: "Qalam Majeed", "Noto Naskh Arabic", serif;
  font-size: 1.35rem;
  color: var(--navy);
  direction: rtl;
}

.empty, .loading, .error {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
  font-size: 0.95rem;
}
.error { color: var(--danger); }

.ayah-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 0.95rem 0.85rem;
  margin-bottom: 0.7rem;
  scroll-margin-top: 9.5rem;
}
.ayah-card.match {
  border-color: rgba(26, 166, 183, 0.55);
  box-shadow: 0 0 0 2px rgba(26, 166, 183, 0.18);
}
.ayah-card.flash {
  animation: flash 1.2s ease;
}
@keyframes flash {
  0%, 100% { background: var(--card); }
  30% { background: #dff5f7; }
}
.ayah-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}
.ayah-toolbar-left {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.ayah-num {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy);
  background: var(--cyan-soft);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
}
.ayah-focus-btn {
  width: 2.45rem;
  height: 2.45rem;
  background: var(--cyan-soft);
  color: var(--navy);
  border: 1px solid rgba(26, 166, 183, 0.4);
  flex-shrink: 0;
}
.ayah-focus-btn:hover {
  background: var(--cyan);
  color: #fff;
  border-color: transparent;
}
.ayah-focus-btn .icon {
  display: block;
  width: 1.45rem;
  height: 1.45rem;
}
.ayah-actions { display: flex; gap: 0.25rem; }
.ayah-actions .icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 0.95rem;
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.ayah-actions .icon-btn .icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}
.ayah-actions .icon-btn.on {
  background: var(--cyan-soft);
  color: var(--cyan);
  border-color: rgba(26, 166, 183, 0.45);
}
.ayah-actions .icon-btn.on[data-kind="bookmark"] {
  color: var(--cyan);
}

.ayah-ar {
  font-family: "Qalam Majeed", "Noto Naskh Arabic", serif;
  font-size: calc(var(--ayah-base) * var(--scale));
  line-height: 1.85;
  direction: rtl;
  text-align: right;
  color: #0a2f38;
  margin: 0.35rem 0 0.55rem;
  /* jangan pecah shaping Arab / posisi tanda waqf */
  word-break: normal;
  overflow-wrap: anywhere;
  white-space: normal;
  font-feature-settings: "liga" 1, "calt" 1;
}
/* Legacy no-op: waqf kini glyph biasa menempel kata (lihat arabicDisplayHtml). */
.ayah-ar .waqf-slot,
.ayah-ar .waqf-mark {
  font-size: inherit;
  line-height: inherit;
}
.ayah-latin {
  font-style: italic;
  text-align: right;
  color: var(--muted);
  font-size: calc(var(--tr-base) * var(--scale));
  line-height: 1.55;
  margin: 0 0 0.45rem;
}
.ayah-tr {
  font-style: italic;
  text-align: right;
  color: var(--teal);
  font-size: calc(var(--tr-base) * var(--scale));
  line-height: 1.65;
  margin: 0;
}
.ayah-tr .fn-mark {
  font-style: normal;
  /* 75% dari ukuran font terjemahan */
  font-size: 0.75em;
  vertical-align: super;
  color: var(--danger);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}
.ayah-tr .fn-mark:hover { text-decoration: underline; }
.fn-card {
  margin-top: 0.65rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  background: #f0f7f8;
  border: 1px solid var(--line);
  /* 80% dari ukuran font terjemahan */
  font-size: calc(var(--tr-base) * var(--scale) * 0.8);
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
}
.fn-card .fn-num {
  color: var(--danger);
  font-weight: 700;
}
.fn-card a {
  color: var(--cyan);
  font-weight: 600;
  text-decoration: none;
}
.fn-card a:hover { text-decoration: underline; }

.wbw-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0.35rem;
  direction: rtl;
}
.wbw-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.2rem;
  padding: 0.25rem 0.2rem;
}
.wbw-ar {
  font-family: "Qalam Majeed", "Noto Naskh Arabic", serif;
  font-size: calc(var(--ayah-base) * var(--scale) * 0.72);
  line-height: 1.4;
  direction: rtl;
}
.wbw-tr {
  font-size: calc(0.72rem * var(--scale));
  color: var(--teal);
  text-align: center;
  margin-top: 0.15rem;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 42, 51, 0.45);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(720px, 100%);
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 0.65rem 1rem calc(1.1rem + var(--safe-bottom));
  z-index: 50;
  box-shadow: var(--shadow);
  max-height: 78vh;
  overflow: auto;
}
.sheet-tall { max-height: 86vh; }
.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #c9d6da;
  margin: 0.2rem auto 0.75rem;
}
.sheet h2 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
  color: var(--navy);
}
.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}
#font-slider { width: 100%; accent-color: var(--cyan); margin-bottom: 0.85rem; }
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
}
.toggle-row input { width: 1.15rem; height: 1.15rem; accent-color: var(--cyan); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--navy);
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}
.btn.primary {
  background: var(--cyan);
  border-color: transparent;
  color: #fff;
}
.btn.danger { color: var(--danger); border-color: rgba(180, 35, 24, 0.35); }
.btn.block { width: 100%; margin-top: 0.85rem; }
.btn-row { display: flex; gap: 0.55rem; margin-top: 0.85rem; }
.btn-row .btn { flex: 1; }

.bookmark-list { display: flex; flex-direction: column; gap: 0.55rem; margin: 0.75rem 0; }
.bookmark-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.8rem;
  background: #f7fbfc;
  cursor: pointer;
}
.bookmark-item strong { display: block; color: var(--navy); font-size: 0.95rem; }
.bookmark-item .ar {
  font-family: "Qalam Majeed", "Noto Naskh Arabic", serif;
  direction: rtl;
  text-align: right;
  margin: 0.4rem 0;
  font-size: 1.15rem;
  line-height: 1.6;
}
.bookmark-item .tr {
  font-style: italic;
  color: var(--teal);
  font-size: 0.88rem;
  text-align: right;
}
.bookmark-item .note {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.bookmark-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.bookmark-actions .btn { padding: 0.4rem 0.7rem; font-size: 0.8rem; }

#bookmark-search { margin-bottom: 0.25rem; background: #f2f7f8; }
#note-input {
  resize: vertical;
  min-height: 6rem;
  background: #f2f7f8;
  font: inherit;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.4rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(7, 42, 51, 0.28);
  max-width: min(90vw, 420px);
  text-align: center;
}
.hidden { display: none !important; }
mark.search-hit {
  background: #ffe08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.sheet-chat {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 720px);
  overflow: hidden;
  padding-bottom: calc(0.85rem + var(--safe-bottom));
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.chat-head h2 { margin: 0; }
.chat-hint {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}
.chat-messages {
  flex: 1;
  min-height: 220px;
  max-height: 48vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.15rem 0.1rem 0.55rem;
}
.chat-bubble {
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
}
.chat-bubble p { margin: 0; }
.chat-bubble.user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: #eef8fa;
  border: 1px solid rgba(26, 166, 183, 0.28);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-bubble.pending { opacity: 0.78; font-style: italic; }
.chat-ref {
  color: var(--teal);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-sources { margin-top: 0.65rem; }
.chat-sources-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.chat-sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.chat-source-chip {
  appearance: none;
  border: 1px solid rgba(26, 166, 183, 0.4);
  background: #fff;
  color: var(--navy);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 650;
  cursor: pointer;
}
.chat-source-chip:hover {
  background: var(--cyan-soft);
  border-color: var(--cyan);
}
.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
}
#chat-input {
  width: 100%;
  resize: none;
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: #f2f7f8;
  color: var(--text);
  font: inherit;
  outline: none;
  min-height: 3.1rem;
}
#btn-chat-send { min-width: 4.8rem; }

/* FAB Chat AI — pojok kanan bawah, melayang di atas konten */
.chat-fab {
  position: fixed;
  right: max(0.85rem, env(safe-area-inset-right, 0px));
  bottom: max(1.35rem, calc(0.85rem + env(safe-area-inset-bottom, 0px)));
  z-index: 70;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 10px 18px rgba(11, 61, 74, 0.3));
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.chat-fab:hover {
  transform: translateY(-2px) scale(1.03);
}
.chat-fab:active {
  transform: scale(0.97);
}
.chat-fab-icon {
  width: 4.1rem;
  height: 4.1rem;
  border-radius: 50%;
  display: block;
  object-fit: cover;
  background: #0b1220;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(26, 166, 183, 0.4);
}
body.sheet-open .chat-fab {
  opacity: 0;
  pointer-events: none;
}

.chat-tips {
  margin: 0.45rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text);
}
.chat-tips li { margin: 0.2rem 0; }
.chat-ayah-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.7rem;
}
.chat-ayah-card {
  border: 1px solid rgba(26, 166, 183, 0.3);
  background: #fff;
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
}
.chat-ayah-card:hover { border-color: var(--cyan); }
.chat-ayah-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.chat-ayah-head strong {
  font-size: 0.86rem;
  color: var(--navy);
}
.chat-ayah-open {
  appearance: none;
  border: 1px solid rgba(26, 166, 183, 0.45);
  background: var(--cyan-soft);
  color: var(--navy);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}
.chat-ayah-ar {
  margin: 0.25rem 0;
  font-family: "Qalam Majeed", "Noto Naskh Arabic", serif;
  font-size: 1.35rem;
  line-height: 1.7;
  text-align: right;
  color: var(--navy-deep);
}
.chat-ayah-latin {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}
.chat-ayah-tr {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  color: var(--teal);
  line-height: 1.4;
}
