:root {
  color-scheme: light dark;
  --bg: #faf6ef;
  --bg-accent: linear-gradient(135deg, #fdf8ee 0%, #f3e8d4 50%, #e8dcc8 100%);
  --surface: #ffffff;
  --surface-muted: #f7f2ea;
  --text: #2c2416;
  --text-muted: #7a6f5e;
  --accent: #8b6914;
  --accent-light: #c49a2a;
  --accent-soft: #f5ecd8;
  --accent-glow: rgba(196, 154, 42, 0.18);
  --border: #e5dcc8;
  --shadow: 0 4px 20px rgba(44, 36, 22, 0.07);
  --shadow-lg: 0 12px 40px rgba(44, 36, 22, 0.1);
  --radius: 16px;
  --font-ui: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --font-urdu: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --page-pad: 1rem;
}

[data-theme="dark"] {
  --bg: #14110d;
  --bg-accent: linear-gradient(135deg, #1a1610 0%, #221c14 50%, #1e1812 100%);
  --surface: #1f1a14;
  --surface-muted: #2a2319;
  --text: #f5efe6;
  --text-muted: #a89880;
  --accent: #d4a843;
  --accent-light: #e8c068;
  --accent-soft: #2e2618;
  --accent-glow: rgba(212, 168, 67, 0.15);
  --border: #3d3428;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
}

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

html {
  scroll-behavior: smooth;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.65;
}

body[dir="rtl"] {
  font-family: var(--font-urdu);
  line-height: 2;
}

a {
  color: var(--accent);
}

.hidden {
  display: none !important;
}

/* ── Mobile: scrollable, device-flexible layout ── */
body.layout-mobile {
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.layout-mobile .app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 640px;
  margin-inline: auto;
  padding-inline: var(--page-pad);
  padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
  padding-bottom: max(0.75rem, var(--safe-bottom));
}

body.layout-mobile .layout-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

body.layout-mobile .sidebar {
  flex-shrink: 0;
}

/* About card duplicates the header About dialog — hide on small screens */
body.layout-mobile .about-card {
  display: none;
}

body.layout-mobile .main {
  flex: 1;
  display: block;
}

body.layout-mobile .devotional {
  display: block;
}

body.layout-mobile .card {
  display: block;
  overflow: visible;
}

body.layout-mobile .content-panels {
  min-height: auto;
}

body.layout-mobile .content-panel.active {
  height: auto;
  overflow: visible;
  padding-bottom: 1rem;
}

body.layout-mobile .compact-head {
  padding: 0.75rem 0.85rem;
}

body.layout-mobile .thumb-image {
  width: 3.75rem;
  height: 3.75rem;
}

body.layout-mobile .devotional h2 {
  font-size: 1rem;
}

body.layout-mobile .content-tab {
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  min-height: 2.35rem;
}

body.layout-mobile .footer-tagline {
  display: none;
}

body.layout-mobile .install-banner {
  position: sticky;
  top: 0;
  z-index: 50;
}

/* ── Desktop: website / desktop-app layout ── */
body.layout-desktop {
  overflow-x: hidden;
  overflow-y: auto;
}

body.layout-desktop .app-shell {
  max-width: 1180px;
  margin-inline: auto;
  padding: 1.25rem 1.5rem 2.5rem;
  min-height: 100vh;
}

body.layout-desktop .layout-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

body.layout-desktop .sidebar {
  position: sticky;
  top: 1rem;
}

body.layout-desktop .sidebar-card {
  padding: 1rem;
}

body.layout-desktop .date-strip {
  flex-wrap: wrap;
  overflow: visible;
  max-height: 320px;
  overflow-y: auto;
}

body.layout-desktop .day-pill {
  min-width: calc(33.333% - 0.35rem);
}

body.layout-desktop .main {
  min-height: 520px;
}

body.layout-desktop .card {
  box-shadow: var(--shadow-lg);
}

body.layout-desktop .compact-head {
  padding: 1.25rem 1.35rem;
}

body.layout-desktop .head-audio audio {
  height: 2.35rem;
  max-width: 28rem;
}

body.layout-desktop .thumb-image {
  width: 7rem;
  height: 7rem;
  border-radius: 14px;
}

body.layout-desktop .devotional h2 {
  font-size: 1.55rem;
}

body.layout-desktop .content-tabs {
  padding: 0.65rem 1rem 0;
  gap: 0.4rem;
}

body.layout-desktop .content-tab {
  font-size: 0.88rem;
  padding: 0.5rem 1rem;
}

body.layout-desktop .content-panel {
  padding: 1.25rem 1.35rem 2rem;
  font-size: 1.02rem;
  line-height: 1.75;
}

body.layout-desktop .content-panel.active {
  display: block;
  overflow: visible;
  height: auto;
}

body.layout-desktop .content-panels {
  overflow: visible;
}

body.layout-desktop .app-footer {
  margin-top: 1.5rem;
  padding-bottom: 1rem;
}

/* ── Shared components ── */
.install-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--accent);
  color: #fff;
}

.install-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}

.install-text strong {
  font-size: 0.85rem;
}

.install-help {
  font-size: 0.72rem;
  opacity: 0.9;
}

.install-action {
  border: 0;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.install-dismiss {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
}

.ios-hint,
.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 17, 13, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.ios-hint-card,
.app-dialog-card {
  max-width: 340px;
  padding: 1.15rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.about-dialog-card {
  max-width: 420px;
  max-height: min(85vh, 640px);
  overflow-y: auto;
}

.about-dialog-card h2 {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
}

.about-dialog-card h3 {
  margin: 1rem 0 0.45rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.about-dialog-card p {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

body[dir="rtl"] .about-dialog-card p {
  line-height: 2;
}

.ios-hint-card h3 {
  margin: 0 0 0.5rem;
}

.ios-hint-card p {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
}

.app-header {
  flex-shrink: 0;
  margin-bottom: 0.75rem;
}

body.layout-desktop .app-header {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

body.layout-desktop .brand h1 {
  font-size: 1.75rem;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.toolbar-select,
.toolbar-btn,
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}

.toolbar-select {
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.toolbar-btn {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.icon-btn {
  width: 2.35rem;
  height: 2.35rem;
  font-size: 1rem;
}

.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

.about-card {
  margin-top: 0.75rem;
}

.about-heading {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
}

.about-lead {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
}

body[dir="rtl"] .about-lead {
  line-height: 2;
}

.about-list {
  margin: 0 0 0.65rem;
  padding-inline-start: 1.1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

body[dir="rtl"] .about-list {
  line-height: 1.9;
}

.about-list li {
  margin-bottom: 0.3rem;
}

.about-more-btn {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  background: var(--surface-muted);
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.about-more-btn:hover {
  background: var(--accent-soft);
}

body.layout-desktop .about-card {
  margin-top: 1rem;
}

.footer-tagline {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text);
  font-weight: 600;
}

body[dir="rtl"] .footer-tagline {
  line-height: 2;
}

.meta-bar {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.65rem;
}

.range-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.range-value {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.92rem;
}

.sync-hint {
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.4;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-arrow {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--accent);
  font-size: 1.2rem;
  cursor: pointer;
}

body.layout-desktop .nav-arrow {
  display: none;
}

.nav-arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.date-strip {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  scroll-behavior: smooth;
  flex: 1;
  scrollbar-width: thin;
}

.day-pill {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.75rem;
  padding: 0.4rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
}

.day-pill.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.day-pill.is-today:not(.active) {
  border-color: var(--accent-light);
}

.day-name {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
}

.day-num {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.day-pill.active .day-name,
.day-pill.active .day-num {
  color: #fff;
}

.main {
  padding: 0;
}

body.layout-mobile .main {
  padding-top: 0.35rem;
}

.status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.retry-btn {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.devotional {
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.compact-head {
  display: flex;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.thumb-image {
  width: 4.75rem;
  height: 4.75rem;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.head-text {
  min-width: 0;
  flex: 1;
}

.compact-meta {
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  color: var(--text-muted);
}

.meta-row .chip {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
}

.devotional h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.3;
  font-weight: 700;
}

body[dir="rtl"] .devotional h2 {
  line-height: 2.15;
  margin-bottom: 0.15rem;
}

body[dir="rtl"] .head-text {
  line-height: 2.1;
}

body[dir="rtl"] .author-line {
  line-height: 1.9;
  margin-top: 0.5rem;
}

body[dir="rtl"] .content-tab {
  line-height: 1.6;
  padding-block: 0.55rem;
}

body[dir="rtl"] .content-panel h4 {
  line-height: 1.9;
  margin-bottom: 0.65rem;
}

.author-line {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.head-audio {
  margin-top: 0.45rem;
}

.head-audio audio {
  width: 100%;
  height: 2rem;
  margin: 0;
}

.translate-notice {
  padding: 0.55rem 1rem 0;
}

.translate-notice .notice {
  margin: 0;
}

.card-footer {
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

.bible-in-year {
  margin: 0 0 0.75rem;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.card-footer .actions {
  margin-top: 0;
}

.content-tabs {
  display: flex;
  gap: 0.3rem;
  padding: 0.5rem 0.75rem 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}

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

.content-tab {
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.content-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.content-panel {
  display: none;
  padding: 0.85rem 1rem 1rem;
}

.content-panel.active {
  display: block;
}

.content-panel p {
  margin: 0 0 1rem;
}

.content-panel p:last-child {
  margin-bottom: 0;
}

.content-panel h4 {
  margin: 1rem 0 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.content-panel h4:first-child {
  margin-top: 0;
}

.key-verse {
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  border-radius: 10px;
  background: var(--accent-soft);
  border-inline-start: 3px solid var(--accent-light);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.55;
}

body[dir="rtl"] .key-verse {
  line-height: 2.3;
  padding: 0.95rem 1rem;
}

.passage-ref {
  margin: 0 0 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

.urdu-text,
body[dir="rtl"] .content-panel {
  font-family: var(--font-urdu);
  font-size: 1.08rem;
  line-height: 2.25;
}

body[dir="rtl"] .content-panel p {
  line-height: 2.25;
  margin-bottom: 1.35rem;
}

body[dir="rtl"] .verse-item {
  line-height: 2.3;
  margin-bottom: 1rem;
}

body[dir="rtl"] .notice,
body[dir="rtl"] .bible-in-year {
  line-height: 2;
}

body[dir="rtl"] .content-panel {
  text-align: right;
}

.verse-item {
  margin-bottom: 0.65rem;
}

.verse-num {
  color: var(--accent);
  font-weight: 700;
  margin-inline-end: 0.35rem;
}

.notice {
  padding: 0.65rem 0.8rem;
  margin-bottom: 1rem;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
}

.empty-panel {
  color: var(--text-muted);
}

audio {
  width: 100%;
  margin: 0.35rem 0 0.75rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.primary-link {
  display: inline-flex;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  background: var(--accent);
  color: #fff !important;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
}

.subtle-link {
  background: var(--surface-muted);
  color: var(--accent) !important;
  border: 1px solid var(--border);
}

.app-footer {
  flex-shrink: 0;
  padding: 0.75rem 0 0.25rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.source-credits {
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.55;
}

.source-credits p {
  margin: 0 0 0.35rem;
}

.source-credits p:last-child {
  margin-bottom: 0;
}

.source-credits a {
  font-weight: 600;
}

.developer-line {
  margin: 0;
}

body[dir="rtl"] .source-credits {
  line-height: 2;
}

.source-note {
  margin: 1rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

body[dir="rtl"] .source-note {
  line-height: 2;
}

body.layout-mobile .app-footer {
  padding-bottom: max(0.5rem, var(--safe-bottom));
}

.app-footer strong {
  color: var(--accent);
}

@media (max-width: 767px) {
  .subtitle {
    display: none;
  }

  .brand h1 {
    font-size: 1.05rem;
  }

  .toolbar-select {
    max-width: 5.5rem;
  }

  .toolbar-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.78rem;
  }

  .icon-btn {
    width: 2.15rem;
    height: 2.15rem;
    font-size: 0.95rem;
  }

  .sidebar-card {
    padding: 0.65rem;
  }

  .meta-bar {
    margin-bottom: 0.5rem;
  }

  .day-pill {
    min-width: 2.5rem;
    padding: 0.35rem 0.4rem;
  }

  .content-panel {
    padding: 0.85rem 0.85rem 1rem;
    font-size: 0.95rem;
    line-height: 1.7;
  }

  body[dir="rtl"] .content-panel {
    font-size: 1rem;
    line-height: 2.1;
  }

  .key-verse {
    font-size: 0.9rem;
    padding: 0.65rem 0.8rem;
  }

  .urdu-text {
    font-size: 1rem;
    line-height: 2.1;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .card-footer {
    padding: 0.75rem 0.85rem 0.85rem;
  }

  .primary-link {
    font-size: 0.82rem;
    padding: 0.55rem 0.85rem;
  }

  .app-footer {
    font-size: 0.72rem;
    padding-top: 0.5rem;
  }

  .source-credits {
    font-size: 0.72rem;
    line-height: 1.45;
  }
}

@media (max-width: 380px) {
  .brand-icon {
    width: 32px;
    height: 32px;
  }

  .brand h1 {
    font-size: 0.95rem;
  }

  .toolbar {
    gap: 0.25rem;
  }

  .toolbar-select {
    max-width: 4.75rem;
    font-size: 0.78rem;
    padding: 0.4rem 0.45rem;
  }

  .content-tab {
    padding: 0.45rem 0.7rem;
    font-size: 0.76rem;
  }
}

@media (min-width: 768px) and (max-width: 899px) {
  body.layout-desktop .app-shell {
    max-width: 900px;
    padding-inline: 1rem;
  }

  body.layout-desktop .layout-grid {
    grid-template-columns: 240px minmax(0, 1fr);
  }
}
