:root {
  --paper: #FBFAF7; --card: #FFFFFF; --ink: #1A1814; --ink2: #5E5850; --ink3: #8E877C;
  --line: #E8E3D9; --wash: #F3F0E9; --green: #2F6B45; --green-ink: #FFFFFF; --green-wash: #E6EFE8;
  --gold: #A8823A; --red: #B3412E; --red-wash: #F8E7E3; --amber: #9A6A12; --amber-wash: #FBF0D9;
  --radius: 16px; --shadow: 0 1px 2px rgba(26,24,20,.05), 0 6px 20px rgba(26,24,20,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141311; --card: #1D1B18; --ink: #F2F0EC; --ink2: #BDB6AA; --ink3: #8A8378;
    --line: #2E2B27; --wash: #23211D; --green: #5FA77A; --green-ink: #0F1A13; --green-wash: #1E2C22;
    --gold: #D9B45A; --red: #E2735F; --red-wash: #3A211C; --amber: #E3B04F; --amber-wash: #33291A;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: "SF Arabic", "Geeza Pro", "Noto Sans Arabic", "Segoe UI", system-ui, sans-serif;
  font-size: 17px; line-height: 1.55; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px calc(120px + env(safe-area-inset-bottom)); }
header.top {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
header.top .row { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
header.top h1 { font-size: 19px; margin: 0; font-weight: 750; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .sub { color: var(--ink3); font-size: 13px; font-weight: 500; }
.tabs { display: flex; gap: 6px; max-width: 760px; margin: 10px auto 0; }
.tabs a {
  flex: 1; text-align: center; padding: 8px 10px; border-radius: 999px; text-decoration: none; color: var(--ink2);
  background: var(--wash); font-weight: 650; font-size: 15px; position: relative;
}
.tabs a.on { background: var(--green); color: var(--green-ink); }
.tabs .badge { position: absolute; top: -4px; left: 10px; }

.iconbtn { width: 40px; height: 40px; border-radius: 999px; border: 0; background: var(--wash); display: grid; place-items: center; flex: none; }
.iconbtn svg { width: 20px; height: 20px; }

h2 { font-size: 15px; color: var(--ink3); font-weight: 650; margin: 22px 4px 8px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }

.search { display: flex; gap: 8px; margin-top: 16px; }
.search input { flex: 1; min-width: 0; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-wash); }

.surah { display: flex; align-items: center; gap: 14px; padding: 13px 16px; text-decoration: none; color: inherit; }
.surah:active { background: var(--wash); }
.surah .n { width: 34px; height: 34px; border-radius: 10px; background: var(--wash); display: grid; place-items: center; font-size: 14px; font-weight: 650; color: var(--ink2); flex: none; }
.surah .name { flex: 1; font-weight: 650; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--amber-wash); color: var(--amber); white-space: nowrap; }
.badge.ok { background: var(--green-wash); color: var(--green); }
.badge.bad { background: var(--red-wash); color: var(--red); }
.badge.muted { background: var(--wash); color: var(--ink3); }

.ayah { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 10px; }
.ayah.now { background: var(--green-wash); }
.ayah .play { flex: 1; display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 0; text-align: start; min-width: 0; }
.ayah .no { width: 38px; height: 38px; border-radius: 999px; border: 1.5px solid var(--line); display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.ayah.now .no { border-color: var(--green); color: var(--green); }
.ayah .t { color: var(--ink3); font-size: 14px; }
.ayah .fix { border: 0; background: var(--wash); color: var(--ink); font-weight: 650; font-size: 14px; padding: 7px 14px; border-radius: 999px; }
.ayah .marks { display: flex; gap: 4px; }

.btn { border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; background: var(--wash); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--green); color: var(--green-ink); }
.btn.danger { background: var(--red-wash); color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.btn svg { width: 18px; height: 18px; }
.btn.small { padding: 8px 12px; border-radius: 11px; font-size: 14px; }

/* the player, at the foot of the surah */
.dock {
  position: fixed; inset: auto 0 0 0; z-index: 20; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.dock .in { max-width: 760px; margin: 0 auto; }
.dock .bar { display: flex; align-items: center; gap: 10px; }
.dock .times { display: flex; justify-content: space-between; color: var(--ink3); font-size: 13px; margin-top: 2px; }
.dock .big { width: 52px; height: 52px; border-radius: 999px; border: 0; background: var(--green); color: var(--green-ink); display: grid; place-items: center; flex: none; }
.dock .big svg { width: 24px; height: 24px; }
.dock .where { flex: 1; min-width: 0; }
.dock .where b { display: block; font-size: 15px; }
.dock .where span { color: var(--ink3); font-size: 13px; }
.dock .speed { border: 0; background: var(--wash); border-radius: 999px; padding: 6px 10px; font-weight: 700; font-size: 13px; }
input[type=range] { width: 100%; accent-color: var(--green); direction: ltr; margin: 8px 0 0; }

/* the correction sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(10,9,8,.42); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--paper); width: 100%; max-width: 640px; max-height: 94dvh; overflow: auto; border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.2);
}
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 22px; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 2px; font-size: 20px; }
.sheet .lead { color: var(--ink3); font-size: 14px; margin: 0 0 6px; }
.field { margin-top: 16px; }
.field > label, .field > .label { display: block; font-weight: 700; font-size: 14px; color: var(--ink2); margin: 0 2px 6px; }
.ends { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.end { background: var(--card); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }
.end .cap { font-size: 13px; color: var(--ink3); font-weight: 650; }
.end .val { font-size: 20px; font-weight: 750; margin: 2px 0 6px; }
.end .nudges { display: flex; gap: 6px; flex-wrap: wrap; }
.end .nudges button { border: 0; background: var(--wash); border-radius: 9px; padding: 6px 9px; font-size: 13px; font-weight: 700; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice { border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 8px; text-align: center; font-weight: 700; font-size: 14px; }
.choice small { display: block; font-weight: 500; color: var(--ink3); font-size: 12px; margin-top: 2px; }
.choice.on { border-color: var(--green); background: var(--green-wash); color: var(--green); }
.rec { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 12px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }
.recbtn { width: 76px; height: 76px; border-radius: 999px; border: 5px solid var(--red-wash); background: var(--red); display: grid; place-items: center; }
.recbtn i { width: 26px; height: 26px; border-radius: 999px; background: #fff; transition: border-radius .15s; }
.recbtn.on i { border-radius: 6px; width: 24px; height: 24px; }
.meter { width: 100%; max-width: 280px; height: 6px; border-radius: 9px; background: var(--wash); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width .06s; }
.clock { font-size: 22px; font-weight: 750; }
audio.inline { width: 100%; height: 40px; }
.hint { color: var(--ink3); font-size: 13px; text-align: center; }
.linkish { border: 0; background: none; color: var(--green); font-weight: 700; padding: 6px; }

.sub { padding: 14px 16px; }
.sub .head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sub .head b { font-size: 16px; }
.sub .meta { color: var(--ink3); font-size: 13px; margin-top: 2px; }
.sub .note { margin: 8px 0 0; background: var(--wash); border-radius: 10px; padding: 8px 10px; font-size: 15px; white-space: pre-wrap; }
.sub .mgr { margin: 8px 0 0; background: var(--red-wash); color: var(--red); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.sub .players { display: grid; gap: 8px; margin-top: 10px; }
.sub .players label { font-size: 13px; color: var(--ink3); font-weight: 650; }
.sub .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.sub .tune { margin-top: 10px; display: grid; gap: 6px; font-size: 14px; }
.sub .tune .r { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sub .tune .r span { min-width: 74px; color: var(--ink2); font-weight: 650; }
.sub .tune .nb { padding-inline-start: 80px; margin-top: -2px; }
@media (max-width: 420px) { .sub .tune .nb { padding-inline-start: 0; } }
.sub .tune button { border: 0; background: var(--wash); border-radius: 9px; padding: 5px 9px; font-weight: 700; font-size: 13px; }
.warn { color: var(--amber); font-weight: 650; font-size: 13px; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 380px; display: grid; gap: 12px; }
.login .logo { width: 64px; height: 64px; margin: 0 auto 4px; }
.login h1 { text-align: center; margin: 0; font-size: 24px; }
.login p { text-align: center; color: var(--ink3); margin: 0 0 8px; }
.err { color: var(--red); font-size: 14px; text-align: center; min-height: 1.2em; }
.empty { text-align: center; color: var(--ink3); padding: 36px 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 650; font-size: 15px;
  transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
:focus-visible { outline: 2.5px solid var(--green); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
