:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #181b21;
  --panel-2: #20242c;
  --text: #f4f5f7;
  --muted: #a9b0bc;
  --line: #303641;
  --accent: #cfaa64;
  --accent-2: #f1d59b;
  --danger: #d67b7b;
  --shadow: 0 10px 26px rgba(0,0,0,.18);
  --radius: 18px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f1eb;
  --panel: #fffdf8;
  --panel-2: #f5f0e6;
  --text: #202226;
  --muted: #686d76;
  --line: #ded8cd;
  --accent: #8b6428;
  --accent-2: #6b4a18;
  --shadow: 0 8px 22px rgba(47,42,32,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, select, input { font: inherit; }
button { color: inherit; }
.app-shell { width: min(920px, 100%); margin: 0 auto; min-height: 100vh; padding-bottom: 84px; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 14px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.brand { font-size: 1.18rem; font-weight: 750; letter-spacing: .1px; }
.subtle { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.top-actions { display: flex; gap: 8px; }
.icon-btn, .favorite-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; min-width: 42px; min-height: 42px; cursor: pointer; }
main { padding: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.controls { padding: 14px; }
.control-grid { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 10px; }
label span { display: block; color: var(--muted); font-size: .76rem; margin-bottom: 5px; }
select, input[type="search"] { width: 100%; min-height: 44px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 12px; padding: 0 11px; }
.number-picker { appearance: none; }
.surah-picker { position:relative; }
.author-picker { position:relative; }
.author-picker input[type="search"] { padding-right:42px; }
.author-picker-toggle { position:absolute; top:3px; right:4px; width:38px; height:38px; border:0; border-radius:9px; background:transparent; color:var(--muted); font-size:1.15rem; cursor:pointer; }
.author-picker-toggle:hover, .author-picker-toggle:focus-visible { background:var(--panel); outline:none; }
.visually-hidden { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.surah-options, .author-options { position:absolute; z-index:30; top:calc(100% + 5px); left:0; right:0; max-height:min(52vh,360px); overflow:auto; overscroll-behavior:contain; padding:5px; border:1px solid var(--line); border-radius:12px; background:var(--panel); box-shadow:var(--shadow); }
.surah-option { display:block; width:100%; min-height:40px; padding:8px 10px; border:0; border-radius:8px; background:transparent; color:var(--text); text-align:left; cursor:pointer; }
.surah-option:hover, .surah-option:focus-visible { outline:none; background:var(--panel-2); }
.author-option { display:block; width:100%; min-height:42px; padding:9px 10px; border:0; border-radius:8px; background:transparent; color:var(--text); text-align:left; cursor:pointer; }
.author-option:hover, .author-option:focus-visible, .author-option[aria-selected="true"] { outline:none; background:var(--panel-2); }
.surah-no-match { padding:10px; color:var(--muted); font-size:.86rem; }
.verse-nav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 12px; }
.verse-nav button, .dialog-tools button, .search-row button { min-height: 42px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; cursor: pointer; }
.verse-nav button:last-child { justify-self: stretch; }
.verse-ref { font-weight: 700; text-align: center; min-width: 94px; }
.verse-section { margin-top: 14px; display: grid; gap: 12px; }
.arabic-card { padding: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .82rem; }
.arabic { margin: 18px 2px 8px; font-family: "Noto Naskh Arabic", "Amiri", serif; font-size: clamp(1.8rem, 6vw, 2.55rem); line-height: 1.9; text-align: right; }
.quran-word { display:inline-flex; flex-direction:column; align-items:center; vertical-align:bottom; border:0; border-radius:7px; padding:0 3px; background:transparent; color:inherit; font:inherit; cursor:pointer; }
.quran-word-phrase { display:inline-flex; align-items:flex-end; gap:.12em; direction:rtl; vertical-align:bottom; white-space:nowrap; }
.quran-word-arabic { display:block; }
.quran-word-reading { display:block; margin-top:.12em; color:var(--muted); font-family:system-ui,sans-serif; font-size:.62em; font-weight:450; line-height:1.3; white-space:nowrap; }
.quran-reading-phrase { display:inline-flex; flex-direction:column; align-items:center; vertical-align:bottom; white-space:nowrap; }
.quran-reading-arabic { display:inline-flex; align-items:flex-end; direction:rtl; white-space:nowrap; }
.quran-word:hover, .quran-word:focus-visible { outline:1px solid var(--accent); background:color-mix(in srgb,var(--accent) 16%,transparent); }
.quran-word-group .quran-word-arabic { text-decoration:underline dotted var(--line); text-underline-offset:.14em; }
.quran-word.group-active { outline:1px solid var(--accent); background:color-mix(in srgb,var(--accent) 20%,transparent); }
.word-meaning-tooltip { position:fixed; z-index:90; max-width:min(300px,calc(100vw - 24px)); padding:7px 11px; border:1px solid #7fa7bc; border-radius:5px; background:var(--panel); color:var(--accent-2); box-shadow:var(--shadow); font-family:Georgia,serif; font-size:.95rem; line-height:1.35; }
.word-meaning-tooltip::after { position:absolute; top:100%; left:50%; width:0; height:0; border:7px solid transparent; border-top-color:#7fa7bc; content:""; transform:translateX(-50%); }
.word-meaning-tooltip.below::after { top:auto; bottom:100%; border-top-color:transparent; border-bottom-color:#7fa7bc; }
.reading-label { margin:8px 2px 0; color:var(--muted); font-size:.76rem; }
.reading-label span { margin-left:6px; opacity:.75; }
.arabic-reading { margin:2px 2px 8px; color:var(--accent-2); font-size:.96rem; line-height:1.55; }
.favorite-btn { font-size: 1.45rem; color: var(--accent); }
.translation-list { display: grid; gap: 10px; }
.translation-card { padding: 14px 15px 15px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.translation-name { color: var(--accent-2); font-weight: 720; font-size: .92rem; margin-bottom: 8px; }
.translation-text { line-height: 1.58; white-space: pre-wrap; }
.inline-footnote, .author-inline-footnote { display:inline; border:0; padding:0 1px; background:transparent; color:#76a9df; font:inherit; font-size:.78em; vertical-align:super; line-height:1; cursor:pointer; }
.inline-footnote:hover, .author-inline-footnote:hover { text-decoration:underline; }
.footnote-full { padding: 18px 20px 24px; line-height: 1.65; white-space: pre-wrap; }
.footnote-dialog { width: min(660px, calc(100% - 22px)); }
.word-dialog { width:min(620px,calc(100% - 22px)); }
.word-dialog-body { padding:14px 16px 20px; }
.word-dialog-body h3 { margin:17px 0 8px; font-size:.94rem; }
.word-root-summary { display:grid; gap:3px; padding:11px 12px; border:1px solid var(--line); border-radius:12px; background:var(--panel-2); }
.word-root-summary span,.word-data-note,.word-loading { color:var(--muted); font-size:.82rem; }
.word-root-summary strong { font-size:.9rem; }
.word-tabs { display:flex; gap:7px; margin-top:12px; border-bottom:1px solid var(--line); }
.word-tabs button { padding:8px 11px; border:1px solid var(--line); border-bottom:0; border-radius:10px 10px 0 0; background:var(--panel-2); color:var(--muted); cursor:pointer; }
.word-tabs button[aria-selected="true"] { color:var(--text); border-color:var(--accent); }
.word-tabs button:disabled { opacity:.48; cursor:not-allowed; }
.word-occurrences { display:grid; gap:6px; max-height:45vh; overflow:auto; }
.word-occurrence { display:flex; align-items:center; justify-content:space-between; gap:12px; min-height:44px; padding:8px 11px; border:1px solid var(--line); border-radius:11px; background:var(--panel-2); color:var(--text); text-align:left; cursor:pointer; }
.word-occurrence-ref { font-size:.88rem; }
.word-occurrence-token { color:var(--accent-2); font-family:"Noto Naskh Arabic","Amiri",serif; font-size:1.15rem; }
.word-loading { padding:12px; text-align:center; }
.word-data-note { margin:12px 1px 0; line-height:1.45; }
.word-attribution { margin:5px 1px 0; color:var(--muted); font-size:.74rem; }
.word-attribution a { color:var(--accent-2); }
.word-hit { padding:8px 0; border-bottom:1px solid var(--line); }
.root-hit-go { display:flex; justify-content:space-between; gap:10px; width:100%; padding:5px 0; border:0; background:transparent; color:var(--accent-2); text-align:left; cursor:pointer; }
.root-hit-go span:last-child { color:var(--text); font-family:"Noto Naskh Arabic","Amiri",serif; font-size:1.1rem; }
.root-hit-meaning { padding:2px 0 0; font-size:.82rem; line-height:1.45; }
.root-hit-meaning strong { color:var(--muted); font-size:.74rem; }
.word-more { width:100%; min-height:40px; margin-top:8px; border:1px solid var(--line); border-radius:10px; background:var(--panel-2); color:var(--text); cursor:pointer; }
.word-pagination { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
.root-hit-translation { padding:5px 0 7px; border-bottom:1px solid var(--line); font-size:.84rem; line-height:1.45; }
.root-hit-translation:last-child { border-bottom:0; }
.root-hit-translation strong { display:block; color:var(--accent-2); font-size:.76rem; margin-bottom:2px; }
.author-heading { display:flex; align-items:end; justify-content:space-between; gap:16px; padding:12px 2px 16px; }
.author-heading h1 { margin:0; font-size:clamp(1.35rem,4vw,2rem); }
.author-controls { display:flex; gap:10px; min-width:min(540px,65%); }
.author-controls label { flex:1; min-width:0; }
.author-surahs { display:grid; gap:2px; }
.author-surah { background:var(--panel); border-bottom:1px solid var(--line); }
.author-surah summary { padding:10px 12px; cursor:pointer; background:var(--panel-2); }
.author-surah:nth-child(even) summary { background:color-mix(in srgb,var(--panel-2) 65%,var(--panel)); }
.author-surah summary small { float:right; color:var(--muted); font-size:.74rem; }
.author-verses { padding:7px 12px 10px; }
.author-verse { display:grid; grid-template-columns:34px minmax(0,1fr); gap:9px; padding:7px 5px; line-height:1.5; }
.author-verse:nth-child(even) { background:var(--panel-2); }
.author-ayah-number { color:var(--accent-2); text-align:center; }
.author-pending { padding:12px; color:var(--muted); font-size:.86rem; }
.single-author-choice { padding:16px; display:grid; gap:12px; }
.single-author-choice button { min-height:44px; border:1px solid var(--line); border-radius:12px; background:var(--panel-2); color:var(--text); cursor:pointer; }
[hidden] { display:none !important; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 15px; }
.bottom-nav { position: fixed; z-index: 25; left: 50%; transform: translateX(-50%); bottom: 0; width: min(920px, 100%); display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); background: color-mix(in srgb, var(--panel) 95%, transparent); backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
.bottom-nav button { border: 0; background: transparent; color: var(--muted); min-height: 44px; border-radius: 12px; }
.bottom-nav button.active { background: var(--panel-2); color: var(--text); }
.dialog-panel.notes-dialog { box-sizing:border-box; position:fixed; inset:auto 18px 72px auto; margin:0; display:none; flex-direction:column; width:min(560px,calc(100vw - 22px)); min-width:min(320px,calc(100vw - 22px)); height:min(440px,calc(100dvh - 28px)); min-height:min(260px,calc(100dvh - 28px)); max-width:calc(100vw - 22px); max-height:calc(100dvh - 28px); overflow:auto; resize:both; background:var(--panel); opacity:1; }
.notes-dialog[open] { display:flex; }
.notes-dialog-head { cursor:move; touch-action:none; }
.notes-window-actions { display:flex; align-items:center; gap:8px; }
.notes-clear-btn { min-height:38px; padding:0 11px; border:1px solid var(--line); border-radius:10px; background:var(--panel-2); color:var(--muted); cursor:pointer; }
.notes-text { box-sizing:border-box; display:block; flex:1 1 auto; width:100%; height:auto; min-height:160px; resize:none; padding:15px; border:0; outline:0; background:var(--panel); color:var(--text); font:inherit; line-height:1.55; }
.notes-save-status { padding:8px 14px; border-top:1px solid var(--line); color:var(--muted); font-size:.76rem; }
@media (max-width: 420px) { .bottom-nav button { font-size:.76rem; padding:0 2px; } }
.dialog-panel { width: min(720px, calc(100% - 22px)); max-height: 86vh; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--text); padding: 0; box-shadow: 0 18px 70px rgba(0,0,0,.45); }
.dialog-panel::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
.dialog-head { position: sticky; top: 0; z-index: 2; background: var(--panel); display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 1.1rem; }
.dialog-head-actions { display:flex; align-items:center; gap:8px; }
.about-open-btn { min-height:38px; padding:0 12px; border:1px solid var(--line); border-radius:10px; background:var(--panel-2); color:var(--text); cursor:pointer; }
.about-dialog { width:min(620px,calc(100% - 22px)); }
.about-copy { padding:8px 18px 18px; line-height:1.62; }
.about-copy p { margin:12px 0; }
.dialog-head p { margin: 3px 0 0; color: var(--muted); font-size: .8rem; }
.dialog-tools, .search-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.dialog-tools button, .search-row button { padding: 0 14px; }
.translator-actions { display:flex; gap:6px; }
.translator-actions button { white-space:nowrap; }
.translator-manager { padding: 6px 14px 18px; }
.translator-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; min-height: 52px; border-bottom: 1px solid var(--line); }
.translator-row small { display: block; color: var(--muted); margin-top: 2px; }
.move-btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 9px; min-width: 34px; height: 34px; }
.search-results { padding: 12px 14px 18px; display: grid; gap: 9px; }
.result { border: 1px solid var(--line); background: var(--panel-2); border-radius: 13px; padding: 11px; cursor: pointer; }
.result strong { color: var(--accent-2); }
.result p { margin: 5px 0 0; color: var(--muted); line-height: 1.42; }
.status-warning { color: var(--danger); }
@media (max-width: 620px) {
  html, body { min-width: 320px; }
  body { overflow-x: hidden; }
  .app-shell { width:100%; padding-bottom:calc(68px + env(safe-area-inset-bottom)); }
  .topbar { gap:8px; padding: max(9px,env(safe-area-inset-top)) 10px 9px; }
  .brand { font-size:1.06rem; }
  .subtle { font-size:.7rem; }
  .top-actions { gap:5px; }
  .icon-btn { min-width:40px; min-height:40px; }
  main { padding:10px 9px; }
  .controls { padding:10px; }
  .control-grid { grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:8px; }
  .control-grid label:nth-child(1) { grid-column:1; grid-row:2; }
  .control-grid label:nth-child(2) { grid-column:1 / -1; grid-row:1; }
  .control-grid label:nth-child(3) { grid-column:2; grid-row:2; }
  .control-grid label span { font-size:.72rem; }
  select, input[type="search"] { min-height:44px; padding-inline:9px; font-size:16px; }
  .verse-nav { grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:7px; margin-top:9px; }
  .verse-nav button { min-height:44px; padding:0 6px; font-size:.9rem; }
  .verse-ref { grid-column:1 / -1; grid-row:1; min-width:0; padding:1px 0; }
  .verse-section { margin-top:10px; gap:9px; }
  .arabic-card { min-width:0; padding:12px 10px; }
  .arabic { margin:14px 0 8px; font-size:clamp(1.72rem,7.2vw,2.25rem); line-height:2.02; overflow-wrap:normal; }
  .quran-word { padding-inline:2px; }
  .quran-word-reading { font-size:.58em; }
  .translation-card { min-width:0; padding:12px; }
  .translation-name { margin-bottom:6px; font-size:.9rem; }
  .translation-text { font-size:.97rem; line-height:1.62; overflow-wrap:anywhere; }
  .bottom-nav { width:100%; grid-template-columns:repeat(5,minmax(0,1fr)); padding:6px max(5px,env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(5px,env(safe-area-inset-left)); }
  .bottom-nav button { min-width:0; min-height:46px; padding:3px 1px; font-size:.7rem; line-height:1.1; white-space:normal; }
  .translator-row { grid-template-columns: auto 1fr auto; }
  .translator-row .move-btn:last-child { display:none; }
  .dialog-tools { grid-template-columns: 1fr; }
  .translator-actions { display:grid; grid-template-columns: 1fr 1fr; }
  .translator-actions button { padding:0 8px; }
  .author-heading { align-items:stretch; flex-direction:column; }
  .author-controls { flex-direction:column; min-width:0; }
  .author-heading h1 { font-size:1.4rem; }
  .author-surah summary { min-height:44px; padding:11px 10px; }
  .author-surah summary small { max-width:45%; text-align:right; }
  .author-verses { padding:6px 8px 9px; }
  .author-verse { grid-template-columns:28px minmax(0,1fr); gap:6px; padding:8px 3px; overflow-wrap:anywhere; }
  .dialog-panel { width:calc(100vw - 16px); max-width:calc(100vw - 16px); max-height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px); border-radius:16px; overscroll-behavior:contain; }
  .dialog-head { gap:8px; padding:11px; }
  .dialog-head h2 { font-size:1.02rem; }
  .dialog-head p { max-width:40vw; font-size:.72rem; }
  .dialog-head .icon-btn { flex:none; }
  .dialog-head-actions { gap:5px; }
  .about-open-btn { min-height:40px; padding:0 9px; font-size:.84rem; }
  .dialog-tools, .search-row { padding:9px; }
  .translator-manager { padding:4px 9px 14px; }
  .translator-row { gap:6px; }
  .translator-row > div { min-width:0; overflow-wrap:anywhere; }
  .translator-row .move-btn { min-width:38px; min-height:40px; }
  .search-results { padding:9px; }
  .word-dialog-body { padding:10px 11px 16px; }
  .word-occurrence { gap:8px; padding:8px; }
  .dialog-panel.notes-dialog { inset:auto 8px calc(62px + env(safe-area-inset-bottom)) 8px !important; width:auto; min-width:0; max-width:none; height:min(68dvh,560px); min-height:220px; max-height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 78px); resize:none; }
  .notes-dialog-head { cursor:default; touch-action:auto; }
  .notes-window-actions { gap:4px; }
  .notes-clear-btn { min-height:38px; padding:0 7px; font-size:.75rem; }
  .notes-text { min-height:120px; padding:12px; }
}
@media (max-width: 360px) {
  .topbar { padding-inline:8px; }
  .top-actions { gap:3px; }
  .icon-btn { min-width:38px; min-height:38px; }
  main { padding-inline:7px; }
  .arabic-card { padding-inline:8px; }
  .bottom-nav button { font-size:.65rem; }
  .translator-actions { grid-template-columns:1fr; }
  .translator-actions button { min-height:42px; }
  .notes-window-actions { gap:3px; }
  .notes-clear-btn { padding-inline:5px; font-size:.7rem; }
}
