:root {
  --bg: #f6f3ee;
  --paper: #fffdf9;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e7e1d7;
  --soft: #efe9df;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --good: #15803d;
  --warn: #b45309;
  --shadow: 0 1px 2px rgba(31, 35, 40, .06), 0 4px 16px rgba(31, 35, 40, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --paper: #1c1f24;
    --ink: #eceae6;
    --muted: #9aa0a8;
    --line: #2c3037;
    --soft: #252930;
    --accent: #2dd4bf;
    --accent-ink: #0b2b28;
    --good: #4ade80;
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 24px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 12px 14px; }

/* header */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.top .dates { text-align: right; }
.hijri { font-size: 13px; color: var(--muted); }

/* hero */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.ring { width: 92px; height: 92px; }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--soft); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring text { font-size: 20px; font-weight: 700; fill: var(--ink); }
.ring text.sub { font-size: 9px; font-weight: 500; fill: var(--muted); }
.pace { font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--soft); font-size: 13px; white-space: nowrap;
}
.chip b { font-variant-numeric: tabular-nums; }

.quote { border-left: 4px solid var(--accent); }
.quote p { margin: 0 0 6px; font-size: 16px; font-style: italic; }

.focus-card { display: flex; gap: 12px; align-items: center; }
.focus-card .icon { font-size: 26px; }

/* category blocks */
.cat { border-top: 4px solid var(--c, var(--accent)); }
.cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.cat-head .emoji { font-size: 20px; }
.cat-head .pct { margin-left: auto; font-weight: 700; color: var(--c); font-variant-numeric: tabular-nums; }
.cat .why { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.bar-line { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.bar-line > span { display: block; height: 100%; width: var(--w, 0%); background: var(--c, var(--accent)); transition: width .4s ease; }

.habit {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 9px 0; border-top: 1px dashed var(--line);
}
.habit:first-of-type { border-top: 0; }
.habit .name { font-size: 15px; }
.habit .name .tag { font-size: 11px; color: var(--c); font-weight: 600; margin-left: 6px; text-transform: uppercase; letter-spacing: .04em; }
.habit.met .name { color: var(--muted); }

.habit.wk { display: flex; flex-wrap: wrap; justify-content: space-between; }
.habit.wk .name { flex: 1 1 130px; }
.boxes { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; margin-left: auto; }
.box {
  width: 30px; height: 30px; border-radius: 7px;
  border: 2px solid var(--line); background: transparent;
  display: grid; place-items: center; padding: 0;
  font-size: 11px; font-weight: 700; color: var(--accent-ink);
  transition: transform .12s ease, background .2s ease;
}
.box:active { transform: scale(.9); }
.box.on { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); color: #fff; }
.box.extra { border-style: dashed; }
.box.add { border-style: dashed; color: var(--muted); font-size: 16px; }

.today-btns { display: flex; gap: 6px; align-items: center; }
.count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.tick-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--c, var(--accent));
  background: transparent; color: var(--c); font-size: 20px; font-weight: 700; line-height: 1;
}
.tick-btn.done { background: var(--c); color: #fff; }
.undo { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 4px; }

/* week nav + day picker */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.weeknav .label { text-align: center; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--paper); font-size: 18px;
}
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  border: 1px solid var(--line); background: var(--paper); border-radius: 12px;
  padding: 6px 0; text-align: center; font-size: 12px; line-height: 1.2;
}
.day b { display: block; font-size: 15px; }
.day.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.day.future { opacity: .45; }
.day .dot { display: block; width: 5px; height: 5px; margin: 3px auto 0; border-radius: 50%; background: currentColor; opacity: var(--o, 0); }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: transparent; color: #dc2626; border: 1px solid currentColor; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

/* roadmap */
.period { border-left: 4px solid var(--line); }
.period.now { border-left-color: var(--accent); }
.period summary { list-style: none; cursor: pointer; }
.period summary::-webkit-details-marker { display: none; }
.period .badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px dashed var(--line); }
.task input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.task.done span { color: var(--muted); text-decoration: line-through; }
.task small { display: block; color: var(--good); font-size: 11px; }
.output { font-size: 13px; background: var(--soft); border-radius: 10px; padding: 8px 10px; margin: 8px 0 4px; }
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.timeline li { list-style: none; position: relative; margin: 0 0 10px; }
.timeline li::before { content: ""; position: absolute; left: -17px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: 2px solid var(--accent); }
.timeline li.past::before { background: var(--accent); }
.timeline { margin: 0; }

/* history chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .b { width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px; background: var(--accent); height: var(--h, 2%); min-height: 3px; opacity: .85; }
.chart .b.low { background: var(--warn); }
.chart .b.cur { opacity: .45; }
.chart small { font-size: 10px; color: var(--muted); }
.stars { display: flex; gap: 4px; }
.stars button { border: 0; background: none; font-size: 26px; padding: 0; filter: grayscale(1); opacity: .4; }
.stars button.on { filter: none; opacity: 1; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* settings editor */
.edit-cat { border-top: 4px solid var(--c); }
.edit-habit { display: grid; grid-template-columns: 1fr 64px auto; gap: 6px; margin-top: 6px; }
.edit-days { grid-column: 1 / -1; display: flex; gap: 4px; flex-wrap: wrap; }
.edit-days label { font-size: 12px; display: inline-flex; gap: 3px; align-items: center; padding: 3px 6px; border-radius: 6px; background: var(--soft); }
.edit-row { display: grid; grid-template-columns: 56px 1fr 52px; gap: 6px; }
input[type=color] { width: 52px; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--bg); }

/* tab bar */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--paper); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs button {
  border: 0; background: none; padding: 4px 0; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted);
}
nav.tabs button span { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
nav.tabs button.active { color: var(--accent); font-weight: 700; }
nav.tabs button.active span { filter: none; opacity: 1; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; text-align: center; }
.login .logo { font-size: 44px; }
.login form { display: grid; gap: 10px; margin-top: 16px; }
.err { color: #dc2626; font-size: 13px; min-height: 18px; }

/* toast + confetti */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px; opacity: 0; transition: all .25s ease; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

@media (min-width: 700px) {
  nav.tabs { left: 50%; right: auto; width: 600px; transform: translateX(-50%); bottom: 12px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 6px; }
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid2 > * + * { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* character */
:root { --pos: #15803d; --neg: #dc2626; --rep: #d97706; }
@media (prefers-color-scheme: dark) { :root { --pos: #4ade80; --neg: #f87171; --rep: #fbbf24; } }
.chip.good b, .good-t, .lg.good { color: var(--pos); }
.chip.bad b, .bad-t, .lg.bad { color: var(--neg); }
.chip.rep b { color: var(--rep); }
.circles { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.circles::-webkit-scrollbar { display: none; }
.circle {
  flex: none; min-width: 74px; padding: 8px 10px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--paper);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; font-weight: 600;
}
.circle .ci { font-size: 22px; }
.circle small { font-size: 11px; font-weight: 500; color: var(--muted); }
.circle.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.bchips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.bchip {
  border: 1.5px solid var(--line); background: transparent; border-radius: 999px;
  padding: 7px 12px; font-size: 13px; transition: transform .1s ease;
}
.bchip:active { transform: scale(.95); }
.bchip.focus { border-style: dashed; border-color: var(--accent); }
.bchip.on-pos { background: var(--pos); border-color: var(--pos); color: #fff; }
.bchip.on-neg { background: var(--neg); border-color: var(--neg); color: #fff; }
.bchip.on-rep { background: transparent; border-color: var(--rep); color: var(--rep); font-weight: 600; }
.chart.duo .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart.duo .b { max-width: 12px; border-radius: 4px 4px 1px 1px; min-height: 2px; opacity: 1; }
.chart.duo .b.g { background: var(--pos); }
.chart.duo .b.r { background: var(--neg); }
.edit-beh { display: grid; grid-template-columns: 96px 1fr auto; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.edit-beh .tip { grid-column: 1 / -1; font-size: 13px; }
details > summary { cursor: pointer; }
nav.tabs button { font-size: 10px; }
