/* Keep border-box local to Render v2 and its qiraat controls. */
body.rv2-active .rv2-wrap,
body.rv2-active .rv2-wrap *,
body.rv2-active [id^="rv2-"],
body.rv2-active [id^="rv2-"] *,
body.rv2-active .rv2-qiraat-control,
body.rv2-active .rv2-qiraat-control * {
  box-sizing: border-box;
}

.rv2-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 24px auto;
  padding-inline: clamp(8px, 2vw, 20px);
  text-align: center;
}

body.rv2-active .navbar-main,
body.rv2-active .navbar-right,
body.rv2-active .search-select-forms.has-rv2-qiraat {
  min-width: 0;
}

body.rv2-active .navbar-right {
  flex: 1 1 auto;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
}

body.rv2-active .search-select-forms.has-rv2-qiraat {
  display: flex;
  flex: 1 1 auto;
  flex-flow: row wrap;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 6px 10px;
  min-width: 0;
  max-width: 100%;
}

body.rv2-active .authentication,
body.rv2-active .not-loggedin-user-icon,
body.rv2-active .login-signup-buttons {
  flex: 0 0 auto;
}

.search-select-forms.has-rv2-qiraat .surah-verse-submit-btn-bigscreen {
  margin-right: 10px;
}

.rv2-qiraat-control,
.rv2-qiraat-control-navbar {
  display: flex;
  flex: 0 1 auto;
  align-items: flex-end;
  align-self: flex-end;
  gap: 4px;
  width: auto;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  white-space: nowrap;
}

.rv2-qiraat-control label,
.rv2-qiraat-control-navbar label,
label[for="rv2-qiraat-select"] {
  display: block;
  flex: 0 0 auto;
  position: static;
  top: auto;
  height: 21px;
  margin: 0 5px 0 0;
  color: #222;
  font-family: "futura-pt", sans-serif;
  font-size: 14px;
  font-style: normal;
  font-weight: 500;
  line-height: 21px;
  white-space: nowrap;
  cursor: default;
}

.rv2-qiraat-select,
#rv2-qiraat-select {
  flex: 0 1 190px;
  width: 190px;
  min-width: 0;
  max-width: 190px;
  height: 21px;
  min-height: 21px;
  margin: 0;
  padding: 0 24px 0 5px;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  background-color: #5db3e1;
  color: #000;
  font-family: Arial, sans-serif;
  font-size: 13.3333px;
  font-style: normal;
  font-weight: 400;
  line-height: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
  align-self: flex-end;
}

.rv2-qiraat-select option {
  color: #000;
  font-family: Arial, sans-serif;
  font-size: 13.3333px;
  font-style: normal;
  font-weight: 400;
}

.rv2-verse {
  direction: rtl;
  font-family: "Scheherazade New", serif;
  font-size: 56px;
  line-height: 2.2;
  word-spacing: 0.35em;
}

@media (max-width: 700px) {
  body.rv2-active .search-select-forms.has-rv2-qiraat {
    display: flex;
    flex: 0 1 auto;
    flex-flow: row wrap;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 7px 8px;
    width: auto;
    max-width: 100%;
  }

  body.rv2-active .surah-verse-selection-form,
  body.rv2-active .search-container-bigscreen {
    min-width: 0;
    max-width: 100%;
  }

  .rv2-qiraat-control,
  .rv2-qiraat-control-navbar {
    display: flex;
    flex: 0 1 auto;
    align-items: flex-end;
    gap: 4px;
    width: auto;
    max-width: 100%;
  }

  .rv2-qiraat-select,
  #rv2-qiraat-select {
    flex: 0 1 auto;
    width: clamp(100px, 32vw, 190px);
    max-width: 190px;
    height: 21px;
    min-height: 21px;
    padding: 0 24px 0 5px;
  }

  body.rv2-active .rv2-verse {
    font-size: clamp(2.6rem, 8vw, 3.5rem);
    line-height: 2.05;
    word-spacing: 0.25em;
  }
}

@media (max-width: 600px) {
  body.rv2-active .navbar-right {
    align-items: flex-end;
    gap: 8px;
  }

  .rv2-qiraat-control label,
  .rv2-qiraat-control-navbar label,
  label[for="rv2-qiraat-select"] {
    height: 21px;
    margin-right: 3px;
    line-height: 21px;
  }

  .rv2-qiraat-select,
  #rv2-qiraat-select {
    height: 21px;
    min-height: 21px;
  }

  body.rv2-active .not-loggedin-user-icon {
    display: flex;
    position: relative;
    right: auto;
    bottom: auto;
    width: 36px;
    height: 36px;
  }

  body.rv2-active .login-signup-logo {
    position: static;
    width: 32px;
    height: 32px;
  }

  body.rv2-active .rv2-verse {
    word-spacing: 0.22em;
  }
}

@media (max-width: 430px) {
  .rv2-qiraat-control,
  .rv2-qiraat-control-navbar {
    flex: 0 1 auto;
    gap: 3px;
    width: auto;
    max-width: 100%;
  }

  .rv2-qiraat-select,
  #rv2-qiraat-select {
    width: clamp(96px, 32vw, 138px);
    max-width: 138px;
  }
}

@media (max-width: 360px) {
  .rv2-qiraat-control label,
  .rv2-qiraat-control-navbar label,
  label[for="rv2-qiraat-select"] {
    margin-right: 2px;
    font-size: 13px;
  }

  .rv2-qiraat-select,
  #rv2-qiraat-select {
    width: clamp(92px, 31vw, 112px);
    max-width: 112px;
  }

  body.rv2-active .rv2-verse {
    font-size: clamp(2rem, 9vw, 2.4rem);
    line-height: 2.1;
  }
}

.rv2-group {
  display: inline;
  white-space: normal;
}

.rv2-qiraat-active-group {
  border-radius: 7px;
}

.rv2-qiraat-locus-marker {
  box-shadow:
    inset 0 -0.075em 0
    rgba(180, 120, 20, 0.38);
  cursor: pointer;
}

.rv2-qiraat-flash {
  animation: rv2QiraatSwapFlash 1800ms ease-out;
}

@keyframes rv2QiraatSwapFlash {
  0% {
    background: rgba(245, 158, 11, 0.38);
    box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.22);
  }
  55% {
    background: rgba(245, 158, 11, 0.18);
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.12);
  }
  100% {
    background: transparent;
    box-shadow: none;
  }
}

.rv2-hitbox {
  position: absolute;
  background: transparent;
  cursor: pointer;
  z-index: 900;
}

.rv2-hitbox-qiraat-group {
  border-radius: 7px;
}

.rv2-hitbox-qiraat-char {
  border-radius: 3px;
}

::highlight(rv2-hover-char) {
  color: #d32f2f;
}

::highlight(rv2-active-word) {
  background-color: rgba(255, 214, 102, 0.55);
}

.rv2-hitbox-active-word {
  background-color: rgba(255, 214, 102, 0.22);
}

body.rv2-active .rv2-draggable-modal-handle {
  position: relative;
  cursor: move;
  touch-action: none;
  user-select: none;
}

body.rv2-active .rv2-modal-close {
  position: absolute;
  top: 50%;
  right: 9px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 24px;
  padding: 0;
}

body.rv2-active .rv2-modal-close:hover,
body.rv2-active .rv2-modal-close:focus {
  background: rgba(255, 255, 255, 0.34);
  outline: none;
}

body.rv2-modal-dragging,
body.rv2-modal-dragging * {
  user-select: none;
}

body.rv2-active #rv2-word-modal {
  width: min(520px, calc(100vw - 28px));
  max-height: min(78vh, 680px);
  overflow-y: auto;
  padding: 0.75rem 0.85rem;
  font-size: 0.82rem;
  line-height: 1.25;
}

body.rv2-active #rv2-word-modal .modal-header {
  margin-top: -28px;
  margin-right: -13px;
  margin-left: -13px;
}

body.rv2-active #rv2-word-modal .word-modal-header {
  padding: 10px 18px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

body.rv2-active .rv2-word-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 12px;
}

body.rv2-active .rv2-word-grid p,
body.rv2-active #rv2-word-profile p {
  margin: 3px 0;
}

body.rv2-active #rv2-profile-divider,
body.rv2-active #rv2-morph-divider,
body.rv2-active #rv2-qiraat-divider {
  border: 0;
  border-top: 1px solid #e0e0e0;
  margin: 8px 0;
}

body.rv2-active #rv2-morph-section h3,
body.rv2-active #rv2-qiraat-section h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  font-weight: 700;
}

body.rv2-active #rv2-morph-list,
body.rv2-active #rv2-qiraat-list {
  display: grid;
  gap: 6px;
}

body.rv2-active .rv2-morph-row {
  border: 1px solid #e6e6e6;
  border-radius: 6px;
  padding: 6px 8px;
  background: #fbfbfb;
}

body.rv2-active .rv2-morph-row-header {
  font-weight: 700;
  margin-bottom: 3px;
}

body.rv2-active .rv2-morph-text {
  font-family: "Scheherazade New", serif;
  font-size: 1.28rem;
  line-height: 1;
}

body.rv2-active .rv2-morph-label {
  color: #263238;
}

body.rv2-active .rv2-morph-arabic,
body.rv2-active .rv2-morph-irab {
  font-family: "Scheherazade New", serif;
  font-size: 1rem;
  line-height: 1.25;
}

body.rv2-active .rv2-morph-line,
body.rv2-active .rv2-morph-note {
  color: #333;
}

body.rv2-active .rv2-morph-note {
  font-size: 0.78rem;
  color: #666;
}

body.rv2-active .rv2-qiraat-row {
  border: 1px solid rgba(245, 158, 11, 0.24);
  border-radius: 6px;
  padding: 7px 8px;
  background: rgba(245, 158, 11, 0.07);
}

body.rv2-active .rv2-qiraat-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 3px;
}

body.rv2-active .rv2-qiraat-badge {
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}

body.rv2-active .rv2-qiraat-tone-amber {
  background: #f59e0b;
  color: #fff7ed;
}

body.rv2-active .rv2-qiraat-tone-green,
body.rv2-active .rv2-qiraat-tone-light-green {
  background: #15803d;
  color: #f0fdf4;
}

body.rv2-active .rv2-qiraat-tone-neutral {
  background: #64748b;
  color: #f8fafc;
}

body.rv2-active .rv2-qiraat-readings {
  font-family: "Scheherazade New", serif;
  font-size: 1.28rem;
  line-height: 1.2;
}


body.rv2-active .rv2-qiraat-reading-line {
  display: grid;
  grid-template-columns: minmax(112px, auto) minmax(0, 1fr);
  align-items: baseline;
  gap: 6px 10px;
  margin: 3px 0;
}

body.rv2-active .rv2-qiraat-reading-label {
  font-family: "Open Sans", sans-serif;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: left;
}

body.rv2-active .rv2-qiraat-reading-arabic {
  min-width: 0;
  overflow-wrap: break-word;
  text-align: right;
}

body.rv2-active .rv2-qiraat-line {
  color: #444;
  font-size: 0.76rem;
  line-height: 1.25;
}

body.rv2-active #verse-modal {
  width: min(430px, calc(100vw - 28px));
  max-height: min(76vh, 620px);
  overflow-y: auto;
  padding: 0.72rem 0.85rem;
  font-size: 0.82rem;
  line-height: 1.25;
}

body.rv2-active #verse-modal .modal-header {
  margin-top: -28px;
  margin-right: -13px;
  margin-left: -13px;
}

body.rv2-active #verse-modal .verse-modal-header {
  padding: 10px 18px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

body.rv2-active #verse-modal p {
  margin: 4px 0;
}

body.rv2-active #verse-character-list,
body.rv2-active #verse-character-list-lafz {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 10px;
  margin: 4px 0 8px;
}

body.rv2-active #verse-character-list li,
body.rv2-active #verse-character-list-lafz li {
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 520px) {
  body.rv2-active .rv2-qiraat-reading-line {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  body.rv2-active .rv2-qiraat-reading-label {
    text-align: left;
  }

  body.rv2-active #verse-character-list,
  body.rv2-active #verse-character-list-lafz {
    grid-template-columns: 1fr;
  }
}

/* Render v2: use the existing char-modal position, only smooth visibility/content */
body.rv2-active #char-modal {
  display: flex !important;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 260ms ease-in-out,
    visibility 260ms ease-in-out;
}

body.rv2-active #char-modal.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

body.rv2-active #char-modal.hidden {
  display: flex !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Responsive modal and safe-area maintenance. */
@media (max-width: 700px) {
  body.rv2-active #rv2-word-modal,
  body.rv2-active #verse-modal,
  body.rv2-active #surah-modal {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }

  body.rv2-active .rv2-modal-close {
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
}

@media (max-width: 520px) {
  body.rv2-active .rv2-word-grid,
  body.rv2-active #verse-character-list,
  body.rv2-active #verse-character-list-lafz {
    grid-template-columns: 1fr;
  }

  body.rv2-active .rv2-qiraat-row-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  body.rv2-active #char-modal {
    top: auto;
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    max-height: min(42vh, 320px);
    max-height: min(42dvh, 320px);
    margin: 0;
    overflow-y: auto;
    gap: 8px 12px;
    overscroll-behavior: contain;
  }

  body.rv2-active #char-modal .char-info {
    min-width: 0;
    white-space: normal;
  }
}

/* Qiraat card: user-facing two-vocabulary layout. */
.rv2-qiraat-row-header {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.rv2-qiraat-subheading {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  font-weight: 700;
}

.rv2-qiraat-rule-ar {
  display: inline-block;
  font-family: "Scheherazade New", serif;
  font-size: 1.15em;
}

.rv2-qiraat-quantitative {
  margin-top: 10px;
  padding-top: 6px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.rv2-qiraat-quantitative summary {
  cursor: pointer;
  font-weight: 650;
}

.rv2-qiraat-quantitative-narrative {
  margin: 8px 0;
}
