:root {
  --bg: #F7F1E8;
  --surface: #FFFDF8;
  --surface-2: #F1E9DC;
  --ink: #3B3A2E;
  --muted: #7A7565;
  --line: #E6DCCB;
  --sage: #8FA98A;
  --sage-soft: #E3EBDD;
  --sage-deep: #5E7D5A;
  --clay: #C98B6B;
  --clay-soft: #F4E3D8;
  --gold: #D2A54F;
  --gold-soft: #F6EAD0;
  --lilac: #8C7BA6;
  --p-allah: #5E8C7E;
  --p-income: #C98B6B;
  --p-fun: #D2A54F;
  --p-community: #8C7BA6;
  --shadow: 0 1px 2px rgba(59, 58, 46, .06), 0 4px 14px rgba(59, 58, 46, .05);
  --radius: 18px;
  --font-head: 'Fraunces', Georgia, serif;
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F1D18;
    --surface: #2A2721;
    --surface-2: #34302A;
    --ink: #EFE8DA;
    --muted: #B3AA98;
    --line: #403B33;
    --sage: #9DB898;
    --sage-soft: #2F3A2D;
    --sage-deep: #B5CCAF;
    --clay: #D9A083;
    --clay-soft: #3D2F27;
    --gold: #E0B866;
    --gold-soft: #3B3222;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1F1D18; --surface: #2A2721; --surface-2: #34302A; --ink: #EFE8DA; --muted: #B3AA98;
  --line: #403B33; --sage: #9DB898; --sage-soft: #2F3A2D; --sage-deep: #B5CCAF; --clay: #D9A083;
  --clay-soft: #3D2F27; --gold: #E0B866; --gold-soft: #3B3222; --shadow: none; 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 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 500; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 28px 0 10px; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.lock::before { content: "🔒 "; }

/* Splash + sign in */
.splash { min-height: 70vh; display: grid; place-content: center; text-align: center; gap: 6px; }
.splash-title { font-family: var(--font-head); font-size: 1.8rem; }
.auth { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 14px; }
.auth h1 { text-align: center; }
.auth p { text-align: center; }

/* Top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.date-nav { display: flex; align-items: center; gap: 10px; }
.date-nav .label { text-align: center; min-width: 9.5em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; font-size: 1.2rem; line-height: 1;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.sync { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.sync.ok::before { content: "● "; color: var(--sage); }
.sync.wait::before { content: "● "; color: var(--gold); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.dua { background: var(--sage-soft); border-color: transparent; }
.dua-text { font-family: var(--font-head); font-size: 1.05rem; line-height: 1.55; margin-top: 6px; }
.banner { margin-top: 12px; padding: 12px 14px; border-radius: 14px; background: var(--gold-soft); font-size: .95rem; }
.banner.grace { background: var(--clay-soft); }

/* Toggle chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: .9rem; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--clay-soft); border-color: var(--clay); }
.chip.sage[aria-pressed="true"] { background: var(--sage-soft); border-color: var(--sage); }

/* Tiles */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  position: relative; text-align: left; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 14px; min-height: 92px; display: flex; flex-direction: column;
  gap: 2px; box-shadow: var(--shadow); transition: background .15s, border-color .15s, transform .08s;
}
.tile:active { transform: scale(.98); }
.tile .ti { font-size: 1.35rem; line-height: 1; margin-bottom: 6px; }
.tile .tl { font-weight: 700; line-height: 1.25; }
.tile .ts { font-size: .82rem; color: var(--muted); }
.tile.on { background: var(--sage-soft); border-color: var(--sage); }
.tile.on::after, .tile.soft::after {
  content: "✓"; position: absolute; top: 10px; right: 12px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--sage-deep); color: var(--surface); font-size: .8rem; display: grid; place-items: center; font-weight: 700;
}
.tile.soft { background: var(--gold-soft); border-color: var(--gold); }
.tile.soft::after { background: var(--gold); content: "~"; }
.tile.paused { background: var(--surface-2); border-style: dashed; cursor: default; }
.tile.wide { grid-column: 1 / -1; }
.counter-row { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 6px; }
.step {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg);
  font-size: 1.15rem; line-height: 1; display: grid; place-items: center;
}
.step.plus { background: var(--sage-deep); border-color: var(--sage-deep); color: var(--surface); }
.count { font-weight: 700; font-size: 1.15rem; min-width: 2.2em; text-align: center; }
.tile.counter { cursor: default; }
.tile.counter.on::after { display: none; }

/* Inline fields */
.field { display: grid; gap: 6px; margin-top: 10px; }
.field label, .field .lbl { font-size: .85rem; font-weight: 700; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="time"], input[type="date"], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 11px 12px; font-size: 16px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--sage); box-shadow: 0 0 0 3px var(--sage-soft); }
textarea { resize: vertical; min-height: 64px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.private-note { font-size: .8rem; color: var(--muted); }

.btn {
  border: 0; border-radius: 999px; padding: 12px 18px; font-weight: 700;
  background: var(--sage-deep); color: var(--surface);
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 8px 14px; font-size: .9rem; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; padding: 0; color: var(--sage-deep); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* Rating */
.rating { display: flex; gap: 8px; margin-top: 8px; }
.rating button {
  flex: 1; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; font-size: 1.05rem;
}
.rating button[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); }
.rating-words { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg); }
.pill { font-size: .75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.pill.memorizing { background: var(--gold-soft); }
.pill.memorized { background: var(--sage-soft); }
.pill.reviewing { background: var(--clay-soft); }

/* Week view */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.day-dot { display: grid; gap: 4px; justify-items: center; font-size: .75rem; color: var(--muted); font-weight: 700; }
.day-dot span {
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center;
  font-size: .85rem; color: var(--ink); background: var(--surface);
}
.day-dot.done span { background: var(--sage-soft); border-color: var(--sage); }
.day-dot.grace span { background: var(--clay-soft); border-color: var(--clay); }
.day-dot.today span { box-shadow: 0 0 0 3px var(--gold-soft); }
.rings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 8px; }
.ring { display: grid; justify-items: center; text-align: center; gap: 4px; }
.ring svg { width: 78px; height: 78px; }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--sage); transition: stroke-dashoffset .4s ease; }
.ring.met .fill { stroke: var(--gold); }
.ring .num { font-family: var(--font-head); font-size: 17px; fill: var(--ink); }
.ring .name { font-size: .8rem; font-weight: 700; line-height: 1.2; }
.ring .note { font-size: .72rem; color: var(--muted); }
.bars { display: grid; gap: 12px; }
.bar-label { display: flex; justify-content: space-between; font-size: .9rem; font-weight: 700; }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 999px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-family: var(--font-head); font-size: 1.4rem; font-weight: 500; }
.stat small { color: var(--muted); font-size: .8rem; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
}
.tabs-inner { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; max-width: 560px; }
.tabs button {
  border: 0; background: none; padding: 6px 4px; display: grid; justify-items: center; gap: 2px;
  font-size: .75rem; font-weight: 700; color: var(--muted);
}
.tabs button .tab-ico { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs button[aria-current="page"] { color: var(--sage-deep); }
.tabs button[aria-current="page"] .tab-ico { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 84px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem;
  font-weight: 600; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.err { color: var(--clay); font-size: .9rem; }
.spacer { height: 8px; }
@media (min-width: 720px) {
  main { padding-top: 32px; }
}
.grid + .card { margin-top: 12px; }

/* Settings: goal editor */
.goal-row { border-top: 1px solid var(--line); padding: 12px 0; display: grid; gap: 8px; }
.goal-row:first-of-type { border-top: 0; }
.goal-row.off { opacity: .55; }
.goal-head { display: flex; gap: 8px; align-items: center; }
.goal-head input[type="text"] { flex: 1; min-width: 0; }
.goal-head input.icon-input { flex: 0 0 52px; text-align: center; padding: 10px 4px; font-size: 1.2rem; }
.goal-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: .88rem; color: var(--muted); }
.goal-meta label { display: flex; align-items: center; gap: 6px; }
.goal-meta select { width: auto; padding: 7px 8px; font-size: 16px; }
.goal-meta input[type="number"] { width: 72px; padding: 7px 8px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--sage-deep); }
.day-chip { display: inline-flex; align-items: center; cursor: pointer; }
.day-chip input { position: absolute; opacity: 0; pointer-events: none; }
.day-chip:has(input:checked) { background: var(--sage-soft); border-color: var(--sage); }
.new-goal { margin-top: 12px; background: var(--bg); box-shadow: none; }
.save-bar { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 76px); margin-top: 14px; display: flex; justify-content: center; }
.save-bar .btn { box-shadow: 0 6px 20px rgba(59, 58, 46, .18); padding: 14px 28px; }
#settingsForm .card + .card { margin-top: 12px; }

/* First-time setup */
.ob { padding-top: 8px; }
.ob h1 { margin: 4px 0 10px; }
.ob-lead { font-size: 1.05rem; margin-bottom: 10px; }
.ob-points { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 10px; }
.ob-points li { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.ob-progress { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 18px; }
.ob-progress i { height: 5px; border-radius: 999px; background: var(--surface-2); }
.ob-progress i.on { background: var(--sage); }
.ob-bucket { margin-top: 18px; }
.ob .chips { margin-top: 8px; }
.ob-nav {
  position: sticky; bottom: 0; display: flex; justify-content: space-between; gap: 10px;
  margin: 24px -16px 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.ob-nav .btn { min-width: 120px; }
.pace-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.pace-row:first-child { border-top: 0; }
.pace-input { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.pace-input input { width: 64px; padding: 7px 8px; }
[hidden] { display: none !important; }
.ob-points li { display: flex; gap: 10px; }
:root { --p-family: #B5838D; }
.list .pill { margin-right: 4px; }
:root { --p-health: #7FA7B5; }

/* 1.5: areas, details, arranging */
.area { margin-top: 6px; }
.area-title { display: flex; align-items: center; gap: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.dot.big { width: 14px; height: 14px; }
.details { display: grid; gap: 8px; margin-top: 10px; }
.detail-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; padding: 10px 12px; font-size: .92rem;
}
.detail-row span:first-child { font-weight: 700; white-space: nowrap; }
.detail-row .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.detail-row.open { border-style: solid; border-color: var(--sage); }
.detail-editor { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px 14px; }
.detail-editor .row { align-items: center; }
.detail-editor .row > .link { flex: 0 0 auto; }
.ring { background: none; border: 0; padding: 0; color: inherit; font: inherit; }
.stat { text-align: left; font: inherit; color: inherit; }
button.stat { cursor: pointer; }
.day-dot { border: 0; background: none; padding: 0; font: inherit; }
.history { border-color: var(--sage); }
.history .row > h3 { flex: 1; }
.pre { white-space: pre-wrap; }

.area-label { display: flex; align-items: center; gap: 6px; margin-top: 18px; }
.goal-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.goal-line:first-of-type { border-top: 0; }
.goal-name { flex: 1; min-width: 0; display: grid; text-align: left; background: none; border: 0; padding: 4px 0; font: inherit; color: inherit; }
.goal-name > span:first-child { font-weight: 700; }
.goal-line.open .goal-name > span:first-child { color: var(--sage-deep); }
.arrows { display: flex; gap: 6px; }
.arrows .step, .goal-head .step { width: 34px; height: 34px; font-size: 1rem; }
.step:disabled { opacity: .3; cursor: default; }
.goal-editor { background: var(--bg); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.goal-head .link { flex: 0 0 auto; }
.build-row { display: grid; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.build-row:first-of-type { border-top: 0; }

.season-list { display: grid; gap: 10px; margin-top: 8px; }
.season {
  display: grid; gap: 2px; text-align: left; padding: 14px 16px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); font: inherit; color: inherit;
}
.season span { font-size: .9rem; color: var(--muted); }
.season.on { background: var(--sage-soft); border-color: var(--sage); }
.pace-row { display: grid; gap: 6px; }
.pace-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pace-min { font-size: 15px !important; padding: 8px 10px !important; }
