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

:root {
  --bg:           #0e0c0a;
  --bg-sidebar:   #13100d;
  --bg-card:      #1a1510;
  --bg-hover:     #201a13;
  --border:       #2e261a;
  --border-light: #3d3328;
  --gold:         #c9a96e;
  --gold-dim:     #8a6f45;
  --gold-bright:  #e8c88a;
  --cream:        #f0e6d0;
  --cream-dim:    #b8a98c;
  --text:         #d4c8b0;
  --text-muted:   #7a6e5c;
  --player-h:     80px;
  --font-arabic:  'Scheherazade New', serif;
  --font-body:    Verdana, Geneva, sans-serif;
  --sidebar-w:    400px;
  --radius:       6px;
  --transition:   0.22s ease;
}

html { scroll-behavior: smooth; }

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

/* Page mode */
body.page-mode #reader { padding: 40px 0 120px; }
body.page-mode .surah-view { max-width: 100%; }
body.page-mode .ayahs-container { padding: 0; }
body.page-mode .ayah {
  padding: 40px 60px;
  border-bottom: 1px solid var(--border);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
body.page-mode .surah-header { padding: 80px 60px 60px; }
body.page-mode .surah-nav { margin: 0 60px; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 24px 22px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.logo { display: flex; flex-direction: column; gap: 4px; }

.logo-arabic {
  font-family: var(--font-arabic);
  font-size: 2rem;
  color: var(--gold);
  line-height: 1;
}

.logo-english {
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.view-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.view-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 0;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.view-btn.view-active { background: var(--gold-dim); color: var(--bg); }

.search-wrap { position: relative; }

#search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 9px 14px;
  outline: none;
  transition: border-color var(--transition);
}

#search-input::placeholder { color: var(--text-muted); }
#search-input:focus { border-color: var(--gold-dim); }

#search-results {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  max-height: 340px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

#search-results.visible { display: block; }

.search-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-hover); }

.search-item-ref {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 3px;
}

.search-item-text {
  font-size: 0.8rem;
  color: var(--cream-dim);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Surah list — smooth scroll */
.surah-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  min-height: 0;
  scroll-behavior: smooth;
}

.surah-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  cursor: pointer;
  transition: background var(--transition);
  border-left: 2px solid transparent;
}

.surah-item:hover { background: var(--bg-hover); border-left-color: var(--gold-dim); }
.surah-item.active { background: var(--bg-card); border-left-color: var(--gold); }

.surah-number {
  font-size: 0.68rem;
  color: var(--text-muted);
  width: 26px;
  text-align: right;
  flex-shrink: 0;
}

.surah-info { flex: 1; min-width: 0; }

.surah-item-english {
  font-size: 0.84rem;
  color: var(--cream-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.surah-item-meaning {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
}

.surah-item-arabic {
  font-family: var(--font-arabic);
  font-size: 1.15rem;
  color: var(--gold-dim);
  flex-shrink: 0;
  direction: rtl;
}

/* ── Top controls ────────────────────────────────────────────────────────── */
.top-controls {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 300;
  display: flex;
  gap: 8px;
}

.top-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  color: var(--gold-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), border-color var(--transition);
}

.top-btn svg { width: 18px; height: 18px; }
.top-btn:hover, .top-btn.active { color: var(--gold); border-color: var(--gold-dim); }

/* ── Mobile toggle ───────────────────────────────────────────────────────── */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 11px;
  cursor: pointer;
  flex-direction: column;
  gap: 5px;
}

#sidebar-toggle span {
  display: block;
  width: 20px; height: 1.5px;
  background: var(--gold);
  border-radius: 2px;
}

/* ── Theme panel ─────────────────────────────────────────────────────────── */
.theme-panel {
  position: fixed;
  top: 52px; right: 16px;
  z-index: 300;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.theme-panel-title {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.theme-panel-divider { height: 1px; background: var(--border); margin: 14px 0; }

.theme-buttons { display: flex; flex-direction: column; gap: 6px; }

.theme-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  text-align: left;
}

.theme-btn.active { border-color: var(--gold-dim); color: var(--gold); }
.theme-btn:hover  { border-color: var(--gold-dim); color: var(--cream-dim); }

.theme-swatch {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
}

.custom-theme-inputs {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.rgb-input-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.rgb-input-group label {
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.rgb-input-group input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.78rem;
  padding: 5px 4px;
  text-align: center;
  outline: none;
}

/* Hide spinners */
.rgb-input-group input::-webkit-outer-spin-button,
.rgb-input-group input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rgb-input-group input[type=number] { -moz-appearance: textfield; }

.custom-apply-btn {
  background: var(--gold-dim);
  border: none;
  border-radius: 4px;
  color: var(--bg);
  font-family: var(--font-body);
  font-size: 0.72rem;
  padding: 7px 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
  white-space: nowrap;
}

.custom-apply-btn:hover { background: var(--gold); }

/* ── Main Reader ─────────────────────────────────────────────────────────── */
#reader {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 60px 24px 120px;
  position: relative;
  z-index: 1;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  min-height: 80vh;
  gap: 18px;
  animation: fadeUp 0.7s ease both;
}

.welcome-ornament { font-size: 1.4rem; color: var(--gold-dim); animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:0.5} 50%{opacity:1} }

.welcome-arabic {
  font-family: var(--font-arabic);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  color: var(--gold);
  direction: rtl;
  line-height: 1.6;
}

.welcome-translation { font-size: 0.95rem; color: var(--cream-dim); font-style: italic; letter-spacing: 0.02em; }
.welcome-hint { font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-muted); margin-top: 12px; }

.surah-view { width: 100%; max-width: 800px; animation: fadeUp 0.5s ease both; }

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

.surah-header { text-align: center; padding: 48px 0 36px; border-bottom: 1px solid var(--border); }
.surah-meta { display: flex; gap: 8px; justify-content: center; margin-bottom: 22px; }

.badge {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
}

.surah-arabic-name {
  font-family: var(--font-arabic);
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  color: var(--gold);
  direction: rtl;
  line-height: 1.4;
  margin-bottom: 12px;
}

.surah-title-divider {
  width: 50px; height: 1px;
  background: linear-gradient(to right, transparent, var(--gold-dim), transparent);
  margin: 12px auto;
}

.surah-english-name { font-size: clamp(1rem, 3vw, 1.4rem); color: var(--cream); letter-spacing: 0.06em; margin-bottom: 5px; }
.surah-meaning { font-size: 0.85rem; color: var(--text-muted); font-style: italic; }

.bismillah {
  font-family: var(--font-arabic);
  font-size: clamp(1.3rem, 3.5vw, 1.9rem);
  color: var(--gold-dim);
  direction: rtl;
  margin-top: 28px;
  line-height: 1.6;
}

/* ── Ayahs ───────────────────────────────────────────────────────────────── */
.ayahs-container { padding: 10px 0 40px; }

.ayah {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  padding: 28px 0 28px 4px;
  transition: background var(--transition), padding-left var(--transition);
  cursor: pointer;
  border-left: 2px solid transparent;
}

.ayah:last-child { border-bottom: none; }
.ayah:hover { background: rgba(201,169,110,0.03); }

.ayah.playing { background: rgba(201,169,110,0.06); border-left-color: var(--gold); padding-left: 18px; }
.ayah.sajdah  { border-left-color: var(--gold-dim); padding-left: 18px; }
.ayah.sajdah.playing { border-left-color: var(--gold); }

.sajdah-badge {
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 8px;
}

.ayah-arabic {
  font-family: var(--font-arabic);
  font-size: clamp(1.5rem, 3.5vw, 2rem);
  line-height: 2;
  direction: rtl;
  text-align: right;
  color: var(--cream);
}

.ayah-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 10px;
}

.ayah-divider::before, .ayah-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.ayah-number {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-dim);
  flex-shrink: 0;
}

.ayah-translation {
  font-size: 0.95rem;
  line-height: 1.85;
  color: var(--text-muted);
  font-style: italic;
}

.surah-nav {
  display: flex;
  justify-content: space-between;
  padding: 28px 0 16px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  padding: 10px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.nav-btn:hover:not(:disabled) { color: var(--gold); border-color: var(--gold-dim); background: var(--bg-hover); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Loading ─────────────────────────────────────────────────────────────── */
.reader-loading { display:flex; align-items:center; justify-content:center; min-height:60vh; width:100%; }
.loading-surahs { display:flex; align-items:center; justify-content:center; padding:40px; }

.spinner { width:22px; height:22px; border:2px solid var(--border-light); border-top-color:var(--gold-dim); border-radius:50%; animation:spin .7s linear infinite; }
.spinner.large { width:36px; height:36px; border-width:3px; }
@keyframes spin { to{transform:rotate(360deg)} }

/* ── Player ──────────────────────────────────────────────────────────────── */
.player {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-w); right: 0;
  height: var(--player-h);
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 28px;
  z-index: 99;
  transition: transform 0.3s ease;
}

.player.hidden { transform: translateY(100%); display: flex !important; }

.player-surah-info { display:flex; flex-direction:column; min-width:130px; gap:2px; }
.player-surah-name { font-size:0.8rem; color:var(--cream-dim); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.player-ayah-label { font-size:0.62rem; letter-spacing:.15em; text-transform:uppercase; color:var(--gold-dim); }

.player-controls { display:flex; align-items:center; gap:6px; flex-shrink:0; }

.player-btn {
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
  width: 36px; height: 36px;
}

.player-btn svg { width:16px; height:16px; }
.player-btn:hover { color:var(--gold); background:rgba(201,169,110,0.08); }

.play-btn { background:var(--gold-dim); color:var(--bg); width:42px; height:42px; }
.play-btn svg { width:18px; height:18px; }
.play-btn:hover { background:var(--gold); color:var(--bg); }

.player-right { flex:1; display:flex; flex-direction:column; gap:4px; min-width:0; }

.player-progress-wrap { display:flex; align-items:center; gap:10px; }

.player-time { font-size:0.62rem; color:var(--text-muted); font-variant-numeric:tabular-nums; flex-shrink:0; width:28px; }

.player-progress-bar {
  flex:1; height:3px;
  background:var(--border-light);
  border-radius:2px; cursor:pointer; position:relative;
}

.player-progress-fill {
  height:100%; width:0%;
  background:var(--gold-dim);
  border-radius:2px;
  transition:width .25s linear;
  pointer-events:none;
}

.player-progress-bar:hover .player-progress-fill { background:var(--gold); }

.player-bottom-row { display:flex; align-items:center; gap:18px; }

.player-volume-wrap { display:flex; align-items:center; gap:8px; }
.volume-icon { width:14px; height:14px; color:var(--text-muted); flex-shrink:0; }

.volume-slider {
  -webkit-appearance:none; appearance:none;
  width:70px; height:3px;
  background:var(--border-light); border-radius:2px; outline:none; cursor:pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance:none;
  width:10px; height:10px; border-radius:50%;
  background:var(--gold-dim); cursor:pointer;
}

.volume-slider:hover::-webkit-slider-thumb { background:var(--gold); }

.player-speed-wrap, .player-reciter-wrap { display:flex; align-items:center; gap:6px; }

.speed-label { font-size:0.6rem; letter-spacing:.12em; text-transform:uppercase; color:var(--text-muted); white-space:nowrap; }

.speed-select, .reciter-select {
  background:var(--bg-card); border:1px solid var(--border);
  border-radius:4px; color:var(--text-muted);
  font-family:var(--font-body); font-size:0.72rem;
  padding:3px 6px; outline:none; cursor:pointer;
}

.speed-select:focus, .reciter-select:focus { border-color:var(--gold-dim); }

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

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { transform:translateX(-100%); width:85vw; }
  #sidebar.open { transform:translateX(0); }
  #sidebar-toggle { display:flex; }
  #reader { margin-left:0; padding:70px 16px 130px; }
  .player { left:0; padding:0 16px; gap:12px; }
  .player-surah-info { min-width:80px; }
  .player-right { display:none; }
  .surah-nav { flex-direction:column; }
  .nav-btn { text-align:center; }
  body.page-mode .ayah { padding:30px 20px; min-height:auto; }
  body.page-mode .surah-header { padding:40px 20px 30px; }
  body.page-mode .surah-nav { margin:0 20px; }
}

/* ── Texture ─────────────────────────────────────────────────────────────── */
body::before {
  content:''; position:fixed; inset:0; pointer-events:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  opacity:0.4; z-index:0;
}

#sidebar { z-index:100; }