:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1f2a24;
  --muted: #66706a;
  --border: #e2ddd1;
  --accent: #1f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe3;
  --done: #2f8a63;
  --reserved: #e0a63a;
  --reserved-soft: #fbefd6;
  --mine: #1d5fa8;
  --danger: #b4412f;
  --free: #ebe7dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1a211d;
    --surface-2: #222b26;
    --text: #e8ece9;
    --muted: #9aa49e;
    --border: #2d3832;
    --accent: #3fa57a;
    --accent-ink: #0d1411;
    --accent-soft: #1f3a2e;
    --done: #3fa57a;
    --reserved: #e7b14e;
    --reserved-soft: #3a3020;
    --mine: #5b9be0;
    --danger: #e0715f;
    --free: #27302b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
p { margin: 0 0 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  max-width: 760px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
#nav { display: flex; gap: 8px; }
#nav a { color: var(--muted); text-decoration: none; font-weight: 500; padding: 6px 10px; border-radius: 8px; }
#nav a:hover { background: var(--surface-2); color: var(--text); }

main { max-width: 760px; margin: 0 auto; padding: 8px 16px 120px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack > * + * { margin-top: 12px; }

label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
input, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px;
  padding: 12px 18px; cursor: pointer; text-decoration: none; min-height: 46px;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.block { width: 100%; }
.btn.big { font-size: 18px; min-height: 56px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.hero { padding: 28px 0 12px; }
.hero h1 { font-size: 32px; }
.hero .lead { font-size: 18px; color: var(--muted); }
.steps { display: grid; gap: 10px; margin: 18px 0 24px; padding: 0; list-style: none; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps .num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 14px;
}

.progress { height: 10px; background: var(--free); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--done); border-radius: 99px; transition: width 0.4s; }

.list-item {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.list-item:hover { border-color: var(--accent); }
.list-item h3 { margin-bottom: 4px; }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; background: var(--accent-soft); }
.banner.warn { background: var(--reserved-soft); }

/* Parts grid */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin: 10px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.grid { display: grid; gap: 4px; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); }
.grid.juz { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.cell {
  font: inherit; font-size: 12px; font-variant-numeric: tabular-nums; aspect-ratio: 1;
  border: 0; border-radius: 6px; background: var(--free); color: var(--muted); cursor: pointer; padding: 0;
}
.grid.juz .cell { font-size: 16px; font-weight: 600; aspect-ratio: 1.3; border-radius: 10px; }
.cell.completed { background: var(--done); color: #fff; }
.cell.reserved { background: var(--reserved); color: #2b1d00; }
.cell.mine { outline: 3px solid var(--mine); outline-offset: -3px; }
.cell:focus-visible { outline: 3px solid var(--text); outline-offset: 1px; }

.members { list-style: none; padding: 0; margin: 0; }
.members li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.members li:last-child { border-bottom: 0; }
.tag { font-size: 12px; background: var(--surface-2); color: var(--muted); border-radius: 99px; padding: 2px 8px; margin-left: 6px; }

/* Reader */
.reader-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
.mushaf {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 18px; box-shadow: var(--shadow);
}
.quran {
  font-family: "Amiri Quran", "Amiri", "Scheherazade New", serif; direction: rtl; text-align: justify;
  font-size: clamp(22px, 5.6vw, 30px); line-height: 2.3; word-spacing: 2px;
}
.ayah-num { font-family: "Amiri Quran", serif; color: var(--accent); white-space: nowrap; }
.surah-head {
  text-align: center; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px;
  padding: 6px; margin: 10px 0 6px; font-size: 22px; line-height: 1.8;
}
.surah-head small { display: block; font-family: Inter, system-ui, sans-serif; font-size: 12px; color: var(--muted); direction: ltr; line-height: 1.4; }
.basmala { text-align: center; margin-bottom: 4px; }
.page-label { text-align: center; color: var(--muted); font-size: 13px; margin-top: 12px; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.actionbar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; }
.actionbar .btn { flex: 1; padding-left: 8px; padding-right: 8px; }
.timer { font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,0.2);
}

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }

@media (max-width: 480px) {
  h1 { font-size: 23px; }
  .hero h1 { font-size: 27px; }
  .card { padding: 16px; }
}
