@import url('/css/fonts.css');

/* Apple Human Interface style: grouped background, inset grouped lists, system blue,
   SF Pro for interface text (system font on Apple devices), a book serif for reading. */
:root {
  --bg: #f2f2f7;                 /* systemGroupedBackground */
  --cell: #ffffff;               /* secondarySystemGroupedBackground */
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);   /* secondaryLabel */
  --label-3: rgba(60, 60, 67, 0.3);   /* tertiaryLabel */
  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(118, 118, 128, 0.12);  /* tertiarySystemFill */
  --fill-2: rgba(120, 120, 128, 0.16);
  --blue: #007aff;
  --blue-tint: rgba(0, 122, 255, 0.12);
  --green: #34c759;
  --green-text: #248a3d;
  --green-tint: rgba(52, 199, 89, 0.15);
  --red: #ff3b30;
  --bar: rgba(249, 249, 249, 0.82);
  --blue-fill: #007aff;          /* filled buttons and badges (text on it is --on-blue) */
  --on-blue: #ffffff;
  --pressed: #e5e5ea;
  --chevron: #c4c4c7;
  --text-soft: #3a3a3c;          /* quotes, sources */
  --menu-bg: rgba(249, 249, 249, 0.92);
  --alert-bg: rgba(242, 242, 242, 0.94);
  --input-bg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.18);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --read-size: 20px;
  --ui: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --serif: ui-serif, 'New York', 'Iowan Old Style', 'Literata Variable', Georgia, 'Times New Roman', serif;
  --arabic: 'Amiri', 'Geeza Pro', 'Noto Naskh Arabic', 'Traditional Arabic', serif;
  --radius: 12px;
  --bar-h: 76px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: var(--ui);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 45%, transparent); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }

.wrap { max-width: 680px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* ---------- navigation bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding-top: 6px; padding-bottom: 6px;
}
.brand { font-weight: 600; color: var(--label); }
.back {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; margin-left: -6px;
  color: var(--blue); font-size: 17px; max-width: 62vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.back::before {
  content: ''; flex: 0 0 auto; width: 13px; height: 21px; margin-right: 4px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 13 21'%3E%3Cpath d='M11 2 3 10.5 11 19' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 13 21'%3E%3Cpath d='M11 2 3 10.5 11 19' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.large-title, .list-head h1, .login h1 {
  font-family: var(--display); font-size: 34px; line-height: 1.2; font-weight: 700; letter-spacing: 0.01em;
  margin: 4px 0 14px; text-wrap: balance;
}

.who { position: relative; }
.who-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px;
  border: 0; border-radius: 999px; background: var(--fill); color: var(--blue); font-size: 15px; font-weight: 600; cursor: pointer;
}
.who-btn::before {
  content: ''; width: 16px; height: 16px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='5' r='3.2'/%3E%3Cpath d='M1.5 15c.6-3.4 3.2-5.2 6.5-5.2s5.9 1.8 6.5 5.2z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='5' r='3.2'/%3E%3Cpath d='M1.5 15c.6-3.4 3.2-5.2 6.5-5.2s5.9 1.8 6.5 5.2z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.who-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: 250px; overflow: hidden;
  background: var(--menu-bg); -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  border-radius: 13px; box-shadow: 0 10px 40px var(--shadow), 0 0 0 0.5px var(--separator);
}
.who-menu p { margin: 0; padding: 12px 16px; color: var(--label-2); font-size: 13px; border-bottom: 0.5px solid var(--separator); }
.who-menu button {
  display: block; width: 100%; text-align: left; padding: 12px 16px; border: 0; background: none; cursor: pointer; font-size: 17px; color: var(--red);
}
.who-menu button:active { background: var(--fill-2); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 0 20px; border: 0; border-radius: 14px;
  background: var(--fill); color: var(--blue); font-size: 17px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.6; }
.btn-primary { background: var(--blue-fill); color: var(--on-blue); }
.btn-tinted { background: var(--blue-tint); color: var(--blue); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: default; }
.link-btn { background: none; border: 0; padding: 10px 0; color: var(--blue); font-size: 17px; cursor: pointer; }

/* ---------- inset grouped lists ---------- */
.group-title { font-family: var(--display); font-size: 22px; font-weight: 700; margin: 28px 0 8px; padding-left: 4px; letter-spacing: 0.01em; }
.group-footer, .empty { color: var(--label-2); font-size: 13px; margin: 8px 16px 0; }
.group, .lessons {
  list-style: none; margin: 0; padding: 0; background: var(--cell); border-radius: var(--radius); overflow: hidden;
}
.group li, .lessons li { position: relative; }
.group li + li::before, .lessons li + li::before {
  content: ''; position: absolute; top: 0; right: 0; left: 16px; border-top: 0.5px solid var(--separator);
}
.group li:has(.ring) + li::before { left: 58px; }
.cell { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 11px 16px; color: var(--label); }
.cell:active, .lessons a:active { background: var(--pressed); }
.cell::after, .lessons a::after {
  content: ''; flex: 0 0 auto; width: 8px; height: 13px; margin-left: 2px; background: var(--chevron);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'%3E%3Cpath d='M1.5 1.5 6.5 6.5 1.5 11.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'%3E%3Cpath d='M1.5 1.5 6.5 6.5 1.5 11.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.cell-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.cell-title { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { font-size: 15px; color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-detail { flex: 0 0 auto; color: var(--label-2); font-size: 17px; font-variant-numeric: tabular-nums; }

.ring {
  --p: 0; flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: conic-gradient(var(--blue) calc(var(--p) * 1%), var(--fill-2) 0);
  -webkit-mask: radial-gradient(circle, transparent 10px, #000 10.5px);
          mask: radial-gradient(circle, transparent 10px, #000 10.5px);
}
.ring.is-full { background: var(--green); }

/* ---------- home: continue card ---------- */
.next {
  margin: 0 0 4px; padding: 20px; border-radius: 18px; background: var(--cell);
  box-shadow: var(--card-shadow);
  display: grid; gap: 14px;
}
.next-meta { margin: 0; color: var(--label-2); font-size: 15px; }
.next-title {
  margin: 0; font-family: var(--serif); font-weight: 700; font-size: clamp(26px, 7vw, 32px); line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance;
}
.next-done { margin: 0; font-size: 20px; font-weight: 600; }
.progress { height: 4px; border-radius: 2px; background: var(--fill-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 2px; background: var(--blue); }

/* ---------- login ---------- */
.login { padding: 6vh 0 40px; }
.login > p { color: var(--label-2); margin: 0 0 28px; font-size: 17px; }
.login form { display: grid; gap: 10px; }
.field { display: grid; gap: 6px; }
.field label, .field .label { font-size: 13px; color: var(--label-2); text-transform: uppercase; letter-spacing: 0.02em; padding-left: 16px; }
.field input {
  min-height: 50px; padding: 0 16px; border: 0; border-radius: var(--radius); background: var(--cell); font-size: 17px; outline: none;
}
.field input:focus { box-shadow: 0 0 0 2px var(--blue); }
.hint { color: var(--label-2); font-size: 13px; margin: 0; padding: 0 16px; }
.error { color: var(--red); font-size: 15px; margin: 0; padding: 0 16px; }
.login .btn-primary { margin-top: 14px; }
.confirm { background: var(--cell); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; margin-top: 6px; }
.confirm p { margin: 0; }
.confirm .hint { padding: 0; }
.confirm .row { display: flex; gap: 10px; }
.confirm .row .btn { flex: 1; }
.guest-link { margin-top: 30px; text-align: center; }
.guest-link .hint { padding: 0; }
.turnstile { min-height: 65px; display: flex; justify-content: center; }

/* ---------- list page ---------- */
.list-head p { margin: -8px 0 16px; color: var(--label-2); font-size: 15px; }
.search {
  width: 100%; min-height: 36px; padding: 0 12px 0 34px; margin-bottom: 14px; border: 0; border-radius: 10px;
  background: var(--fill) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='6.8' cy='6.8' r='5.2' fill='none' stroke='%238e8e93' stroke-width='1.8'/%3E%3Cpath d='m10.8 10.8 4 4' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 11px 50% / 15px no-repeat;
  font-size: 17px; outline: none; -webkit-appearance: none; appearance: none;
}
.lessons { margin-bottom: 48px; }
.lessons a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 11px 16px; color: var(--label); }
.lessons .num { flex: 0 0 1.6em; color: var(--label-2); font-size: 15px; font-variant-numeric: tabular-nums; }
.lessons .t { flex: 1; min-width: 0; font-size: 17px; }
.lessons .state { flex: 0 0 auto; font-size: 15px; color: var(--label-2); white-space: nowrap; }
.lessons li.is-read .t { color: var(--label-2); }
.lessons li.is-read .state { color: var(--green-text); }
.lessons li.is-read .state::before { content: '✓ '; font-weight: 700; }
.lessons li.is-next .state { color: var(--on-blue); background: var(--blue-fill); font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.lessons li.is-next .t { font-weight: 600; }

/* ---------- reader ---------- */
.reader-top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bar); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
}
body:has(.reader-top) { background: var(--cell); }
.size { display: flex; padding: 2px; border-radius: 9px; background: var(--fill); }
.size button { width: 44px; height: 30px; border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--label); font-family: var(--ui); }
.size button:nth-child(1) { font-size: 13px; }
.size button:nth-child(2) { font-size: 19px; font-weight: 500; }
.size button:nth-child(3) { font-size: 16px; }
.size button + button { position: relative; }
.size button + button::before { content: ''; position: absolute; left: 0; top: 7px; bottom: 7px; border-left: 1px solid var(--separator); }
.size button:active { background: var(--cell); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.size button:disabled { color: var(--label-3); }

.lesson { padding-top: 12px; padding-bottom: calc(var(--bar-h) + 48px + env(safe-area-inset-bottom, 0px)); }
.lesson h1 {
  font-family: var(--serif); font-weight: 700; font-size: calc(var(--read-size) * 1.55); line-height: 1.18;
  letter-spacing: -0.01em; margin: 8px 0 12px; text-wrap: balance;
}
.lesson-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.lesson-tags a { font-size: 13px; font-weight: 600; color: var(--blue); background: var(--blue-tint); padding: 5px 11px; border-radius: 999px; }
.prior {
  display: flex; gap: 10px; align-items: flex-start; margin: 0 0 24px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--fill); color: var(--label-2); font-size: 15px;
}
.prior::before {
  content: 'i'; flex: 0 0 auto; display: grid; place-items: center; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%;
  background: var(--blue-fill); color: var(--on-blue); font: italic 700 13px/1 Georgia, serif;
}

.body { font-family: var(--serif); font-size: var(--read-size); line-height: 1.65; letter-spacing: 0; }
.body p { margin: 0 0 0.85em; }
.body h3 { font-family: var(--display); font-size: 1.05em; font-weight: 700; margin: 1.5em 0 0.45em; line-height: 1.3; }
.body ul, .body ol { padding-left: 1.3em; margin: 0 0 0.85em; }
.body blockquote { margin: 0 0 0.85em; padding-left: 0.9em; border-left: 3px solid var(--fill-2); color: var(--text-soft); }
.body .ar { font-family: var(--arabic); font-size: 1.5em; line-height: 2.05; text-align: center; margin: 1.1em 0; color: var(--label); }
.body .ar-i { font-family: var(--arabic); font-size: 1.3em; line-height: 1; }

.sources { margin-top: 2.4em; }
.sources h2 { font-size: 13px; font-weight: 400; color: var(--label-2); text-transform: uppercase; letter-spacing: 0.02em; margin: 0 0 6px 16px; }
.sources ol { margin: 0; padding: 10px 16px 10px 36px; background: var(--bg); border-radius: var(--radius); font-size: 15px; color: var(--text-soft); }
.sources li { margin: 4px 0; }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: var(--bar); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid var(--separator);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
}
.bar .wrap { display: flex; gap: 10px; align-items: center; }
.bar .btn { flex: 1; white-space: nowrap; }
.mark.is-done, .mark.is-done:disabled { background: var(--green-tint); color: var(--green-text); opacity: 1; }
.undo { flex: 0 0 auto !important; padding: 0 6px; border: 0; background: none; color: var(--blue); cursor: pointer; min-height: 50px; font-size: 17px; }

/* ---------- HUD toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px); padding: 12px 20px; border-radius: 999px;
  background: rgba(30, 30, 30, 0.86); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  color: #fff; font-size: 15px; font-weight: 500; text-align: center;
}

/* ---------- alert (in-page confirm/prompt) ---------- */
.ask { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.2); }
.ask-box {
  width: 270px; display: grid; overflow: hidden; border-radius: 14px; text-align: center;
  background: var(--alert-bg); -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
}
.ask-box p { margin: 0; padding: 19px 16px 15px; font-size: 15px; font-weight: 600; line-height: 1.3; }
.ask-input { margin: 0 16px 16px; min-height: 30px; padding: 0 8px; border: 0.5px solid var(--separator); border-radius: 7px; background: var(--input-bg); font-size: 15px; outline: none; }
.ask-actions { display: flex; border-top: 0.5px solid var(--separator); }
.ask-actions .btn { flex: 1; min-height: 44px; border-radius: 0; background: none; color: var(--blue); font-weight: 400; padding: 0 8px; }
.ask-actions .btn + .btn { border-left: 0.5px solid var(--separator); }
.ask-actions .btn[type='submit'] { font-weight: 600; }
.ask-actions .btn-danger-solid { color: var(--red); }

.loading { color: var(--label-2); padding: 40px 0; }

@media (min-width: 720px) {
  .login { padding-top: 10vh; }
}
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

.site-footer { margin: 40px 0 32px; text-align: center; font-size: 13px; }
.site-footer a { color: var(--label-3); }

/* ---------- Night reading (set by js/theme.js on reader pages) ----------
   Dark grey instead of black and warm off-white instead of white: less glare and halo around
   letters, less blue light. Accents desaturated so they don't vibrate on the dark background. */
:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #18181a;
  --cell: #1f1f21;
  --label: #ddd5c6;
  --label-2: #9d978c;
  --label-3: #67635c;
  --separator: rgba(221, 213, 198, 0.14);
  --fill: rgba(221, 213, 198, 0.08);
  --fill-2: rgba(221, 213, 198, 0.13);
  --blue: #7fb0e8;
  --blue-fill: #2e5f9c;
  --on-blue: #eaf1fa;
  --blue-tint: rgba(127, 176, 232, 0.15);
  --green: #4e9e66;
  --green-text: #8cc79c;
  --green-tint: rgba(78, 158, 102, 0.2);
  --red: #e0756c;
  --bar: rgba(31, 31, 33, 0.9);
  --pressed: #2a2a2d;
  --chevron: #55524d;
  --text-soft: #c4bcae;
  --menu-bg: rgba(44, 44, 47, 0.97);
  --alert-bg: rgba(44, 44, 47, 0.97);
  --input-bg: #18181a;
  --shadow: rgba(0, 0, 0, 0.55);
  --card-shadow: 0 0 0 0.5px rgba(221, 213, 198, 0.08);
}
:root[data-theme="night"] .body { -webkit-font-smoothing: antialiased; }
:root[data-theme="night"] .toast { background: rgba(60, 60, 64, 0.95); color: var(--label); }
:root[data-theme="night"] .ring.is-full { background: var(--green); }
:root[data-theme="night"] .mark.is-done, :root[data-theme="night"] .mark.is-done:disabled { color: var(--green-text); }

/* Theme choice (in the account menu and on the lesson page) */
.theme-row { display: flex; gap: 2px; margin: 4px 10px 10px; padding: 2px; border-radius: 9px; background: var(--fill); }
.theme-row button {
  flex: 1; padding: 7px 4px !important; border: 0; border-radius: 7px; background: none; color: var(--label) !important;
  font-size: 13px !important; text-align: center !important; cursor: pointer;
}
.theme-row button[aria-pressed="true"] { background: var(--cell); font-weight: 600; box-shadow: 0 1px 3px var(--shadow); }
.who-menu .theme-label { margin: 0; padding: 10px 16px 0; border: 0; font-size: 13px; color: var(--label-2); }

/* Chapter page: link back to its book, like an iOS back button */
.list-parent { display: inline-flex; align-items: center; gap: 2px; margin: 4px 0 0; min-height: 44px; color: var(--blue); font-size: 17px; text-decoration: none; }
.list-parent::before { content: '‹'; font-size: 28px; line-height: 1; margin-top: -3px; }
