:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --surface: #fffaf0;
  --surface-soft: #eee7dc;
  --ink: #1f2520;
  --muted: #74736b;
  --line: #ded5c4;
  --accent: #2f5d50;
  --accent-soft: #e3ede7;
  --warm: #a7753a;
  --shadow: 0 16px 44px rgba(53, 43, 30, 0.1);
  --arabic-size: 36px;
  --dhivehi-size: 22px;
  font-family: "MV Waheed", Faruma, "Noto Sans Thaana", "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151713;
  --surface: #1d211b;
  --surface-soft: #252a23;
  --ink: #f5efe2;
  --muted: #b8b09f;
  --line: #38392f;
  --accent: #9ec9b7;
  --accent-soft: #26362f;
  --warm: #d8b16d;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    url("asset-2.png") top -130px left -120px / 260px auto no-repeat,
    url("asset-4.png") bottom -150px right -120px / 260px auto no-repeat,
    radial-gradient(circle at top right, rgba(167, 117, 58, 0.1), transparent 34rem),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  max-width: 1120px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.sidebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  direction: rtl;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  border: 1px solid var(--line);
  object-fit: contain;
  object-position: center;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(53, 43, 30, 0.12);
}

.eyebrow,
.brand .eyebrow,
.hero-band,
.hero-stats,
.content-notice,
.install-button,
.import-panel {
  display: none;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 650;
  color: var(--ink);
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 620;
}

.nav-list {
  display: flex;
  align-items: center;
  gap: 6px;
  direction: rtl;
}

.nav-item {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.nav-item small {
  display: none;
}

.nav-item span {
  font-size: 15px;
}

.nav-item.is-active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.main {
  position: relative;
  min-width: 0;
}

/* FIX 1: Shifts the top image up and cleanly cuts off its transparent bottom margin */
.book-accent {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  margin: 28px 0 0;
  height: 105px; 
  overflow: hidden;
  pointer-events: none;
}

.book-accent > img:first-child {
  width: min(160px, 34vw);
  height: auto;
  display: block;
  opacity: 0.95;
  filter: drop-shadow(0 14px 24px rgba(53, 43, 30, 0.12));
}

/* FIX 2: Creates a totally separate, clean block for the text image below it */
.ministry-mark {
  position: relative;
  display: block;
  width: min(240px, 50vw);
  height: auto;
  margin: 5px auto 15px;
  opacity: 0.95;
}

.ministry-mark img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  margin-bottom: 24px;
  direction: rtl;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 900px;
  min-height: 50px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 18px;
  box-shadow: 0 10px 30px rgba(53, 43, 30, 0.05);
}

.search-box span {
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-height: 48px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  direction: rtl;
  font-size: 18px;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.icon-button,
.close-button,
.chip,
.action-button,
.text-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.action-button {
  min-height: 42px;
  padding: 0 16px;
}

.text-button {
  display: inline-grid;
  place-items: center;
  min-height: 44px;
  padding: 0 14px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.text-button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffaf0;
}

.primary-download {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffaf0;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

.section-heading {
  display: none;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 16px;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
}

.chip.is-active {
  background: var(--accent);
  color: #fffaf0;
  border-color: var(--accent);
}

.dua-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.dua-card,
.daily-card,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 8px 30px rgba(53, 43, 30, 0.055);
}

.dua-card {
  position: relative;
  display: grid;
  gap: 12px;
  min-height: 192px;
  padding: 18px;
  text-align: right;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.dua-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 36%, var(--line));
  box-shadow: var(--shadow);
}

.dua-card::before,
.dua-card::after {
  content: "";
  position: absolute;
  width: 96px;
  height: 126px;
  pointer-events: none;
  opacity: 0.12;
  background-repeat: no-repeat;
  background-size: contain;
}

.dua-card::before {
  top: 10px;
  left: 10px;
  background-image: url("asset-2.png");
}

.dua-card::after {
  right: 8px;
  bottom: 48px;
  background-image: url("asset-4.png");
}

.dua-heading-frame {
  display: block;
  text-align: right;
  justify-self: stretch;
}

.dua-card h3 {
  margin: 0;
  text-align: right;
  font-size: 20px;
  font-weight: 620;
  line-height: 1.45;
  font-family: "MV Waheed", Faruma, "Noto Sans Thaana", sans-serif;
}

.dua-card p {
  margin: 0;
}

.card-arabic {
  color: var(--accent);
  font-family: "Scheherazade New", "Traditional Arabic", "Amiri", "Times New Roman", serif;
  font-size: max(25px, calc(var(--arabic-size) - 7px));
  line-height: 1.65;
}

.card-meaning {
  margin: 0;
  color: var(--ink);
  font-family: "MV Waheed", Faruma, "Noto Sans Thaana", sans-serif;
  font-size: max(16px, calc(var(--dhivehi-size) - 3px));
  line-height: 1.85;
}

.dialog-footer-mark {
  display: flex;
  justify-content: center;
  margin-top: 22px;
  opacity: 0.82;
}

.ministry-mark-dialog {
  width: min(190px, 46vw);
  height: 52px;
  margin: 10px auto 0;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}

.card-meta span {
  display: none;
}

.favorite-toggle {
  width: 38px;
  height: 38px;
  color: var(--warm);
  font-size: 20px;
}

.image-save {
  min-height: 38px;
  padding: 0 12px;
  font-size: 14px;
}

.dua-dialog,
.image-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: min(86vh, 860px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.dua-dialog::backdrop,
.image-dialog::backdrop {
  background: rgba(22, 20, 16, 0.48);
}

.image-preview {
  display: grid;
  gap: 14px;
  padding: 56px 18px 18px;
}

.image-preview img {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffaf0;
}

.image-preview .action-button {
  display: inline-grid;
  place-items: center;
  justify-self: center;
  min-width: 130px;
  text-decoration: none;
}

.close-button {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 42px;
  height: 42px;
  font-size: 26px;
}

.dua-detail {
  padding: 34px;
}

.dua-detail h2 {
  max-width: 620px;
  padding-left: 48px;
  line-height: 1.45;
}

.dua-detail > p:not(.dhivehi-text):not(.reference) {
  display: none;
}

.arabic-text {
  margin: 26px 0 20px;
  color: var(--accent);
  font-family: "Scheherazade New", "Traditional Arabic", "Amiri", "Times New Roman", serif;
  font-size: var(--arabic-size);
  font-weight: 400;
  line-height: 2;
  text-align: right;
}

.dhivehi-text {
  margin-bottom: 0;
  font-family: "MV Waheed", Faruma, "Noto Sans Thaana", sans-serif;
  font-size: var(--dhivehi-size);
  line-height: 2;
}

.reference {
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 22px;
  padding-top: 14px;
  font-size: 15px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.settings-panel {
  display: grid;
  gap: 20px;
  max-width: 640px;
  padding: 22px;
}

.settings-panel label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.settings-panel input[type="range"] {
  width: 100%;
}

.toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
}

:root[data-offline-mode="true"] .sidebar,
:root[data-offline-mode="true"] .category-tabs,
:root[data-offline-mode="true"] .card-meta {
  display: none;
}

:root[data-offline-mode="true"] .topbar {
  justify-content: flex-start;
}

:root[data-offline-mode="true"] .search-box {
  display: none;
}

:root[data-offline-mode="true"] .app-shell {
  max-width: 780px;
  padding-top: 20px;
}

:root[data-offline-mode="true"] .dua-grid {
  grid-template-columns: 1fr;
}

:root[data-offline-mode="true"] .dua-card {
  box-shadow: none;
}

@media print {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --ink: #111111;
    --accent: #111111;
    --line: #d8d8d8;
  }

  body {
    background: #ffffff;
  }

  .book-accent,
  .dialog-footer-mark {
    display: none;
  }

  .app-shell {
    max-width: none;
    padding: 0;
  }

  .sidebar,
  .topbar,
  .category-tabs,
  .card-meta,
  .dua-dialog,
  .favoritesView,
  #favoritesView,
  #dailyView,
  #settingsView {
    display: none !important;
  }

  .view,
  .view.is-visible,
  #libraryView {
    display: block !important;
  }

  .dua-grid {
    display: block;
  }

  .dua-card {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    padding: 22px 0;
  }

  .dua-card h3 {
    font-size: 20px;
  }

  .card-arabic {
    color: #111111;
    font-size: 30px;
  }

  .card-meaning {
    color: #111111;
    font-size: 17px;
  }
}

@media (max-width: 760px) {
  body {
    background:
      url("asset-2.png") top -140px left -130px / 220px auto no-repeat,
      url("asset-4.png") bottom -150px right -130px / 220px auto no-repeat,
      radial-gradient(circle at top right, rgba(167, 117, 58, 0.1), transparent 28rem),
      var(--bg);
  }

  .app-shell {
    padding: 18px 12px 34px;
  }

  .sidebar {
    display: grid;
    gap: 14px;
    padding-bottom: 16px;
  }

  .nav-list {
    justify-content: space-between;
    overflow-x: auto;
  }

  .nav-item {
    padding: 0 12px;
  }

  /* Responsive mobile override to preserve layout separation */
  .book-accent {
    margin: 18px 0 0;
    height: 90px;
  }

  .book-accent > img:first-child {
    width: min(140px, 38vw);
  }

  .ministry-mark {
    width: min(200px, 54vw);
    height: auto;
    margin: 0 auto 10px;
  }

  .topbar {
    flex-wrap: wrap;
    margin-top: 8px;
  }

  .search-box {
    order: 1;
    flex: 1 1 100%;
    max-width: 100%;
  }

  .toolbar {
    order: 2;
    width: 100%;
    justify-content: center;
  }

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

  .dua-card {
    min-height: 172px;
  }

  .dua-detail {
    padding: 28px 20px 22px;
  }

  .arabic-text {
    font-size: calc(var(--arabic-size) - 2px);
  }
}