/* Ihtisaabi — app styles.
   Tokens live on :root. Dark follows the system unless [data-theme] forces it.
   One memorable element: the tasbih bead. Everything else is a plain ledger. */

:root {
  color-scheme: light dark;
  --canvas: #F0F3EF;
  --surface: #FFFFFF;
  --ink: #14261F;
  --muted: #5A6862;
  --line: #D5DCD7;
  --accent: #0F6E56;
  --accent-soft: #DCEEE6;
  --amber: #C9862B;
  --danger: #B3261E;
  --on-accent: #FFFFFF;
  --font: Manjari, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Malayalam", sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", var(--font);
  --tabs: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0E1512;
    --surface: #16201B;
    --ink: #E6EDE8;
    --muted: #93A39B;
    --line: #263029;
    --accent: #3FB48F;
    --accent-soft: #163A2F;
    --amber: #E0A24A;
    --danger: #FF8A80;
    --on-accent: #0E1512;
  }
}

:root[data-theme="dark"] {
  --canvas: #0E1512;
  --surface: #16201B;
  --ink: #E6EDE8;
  --muted: #93A39B;
  --line: #263029;
  --accent: #3FB48F;
  --accent-soft: #163A2F;
  --amber: #E0A24A;
  --danger: #FF8A80;
  --on-accent: #0E1512;
}

/* ---------- base ---------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: default; }

input, output { font: inherit; color: inherit; }

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

h1, h2, h3 { margin: 0; line-height: 1.25; }

.p { font-weight: 700; }
.s { font-size: 13px; color: var(--muted); font-weight: 400; }

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(var(--tabs) + 40px + env(safe-area-inset-bottom));
}

main:focus { outline: none; }

.notice {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
}
.notice[hidden] { display: none; }

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

.ic { width: 18px; height: 18px; display: block; flex: none; }

/* ---------- screen header ---------- */

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 8px;
}
.top h1 { font-size: 22px; font-weight: 700; }
.top .s { margin-top: 1px; }
.daycount {
  flex: none;
  padding-bottom: 3px;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- date navigation ---------- */

.datenav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0 10px;
}
.navbtn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
}
.navbtn:disabled { color: var(--line); }
.datelabel { flex: 1; min-width: 0; text-align: center; }
.datelabel .p { font-size: 16px; line-height: 1.3; }
/* The invisible native date input covers the label; the label is what you see,
   the input is what you tap. Opacity rather than display:none so every mobile
   browser still opens its picker. */
.datepick { position: relative; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.datepick-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.datepick-input:focus-visible + .p, .datepick:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.datelabel .s { line-height: 1.3; }
.linkbtn {
  min-height: 44px;
  margin: -10px 0;
  padding: 0 10px;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
}

/* One tiny bead per campaign day. */
.month {
  display: flex;
  gap: 3px;
  padding: 2px 1px 16px;
}
.mbead {
  flex: 1 1 0;
  max-width: 10px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
}
.mbead.on { background: var(--accent); border-color: var(--accent); }
.mbead.future { border-style: dotted; }
.mbead.viewed { outline: 2px solid var(--amber); outline-offset: 1px; }

/* ---------- ledger ---------- */

.sechead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 0 8px;
  font-size: 16px;
}
.sechead .p { font-size: 16px; }

.ledger {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}
.row {
  padding: 14px 0 14px 12px;
  margin-left: -12px;
  border-bottom: 1px solid var(--line);
  box-shadow: inset 3px 0 0 transparent;
}
.row.done { box-shadow: inset 3px 0 0 var(--accent-soft); }
@supports (color: color-mix(in srgb, red, blue)) {
  .row.done { box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
}

.rowhead {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.emoji {
  flex: none;
  width: 28px;
  font-family: var(--emoji);
  font-size: 20px;
  line-height: 1.35;
  text-align: center;
}
.labels { flex: 1; min-width: 0; }
.labels .p { font-size: 17px; line-height: 1.35; overflow-wrap: anywhere; }
.labels .s { margin-top: 1px; }

.count {
  flex: none;
  padding-top: 2px;
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.count .n {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}

.rowbody { margin-top: 12px; padding-left: 38px; }
@media (max-width: 379px) { .rowbody { padding-left: 0; } }

/* Five beads on a thread. --n is set from JS to the bead count. */
.thread {
  position: relative;
  display: flex;
}
.thread::before {
  content: "";
  position: absolute;
  top: 19px;
  height: 2px;
  left: calc(100% / var(--n, 5) / 2);
  right: calc(100% / var(--n, 5) / 2);
  background: var(--line);
  transition: background 150ms ease;
}
.thread.full::before { background: var(--accent); }
.bead {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0 4px;
  min-height: 44px;
  border-radius: 8px;
}
.bead .dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line);
  transition: background 150ms ease, border-color 150ms ease, transform 120ms ease;
}
.bead.on .dot { background: var(--accent); border-color: var(--accent); }
.bead:active .dot { transform: scale(0.88); }
.beadlabel {
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
}
.bead.on .beadlabel { color: var(--ink); font-weight: 700; }
.bead:disabled { opacity: 0.5; }

/* Toggle chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 22px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-weight: 700;
  font-size: 15px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip .ic { width: 16px; height: 16px; }
.chip:disabled { opacity: 0.5; }

/* Round check */
.check {
  flex: none;
  width: 44px;
  height: 44px;
  margin-top: -3px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: transparent;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.check.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.check .ic { width: 22px; height: 22px; }
.check:disabled { opacity: 0.5; }

/* Stepper */
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .unit { flex: 1; font-size: 13px; color: var(--muted); }
.stepbtn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
}
.stepbtn:disabled { color: var(--line); }
.stepper output {
  min-width: 2.5ch;
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 4px;
  margin-top: 10px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 200ms ease;
}

/* People */
.people { list-style: none; margin: 0 0 4px; padding: 0; }
.person {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.person .name { font-weight: 700; overflow-wrap: anywhere; }
.person .when { font-size: 13px; color: var(--muted); white-space: nowrap; }
.person .rm {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.addbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 4px;
  color: var(--accent);
  font-weight: 700;
}
.addform { display: flex; flex-wrap: wrap; gap: 8px; }
.addform input {
  flex: 1 1 140px;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-weight: 700;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.5; }

/* ---------- progress ---------- */

.stats {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.beads {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.pbead {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
}
.pbead.on { background: var(--accent); border-color: var(--accent); }
.pbead.on[data-fill="1"] { opacity: 0.3; }
.pbead.on[data-fill="2"] { opacity: 0.45; }
.pbead.on[data-fill="3"] { opacity: 0.6; }
.pbead.on[data-fill="4"] { opacity: 0.8; }
.pbead.future { border-style: dotted; }
.pbead.today { outline: 2px solid var(--amber); outline-offset: 1px; }

.goal .bar { margin-top: 10px; }

/* ---------- settings ---------- */

.group { padding: 14px 0; border-bottom: 1px solid var(--line); }
.group h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 16px;
}
.field {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}
.field label { flex: 1; }
.field input[type="date"] {
  min-height: 44px;
  padding: 0 10px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
}
.readout { margin: 6px 0 10px; font-size: 14px; color: var(--muted); }
.readout.err { color: var(--danger); }
.seg {
  display: inline-flex;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}
.seg button { min-height: 44px; padding: 0 18px; font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.confirm {
  margin-top: 10px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.confirm p { margin: 0 0 10px; }
.foot { padding: 20px 0; font-size: 13px; color: var(--muted); }
.foot .s { display: block; }

/* ---------- tab bar ---------- */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative;
  flex: 1 1 0;
  max-width: 160px;
  min-height: var(--tabs);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
}
.tab.on { color: var(--accent); }
.tab.on::after {
  content: "";
  position: absolute;
  top: -1px;
  left: 22%;
  right: 22%;
  height: 2px;
  background: var(--accent);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs) + 16px + env(safe-area-inset-bottom));
  z-index: 11;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--canvas);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #FFFFFF; }

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