/* =====================================================================
   وِردي — الأنماط
   Layout: a deep-green "binding" header over ivory pages. One column on
   phones, two columns on wide screens, a fixed tab bar at the bottom.
   Every color is a token; dark values are redefined below.
   ===================================================================== */

:root {
  /* Color */
  --paper: #F6F3E6;          /* ivory page */
  --card: #FFFDF7;           /* card surface */
  --tint: #ECF2E3;           /* light green wash */
  --ink: #1C2A22;            /* primary text */
  --ink-2: #4A5A51;          /* secondary text */
  --ink-3: #61705F;          /* muted text */
  --line: #E0DAC7;           /* hairlines */
  --cover: #1B4636;          /* dark green header */
  --cover-ink: #F6F3E6;
  --cover-ink-2: #C3D7C6;
  --leaf: #A8D49E;           /* light green accent on the header */
  --mark-fill: #2D5E4A;
  --bar-track: rgba(246, 243, 230, 0.17);
  --cover-line: rgba(246, 243, 230, 0.14);
  --primary: #1E5B43;
  --primary-hover: #184C38;
  --primary-ink: #FFFDF5;
  --primary-soft: #DCEAD3;
  --primary-soft-ink: #19493A;
  --amber: #A66A12;          /* streak flame, goal line */
  --danger: #A13A2B;
  --danger-soft: #F7E3DE;
  --danger-ink: #FFFDF7;
  --focus: #2F7D5C;
  --focus-ring: rgba(30, 91, 67, 0.22);
  --scrim: rgba(17, 27, 21, 0.48);
  --bar-bg: rgba(255, 253, 247, 0.95);
  --toast-bg: #1C2A22;
  --toast-ink: #F6F3E6;
  --toast-action: #A8D49E;
  --seg-shadow: 0 1px 3px rgba(28, 42, 34, 0.14);
  --shadow-1: 0 1px 2px rgba(28, 42, 34, 0.05), 0 10px 28px rgba(28, 42, 34, 0.08);
  --shadow-2: 0 -10px 30px rgba(28, 42, 34, 0.08);

  /* Type: the system Arabic face (SF Arabic on iPhone) keeps the app fast and legible */
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "SF Arabic", "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, "DejaVu Sans", sans-serif;
  --fs-xs: 0.78rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.1875rem;
  --fs-xl: 1.4rem;
  --fs-2xl: 2.1rem;

  /* Shape */
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1813;
    --card: #17221C;
    --tint: #1F2E26;
    --ink: #E5EDE6;
    --ink-2: #B5C4BA;
    --ink-3: #95A59A;
    --line: #2B3B32;
    --cover: #143326;
    --cover-ink: #EEF2E8;
    --cover-ink-2: #AFC6B6;
    --leaf: #95D190;
    --mark-fill: #20473A;
    --bar-track: rgba(238, 242, 232, 0.13);
    --cover-line: rgba(238, 242, 232, 0.12);
    --primary: #93CDA3;
    --primary-hover: #A9DBB6;
    --primary-ink: #0C1A12;
    --primary-soft: #223A2D;
    --primary-soft-ink: #BCE4C6;
    --amber: #E5A84A;
    --danger: #F29886;
    --danger-soft: #3B231E;
    --danger-ink: #1A0D0A;
    --focus: #A9DBB6;
    --focus-ring: rgba(147, 205, 163, 0.32);
    --scrim: rgba(0, 0, 0, 0.62);
    --bar-bg: rgba(23, 34, 28, 0.95);
    --toast-bg: #E5EDE6;
    --toast-ink: #0F1813;
    --toast-action: #1E5B43;
    --seg-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 -10px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0F1813;
  --card: #17221C;
  --tint: #1F2E26;
  --ink: #E5EDE6;
  --ink-2: #B5C4BA;
  --ink-3: #95A59A;
  --line: #2B3B32;
  --cover: #143326;
  --cover-ink: #EEF2E8;
  --cover-ink-2: #AFC6B6;
  --leaf: #95D190;
  --mark-fill: #20473A;
  --bar-track: rgba(238, 242, 232, 0.13);
  --cover-line: rgba(238, 242, 232, 0.12);
  --primary: #93CDA3;
  --primary-hover: #A9DBB6;
  --primary-ink: #0C1A12;
  --primary-soft: #223A2D;
  --primary-soft-ink: #BCE4C6;
  --amber: #E5A84A;
  --danger: #F29886;
  --danger-soft: #3B231E;
  --danger-ink: #1A0D0A;
  --focus: #A9DBB6;
  --focus-ring: rgba(147, 205, 163, 0.32);
  --scrim: rgba(0, 0, 0, 0.62);
  --bar-bg: rgba(23, 34, 28, 0.95);
  --toast-bg: #E5EDE6;
  --toast-ink: #0F1813;
  --toast-action: #1E5B43;
  --seg-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 -10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ---------------------------------------------------------------------
   Base
   --------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 106.25%; /* 17px, like iOS body text */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html[data-text="large"] { font-size: 118.75%; }
html[data-text="xlarge"] { font-size: 131.25%; }

:root {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.65;
  direction: rtl;
  text-align: right;
  -webkit-tap-highlight-color: transparent;
}

/* paints the status-bar strip on iPhone home-screen apps */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: env(safe-area-inset-top, 0px);
  background: var(--cover);
  z-index: 40;
}

body.modal-open { overflow: hidden; }

[hidden] { display: none !important; }

h1, h2, h3, p, ul, dl, dd, fieldset { margin: 0; }
fieldset { border: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
svg { flex: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ic {
  width: 1.3em;
  height: 1.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.28em;
}

/* the band carries the side gutter for every full-width stripe */
.band {
  width: 100%;
  max-width: 68rem;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------------------------------------------------------------------
   Buttons & fields
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.6rem 1.15rem;
  border: 1.5px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  font-weight: 700;
  font-size: var(--fs-md);
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-soft-ink); }
.btn-ghost { border-color: var(--line); color: var(--ink); background: var(--card); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger-solid { background: var(--danger); color: var(--danger-ink); }
.btn-block { width: 100%; }
.btn-lg { min-height: 3.5rem; font-size: var(--fs-lg); border-radius: 18px; }

.btn-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.25rem 0.1rem;
  border: 0;
  background: none;
  color: var(--primary-soft-ink);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 1.5px;
}

.field-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 700;
  line-height: 1.45;
}
.field-label-lg { font-size: var(--fs-lg); }
.field-help { margin-top: 0.5rem; font-size: var(--fs-sm); color: var(--ink-3); line-height: 1.55; }
.field-error { margin-top: 0.5rem; font-size: 0.9375rem; color: var(--danger); font-weight: 700; }

.input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 3rem;
  padding: 0.5rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.0625rem;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus-ring); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-num { font-weight: 700; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
input[type="date"].input { text-align: right; line-height: 2; }
input[type="date"].input::-webkit-date-and-time-value { text-align: right; }
textarea.input { min-height: 9rem; resize: vertical; font-size: 0.875rem; line-height: 1.5; direction: ltr; text-align: left; }

.inline-form { display: flex; gap: 0.5rem; align-items: stretch; }
.inline-form .input { flex: 1 1 auto; }
.inline-form .btn { flex: none; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.625rem; }
.btn-row > * { flex: 1 1 12rem; }
.file-btn { display: flex; }
.file-btn .btn { width: 100%; cursor: pointer; }
.file-btn input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* switch */
.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 3.4rem;
  height: 2.05rem;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: calc(2.05rem - 6px);
  height: calc(2.05rem - 6px);
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--seg-shadow);
  transition: transform 0.2s ease;
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(calc(2.05rem - 3.4rem)); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.toggle-label { font-weight: 700; line-height: 1.45; cursor: pointer; }

/* stepper: − on the right, + on the left, as iOS mirrors it in Arabic */
.stepper {
  display: grid;
  grid-template-columns: 3.6rem minmax(0, 1fr) 3.6rem;
  gap: 0.625rem;
  align-items: center;
}
.step-btn {
  display: grid;
  place-items: center;
  height: 3.6rem;
  border: 0;
  border-radius: 18px;
  background: var(--primary-soft);
  color: var(--primary-soft-ink);
  font-size: 1.35rem;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.step-btn .ic { stroke-width: 2.6; }
.step-btn:active:not(:disabled) { transform: scale(0.95); }
.step-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.step-input {
  width: 100%;
  min-width: 0;
  height: 3.6rem;
  padding: 0 0.5rem;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.85rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
}
.step-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus-ring); }
.step-input[aria-invalid="true"] { border-color: var(--danger); }

/* goal tiles */
.goal-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}
@media (min-width: 34rem) {
  .goal-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.goal-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-height: 5.6rem;
  padding: 0.75rem 0.85rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.goal-tile input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.goal-tile .num { font-size: 1.6rem; font-weight: 800; line-height: 1.15; }
.goal-tile .unit { font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
.goal-tile .sub { margin-top: 0.25rem; font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.4; }
.goal-tile.is-checked { border-color: var(--primary); background: var(--tint); box-shadow: inset 0 0 0 1px var(--primary); }
.goal-tile:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.goal-tile:not(:focus-within) { outline: none; }
.custom-goal { margin-top: 0.875rem; }

/* segmented control */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--tint);
}
.segmented label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.25rem 0.4rem;
  border-radius: 10px;
  color: var(--ink-2);
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
}
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented label.is-checked { background: var(--card); color: var(--ink); box-shadow: var(--seg-shadow); }
.segmented label:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.segmented label:not(:focus-within) { outline: none; }

/* ---------------------------------------------------------------------
   Header (cover)
   --------------------------------------------------------------------- */
.cover {
  background: var(--cover);
  color: var(--cover-ink);
  border-radius: 0 0 28px 28px;
}
.cover > .band { padding-block: 0.8rem 1.35rem; }

.brandbar { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
}
.mark { width: 1.75em; height: 1.75em; flex: none; }
.mark-shape rect { fill: var(--mark-fill); stroke: var(--leaf); stroke-width: 1.35; stroke-linejoin: round; }
.mark-line { fill: none; stroke: var(--leaf); stroke-width: 1.35; stroke-linejoin: round; }
.mark-dot { fill: var(--leaf); }
.brand .mark { width: 1.45em; height: 1.45em; }
.ob-brand .mark { width: 1.2em; height: 1.2em; }
.hdr-date {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: left;
  font-size: var(--fs-sm);
  line-height: 1.35;
  color: var(--cover-ink-2);
}
.hdr-date strong { color: var(--cover-ink); font-weight: 700; }

.greeting {
  margin-top: 0.85rem;
  font-size: var(--fs-xl);
  font-weight: 800;
  line-height: 1.45;
  text-wrap: balance;
}

/* khatma progress: one bar segment per juz */
.kp { display: grid; gap: 0.7rem; margin-top: 0.95rem; }
.kp-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.3rem 1rem; }
.kp-pct { display: flex; align-items: center; gap: 0.65rem; }
.kp-num { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.kp-of { display: flex; flex-direction: column; font-size: 0.875rem; line-height: 1.4; color: var(--cover-ink-2); }
.kp-of > span:first-child { color: var(--cover-ink); font-weight: 700; }
.kp-pages { font-size: 0.9375rem; font-weight: 700; color: var(--cover-ink); padding-bottom: 0.1rem; }
.juz-bar { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 3px; height: 0.8rem; }
.juz { position: relative; overflow: hidden; border-radius: 3px; background: var(--bar-track); }
.juz-fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: calc(var(--f, 0) * 100%);
  background: var(--leaf);
  transition: width 0.6s ease;
}
.kp-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--cover-line);
}
.kp-stats dt { font-size: 0.8125rem; color: var(--cover-ink-2); line-height: 1.4; }
.kp-stats dd { font-size: var(--fs-lg); font-weight: 800; line-height: 1.35; }
.kp-note { margin-top: -0.4rem; font-size: var(--fs-xs); color: var(--cover-ink-2); line-height: 1.5; }

.page-title { margin-top: 1rem; font-size: var(--fs-xl); font-weight: 800; line-height: 1.4; }
.page-sub { margin-top: 0.15rem; color: var(--cover-ink-2); font-size: 0.9375rem; }

/* ---------------------------------------------------------------------
   Main & cards
   --------------------------------------------------------------------- */
.main { padding-block: 1.1rem calc(6.25rem + 8px); }
.view { display: grid; gap: 1rem; min-width: 0; }
.notices { display: grid; gap: 0.5rem; padding-top: 0.9rem; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--r-md);
  background: var(--tint);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.notice .ic { color: var(--primary); margin-top: 0.1rem; }
.notice.is-warn { background: var(--danger-soft); }
.notice.is-warn .ic { color: var(--danger); }
.notice p { flex: 1 1 auto; min-width: 0; }
.notice .icon-btn { margin: -0.4rem -0.4rem -0.4rem 0; }

.home-grid { display: grid; gap: 1rem; align-items: start; }
@media (min-width: 56rem) {
  .home-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
  .home-grid .today, .home-grid .done-card { grid-row: span 2; }
}

.card {
  min-width: 0;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--card);
}
.card-raised { border-color: transparent; box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.7rem; }
.card-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--fs-lg);
  font-weight: 800;
  line-height: 1.35;
}
.card-title .ic { color: var(--primary); }
.card-meta { font-size: var(--fs-sm); color: var(--ink-3); font-weight: 700; white-space: nowrap; }
.card-text { color: var(--ink-2); line-height: 1.6; margin-bottom: 0.9rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  background: var(--tint);
  color: var(--primary-soft-ink);
  font-size: 0.9375rem;
  font-weight: 800;
  white-space: nowrap;
}
.pill .ic { width: 1.1em; height: 1.1em; stroke-width: 2.6; }
.pill.is-done { background: var(--primary); color: var(--primary-ink); }

.meter { height: 0.6rem; border-radius: 999px; background: var(--tint); overflow: hidden; }
.meter-fill {
  display: block;
  height: 100%;
  width: calc(var(--p, 0) * 1%);
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.5s ease;
}
.today-status { margin-top: 0.55rem; color: var(--ink-2); line-height: 1.55; }
.log-form { margin-top: 0.85rem; display: grid; }
.log-form .btn { margin-top: 0.8rem; }
.today-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.streak { display: flex; align-items: center; gap: 0.45rem; color: var(--ink-2); font-weight: 600; line-height: 1.45; min-width: 0; }
.ic-flame { color: var(--amber); }
.streak.is-active .ic-flame { fill: var(--amber); fill-opacity: 0.18; }

/* completed khatma */
.done-card { text-align: center; }
.done-star { width: 6.5rem; height: 6.5rem; margin: 0.4rem auto 0.9rem; }
.done-star svg { display: block; width: 100%; height: 100%; }
.star-fill rect { fill: var(--tint); }
.star-line rect { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; }
.star-disc { fill: var(--primary); }
.done-title { font-size: var(--fs-xl); font-weight: 800; line-height: 1.4; }
.done-dua { margin-top: 0.35rem; color: var(--ink-2); }
.done-summary { margin: 0.9rem 0 1.1rem; color: var(--ink); line-height: 1.7; }
.done-note { margin-top: 0.6rem; }
@media (prefers-reduced-motion: no-preference) {
  .done-star svg { animation: star-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
}
@keyframes star-in {
  from { transform: scale(0.5) rotate(-45deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* bookmark */
.bookmark-body { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.hizb { position: relative; flex: none; display: grid; place-items: center; width: 5.4rem; height: 5.4rem; }
.hizb svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.sq-fill rect { fill: var(--tint); }
.sq-line rect { fill: none; stroke: var(--primary); stroke-width: 2.2; stroke-linejoin: round; }
.hizb .disc { fill: var(--card); stroke: var(--primary); stroke-width: 1.4; }
.hizb-num { position: relative; font-size: 1.25rem; font-weight: 800; line-height: 1; color: var(--primary-soft-ink); }
.hizb-num.is-long { font-size: 0.98rem; }
.bookmark-text { min-width: 0; }
.bm-main { font-size: 1.0625rem; font-weight: 800; line-height: 1.45; }
.bm-sub { margin-top: 0.2rem; color: var(--ink-2); line-height: 1.5; }
.bm-meta { margin-top: 0.15rem; color: var(--ink-3); font-size: 0.9375rem; line-height: 1.5; }

/* week chart */
.chart { margin-top: 0.25rem; }
.plot {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
  height: 7.5rem;
  border-bottom: 1px solid var(--line);
}
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-val { margin-bottom: 3px; font-size: var(--fs-xs); font-weight: 800; color: var(--ink-2); line-height: 1.2; font-variant-numeric: tabular-nums; }
.bar {
  width: min(100%, 24px);
  height: calc(var(--h, 0) * 1%);
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  background: var(--primary);
  transition: height 0.5s ease;
}
.bar.is-zero { background: var(--line); }
.goal-line {
  position: absolute;
  inset-inline: 0;
  bottom: calc(var(--g, 0) * 1%);
  border-top: 2px dashed var(--amber);
  pointer-events: none;
}
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 0.35rem; }
.days > span { overflow: hidden; font-size: 0.75rem; color: var(--ink-3); text-align: center; white-space: nowrap; }
.days > span.is-today { color: var(--ink); font-weight: 800; }
.days .dn { display: none; }
/* when columns get narrow, weekday names give way to day numbers */
@media (max-width: 359px) {
  .days .dl { display: none; }
  .days .dn { display: inline; }
}
@media (max-width: 399px) {
  html[data-text="large"] .days .dl { display: none; }
  html[data-text="large"] .days .dn { display: inline; }
}
@media (max-width: 439px) {
  html[data-text="xlarge"] .days .dl { display: none; }
  html[data-text="xlarge"] .days .dn { display: inline; }
}
.chart-legend { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.7rem; font-size: 0.8125rem; color: var(--ink-3); }
.legend-dash { width: 1.6rem; border-top: 2px dashed var(--amber); }
.week-note { margin-top: 0.35rem; color: var(--ink-2); line-height: 1.55; }

/* ---------------------------------------------------------------------
   Log
   --------------------------------------------------------------------- */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.625rem; }
.summary-item {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
}
.summary-item dt { font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.35; }
@media (max-width: 399px) {
  html[data-text="large"] .summary, html[data-text="xlarge"] .summary { grid-template-columns: minmax(0, 1fr); }
  html[data-text="large"] .summary-item, html[data-text="xlarge"] .summary-item { flex-direction: row; align-items: center; gap: 0.75rem; }
}
.summary-item dd { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 0.3rem; margin-top: 0.15rem; line-height: 1.3; }
.summary-item dd strong { font-size: 1.45rem; font-weight: 800; }
.summary-item dd span { font-size: 0.875rem; font-weight: 700; color: var(--ink-2); }

.list-card { padding: 0; overflow: hidden; }
.month-head {
  padding: 0.8rem 1.1rem 0.3rem;
  font-size: 0.8125rem;
  font-weight: 800;
  color: var(--ink-3);
}
.month-head:not(:first-child) { border-top: 1px solid var(--line); }
.entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.7rem 1.1rem;
}
.entry-when { flex: 1 1 7.5rem; }
.entry-pages, .entry-edit { flex: none; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry-when { min-width: 0; line-height: 1.4; }
.entry-date { font-weight: 800; font-size: 1.05rem; }
.entry-day { display: block; font-size: 0.875rem; color: var(--ink-3); }
.entry-rel {
  display: inline-block;
  margin-inline-start: 0.4rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  background: var(--tint);
  color: var(--primary-soft-ink);
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: 0.1em;
}
.entry-note { display: block; font-size: 0.8125rem; color: var(--ink-3); }
.entry-pages { display: inline-flex; align-items: center; gap: 0.3rem; white-space: nowrap; color: var(--ink-2); }
.entry-pages strong { font-size: 1.15rem; color: var(--ink); }
.entry-pages .ic { color: var(--primary); width: 1.15em; height: 1.15em; stroke-width: 2.6; }
.entry-edit {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 2.75rem;
  padding: 0.3rem 0.7rem;
  border: 0;
  border-radius: 12px;
  background: var(--tint);
  color: var(--primary-soft-ink);
  font-weight: 700;
  font-size: 0.9375rem;
}
.entry.is-prior { background: var(--paper); }

.empty { display: grid; justify-items: center; gap: 0.4rem; padding: 2rem 1.25rem; text-align: center; }
.empty-ic { width: 2.6rem; height: 2.6rem; color: var(--primary); stroke-width: 1.6; margin-bottom: 0.3rem; }
.empty-title { font-weight: 800; font-size: 1.05rem; }
.empty-text { color: var(--ink-2); max-width: 26rem; line-height: 1.6; margin-bottom: 0.6rem; }

.section-title { margin: 0.5rem 0.2rem 0.6rem; font-size: 0.9375rem; font-weight: 800; color: var(--ink-2); }
.archive-list { display: grid; gap: 0.625rem; }
.archive-item {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
}
.archive-item > svg { width: 2.6rem; height: 2.6rem; margin-top: 0.1rem; }
.archive-item div { min-width: 0; display: grid; gap: 0.1rem; line-height: 1.5; }
.archive-item strong { font-size: 1.05rem; }
.archive-item span { color: var(--ink-2); font-size: 0.9375rem; }

/* ---------------------------------------------------------------------
   Settings
   --------------------------------------------------------------------- */
.set-group { display: grid; min-width: 0; }
.set-group .card + .card { margin-top: 0.75rem; }
.card > .field + .field { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }
.prior-row { margin-top: 0.9rem; }
.storage-state { display: flex; gap: 0.5rem; align-items: flex-start; font-weight: 700; margin-bottom: 0.75rem; line-height: 1.5; }
.storage-state .ic { color: var(--primary); margin-top: 0.1rem; }
.storage-state.is-warn { color: var(--danger); }
.storage-state.is-warn .ic { color: var(--danger); }
.plain-list { display: grid; gap: 0.55rem; }
.plain-list li { position: relative; padding-inline-start: 1.1rem; color: var(--ink-2); line-height: 1.6; }
.plain-list li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0.62em;
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 1px;
  background: var(--primary);
  transform: rotate(45deg);
}
.about { padding: 0.5rem 0.25rem 0; text-align: center; color: var(--ink-3); font-size: 0.875rem; line-height: 1.7; }

/* ---------------------------------------------------------------------
   Onboarding
   --------------------------------------------------------------------- */
.cover-tall > .band { padding-block: 2.2rem 2.4rem; }
.ob-brand { display: flex; align-items: center; gap: 0.6rem; font-size: 2.6rem; font-weight: 800; line-height: 1.2; }
.ob-tagline { margin-top: 0.6rem; font-size: var(--fs-xl); font-weight: 800; line-height: 1.45; text-wrap: balance; }
.ob-lead { margin-top: 0.6rem; max-width: 34rem; color: var(--cover-ink-2); line-height: 1.65; }
.ob-main { display: grid; gap: 1.1rem; max-width: 42rem; padding-block: 1.25rem 2.5rem; }
.ob-card { display: grid; gap: 1.25rem; padding: 1.2rem; }
.ob-card > .field + .field { padding-top: 1.1rem; border-top: 1px solid var(--line); }
.ob-foot { display: grid; gap: 0.9rem; }
.ob-privacy { display: flex; align-items: flex-start; gap: 0.55rem; color: var(--ink-2); line-height: 1.6; }
.ob-privacy .ic { color: var(--primary); margin-top: 0.15rem; }

/* ---------------------------------------------------------------------
   Tab bar
   --------------------------------------------------------------------- */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bar-bg);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}
.tabbar-inner {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.375rem;
  max-width: 34rem;
  margin-inline: auto;
  padding-block: 0.375rem;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  min-height: 3.6rem;
  border-radius: 14px;
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.3;
}
.tab-icon { display: grid; place-items: center; width: 3.4rem; height: 1.95rem; border-radius: 999px; transition: background-color 0.2s ease; }
.tab[aria-current="page"] { color: var(--primary-soft-ink); }
.tab[aria-current="page"] .tab-icon { background: var(--primary-soft); }

/* ---------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------- */
.toast {
  position: fixed;
  z-index: 60;
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 5.4rem);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 30rem;
  margin-inline: auto;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
  border-radius: 16px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  box-shadow: var(--shadow-1);
  font-weight: 600;
  line-height: 1.5;
}
.toast.no-tabbar { bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem); }
.toast-msg { flex: 1 1 auto; min-width: 0; padding-inline-start: 0.25rem; }
.toast-action {
  flex: none;
  min-height: 2.5rem;
  padding: 0.3rem 0.8rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--toast-action);
  font-weight: 800;
}
@media (prefers-reduced-motion: no-preference) {
  .toast:not([hidden]) { animation: toast-in 0.22s ease-out; }
}
@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------------------------------------------------------------------
   Dialogs
   --------------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding-bottom: var(--kb, 0px);
}
.modal-backdrop { position: absolute; inset: 0; background: var(--scrim); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 32rem;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.2rem max(18px, env(safe-area-inset-right, 0px)) calc(1.1rem + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  border-radius: 24px 24px 0 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}
.sheet:focus { outline: none; }
.sheet-grip { width: 2.6rem; height: 0.3rem; margin: -0.3rem auto 0.9rem; border-radius: 999px; background: var(--line); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.9rem; }
.sheet-title { font-size: 1.25rem; font-weight: 800; line-height: 1.4; }
.sheet-sub { margin-top: 0.15rem; color: var(--ink-2); font-size: 0.9375rem; }
.sheet-body { display: grid; gap: 0.9rem; }
.sheet-body > p { color: var(--ink-2); line-height: 1.65; }
.sheet-actions { display: grid; gap: 0.6rem; margin-top: 1.25rem; }
.sheet-preview { padding: 0.6rem 0.8rem; border-radius: var(--r-sm); background: var(--tint); color: var(--primary-soft-ink); font-weight: 700; font-size: 0.9375rem; line-height: 1.5; }
.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--tint); }

@media (min-width: 40rem) {
  .modal { align-items: center; padding-inline: 16px; padding-bottom: calc(var(--kb, 0px) + 16px); }
  .sheet { border-radius: 24px; padding-bottom: 1.2rem; }
  .sheet-grip { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .modal .sheet { animation: sheet-in 0.26s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .modal .modal-backdrop { animation: fade-in 0.2s ease-out; }
}
@keyframes sheet-in {
  from { transform: translateY(28px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* celebration */
.celebrate { text-align: center; }
.celebrate .done-star { position: relative; }
.petal {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.55rem;
  height: 0.55rem;
  margin: -0.275rem 0 0 -0.275rem;
  border-radius: 2px;
  background: var(--leaf);
  opacity: 0;
  transform: rotate(var(--a)) translateY(0) rotate(45deg);
}
.petal:nth-child(2) { --a: 0deg; }
.petal:nth-child(3) { --a: 45deg; background: var(--amber); }
.petal:nth-child(4) { --a: 90deg; }
.petal:nth-child(5) { --a: 135deg; background: var(--amber); }
.petal:nth-child(6) { --a: 180deg; }
.petal:nth-child(7) { --a: 225deg; background: var(--amber); }
.petal:nth-child(8) { --a: 270deg; }
.petal:nth-child(9) { --a: 315deg; background: var(--amber); }
@media (prefers-reduced-motion: no-preference) {
  .petal { animation: petal 1.2s 0.35s ease-out both; }
}
@keyframes petal {
  0% { opacity: 0; transform: rotate(var(--a)) translateY(0) rotate(45deg); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(-4.4rem) rotate(45deg); }
}

.noscript { padding: 2rem 1rem; text-align: center; font-weight: 700; }

/* wide screens: float the tab bar */
@media (min-width: 56rem) {
  .tabbar {
    left: 50%;
    right: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    width: 30rem;
    padding: 0 0.4rem;
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 22px;
  }
  .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 6.4rem); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
