/* ============================================================
   Quran Bundle Search — Global Stylesheet
   Design: dark navy, gold accents, Quranic Arabic typography
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Scheherazade+New:wght@400;700&family=Inter:wght@300;400;500;600&display=swap');

/* ---- Design Tokens ---------------------------------------- */
:root {
  /* Palette — warm parchment light theme */
  --c-bg:          #f5f0e8;
  --c-surface:     #faf7f2;
  --c-surface-2:   #ede8df;
  --c-border:      rgba(0,0,0,0.12);
  --c-gold:        #8a6500;
  --c-gold-dim:    rgba(138,101,0,0.12);
  --c-teal:        #1a7a6e;
  --c-teal-dim:    rgba(26,122,110,0.12);
  --c-red:         #9e2b2b;
  --c-red-dim:     rgba(158,43,43,0.10);
  --c-text:        #2c2416;
  --c-text-muted:  #6b5f4e;
  --c-text-dim:    #9e9182;

  /* Typography */
  --font-ui:       'Inter', system-ui, sans-serif;
  --font-arabic:   'Scheherazade New', 'Amiri', serif;

  /* Sizes */
  --radius-sm:  6px;
  --radius:     12px;
  --radius-lg:  18px;
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.10);
  --shadow:     0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.16);

  /* Transitions */
  --t-fast: 0.15s ease;
  --t:      0.25s ease;
  --t-slow: 0.4s ease;
}

/* ---- Reset ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 17.5px;
  scroll-behavior: smooth;
}

body {
  font-family:      var(--font-ui);
  background-color: var(--c-bg);
  color:            var(--c-text);
  min-height:       100vh;
  overflow-x:       hidden;
}

/* ---- Header ----------------------------------------------- */
.app-header {
  position:      sticky;
  top:           0;
  z-index:       100;
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  gap:           1.5rem;
  padding:       0.875rem 2rem;
  background:    rgba(245,240,232,0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-border);
  box-shadow:    var(--shadow-sm);
}

.header-brand {
  display:     flex;
  align-items: center;
  gap:         0.75rem;
  flex-shrink: 0;
}

.header-logo {
  width:  38px;
  height: 38px;
  opacity: 0.9;
}

.header-title {
  font-family: var(--font-arabic);
  font-size:   1.5rem;
  font-weight: 700;
  color:       var(--c-gold);
  line-height: 1;
  letter-spacing: -0.01em;
  direction:   rtl;
}

.header-subtitle {
  font-size:  0.7rem;
  color:      var(--c-text-muted);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* N (bundle size) control in header */
.n-control {
  display:     flex;
  align-items: center;
  gap:         0.5rem;
  background:  var(--c-surface);
  border:      1px solid var(--c-border);
  border-radius: var(--radius);
  padding:     0.4rem 0.8rem;
}

.n-label {
  font-size:  0.75rem;
  color:      var(--c-text-muted);
  white-space: nowrap;
}

.n-input {
  width:       3.5rem;
  padding:     0.25rem 0.4rem;
  background:  var(--c-surface-2);
  border:      1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color:       var(--c-text);
  font-family: var(--font-ui);
  font-size:   0.95rem;
  font-weight: 600;
  text-align:  center;
  direction:   ltr;
  transition:  border-color var(--t-fast), box-shadow var(--t-fast);
}

.n-input:focus {
  outline:      none;
  border-color: var(--c-gold);
  box-shadow:   0 0 0 3px rgba(138,101,0,0.18);
}

.n-apply-btn {
  padding:       0.3rem 0.7rem;
  background:    var(--c-gold-dim);
  border:        1px solid rgba(201,162,39,0.3);
  border-radius: var(--radius-sm);
  color:         var(--c-gold);
  font-size:     0.78rem;
  font-weight:   600;
  cursor:        pointer;
  white-space:   nowrap;
  transition:    background var(--t-fast), transform var(--t-fast);
}

.n-apply-btn:hover {
  background: rgba(201,162,39,0.25);
  transform:  translateY(-1px);
}

/* ---- Main layout ------------------------------------------ */
.app-main {
  max-width: 1200px;
  margin:    0 auto;
  padding:   2rem 1.5rem 4rem;
  display:   flex;
  flex-direction: column;
  gap:       2rem;
}

/* ---- Search panel ---------------------------------------- */
.search-panel {
  background:    var(--c-surface);
  border:        1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding:       1.5rem 1.75rem;
  box-shadow:    var(--shadow);
  display:       flex;
  flex-direction: column;
  gap:           1rem;
}

/* 3-column row: Must Exist | Semantic | Must NOT */
.search-fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 700px) {
  .search-fields-row {
    grid-template-columns: 1fr;
  }
}

.search-panel-title {
  font-family:  var(--font-ui);
  font-size:    1rem;
  font-weight:  600;
  color:        var(--c-gold);
  letter-spacing: 0.01em;
  margin-bottom: 0.25rem;
}

.search-field {
  display:       flex;
  flex-direction: column;
  gap:           0.5rem;
}

.field-label {
  display:     flex;
  align-items: center;
  gap:         0.5rem;
}

.field-label-main {
  font-family:  var(--font-ui);
  font-size:    0.88rem;
  font-weight:  600;
}

.field-label-main.must-exist { color: var(--c-teal); }
.field-label-main.must-not   { color: var(--c-red);  }
.field-label-main.semantic   { color: var(--c-gold); }


.field-label-hint {
  font-size:  0.7rem;
  color:      var(--c-text-muted);
  font-weight: 400;
}

/* legacy alias kept for backwards compat */
.field-label-en {
  font-size:  0.7rem;
  color:      var(--c-text-muted);
  font-weight: 400;
}

/* Tag input container */
.tag-input-wrap {
  position:      relative;
  display:       flex;
  flex-wrap:     wrap;
  align-items:   center;
  gap:           0.4rem;
  min-height:    2.8rem;
  padding:       0.45rem 0.65rem;
  background:    var(--c-bg);
  border:        1px solid var(--c-border);
  border-radius: var(--radius);
  cursor:        text;
  transition:    border-color var(--t-fast), box-shadow var(--t-fast);
}

.tag-input-wrap:focus-within {
  border-color: var(--c-teal);
  box-shadow:   0 0 0 3px rgba(26,122,110,0.20);
}

.tag-input-wrap.field-not-exist:focus-within {
  border-color: var(--c-red);
  box-shadow:   0 0 0 3px rgba(158,43,43,0.18);
}

/* Individual tags */
.tag {
  display:       inline-flex;
  align-items:   center;
  gap:           0.35rem;
  padding:       0.2rem 0.55rem;
  border-radius: 100px;
  font-family:   var(--font-arabic);
  font-size:     0.9rem;
  direction:     rtl;
  animation:     tagPop 0.18s ease;
}

@keyframes tagPop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.tag.tag-root {
  background: rgba(201,162,39,0.15);
  border:     1px solid rgba(201,162,39,0.35);
  color:      var(--c-gold);
}

.tag.tag-word {
  background: rgba(45,154,138,0.15);
  border:     1px solid rgba(45,154,138,0.35);
  color:      var(--c-teal);
}

.tag-type-badge {
  font-size:  0.6rem;
  opacity:    0.7;
  font-family: var(--font-ui);
  direction:  ltr;
  padding:    0 3px;
  border-radius: 3px;
  background: rgba(0,0,0,0.08);
}

.tag-remove {
  background: none;
  border:     none;
  cursor:     pointer;
  opacity:    0.6;
  font-size:  0.9rem;
  line-height: 1;
  padding:    0 2px;
  color:      inherit;
  transition: opacity var(--t-fast);
}
.tag-remove:hover { opacity: 1; }

/* Arabic text input inside tag wrap */
.arabic-input {
  flex:        1;
  min-width:   8rem;
  background:  none;
  border:      none;
  outline:     none;
  color:       var(--c-text);
  font-family: var(--font-arabic);
  font-size:   1rem;
  direction:   rtl;
  padding:     0.15rem 0.2rem;
}

.arabic-input::placeholder {
  color:    var(--c-text-dim);
  direction: rtl;
}

/* Autocomplete dropdown */
.autocomplete-dropdown {
  position:      absolute;
  top:           calc(100% + 4px);
  right:         0;
  left:          0;
  z-index:       200;
  background:    var(--c-surface-2);
  border:        1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow:    var(--shadow-lg);
  overflow:      hidden;
  overflow-y:    auto;
  max-height:    min(360px, 60vh);
  animation:     dropDown 0.15s ease;
}

@keyframes dropDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0);    }
}

.ac-section-header {
  padding:     0.3rem 0.75rem;
  font-size:   0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color:       var(--c-text-dim);
  background:  rgba(0,0,0,0.03);
  border-bottom: 1px solid var(--c-border);
}

.ac-item {
  display:     flex;
  align-items: center;
  justify-content: flex-start;
  padding:     0.5rem 0.75rem;
  cursor:      pointer;
  direction:   rtl;
  transition:  background var(--t-fast);
  gap:         0.4rem;
}

.ac-item:hover, .ac-item.ac-active {
  background: rgba(0,0,0,0.06);
}

.ac-item-text {
  font-family: var(--font-arabic);
  font-size:   1rem;
  display:     flex;
  align-items: baseline;
  gap:         0.4rem;
  direction:   rtl;
  flex-wrap:   wrap;
}

.ac-root-label {
  font-weight: 600;
}

.ac-root-samples {
  font-size:  0.75rem;
  color:      var(--c-text-muted);
  font-weight: 400;
  direction:  rtl;
  line-height: 1.4;
}


.ac-item-badge {
  font-size:   0.65rem;
  font-family: var(--font-ui);
  direction:   ltr;
  padding:     2px 6px;
  border-radius: 100px;
  margin-inline-start: auto;
  flex-shrink: 0;
}

.badge-root {
  background: rgba(201,162,39,0.15);
  color:      var(--c-gold);
  border:     1px solid rgba(201,162,39,0.3);
}

.badge-word {
  background: rgba(45,154,138,0.15);
  color:      var(--c-teal);
  border:     1px solid rgba(45,154,138,0.3);
}

.ac-item-count {
  font-size:   0.65rem;
  font-family: var(--font-arabic);
  direction:   rtl;
  color:       var(--c-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Semantic sort field */
.semantic-input {
  width:         100%;
  min-height:    2.8rem;
  padding:       0.65rem 0.85rem;
  background:    var(--c-bg);
  border:        1px solid var(--c-border);
  border-radius: var(--radius);
  color:         var(--c-text);
  font-family:   var(--font-ui);
  font-size:     0.9rem;
  direction:     ltr;
  transition:    border-color var(--t-fast), box-shadow var(--t-fast);
}

.semantic-input:focus {
  outline:      none;
  border-color: var(--c-gold);
  box-shadow:   0 0 0 3px rgba(138,101,0,0.18);
}

.semantic-input::placeholder { color: var(--c-text-dim); }

/* Search button */
.search-btn {
  display:       flex;
  align-items:   center;
  justify-content: center;
  gap:           0.6rem;
  width:         100%;
  padding:       0.9rem;
  background:    linear-gradient(135deg, #b8890f, #d4a82a);
  border:        none;
  border-radius: var(--radius);
  color:         #0b0d0e;
  font-family:   var(--font-arabic);
  font-size:     1.1rem;
  font-weight:   700;
  cursor:        pointer;
  transition:    filter var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  box-shadow:    0 3px 16px rgba(201,162,39,0.3);
}

.search-btn:hover {
  filter:    brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(201,162,39,0.4);
}

.search-btn:active {
  transform: translateY(0);
}

.search-btn.loading {
  opacity: 0.7;
  cursor:  not-allowed;
}

/* ---- Results panel --------------------------------------- */
.results-panel { display: flex; flex-direction: column; gap: 1rem; }

.results-header {
  display:     flex;
  align-items: center;
  gap:         0.75rem;
}

.results-count {
  display:       flex;
  align-items:   center;
  gap:           0.4rem;
  padding:       0.3rem 0.75rem;
  background:    var(--c-surface);
  border:        1px solid var(--c-border);
  border-radius: 100px;
  font-size:     0.8rem;
  color:         var(--c-text-muted);
}

.results-count .count-num {
  font-weight: 700;
  color:       var(--c-gold);
  font-size:   1rem;
}

/* Semantic status banner */
.sem-banner {
  display:       flex;
  align-items:   center;
  gap:           0.5rem;
  padding:       0.5rem 1rem;
  border-radius: var(--radius);
  font-size:     0.8rem;
  animation:     fadeIn 0.3s ease;
}

.sem-banner.computing {
  background: rgba(201,162,39,0.1);
  border:     1px solid rgba(201,162,39,0.25);
  color:      var(--c-gold);
}

.sem-banner.unavailable {
  background: rgba(0,0,0,0.03);
  border:     1px solid var(--c-border);
  color:      var(--c-text-muted);
}

/* Spinner */
.spinner {
  width:  14px;
  height: 14px;
  border: 2px solid rgba(138,101,0,0.25);
  border-top-color: var(--c-gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Bundle cards grid */
.results-grid {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap:                   1rem;
}

/* Bundle card */
.bundle-card {
  background:    var(--c-surface);
  border:        1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow:      hidden;
  cursor:        pointer;
  transition:    transform var(--t), box-shadow var(--t), border-color var(--t);
  animation:     cardIn 0.35s ease both;
  text-decoration: none;
  color:         inherit;
  display:       block;
}

.bundle-card:hover {
  transform:    translateY(-3px);
  border-color: rgba(138,101,0,0.40);
  box-shadow:   0 0 0 1px rgba(138,101,0,0.18), var(--shadow-lg);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         0.75rem 1rem;
  background:      rgba(0,0,0,0.03);
  border-bottom:   1px solid var(--c-border);
  direction:       rtl;
}

.card-surah-name {
  font-family: var(--font-arabic);
  font-size:   0.95rem;
  font-weight: 700;
  color:       var(--c-gold);
}

.card-surah-en {
  font-size:  0.7rem;
  color:      var(--c-text-muted);
  font-weight: 400;
  direction:  ltr;
}

.card-range {
  display:       flex;
  align-items:   center;
  gap:           0.3rem;
  font-size:     0.72rem;
  color:         var(--c-text-muted);
  direction:     ltr;
  padding:       0.2rem 0.5rem;
  background:    rgba(0,0,0,0.05);
  border-radius: 100px;
  border:        1px solid var(--c-border);
}

.card-body {
  padding:   0.9rem 1rem;
  direction: rtl;
  display:   flex;
  flex-direction: column;
  gap:       0.6rem;
}

.ayah-row {
  display:     flex;
  align-items: flex-start;
  gap:         0.6rem;
  direction:   rtl;
}

.ayah-num {
  flex-shrink:   0;
  width:         1.4rem;
  height:        1.4rem;
  display:       flex;
  align-items:   center;
  justify-content: center;
  font-size:     0.65rem;
  font-weight:   600;
  color:         var(--c-text-dim);
  background:    rgba(0,0,0,0.06);
  border-radius: 50%;
  margin-top:    0.2rem;
  flex-shrink:   0;
  direction:     ltr;
}

.ayah-text {
  font-family:  var(--font-arabic);
  font-size:    1.1rem;
  line-height:  2;
  color:        var(--c-text);
}

/* Highlighted word inside a verse */
mark.word-hl {
  background:    rgba(138, 101, 0, 0.22);
  color:         #4a2e00;
  border-radius: 4px;
  padding:       0 3px;
  font-style:    normal;
  box-shadow:    0 0 0 1px rgba(138, 101, 0, 0.38);
  transition:    background var(--t-fast);
}

/* Root match badge shown in card header */
.card-root-badge {
  display:       inline-flex;
  align-items:   center;
  padding:       0.15rem 0.45rem;
  border-radius: 100px;
  font-family:   var(--font-arabic);
  font-size:     0.8rem;
  direction:     rtl;
  background:    rgba(201, 162, 39, 0.12);
  border:        1px solid rgba(201, 162, 39, 0.3);
  color:         var(--c-gold);
  white-space:   nowrap;
}


/* ---- Empty / error state ---------------------------------- */
.state-empty {
  grid-column: 1 / -1;
  text-align:  center;
  padding:     4rem 2rem;
  color:       var(--c-text-muted);
}

.state-empty .empty-icon {
  font-size:    3rem;
  margin-bottom: 0.75rem;
  opacity:      0.4;
}

.state-empty .empty-title {
  font-size:    1.1rem;
  font-weight:  600;
  margin-bottom: 0.4rem;
  color:        var(--c-text-muted);
}

.state-empty .empty-en {
  font-size:  0.8rem;
  opacity:    0.6;
}

/* Global notice bar */
.notice {
  padding:       0.65rem 1rem;
  border-radius: var(--radius);
  font-size:     0.82rem;
  display:       flex;
  align-items:   center;
  gap:           0.5rem;
}

.notice.error {
  background: var(--c-red-dim);
  border:     1px solid rgba(201,80,80,0.3);
  color:      var(--c-red);
}

/* ---- Surah page ------------------------------------------- */
.surah-page {
  max-width:  min(98vw, 1400px);
  margin:     0 auto;
  padding:    2.5rem 2rem 6rem;
}

.surah-header {
  text-align:    center;
  margin-bottom: 2.5rem;
  padding:       2rem;
  background:    linear-gradient(135deg,
    rgba(138,101,0,0.09),
    rgba(26,122,110,0.06));
  border:        1px solid rgba(138,101,0,0.22);
  border-radius: var(--radius-lg);
}

.surah-header .surah-ar {
  font-family:  var(--font-arabic);
  font-size:    2.4rem;
  font-weight:  700;
  color:        var(--c-gold);
  direction:    rtl;
  line-height:  1.4;
}

.surah-header .surah-en {
  font-size:  0.9rem;
  color:      var(--c-text-muted);
  margin-top: 0.3rem;
}

.surah-header .surah-num {
  font-size:     0.75rem;
  color:         var(--c-text-dim);
  margin-top:    0.5rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Continuous-flow verse layout ──────────────────────────────────────────
   All ayahs flow as one paragraph. Each .verse-unit is display:inline so
   the Arabic text wraps freely across lines mid-ayah. The floating tooltip
   (#surah-tooltip) is positioned by JS on mousemove.
   ──────────────────────────────────────────────────────────────────────── */

.verses-flow {
  font-family:   var(--font-arabic);
  font-size:     1.45rem;
  line-height:   2.2;
  direction:     rtl;
  text-align:    right;
  color:         var(--c-text);
  padding:       0.5rem 0;
}

/* display:inline lets the verse text break mid-ayah across lines */
.verse-unit {
  display:    inline;
  cursor:     default;
  transition: background var(--t-fast), box-shadow var(--t-fast);
}

.verse-unit:hover {
  background:  rgba(138,101,0,0.10);
  box-shadow:  0 0 0 3px rgba(138,101,0,0.10);
  border-radius: 2px;
}

/* Highlighted bundle ayahs */
.verse-unit.highlighted {
  color:       #3a2500;
  background:  rgba(138,101,0,0.13);
  box-shadow:  0 0 0 3px rgba(138,101,0,0.13);
  border-radius: 2px;
}

/* Ayah number — displayed inline, e.g. "10" in a small circle.
   unicode-bidi:bidi-override + direction:ltr forces strict LTR rendering so
   the surrounding RTL context cannot mirror/reverse the numeral. */
.verse-num-inline {
  display:       inline;
  font-family:   serif;          /* keeps numerals upright & readable */
  font-size:     0.72em;
  color:         var(--c-gold);
  opacity:       0.75;
  margin-inline-start: 0.15em;
  margin-inline-end:   0.4em;
  user-select:   none;
  direction:     ltr;
  unicode-bidi:  bidi-override; /* override: force strict LTR, no mirroring */
}
/* Wrap in Arabic ornament brackets via CSS so they are always LTR-context */
.verse-num-inline::before { content: '\FD3E'; }   /* ﴿ */
.verse-num-inline::after  { content: '\FD3F'; }   /* ﴾ */

/* ── Floating translation tooltip (positioned by JS) ──────────────────────── */

.surah-tooltip {
  /* Fixed so it stays relative to the viewport (not the scroll position) */
  position:       fixed;
  z-index:        9999;
  pointer-events: none;

  /* Hidden until JS adds .visible */
  opacity:        0;
  transform:      translateY(4px);
  transition:     opacity 0.13s ease, transform 0.13s ease;

  /* Visual design */
  background:     rgba(252,249,244,0.98);
  border:         1px solid rgba(138,101,0,0.28);
  border-radius:  var(--radius);
  box-shadow:     0 8px 32px rgba(0,0,0,0.14),
                  0 0 0 1px rgba(138,101,0,0.08);
  padding:        0.7rem 1rem;
  max-width:      380px;

  /* Typography — LTR English */
  direction:      ltr;
  text-align:     left;
  font-family:    system-ui, sans-serif;
  font-size:      0.82rem;
  line-height:    1.65;
  font-style:     italic;
  color:          var(--c-text-muted);
}

.surah-tooltip.visible {
  opacity:   1;
  transform: translateY(0);
}

/* Verse number badge inside the floating tooltip */
.surah-tooltip-num {
  display:       inline-block;
  font-style:    normal;
  font-size:     0.72rem;
  font-weight:   700;
  color:         var(--c-gold);
  margin-inline-end: 0.4rem;
  background:    rgba(138,101,0,0.10);
  padding:       0.05rem 0.35rem;
  border-radius: 100px;
  border:        1px solid rgba(138,101,0,0.25);
}

/* ── Translation toggle bar ──────────────────────────────────────────────── */

.trans-bar {
  display:        flex;
  align-items:    center;
  gap:            0.75rem;
  margin-bottom:  1.25rem;
  flex-wrap:      wrap;
}

.trans-bar-label {
  font-size:   0.78rem;
  color:       var(--c-text-dim);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Segmented button group */
.trans-toggle {
  display:        flex;
  align-items:    center;
  background:     var(--c-surface);
  border:         1px solid var(--c-border);
  border-radius:  100px;
  padding:        3px;
  gap:            2px;
}

.trans-btn {
  padding:        0.3rem 0.85rem;
  border:         none;
  border-radius:  100px;
  background:     transparent;
  color:          var(--c-text-muted);
  font-size:      0.78rem;
  font-weight:    500;
  cursor:         pointer;
  transition:     background var(--t-fast), color var(--t-fast);
  white-space:    nowrap;
  line-height:    1.4;
}

.trans-btn:hover:not(:disabled) {
  background: rgba(0,0,0,0.07);
  color:      var(--c-text);
}

.trans-btn.active {
  background: var(--c-gold);
  color:      #0a0e1a;
  font-weight: 600;
}

.trans-btn:disabled {
  opacity:  0.35;
  cursor:   not-allowed;
}

/* Back button on surah page */

.back-btn {
  display:       inline-flex;
  align-items:   center;
  gap:           0.4rem;
  padding:       0.45rem 0.9rem;
  border:        1px solid var(--c-border);
  border-radius: 100px;
  color:         var(--c-text-muted);
  font-size:     0.8rem;
  cursor:        pointer;
  background:    transparent;
  margin-bottom: 1.5rem;
  transition:    color var(--t-fast), border-color var(--t-fast);
  text-decoration: none;
}

.back-btn:hover {
  color:        var(--c-text);
  border-color: var(--c-text-muted);
}

/* ---- Utility ---------------------------------------------- */
.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---- Responsive ------------------------------------------- */

/* Tablet: 3 columns → 2 columns at 900px */
@media (max-width: 900px) {
  .search-fields-row {
    grid-template-columns: 1fr 1fr;
  }
  /* Semantic sort spans full width as the third item */
  .search-fields-row .search-field:last-child {
    grid-column: 1 / -1;
  }
}

/* Mobile: single column below 700px */
@media (max-width: 700px) {
  .search-fields-row {
    grid-template-columns: 1fr;
  }
  .search-fields-row .search-field:last-child {
    grid-column: auto;
  }
}

/* Small screens */
@media (max-width: 640px) {
  .app-header {
    flex-wrap:  wrap;
    padding:    0.65rem 1rem;
    gap:        0.75rem;
  }

  .n-label { display: none; }

  .app-main { padding: 1rem 0.75rem 3rem; }

  .search-panel { padding: 1rem 0.85rem; }

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

  .header-title { font-size: 1.2rem; }

  .tag-remove {
    min-width:  28px;
    min-height: 28px;
    display:    flex;
    align-items: center;
    justify-content: center;
  }
}

/* Very small phones */
@media (max-width: 400px) {
  .app-main { padding: 0.75rem 0.5rem 2rem; }
  .search-panel { padding: 0.85rem 0.65rem; }
  .header-title { font-size: 1.05rem; }
  .header-subtitle { display: none; }
}

/* ---- Semantic character counter --------------------------- */
.semantic-counter {
  font-size:   0.72rem;
  color:       var(--c-text-dim);
  text-align:  right;
  margin-top:  0.3rem;
  transition:  color var(--t-fast);
}

.semantic-counter.over-limit {
  color:       var(--c-red);
  font-weight: 600;
}

/* ---- Results layout (grid + analysis sidebar) ------------- */
.results-layout {
  display:     flex;
  gap:         1.5rem;
  align-items: flex-start;
}

.results-layout .results-grid {
  flex:      1;
  min-width: 0;   /* prevent grid from overflowing flex container */
}

/* ---- Analysis panel --------------------------------------- */
.analysis-panel {
  width:         300px;
  flex-shrink:   0;
  position:      sticky;
  top:           5rem;          /* clears the sticky header */
  max-height:    calc(100vh - 6rem);
  overflow-y:    auto;
  background:    var(--c-surface);
  border:        1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding:       1.1rem 1rem;
  box-shadow:    var(--shadow);
  display:       flex;
  flex-direction: column;
  gap:           0;
}

/* Hide stopword items when checkbox is checked */
.analysis-panel.hide-stopwords .is-stopword { display: none; }

/* Hide word rows when roots-only mode is active */
.analysis-panel.roots-only .ap-row[data-kind="word"] { display: none; }

/* Inline toggle inside a section title */
.ap-inline-toggle {
  font-size:   0.62rem;
  font-weight: 400;
  color:       var(--c-text-muted);
  cursor:      pointer;
  margin-inline-start: 0.6rem;
  letter-spacing: 0;
  text-transform: none;
  vertical-align: middle;
}

.ap-inline-toggle input { cursor: pointer; }

/* Header row */
.ap-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             0.5rem;
  margin-bottom:   0.75rem;
}

.ap-title {
  font-size:   0.9rem;
  font-weight: 700;
  color:       var(--c-gold);
}

.ap-stopword-toggle {
  display:     flex;
  align-items: center;
  gap:         0.3rem;
  font-size:   0.68rem;
  color:       var(--c-text-muted);
  cursor:      pointer;
  white-space: nowrap;
}

.ap-stopword-toggle input { cursor: pointer; }

/* Sections */
.ap-section {
  border-top:  1px solid var(--c-border);
  padding:     0.75rem 0;
}

.ap-section-title {
  font-size:     0.75rem;
  font-weight:   700;
  color:         var(--c-text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.ap-hint {
  font-size:     0.65rem;
  color:         var(--c-text-dim);
  margin-bottom: 0.5rem;
  line-height:   1.4;
}

/* Sub-label (Roots / Words) */
.ap-sub { margin-bottom: 0.5rem; }

.ap-sub-label {
  font-size:   0.65rem;
  font-weight: 600;
  color:       var(--c-text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display:     block;
  margin-bottom: 0.3rem;
}

/* Chips for universal terms */
.ap-chips {
  display:   flex;
  flex-wrap: wrap;
  gap:       0.3rem;
}

.ap-chip {
  display:       inline-flex;
  align-items:   center;
  gap:           0.25rem;
  padding:       0.2rem 0.5rem;
  background:    var(--c-surface-2);
  border:        1px solid var(--c-border);
  border-radius: 100px;
  font-family:   var(--font-arabic);
  font-size:     0.85rem;
}

/* Distinctive term rows */
.ap-distinctive {
  display:        flex;
  flex-direction: column;
  gap:            0.15rem;
}

.ap-row {
  display:     flex;
  align-items: center;
  gap:         0.35rem;
  padding:     0.25rem 0.3rem;
  border-radius: var(--radius-sm);
  transition:  background var(--t-fast);
}

.ap-row:hover { background: rgba(0,0,0,0.05); }

.ap-term {
  flex:        1;
  font-family: var(--font-arabic);
  font-size:   0.9rem;
  min-width:   0;
  overflow:    hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ap-freq {
  font-size:   0.62rem;
  color:       var(--c-text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.ap-ratio {
  font-size:   0.75rem;
  font-weight: 700;
  color:       var(--c-gold);
  white-space: nowrap;
  flex-shrink: 0;
  min-width:   2.5rem;
  text-align:  right;
  direction:   ltr;
}

.ap-empty {
  font-size: 0.75rem;
  color:     var(--c-text-dim);
}

/* Mobile: sidebar collapses below cards */
@media (max-width: 900px) {
  .results-layout {
    flex-direction: column;
  }
  .results-layout .results-grid {
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    padding-right: 0.25rem;
  }
  .analysis-panel {
    width:     100%;
    position:  static;
    max-height: none;
  }
}

/* ---- Surah filter bar ------------------------------------- */
.surah-filter {
  display:     flex;
  align-items: center;
  flex-wrap:   wrap;
  gap:         0.4rem;
  padding:     0.6rem 0 0.9rem;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 1rem;
}

.sf-chips {
  display:   flex;
  flex-wrap: wrap;
  gap:       0.35rem;
  flex:      1;
}

.sf-chip {
  display:       inline-flex;
  align-items:   center;
  gap:           0.3rem;
  padding:       0.22rem 0.65rem;
  background:    var(--c-surface-2);
  border:        1px solid var(--c-border);
  border-radius: 100px;
  cursor:        pointer;
  font-size:     0.8rem;
  transition:    background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  user-select:   none;
}

.sf-chip.active {
  background:   rgba(201, 162, 39, 0.15);
  border-color: var(--c-gold);
  color:        var(--c-gold);
}

.sf-chip:not(.active) { opacity: 0.5; }

.sf-name { font-family: var(--font-arabic); }

.sf-actions {
  display:        flex;
  gap:            0.35rem;
  flex-shrink:    0;
}

.sf-btn {
  padding:       0.22rem 0.6rem;
  font-size:     0.7rem;
  background:    transparent;
  border:        1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color:         var(--c-text-muted);
  cursor:        pointer;
  white-space:   nowrap;
  transition:    color var(--t-fast), border-color var(--t-fast);
}

.sf-btn:hover { color: var(--c-gold); border-color: var(--c-gold); }

/* ---- Term hover highlight (teal — distinct from gold search highlights) --- */
[data-norm].term-hover {
  background:    rgba(56, 189, 176, 0.25);
  border-radius: 3px;
  outline:       1px solid rgba(56, 189, 176, 0.5);
  cursor:        default;
}

/* Chips in analysis panel: show pointer to hint they're hoverable */
.ap-chip[data-norm], .ap-row[data-norm] { cursor: default; }
.ap-chip[data-norm]:hover, .ap-row[data-norm]:hover {
  background: rgba(0,0,0,0.05);
  border-radius: var(--radius-sm);
}

/* ---- Bundle step control bar (in results panel) ----------- */
.step-control-bar {
  display:     flex;
  align-items: center;
  gap:         0.5rem;
  flex-wrap:   wrap;
  padding:     0.5rem 0 0.7rem;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 0.75rem;
}

.step-label {
  font-size:   0.78rem;
  font-weight: 500;
  color:       var(--c-text-muted);
  white-space: nowrap;
}

.step-input {
  width:         3.8rem;
  padding:       0.25rem 0.45rem;
  background:    var(--c-surface-2);
  border:        1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color:         var(--c-text);
  font-size:     0.85rem;
  text-align:    center;
  transition:    border-color var(--t-fast);
}

.step-input:focus {
  outline:      none;
  border-color: var(--c-gold);
}

.step-input::-webkit-inner-spin-button { opacity: 0.5; }

.step-hint {
  font-size:   0.7rem;
  color:       var(--c-text-dim);
  white-space: nowrap;
}

@media (max-width: 500px) {
  .step-hint { display: none; }
}

/* ============================================================
   MOBILE & TOUCH IMPROVEMENTS
   ============================================================ */

/* ---- Remove iOS/Android blue tap flash on all tappables -- */
a, button, [role="button"],
.bundle-card, .sf-chip, .ap-chip, .ap-row, .tag {
  -webkit-tap-highlight-color: transparent;
}

/* ---- Root font-size: reduce slightly on phones ------------ */
@media (max-width: 640px) {
  html { font-size: 16px; }
}

/* ---- Header: tighten on very small phones (≤360px) -------- */
@media (max-width: 360px) {
  .header-logo  { width: 28px; height: 28px; }
  .header-title { font-size: 1rem; }
  .n-input      { width: 2.8rem; }
  .n-apply-btn  { padding: 0.3rem 0.5rem; font-size: 0.7rem; }
}

/* ---- Larger touch targets on touch screens ---------------- */
@media (max-width: 900px) {
  /* Tag remove: ≥44px hit area */
  .tag-remove {
    min-width:   44px;
    min-height:  44px;
    display:     flex;
    align-items: center;
    justify-content: center;
  }

  /* Surah filter chips and buttons */
  .sf-btn {
    min-height: 40px;
    padding:    0.4rem 0.8rem;
  }

  /* N-apply button */
  .n-apply-btn { min-height: 40px; }

  /* Autocomplete rows: easier tap */
  .ac-item {
    min-height: 44px;
    padding:    0.65rem 0.75rem;
  }
}

/* ---- Surah filter: wrap action buttons on small screens --- */
@media (max-width: 640px) {
  .surah-filter {
    flex-direction: column;
    align-items:    flex-start;
  }
  .sf-chips   { width: 100%; }
  .sf-actions { width: 100%; justify-content: flex-start; }
}

/* ---- Analysis panel collapse toggle ----------------------- */
/*
 * The toggle button is always in the DOM (rendered by _renderAnalysis).
 * On desktop (>900px) it stays hidden via display:none.
 * On mobile (≤900px) it's visible and toggles .mobile-collapsed.
 */
.ap-toggle-btn {
  display:    none;       /* hidden on desktop */
  background: none;
  border:     none;
  color:      var(--c-text-muted);
  cursor:     pointer;
  font-size:  0.85rem;
  padding:    0.3rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: color var(--t-fast), transform var(--t-fast);
  flex-shrink: 0;
}

.ap-toggle-btn:hover { color: var(--c-gold); }
.ap-toggle-btn.open  { transform: rotate(180deg); }

@media (max-width: 900px) {
  .ap-toggle-btn { display: flex; align-items: center; }

  /* Collapsed: hide sections but keep the title row visible */
  .analysis-panel.mobile-collapsed .ap-section        { display: none; }
  .analysis-panel.mobile-collapsed .ap-stopword-toggle { display: none; }
}

/* ---- Momentum scroll on analysis panel (iOS) -------------- */
.analysis-panel {
  -webkit-overflow-scrolling: touch;
}

/* ---- Autocomplete: limit height when phone keyboard is up - */
@media (max-width: 700px) {
  .autocomplete-dropdown {
    max-height: min(240px, 40vh);
  }
}

/* ---- Cards: slightly less padding to fit more content ----- */
@media (max-width: 640px) {
  .card-header { padding: 0.6rem 0.75rem; }
  .card-body   { padding: 0.75rem 0.75rem; }
}

/* ---- Surah detail page on mobile -------------------------- */
@media (max-width: 640px) {
  .surah-header            { padding: 1.25rem; margin-bottom: 1.5rem; }
  .surah-header .surah-ar  { font-size: 1.8rem; }
  .verses-flow             { font-size: 1.2rem; line-height: 2.1; }
  /* Keep floating tooltip from overflowing screen edges on small screens */
  .surah-tooltip           { max-width: calc(100vw - 2rem); }
}

/* Prevent highlighted verse from scrolling under the browser bar */
.verse-unit.highlighted {
  scroll-margin-top: 80px;
}

/* ============================================================
   Guide Button & Modal
   ============================================================ */

/* Wrapper to group N-control + guide button in header */
.header-right-controls {
  display:     flex;
  align-items: center;
  gap:         0.6rem;
  flex-shrink: 0;
}

/* The "?" button in the header */
.guide-btn {
  display:       flex;
  align-items:   center;
  justify-content: center;
  width:         32px;
  height:        32px;
  border-radius: 50%;
  border:        1px solid var(--c-border);
  background:    var(--c-surface);
  color:         var(--c-text-muted);
  font-size:     0.9rem;
  font-weight:   600;
  cursor:        pointer;
  transition:    background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  flex-shrink:   0;
}
.guide-btn:hover {
  background:    var(--c-gold-dim);
  border-color:  var(--c-gold);
  color:         var(--c-gold);
}

/* Full-screen overlay */
.guide-overlay {
  position:   fixed;
  inset:      0;
  z-index:    500;
  background: rgba(155,140,120,0.78);
  backdrop-filter: blur(8px);
  display:    flex;
  align-items: center;
  justify-content: center;
  padding:    1.5rem;
  opacity:    0;
  pointer-events: none;
  transition: opacity var(--t);
}
.guide-overlay.open {
  opacity:        1;
  pointer-events: all;
}

/* Modal card */
.guide-modal {
  position:       relative;
  background:     var(--c-surface);
  border:         1px solid var(--c-border);
  border-radius:  var(--radius-lg);
  box-shadow:     var(--shadow-lg);
  max-width:      700px;
  width:          100%;
  max-height:     85vh;
  overflow-y:     auto;
  padding:        2.5rem 2.5rem 2rem;
  transform:      translateY(16px);
  transition:     transform var(--t);
}
.guide-overlay.open .guide-modal {
  transform: translateY(0);
}

/* Close button */
.guide-close {
  position:   absolute;
  top:        1rem;
  right:      1.2rem;
  background: none;
  border:     none;
  color:      var(--c-text-muted);
  font-size:  1.6rem;
  line-height: 1;
  cursor:     pointer;
  transition: color var(--t-fast);
}
.guide-close:hover { color: var(--c-text); }

/* Modal title */
.guide-title {
  font-size:      1.4rem;
  font-weight:    600;
  color:          var(--c-gold);
  margin-bottom:  1.75rem;
  padding-right:  2rem; /* don't overlap close button */
}

/* Section list */
.guide-sections {
  display:        flex;
  flex-direction: column;
  gap:            1.4rem;
}

.guide-section {
  border-left:  2px solid var(--c-border);
  padding-left: 1rem;
}
.guide-section--tip {
  border-left-color: var(--c-gold);
  background:        var(--c-gold-dim);
  border-radius:     0 var(--radius-sm) var(--radius-sm) 0;
  padding:           0.75rem 1rem;
}

.guide-section-title {
  font-size:    0.78rem;
  font-weight:  600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color:        var(--c-gold);
  margin-bottom: 0.45rem;
}

.guide-section p {
  font-size:   0.85rem;
  line-height: 1.7;
  color:       var(--c-text);
}
.guide-section p + p {
  margin-top:  0.6rem;
}

/* The DF ratio formula block */
.guide-formula {
  font-family:  monospace;
  font-size:    0.82rem !important;
  background:   var(--c-surface-2);
  border:       1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding:      0.4rem 0.75rem;
  color:        var(--c-teal) !important;
  margin:       0.5rem 0 !important;
}

/* Code tags inside guide (model name) */
.guide-section code {
  font-family:     monospace;
  font-size:       0.78rem;
  background:      var(--c-surface-2);
  border:          1px solid var(--c-border);
  border-radius:   4px;
  padding:         0.1em 0.4em;
  color:           var(--c-teal);
  white-space:     nowrap;
}

/* Tips list */
.guide-tips {
  list-style: none;
  display:    flex;
  flex-direction: column;
  gap:        0.45rem;
}
.guide-tips li {
  font-size:   0.85rem;
  line-height: 1.6;
  color:       var(--c-text);
  padding-left: 1.2em;
  position:    relative;
}
.guide-tips li::before {
  content:    '›';
  position:   absolute;
  left:       0;
  color:      var(--c-gold);
  font-weight: 700;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .guide-modal   { padding: 1.5rem 1.25rem 1.25rem; max-height: 90vh; }
  .guide-title   { font-size: 1.15rem; }
}


/* ============================================================
   Hero Banner
   ============================================================ */
.hero-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: 1rem;
  margin-bottom: 2rem;
  padding: 0 1rem;
}

.hero-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  opacity: 0.95;
  filter: drop-shadow(0 0 15px rgba(201, 162, 39, 0.25));
  transition: transform var(--t);
}

.hero-logo:hover {
  transform: scale(1.05);
}

.hero-title {
  font-family: var(--font-arabic);
  font-size: 3rem;
  font-weight: 700;
  color: var(--c-gold);
  margin-top: 0.2rem;
  line-height: 1.1;
  text-shadow: 0 1px 6px rgba(0,0,0,0.15);
}

.hero-subtitle {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--c-text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 0.2rem;
  opacity: 0.8;
}

.hero-tagline {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  max-width: 540px;
  margin-top: 0.6rem;
  line-height: 1.5;
}

/* Mobile responsive adjustments */
@media (max-width: 640px) {
  .hero-banner {
    margin-top: 0.5rem;
    margin-bottom: 1.2rem;
  }
  .hero-logo {
    width: 90px;
    height: 90px;
  }
  .hero-title {
    font-size: 2.3rem;
  }
  .hero-subtitle {
    font-size: 0.7rem;
  }
  .hero-tagline {
    font-size: 0.7rem;
    max-width: 100%;
  }
}


