:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --ink: #1c1b19;
  --muted: #6e6a62;
  --line: #e6e2d9;
  --accent: #2a3b8f;
  --accent-soft: #e8ebf7;
  --accent-text: #2a3b8f;
  --ok: #1b7a48;
  --bad: #b42318;
  --bad-soft: #fbe9e7;
  --na: #a29d93;
  --mark: #fde7a8;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.04), 0 8px 24px rgba(28, 27, 25, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1b19;
    --ink: #faf9f6;
    --muted: #a29d93;
    --line: #2f2d2a;
    --accent: #2a3b8f;
    --accent-soft: #23295a;
    --accent-text: #a9b6ff;
    --ok: #5cc98f;
    --bad: #ff8577;
    --bad-soft: #3a1d1a;
    --na: #77726a;
    --mark: #5a4710;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

button { font: inherit; color: inherit; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 18px 16px 4px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mark { width: 24px; height: 22px; }

.title { color: var(--muted); font-size: 14px; }

main {
  flex: 1;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

/* picker and model */
.pick {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 10px;
  margin-bottom: 10px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; position: relative; }
.field > span { font-size: 12px; color: var(--muted); padding-left: 2px; }
.field::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 18px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 34px 10px 12px;
  min-height: 44px;
  text-overflow: ellipsis;
}
select:focus-visible, button:focus-visible, .w:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.seg { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.seg .label { margin-right: 4px; }
.seg .unit { margin-left: 2px; }
.seg button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 3px 10px;
  min-height: 30px;
  cursor: pointer;
  color: var(--muted);
  text-align: left;
}
.seg button[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-text);
  font-weight: 600;
}
.seg button:disabled { opacity: 0.5; cursor: default; }
.seg.model { font-size: 14px; color: var(--muted); margin-bottom: 14px; }

/* the list of recited ayat */
.log-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--muted);
  margin: 4px 2px 6px;
}
.log-head[hidden] { display: none; }
.link { border: 0; background: none; color: var(--accent-text); cursor: pointer; padding: 4px; font-size: 13px; }

.log { display: grid; gap: 10px; margin-bottom: 10px; }

.take {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
}
.take header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.take .sum { text-align: right; }
.take .sum .ok { color: var(--ok); }
.take .sum .bad { color: var(--bad); }

/* the ayah */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
  scroll-margin-bottom: 140px;
}
.card .ref { font-size: 13px; color: var(--muted); text-align: center; }

.ayah {
  font-family: "Hafs", "Amiri Quran", "Amiri", "Noto Naskh Arabic", serif;
  font-size: clamp(28px, 7.4vw, 42px);
  line-height: 2.05;
  text-align: center;
  margin: 0;
  word-spacing: 0.06em;
  overflow-wrap: break-word;
}
.ayah.long { font-size: clamp(24px, 6vw, 34px); line-height: 2.1; }
.ayah.small, .ayah.small.long { font-size: clamp(22px, 5.6vw, 30px); line-height: 1.95; }

.w {
  border-radius: 8px;
  padding: 0 0.06em;
  transition: color 0.25s ease, background-color 0.25s ease;
}
.take .w[role="button"] { cursor: pointer; }
.w.ok, .latin .ok { color: var(--ok); }
.w.bad, .latin .bad {
  color: var(--bad);
  text-decoration: underline dotted;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.35em;
  text-decoration-skip-ink: none;
}
.w.bad.firm, .latin .bad.firm { background: var(--bad-soft); text-decoration: none; }
.w.ok.maybe, .latin .ok.maybe {
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.35em;
  text-decoration-skip-ink: none;
  text-decoration-color: color-mix(in srgb, var(--ok) 35%, transparent);
}
.w.na, .latin .na { color: var(--na); }
.w.sel { box-shadow: 0 0 0 1.5px var(--accent-text); }

.num {
  font-family: "Hafs", serif;
  color: var(--muted);
  margin-inline-start: 0.15em;
}

.latin {
  margin: 4px 0 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
}
.card .latin.expected { color: var(--ink); }
.take .latin { text-align: left; display: flex; gap: 8px; }
.latin .lbl {
  flex: none;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding-top: 0.25em;
  min-width: 58px;
}
.card .latin .lbl { margin-right: 6px; }
.latin mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.notice {
  margin: 4px auto 6px;
  width: fit-content;
  max-width: 100%;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 6px 14px;
}
.notice[hidden] { display: none; }

.detail {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 15px;
}
.detail h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.detail h3 .ar { font-size: 24px; font-weight: 400; }
.detail ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.detail li { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.detail .tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 8px;
  margin-right: 6px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.detail .tag.firm { background: var(--bad); color: var(--surface); }
.detail .meta { color: var(--muted); font-size: 13px; }
.ar { font-family: "Hafs", "Amiri", serif; font-size: 22px; line-height: 1.6; }

/* the recorder, docked at the bottom */
.dock {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 22%);
}
.dock-side { flex: 1; min-width: 0; }

.rec-btn {
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(42, 59, 143, 0.35);
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.rec-btn:active { transform: scale(0.96); }
.rec-btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.rec-btn svg { width: 32px; height: 30px; overflow: visible; }
.rec-btn .b { transform-box: fill-box; transform-origin: center; transition: transform 0.08s linear; }
.rec-btn.live { animation: ring 1.6s ease-out infinite; }
.rec-btn.busy .b { animation: wave 1s ease-in-out infinite; }
.rec-btn.busy .b:nth-child(2) { animation-delay: 0.1s; }
.rec-btn.busy .b:nth-child(3) { animation-delay: 0.2s; }
.rec-btn.busy .b:nth-child(4) { animation-delay: 0.3s; }
.rec-btn.busy .b:nth-child(5) { animation-delay: 0.4s; }

@keyframes ring {
  0% { box-shadow: 0 0 0 0 rgba(42, 59, 143, 0.45), 0 6px 18px rgba(42, 59, 143, 0.35); }
  100% { box-shadow: 0 0 0 16px rgba(42, 59, 143, 0), 0 6px 18px rgba(42, 59, 143, 0.35); }
}
@keyframes wave {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1); }
}

.status { margin: 0; color: var(--muted); font-size: 15px; min-height: 1.5em; }

.progress {
  width: 100%;
  max-width: 260px;
  height: 4px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
  margin-top: 6px;
}
.progress[hidden] { display: none; }
.progress .fill { height: 100%; width: 0; background: var(--accent-text); transition: width 0.2s ease; }

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

.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 14px;
  min-height: 34px;
  cursor: pointer;
  font-size: 14px;
}
.ghost:hover { border-color: var(--muted); }
.ghost:disabled { opacity: 0.5; cursor: default; }

/* legend and settings */
.legend {
  margin: 18px 0 0;
  font-size: 14px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.legend .key { display: inline-flex; align-items: flex-start; gap: 6px; }
.legend .key .dot { margin-top: 0.42em; flex: none; }
.legend .note { flex-basis: 100%; margin-top: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.na { background: var(--na); }

.settings {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  font-size: 14px;
  color: var(--muted);
}
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 30px; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }

footer {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px 28px;
  font-size: 13px;
  color: var(--muted);
}

@media (min-width: 560px) {
  .card { padding: 20px 28px 22px; }
  .pick { grid-template-columns: 1fr 120px; }
}

@media (prefers-reduced-motion: reduce) {
  .rec-btn.live, .rec-btn.busy .b { animation: none; }
}
