:root {
  color-scheme: light;
  --bg: #e7edf2;
  --surface: #f7fafc;
  --ink: #14202b;
  --muted: #3e5163;
  --line: #c5d0da;
  --hover: #dce5ec;
  --accent: #0c5c44;
  --accent-hover: #094833;
  --on-accent: #f4fff9;
  --warn: #8a3b12;
  --on-warn: #fff8f4;
  --miss: #7d1826;
  --on-miss: #fff6f7;
  --focus: #0b4f8a;
  --select: #b7dfd0;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12181e;
    --surface: #1b242c;
    --ink: #e7eef4;
    --muted: #c5d4e0;
    --line: #31414d;
    --hover: #24313b;
    --accent: #8ee0c4;
    --accent-hover: #b6f0dc;
    --on-accent: #04261a;
    --warn: #f0c4a4;
    --on-warn: #2c160c;
    --miss: #f3b7be;
    --on-miss: #2c1016;
    --focus: #a9cff5;
    --select: #1e4d3c;
  }
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--line) var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 1rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--select); color: var(--ink); }
::placeholder { color: var(--muted); opacity: 1; }

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

button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button { -webkit-tap-highlight-color: transparent; }

h1, h2, h3 {
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h1 { font-size: 2rem; margin: 0; }
h2 { font-size: 1.25rem; margin: 2.25rem 0 0.75rem; }
h3 { font-size: 1.0625rem; margin: 0 0 0.35rem; }
p { margin: 0.4rem 0; }

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 5;
  background: var(--ink);
  color: var(--bg);
  padding: 0.5rem 0.8rem;
}

.skip:focus { top: 1rem; }

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

.shell {
  width: 100%;
  max-width: 60rem;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; padding: 1.25rem 1rem 2rem; }

.nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav[hidden] { display: none; }

.nav-btn {
  flex: 1;
  min-height: 3.25rem;
  min-width: 3.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.nav-btn svg { width: 1.35rem; height: 1.35rem; }
.nav-btn[aria-current="page"] { color: var(--accent); }

.status-line {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: calc(4.7rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.75rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: 4px;
  font-size: 0.875rem;
}

.dayhead { display: flex; align-items: center; gap: 0.35rem; }
.dayhead-text { flex: 1; min-width: 0; }
.sub {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: center;
  margin-top: 0.3rem;
  color: var(--muted);
}

.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border-radius: 4px;
  flex: none;
}

.icon-btn:hover,
.habit:hover,
.day-link:hover,
.cal-cell:hover { background: var(--hover); }

.weekstrip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.45rem;
  max-width: 26rem;
  margin-top: 1.25rem;
}

.bar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-height: 2.75rem;
  color: var(--ink);
}

.bar-track {
  width: 100%;
  max-width: 2.25rem;
  height: 4.25rem;
  background: var(--line);
  display: block;
}

.bar-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleY(var(--p));
  transform-origin: bottom;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.bar-btn[aria-current="date"] .bar-track {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.bar-dow { font-size: 0.75rem; color: var(--muted); }
.bar-num { font-weight: 700; }
.bar-btn.is-today .bar-num { color: var(--accent); }

.quiet, .hint, .ledger-meta, .day-meta { color: var(--muted); }
.quiet { max-width: 38rem; margin-top: 0.8rem; }

.habit, .day-link {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  width: calc(100% + 0.8rem);
  margin-left: -0.4rem;
  text-align: left;
  padding: 0.75rem 0.4rem;
  border-bottom: 1px solid var(--line);
  min-height: 3rem;
  color: var(--ink);
}

.day-link { justify-content: space-between; align-items: baseline; }
.habit-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.habit-label, .day-name { font-weight: 600; }
.habit.static { cursor: default; }
.habit.static:hover { background: transparent; }
.habit.is-done .habit-label { font-weight: 700; }

.box {
  width: 1.375rem;
  height: 1.375rem;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  display: grid;
  place-items: center;
  flex: none;
}

.box svg { display: block; opacity: 0; }
.habit[aria-pressed="true"] .box {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.habit[aria-pressed="true"] .box svg { opacity: 1; }

.pushup-field { width: 5.75rem; flex: none; }
.pushup-field input { text-align: right; }

.prayer {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.45rem 0.75rem;
  align-items: center;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.prayer-name { font-weight: 700; }
.prayer-controls { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }

.mosque, .seg button, .primary, .cal-cell {
  min-height: 2.75rem;
}

.mosque, .seg button {
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--line);
  background: var(--surface);
}

.mosque { border-radius: 4px; }
.mosque[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.seg { display: flex; }
.seg button + button { border-left: 0; }
.seg button[aria-pressed="true"][data-status="ontime"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.seg button[aria-pressed="true"][data-status="late"] {
  background: var(--warn);
  border-color: var(--warn);
  color: var(--on-warn);
}
.seg button[aria-pressed="true"][data-status="missed"] {
  background: var(--miss);
  border-color: var(--miss);
  color: var(--on-miss);
}

.inline-note { grid-column: 1 / -1; }

.field span,
.budget-actual span,
.budget-diff span,
.cal-count {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.field { display: block; min-width: 0; }

input, textarea, select {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  min-height: 2.75rem;
  caret-color: var(--accent);
}

textarea { min-height: 5.5rem; resize: vertical; }

.form-grid { display: grid; gap: 0.75rem; margin: 0.75rem 0; }

.primary {
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.55rem 1rem;
  border-radius: 4px;
  font-weight: 700;
}

.primary:hover { background: var(--accent-hover); }

.text-btn {
  color: var(--focus);
  font-weight: 600;
  min-height: 2.75rem;
  padding: 0.2rem 0;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.danger { color: var(--miss); }

.error { color: var(--miss); min-height: 1.25rem; margin: 0.3rem 0; }
.is-over { color: var(--miss); }
.is-under { color: var(--accent); }

.banner {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.banner-actions { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: center; }

.ledger, .schedule, .plain { list-style: none; padding: 0; margin: 0.4rem 0 0; }

.ledger li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.6rem 0.75rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.ledger-item { display: block; font-weight: 600; }
.ledger-amt { font-weight: 700; }

.totals { width: 100%; border-collapse: collapse; margin-top: 0.75rem; }
.totals caption { text-align: left; font-weight: 700; margin-bottom: 0.4rem; }
.totals th, .totals td {
  text-align: left;
  padding: 0.45rem 0.5rem 0.45rem 0;
  border-bottom: 1px solid var(--line);
}
.totals td:last-child, .totals th:last-child { text-align: right; }

.budget-row {
  display: grid;
  grid-template-columns: minmax(7.5rem, 1.2fr) repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  align-items: end;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--line);
}

.budget-name { margin: 0; font-weight: 700; align-self: center; }
.budget-actual, .budget-diff { margin: 0; }
.budget-actual strong, .budget-diff strong { font-size: 1.05rem; }

.save-month, .book { padding: 0.95rem 0; border-bottom: 1px solid var(--line); }
.save-month.is-current h3, .milestone.is-current h3 { color: var(--accent); }

.cal {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
  max-width: 32rem;
}

.cal-dow { color: var(--muted); font-size: 0.75rem; font-weight: 600; text-align: center; }
.cal-cell {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  padding: 0.25rem;
  color: var(--ink);
}
.cal-cell.is-met {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.cal-cell.is-met .cal-count { color: var(--on-accent); }
.cal-empty { min-height: 3.25rem; }
.cal-count { margin: 0; font-weight: 600; }

.milestone { padding: 0.85rem 0; border-bottom: 1px solid var(--line); }

.prose { max-width: 68ch; }
.prose li, .schedule li { margin: 0.45rem 0; }
.schedule li { padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.time { color: var(--accent); font-weight: 700; }

details { margin-top: 2rem; }
summary {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  cursor: pointer;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
}

.noscript { padding: 1rem; }

@media (max-width: 420px) {
  .prayer { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .day-link { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
  .day-meta { text-align: left; }
  .budget-row { grid-template-columns: 1fr 1fr; }
  .budget-name { grid-column: 1 / -1; }
  .ledger li { grid-template-columns: minmax(0, 1fr) auto; }
  .ledger li .text-btn { grid-column: 1 / -1; justify-self: start; }
}

@media (min-width: 700px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: 1 / -1; }
}

@media (min-width: 800px) {
  main { padding: 1.5rem 1.5rem 3rem; }
  .nav {
    position: sticky;
    top: 0;
    bottom: auto;
    order: -1;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0;
  }
  .nav-btn { flex-direction: row; gap: 0.45rem; font-size: 0.9375rem; }
  .status-line { bottom: 1.25rem; }
  .split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 2.5rem;
    align-items: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
