/* =========================================
   TAJWID COLOR SYSTEM
   ========================================= */

/* Tajwid words dengan warna */
.word[class*="tajwid-"] {
  position: relative;
  padding: .2rem .3rem;
  border-radius: .5rem;
  background: rgba(255, 255, 255, .08);
  transition: all .2s ease;
}

.word[class*="tajwid-"]:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 2px 8px currentColor;
}

/* Tooltip untuk menampilkan nama hukum tajwid */
.word[data-tajwid] {
  position: relative;
}

/* Default: Tooltip di atas */
.word[data-tajwid]::before {
  content: attr(data-tajwid);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, .95);
  color: white;
  padding: .4rem .75rem;
  border-radius: .6rem;
  font-size: .7rem;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  line-height: 1.2;
}

/* Arrow di atas (default) */
.word[data-tajwid]::after {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(15, 23, 42, .95);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
  z-index: 999;
}

/* Hover state - tooltip muncul */
.word[data-tajwid]:hover::before {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.word[data-tajwid]:hover::after {
  opacity: 1;
}

/* Fallback: Jika terpotong di atas, tampilkan di bawah */
/* Deteksi baris pertama dengan menggunakan parent container */
.ayah-arab .word[data-tajwid]:hover::before {
  /* Coba tampilkan di atas dulu */
  bottom: calc(100% + 8px);
  top: auto;
}

/* Force tooltip ke bawah untuk safety */
.word[data-tajwid].show-below::before {
  bottom: auto;
  top: calc(100% + 8px);
  transform: translateX(-50%);
}

.word[data-tajwid].show-below::after {
  bottom: auto;
  top: calc(100% + 2px);
  border-top-color: transparent;
  border-bottom-color: rgba(15, 23, 42, .95);
}

.word[data-tajwid].show-below:hover::before {
  transform: translateX(-50%) translateY(2px);
}

/* Alternative: Gunakan max-height pada container untuk mencegah overflow */
.ayah-card {
  overflow: visible !important;
}

.ayah-arab {
  overflow: visible !important;
  position: relative;
  padding-top: 2rem; /* Beri ruang untuk tooltip */
}

/* Dark mode tooltip */
body.dark-mode .word[data-tajwid]::before {
  background: rgba(255, 255, 255, .95);
  color: #0f172a;
}

body.dark-mode .word[data-tajwid]::after {
  border-top-color: rgba(255, 255, 255, .95);
}

/* =========================================
   TAJWID TOGGLE BUTTON
   ========================================= */
.tajwid-toggle-container {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem .9rem;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid rgba(148,163,184,.12);
  border-radius: 1rem;
  box-shadow: 0 4px 12px rgba(15,23,42,.06);
  margin-bottom: .75rem;
}

.tajwid-toggle-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.tajwid-toggle-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -.01em;
}

.tajwid-toggle-desc {
  font-size: .65rem;
  color: var(--color-text-muted);
}

/* Toggle Switch */
.tajwid-switch {
  position: relative;
  width: 48px;
  height: 26px;
  background: #e2e8f0;
  border-radius: 999px;
  cursor: pointer;
  transition: all .3s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .1);
}

.tajwid-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
}

.tajwid-switch.active {
  background: linear-gradient(135deg, var(--color-primary), #22c55e);
}

.tajwid-switch.active::before {
  left: 24px;
}

body.dark-mode .tajwid-toggle-container {
  background: linear-gradient(135deg, rgba(30,41,59,.6), rgba(15,23,42,.5));
  border-color: rgba(148,163,184,.15);
}

body.dark-mode .tajwid-switch {
  background: rgba(30,41,59,.8);
}

/* =========================================
   TAJWID LEGEND (KETERANGAN) - COMPACT VERSION
   ========================================= */
.tajwid-legend {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid rgba(148,163,184,.12);
  border-radius: 1rem;
  padding: .85rem 1rem;
  box-shadow: 0 4px 12px rgba(15,23,42,.06);
  margin-bottom: 1rem;
}

.tajwid-legend-title {
  font-size: .75rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: .65rem;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.tajwid-legend-title i {
  font-size: .85rem;
  color: var(--color-primary);
}

/* Legend Grid - Horizontal & Compact */
.tajwid-legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.tajwid-legend-item {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .55rem;
  background: rgba(248,250,252,.6);
  border: 1px solid rgba(148,163,184,.08);
  border-radius: .6rem;
  transition: all .2s ease;
  white-space: nowrap;
}

.tajwid-legend-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(15,23,42,.08);
  border-color: rgba(11,122,117,.2);
}

.tajwid-legend-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.tajwid-legend-text {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.tajwid-legend-name {
  font-size: .68rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1;
}

/* Hide description by default untuk compact view */
.tajwid-legend-desc {
  display: none;
}

/* Show description on hover atau di desktop */
@media (min-width: 768px) {
  .tajwid-legend-item:hover .tajwid-legend-desc {
    display: inline;
    font-size: .6rem;
    color: var(--color-text-muted);
    margin-left: .25rem;
  }
  
  .tajwid-legend-item:hover .tajwid-legend-name::after {
    content: ' â€¢ ';
    margin: 0 .2rem;
  }
}

body.dark-mode .tajwid-legend {
  background: linear-gradient(135deg, rgba(30,41,59,.6), rgba(15,23,42,.5));
  border-color: rgba(148,163,184,.15);
}

body.dark-mode .tajwid-legend-item {
  background: rgba(30,41,59,.4);
  border-color: rgba(148,163,184,.12);
}

body.dark-mode .tajwid-legend-item:hover {
  background: rgba(30,41,59,.6);
  border-color: rgba(94,234,212,.2);
}

/* =========================================
   FEATURE TOGGLE - MODERN & COMPACT
   ========================================= */
.feature-toggle-container {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .75rem .85rem;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid rgba(148,163,184,.12);
  border-radius: 1rem;
  box-shadow: 0 2px 8px rgba(15,23,42,.04);
  margin-bottom: .65rem;
  transition: all .2s ease;
}

.feature-toggle-container:hover {
  box-shadow: 0 4px 12px rgba(15,23,42,.08);
}

.feature-toggle-icon {
  width: 36px;
  height: 36px;
  border-radius: .8rem;
  background: linear-gradient(135deg, rgba(11,122,117,.12), rgba(11,122,117,.08));
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
  transition: all .3s ease;
}

.feature-toggle-container:hover .feature-toggle-icon {
  transform: scale(1.05);
  background: linear-gradient(135deg, var(--color-primary), #0d9488);
  color: white;
}

.feature-toggle-label {
  flex: 1;
  min-width: 0;
}

.feature-toggle-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -.01em;
  line-height: 1.2;
}

.feature-toggle-desc {
  font-size: .68rem;
  color: var(--color-text-muted);
  margin-top: .15rem;
  line-height: 1.2;
}

/* Toggle Switch - Reuse existing style */
.feature-toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: #e2e8f0;
  border-radius: 999px;
  cursor: pointer;
  transition: all .3s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .1);
  flex-shrink: 0;
}

.feature-toggle-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
}

.feature-toggle-switch.active {
  background: linear-gradient(135deg, var(--color-primary), #22c55e);
}

.feature-toggle-switch.active::before {
  left: 22px;
}

body.dark-mode .feature-toggle-container {
  background: linear-gradient(135deg, rgba(30,41,59,.6), rgba(15,23,42,.5));
  border-color: rgba(148,163,184,.15);
}

body.dark-mode .feature-toggle-icon {
  background: linear-gradient(135deg, rgba(94,234,212,.15), rgba(94,234,212,.1));
  color: #5eead4;
}

body.dark-mode .feature-toggle-container:hover .feature-toggle-icon {
  background: linear-gradient(135deg, var(--color-primary), #0d9488);
  color: white;
}

body.dark-mode .feature-toggle-switch {
  background: rgba(30,41,59,.8);
}

/* =========================================
   FEATURE INFO - COLLAPSIBLE
   ========================================= */
.feature-info-collapsible {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid rgba(245,158,11,.2);
  border-radius: 1rem;
  overflow: hidden;
  margin-bottom: .75rem;
  box-shadow: 0 2px 8px rgba(245,158,11,.1);
}

.feature-info-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem .85rem;
  background: none;
  border: none;
  cursor: pointer;
  transition: all .2s ease;
  text-align: left;
}

.feature-info-toggle:hover {
  background: rgba(255, 255, 255, .3);
}

.feature-info-toggle i:first-child {
  font-size: .85rem;
  color: #d97706;
}

.feature-info-toggle span {
  flex: 1;
  font-size: .75rem;
  font-weight: 600;
  color: #92400e;
}

.feature-info-arrow {
  font-size: .7rem;
  color: #d97706;
  transition: transform .3s ease;
}

.feature-info-collapsible.expanded .feature-info-arrow {
  transform: rotate(180deg);
}

.feature-info-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
}

.feature-info-collapsible.expanded .feature-info-content {
  max-height: 200px;
}

.feature-info-list {
  margin: 0;
  padding: 0 .85rem .75rem 2rem;
  list-style: none;
}

.feature-info-list li {
  font-size: .7rem;
  color: #92400e;
  line-height: 1.5;
  margin-bottom: .35rem;
  position: relative;
}

.feature-info-list li::before {
  content: 'â€¢';
  position: absolute;
  left: -.8rem;
  color: #d97706;
  font-weight: 700;
  font-size: .9rem;
}

.feature-info-list li:last-child {
  margin-bottom: 0;
}

body.dark-mode .feature-info-collapsible {
  background: linear-gradient(135deg, rgba(245,158,11,.2), rgba(217,119,6,.15));
  border-color: rgba(245,158,11,.3);
}

body.dark-mode .feature-info-toggle span {
  color: #fbbf24;
}

body.dark-mode .feature-info-list li {
  color: #fde68a;
}

@media (max-width: 640px) {
  .feature-toggle-container {
    padding: .65rem .75rem;
  }
  
  .feature-toggle-icon {
    width: 32px;
    height: 32px;
    font-size: .85rem;
  }
  
  .feature-toggle-title {
    font-size: .75rem;
  }
  
  .feature-toggle-desc {
    font-size: .65rem;
  }
  
  .feature-toggle-switch {
    width: 40px;
    height: 22px;
  }
  
  .feature-toggle-switch::before {
    width: 18px;
    height: 18px;
  }
  
  .feature-toggle-switch.active::before {
    left: 20px;
  }
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 640px) {
  .tajwid-legend-grid {
    grid-template-columns: 1fr;
  }
  
  .tajwid-toggle-container {
    padding: .6rem .75rem;
  }
  
  .word[data-tajwid]::before {
    font-size: .6rem;
    padding: .3rem .5rem;
  }
}

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes tajwidPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: .7;
  }
}

.word[class*="tajwid-"].pulse {
  animation: tajwidPulse 2s infinite;
}

/* =========================================
   ACCESSIBILITY
   ========================================= */
.tajwid-switch:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

body.dark-mode .tajwid-switch:focus-visible {
  outline-color: #5eead4;
}

/* Print styles - hide colors when printing */
@media print {
  .word[class*="tajwid-"] {
    color: black !important;
    background: none !important;
  }
  
  .tajwid-legend,
  .tajwid-toggle-container {
    display: none;
  }
}