* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Amiri", "Noto Naskh Arabic", serif;
  background: #e8ddc4;
  color: #2b2118;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: #3a2a1a;
  color: #f4ecd8;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: baseline; gap: 0.5rem; }
.topbar h1 { margin: 0; font-size: 1.4rem; }
.topbar .subtitle { font-size: 0.85rem; opacity: 0.7; }
.mode-switch { display: flex; gap: 0.4rem; }
.mode {
  padding: 0.35rem 0.8rem;
  border: 1px solid #c9b896;
  background: #f4ecd8;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
}
.mode.active { background: #3a2a1a; color: #f4ecd8; border-color: #3a2a1a; }
.topbar input[type=text], .topbar input[type=number] {
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: none;
  font-family: inherit;
}
.topbar-actions { display: flex; gap: 0.4rem; margin-inline-start: auto; }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  background: #f0e6d2;
  border-inline-end: 1px solid #c9b896;
  padding: 1rem;
  overflow: auto;
}
.sidebar h3 { margin: 0 0 0.5rem; color: #3a2a1a; }
.sidebar select {
  width: 100%;
  height: 60vh;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid #c9b896;
  border-radius: 6px;
  background: #fbf6e9;
}
.sidebar input[type=number] { width: 100%; padding: 0.4rem; border-radius: 6px; border: 1px solid #c9b896; }
.hint { font-size: 0.8rem; color: #6b5a3a; }

.main {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: auto;
}
.mushaf-header { text-align: center; margin-bottom: 0.5rem; }
.info { color: #6b5a3a; font-size: 0.95rem; }
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 900px;
  margin: 0 auto 0.5rem;
  width: 100%;
}
.pager button {
  padding: 0.4rem 1rem;
  border: 1px solid #c9b896;
  background: #f4ecd8;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.book {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: stretch;
  max-width: 1500px;
  margin: 0 auto 1rem;
  padding: 1rem;
  background: transparent;
}
.mushaf {
  flex: 1;
  max-width: 720px;
  min-width: 320px;
}
.ayah {
  cursor: pointer;
  padding: 0 0.15rem;
  border-radius: 4px;
  transition: background 0.15s;
}
.ayah:hover { background: rgba(139,90,43,0.15); }
.ayah.selected { background: rgba(139,90,43,0.3); }
.ayah-num {
  font-size: 0.75rem;
  color: #8b5a2b;
  vertical-align: super;
  margin: 0 0.15rem;
}
.spinner { color: #8b5a2b; font-style: italic; text-align: center; }

.panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  overflow: auto;
  background: #fff;
  border-top: 3px solid #3a2a1a;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
  padding: 1rem;
  z-index: 10;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.selected-ayah { font-size: 1.1rem; font-weight: bold; color: #3a2a1a; }
.panel-actions { display: flex; align-items: center; gap: 0.5rem; }
#closePanel { background: none; border: none; font-size: 1.6rem; cursor: pointer; }
.tabs { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.tab {
  padding: 0.4rem 1rem;
  border: 1px solid #c9b896;
  background: #f4ecd8;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
}
.tab.active { background: #3a2a1a; color: #f4ecd8; }
.tab-content { white-space: pre-wrap; font-size: 1.05rem; line-height: 1.8; }
.tab-content h4 { color: #3a2a1a; margin: 0.75rem 0 0.25rem; }
.tab-content .uthmani { font-size: 1.3rem; display: block; margin: 0.5rem 0; }

.ctx-menu { position: fixed; display: none; background: #fff; border: 1px solid #c9b896; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 20; padding: 0.25rem; min-width: 140px; }
.ctx-menu button { display: block; width: 100%; text-align: right; padding: 0.4rem 0.8rem; border: none; background: none; cursor: pointer; font-family: inherit; font-size: 1rem; border-radius: 4px; }
.ctx-menu button:hover { background: #f4ecd8; }

.analysis-overlay[hidden] { display: none !important; }
.analysis-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.analysis-box {
  background: #fbf6e9;
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  padding: 1.25rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.analysis-header { display: flex; justify-content: space-between; align-items: center; }
.analysis-header h2 { margin: 0; color: #3a2a1a; }
#closeAnalysis { background: none; border: none; font-size: 1.6rem; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.75rem 0; }
.chip { padding: 0.3rem 0.8rem; border: 1px solid #c9b896; background: #f4ecd8; border-radius: 16px; cursor: pointer; font-family: inherit; font-size: 0.9rem; }
.chip:hover { background: #3a2a1a; color: #f4ecd8; }
#analysisInput { width: 100%; padding: 0.5rem; font-family: inherit; font-size: 1rem; border: 1px solid #c9b896; border-radius: 6px; }
#analysisAsk { margin-top: 0.5rem; padding: 0.5rem 1.2rem; border: none; background: #3a2a1a; color: #f4ecd8; border-radius: 6px; cursor: pointer; font-family: inherit; }
.analysis-output { margin-top: 1rem; white-space: pre-wrap; background: #fff; padding: 1rem; border-radius: 6px; border: 1px solid #c9b896; max-height: 40vh; overflow: auto; }

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { height: 200px; }
  .book { flex-direction: column; }
  .page-left { display: none; }
  .mushaf { font-size: 1.15rem; }
}

.layout-page {
  background: #fbf6e9;
  padding: 2rem 2.2rem;
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  border: 1px solid #b8a07a;
  max-width: 720px;
  margin: 0 auto;
  min-height: 900px;
  position: relative;
  font-family: "Amiri", "Noto Naskh Arabic", serif;
}
.surah-header-line {
  text-align: center;
  font-size: 1.6rem;
  color: #3a2a1a;
  font-weight: bold;
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #8b5a2b;
}
.basmala-line {
  text-align: center;
  font-size: 1.5rem;
  margin: 0.6rem 0;
  color: #3a2a1a;
}
.mushaf-line {
  line-height: 2.6;
  font-size: 1.45rem;
  text-align: justify;
  text-justify: inter-word;
  margin-bottom: 0.15rem;
  cursor: pointer;
  border-radius: 4px;
  padding: 0.1rem 0.25rem;
  letter-spacing: 0.02em;
}
.mushaf-line:hover { background: rgba(139,90,43,0.12); }
.page-number {
  text-align: center;
  color: #8b5a2b;
  margin-top: 1rem;
  font-size: 0.95rem;
  border-top: 1px solid #c9b896;
  padding-top: 0.5rem;
}
