:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #f0ebdf;
  --fg: #1d2420;
  --muted: #69716b;
  --line: #e4ddcd;
  --accent: #0f6b52;
  --accent-fg: #ffffff;
  --accent-soft: #e2efe8;
  --gold: #b58a2c;
  --gold-soft: #f6ecd2;
  --danger: #b23a3a;
  --shadow: 0 1px 2px rgba(30, 40, 30, .06), 0 6px 20px rgba(30, 40, 30, .06);
  --radius: 16px;
  --arab-size: 30px;
  --terj-size: 16px;
  --ui: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --arab: "Amiri Quran", "Amiri", "Scheherazade New", "Traditional Arabic", serif;
  --top-h: 56px;
  --tab-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1714;
    --surface: #13201c;
    --surface-2: #1a2a25;
    --fg: #e8ece9;
    --muted: #94a19b;
    --line: #23352f;
    --accent: #3fbf93;
    --accent-fg: #062018;
    --accent-soft: #173a2f;
    --gold: #e0b75a;
    --gold-soft: #33301f;
    --danger: #ef7a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1714;
  --surface: #13201c;
  --surface-2: #1a2a25;
  --fg: #e8ece9;
  --muted: #94a19b;
  --line: #23352f;
  --accent: #3fbf93;
  --accent-fg: #062018;
  --accent-soft: #173a2f;
  --gold: #e0b75a;
  --gold-soft: #33301f;
  --danger: #ef7a7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #f1e6cf;
  --surface: #f8efdb;
  --surface-2: #eadcbf;
  --fg: #3b2f1e;
  --muted: #7c6a50;
  --line: #ddcca9;
  --accent: #8a5a1c;
  --accent-fg: #fff;
  --accent-soft: #ead7b2;
  --gold: #8a5a1c;
  --gold-soft: #ead7b2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--ui);
  min-height: 100vh;
  padding-top: var(--top-h);
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Topbar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.brand img { border-radius: 8px; }
.topbar-title { flex: 1; min-width: 0; text-align: center; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity .2s; }
.topbar-title.show { opacity: 1; }
.topbar-actions { display: flex; gap: 2px; margin-left: auto; }
body.reading .brand span { display: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; cursor: pointer; color: var(--fg);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.active { color: var(--gold); }
.icon-btn.active svg { fill: currentColor; }

/* Tabbar */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.2; }

main { max-width: 760px; margin: 0 auto; padding: 8px 16px 32px; outline: none; }

/* Home */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #0f6b52, #0b4f3d);
  color: #f6efe0; border-radius: 22px; padding: 20px; margin: 8px 0 20px; box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(233, 196, 106, .35), transparent 70%);
}
.hero small { opacity: .8; font-size: 12.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.hero h2 { margin: 6px 0 2px; font-size: 22px; letter-spacing: -.01em; }
.hero p { margin: 0 0 14px; opacity: .85; font-size: 14px; }
.hero .btn { background: #f6efe0; color: #0b4f3d; }
.hero-greet { font-family: var(--arab); font-size: 26px; direction: rtl; text-align: right; margin: -4px 0 6px; opacity: .95; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 12px; padding: 10px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer; background: var(--accent); color: var(--accent-fg);
}
.btn.ghost { background: var(--surface-2); color: var(--fg); }
.btn svg { width: 18px; height: 18px; }

.search {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 0 14px; height: 48px; margin-bottom: 16px;
}
.search svg { color: var(--muted); width: 20px; height: 20px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit; font-size: 15px; height: 100%; }
.search input::placeholder { color: var(--muted); }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 10px; }
.section-title h3 { margin: 0; font-size: 15px; font-weight: 700; }
.section-title span { color: var(--muted); font-size: 13px; }

.list { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .list.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.item {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); transition: transform .12s, border-color .12s;
}
.item:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.item:active { transform: scale(.99); }
.num {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center; font-weight: 700; font-size: 13.5px;
  color: var(--accent); background: var(--accent-soft); border-radius: 12px; transform: rotate(45deg);
}
.num > span { transform: rotate(-45deg); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-arab { font-family: var(--arab); font-size: 22px; color: var(--accent); direction: rtl; flex: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 99px;
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.juz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.juz-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.juz-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.juz-card b { display: block; font-size: 16px; }
.juz-card small { color: var(--muted); font-size: 12.5px; display: block; }

/* Reader */
.surah-head {
  text-align: center; padding: 22px 16px 18px; margin: 8px 0 12px; border-radius: 22px;
  background: var(--surface); border: 1px solid var(--line); position: relative;
}
.surah-head .arab { font-family: var(--arab); font-size: 38px; color: var(--accent); line-height: 1.6; }
.surah-head h1 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.surah-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.surah-head .actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.bismillah { font-family: var(--arab); font-size: calc(var(--arab-size) * .95); text-align: center; margin: 18px 0 8px; color: var(--fg); line-height: 2; }

.surah-divider { display: flex; align-items: center; gap: 12px; margin: 26px 0 6px; }
.surah-divider::before, .surah-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.surah-divider a { font-weight: 700; font-size: 14px; color: var(--accent); }

.ayat { padding: 16px 2px 18px; border-bottom: 1px solid var(--line); scroll-margin-top: calc(var(--top-h) + 12px); }
.ayat.flash { animation: flash 2s ease-out; }
@keyframes flash { 0%, 30% { background: var(--gold-soft); } 100% { background: transparent; } }
.ayat-bar { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.ayat-key {
  font-size: 12.5px; font-weight: 700; color: var(--accent); background: var(--accent-soft);
  padding: 4px 10px; border-radius: 99px; margin-right: auto;
}
.ayat-bar .icon-btn { width: 36px; height: 36px; color: var(--muted); }
.ayat-bar .icon-btn svg { width: 19px; height: 19px; }
.ayat-bar .icon-btn.active { color: var(--gold); }
.ayat-arab {
  font-family: var(--arab); font-size: var(--arab-size); line-height: 2.15; direction: rtl; text-align: right;
  word-spacing: .05em; margin: 4px 0 12px; overflow-wrap: break-word;
}
.ayat-end {
  display: inline-grid; place-items: center; min-width: 1.35em; height: 1.35em; font-size: .7em;
  border: 1.5px solid var(--gold); border-radius: 50%; color: var(--gold); margin: 0 .15em; vertical-align: middle;
  font-family: var(--ui); font-weight: 600; line-height: 1; padding: 0 .2em;
}
.ayat-terj { font-size: var(--terj-size); line-height: 1.7; margin: 0; }
.ayat-terj + .ayat-terj { margin-top: 10px; }
.ayat-terj small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
body.no-terj .ayat-terj { display: none; }
.sajdah { display: inline-block; font-size: 11px; font-weight: 600; color: var(--gold); background: var(--gold-soft); padding: 2px 8px; border-radius: 99px; margin-left: 6px; }

.reader-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 24px; }
.reader-nav a { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; color: var(--muted); }
.reader-nav a b { display: block; color: var(--fg); font-size: 15px; }
.reader-nav a.next { text-align: right; grid-column: 2; }

.progress { position: fixed; top: var(--top-h); left: 0; height: 2px; background: var(--accent); z-index: 21; width: 0; transition: width .1s; }

/* Loading, empty */
.loader { display: grid; place-items: center; padding: 32px; color: var(--muted); font-size: 14px; gap: 10px; }
.spinner { width: 26px; height: 26px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); height: 66px; }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; stroke-width: 1.3; margin-bottom: 8px; }
.empty h3 { color: var(--fg); margin: 0 0 4px; font-size: 16px; }
.error-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-align: center; }
.error-box p { color: var(--muted); margin: 4px 0 14px; }

/* Bookmarks */
.bm { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.bm-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bm-head b { font-size: 14.5px; }
.bm-head span { color: var(--muted); font-size: 12.5px; margin-right: auto; }
.bm-arab { font-family: var(--arab); font-size: 22px; direction: rtl; text-align: right; line-height: 1.9; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bm-terj { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 86vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .15);
  max-width: 640px; margin: 0 auto; animation: up .25s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; padding: 8px 12px 4px 20px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 4px 20px 24px; }
.sheet-body .info-text { font-size: 14.5px; line-height: 1.7; white-space: pre-line; }
.sheet-body .info-text h2, .sheet-body .info-text h3 { font-size: 15px; margin: 18px 0 4px; }
.sheet-body .info-text p { margin: 0 0 10px; }

.field { padding: 14px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field-label { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.field-label span { color: var(--muted); font-weight: 500; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-size: 13px; font-weight: 500; cursor: pointer; }
.seg button.active { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); font-weight: 600; }
.check { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.check small { color: var(--muted); display: block; font-size: 12px; }
.preview-arab { font-family: var(--arab); font-size: var(--arab-size); direction: rtl; text-align: center; line-height: 2; margin: 4px 0 0; }

.goto { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.goto input, .goto select {
  height: 44px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 12px; padding: 0 12px; font: inherit; min-width: 0;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.muted { color: var(--muted); }
.footer-note { text-align: center; color: var(--muted); font-size: 12px; margin: 32px 0 8px; }

@media (min-width: 900px) {
  main { padding-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Tombol pasang PWA */
.install-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; margin-right: 4px;
  border: 0; border-radius: 99px; background: var(--accent); color: var(--accent-fg); font-weight: 600; font-size: 13px; cursor: pointer;
}
.install-btn svg { width: 17px; height: 17px; stroke-width: 2.2; }
.install-card { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 16px; }
.install-card img { border-radius: 14px; flex: none; }
.install-card div { flex: 1; min-width: 0; }
.install-card b { display: block; font-size: 14.5px; }
.install-card small { color: var(--muted); font-size: 12.5px; }
.ios-steps { margin: 4px 0 0; padding-left: 20px; line-height: 1.9; font-size: 14.5px; }
.ios-steps svg { width: 18px; height: 18px; vertical-align: -3px; color: var(--accent); }
.ssr { padding: 8px 0; }
.ssr h1 { font-size: 22px; }
.ssr ol, .ssr ul { padding-left: 20px; line-height: 1.9; }
.ssr a { color: var(--accent); }
.ssr [lang="ar"] { font-family: var(--arab); font-size: 26px; line-height: 2; }
.js .ssr { display: none; }
@media (min-width: 800px) {
  .tabbar { padding-inline: calc((100vw - 760px) / 2); }
}
