:root {
  --paper: #f4efe4;
  --grid: rgba(60, 80, 140, .10);
  --card: #fffdf7;
  --ink: #1f2540;
  --ink-soft: #5d6483;
  --line: #2b3a8f;
  --line-soft: #d9d3c3;
  --done: #3d9a5b;
  --miss: #d65a52;
  --off: #8d62c6;
  --empty: #ece6d6;
  --pink: #f6a6c8;
  --bonus: #e0a526;
  --lime: #bff08a;
  --sun: #ffe38a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1a1d2b;
    --grid: rgba(150, 170, 255, .06);
    --card: #232738;
    --ink: #eceaf5;
    --ink-soft: #9aa0bd;
    --line: #8aa0ff;
    --line-soft: #343a52;
    --done: #4fb671;
    --miss: #e2685f;
    --off: #a47fe0;
    --empty: #2e3348;
    --pink: #8a3d63;
    --bonus: #d9a22a;
    --lime: #3f6a2c;
    --sun: #7a6420;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
#app { max-width: 640px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 16px 24px; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.hand { font-family: "Marck Script", "Segoe Script", cursive; font-weight: 400; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.top h1 { font-size: 22px; }
.range { font-size: 14px; color: var(--ink-soft); }
.nav { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line-soft);
  background: var(--card); display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { background: var(--line); color: #fff; border-color: var(--line); }
.pill-btn { border: 1px solid var(--line-soft); background: var(--card); border-radius: 10px; padding: 8px 12px; font-size: 14px; }

/* focus of the week */
.focus { margin: 6px 0 14px; }
.focus label { display: inline-block; font-size: 26px; padding: 0 8px; background: linear-gradient(transparent 50%, var(--pink) 50%); }
.focus textarea {
  width: 100%; margin-top: 6px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); padding: 10px 12px; font: inherit; resize: none; min-height: 46px;
}
.focus textarea::placeholder { color: var(--ink-soft); }

/* day strip */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.day {
  text-align: center; background: var(--card); border: 1px solid var(--line-soft);
  border-radius: 10px; padding: 6px 0 7px; position: relative;
}
.day b { display: block; font-size: 11px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; }
.day span { display: block; font-size: 16px; font-weight: 600; }
.day i { display: block; font-style: normal; font-size: 11px; color: var(--ink-soft); margin-top: 1px; }
.day.today { border: 2px solid var(--line); padding: 5px 0 6px; }
.day.weekend b { color: var(--off); }

/* category block */
.block { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 12px 6px; margin-bottom: 16px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.block-head h2 { font-size: 26px; line-height: 1.1; padding: 0 6px; }
.block-head.health h2 { background: linear-gradient(transparent 55%, var(--lime) 55%); }
.block-head.money h2 { background: linear-gradient(transparent 55%, var(--sun) 55%); }
.block-head.growth h2 { background: linear-gradient(transparent 55%, var(--pink) 55%); }
.block-pct { font-weight: 700; font-size: 18px; }
.block-pct small { font-weight: 400; font-size: 12px; color: var(--ink-soft); margin-left: 3px; }

.habit { padding: 10px 0 12px; border-top: 1px dashed var(--line-soft); }
.habit:first-of-type { border-top: 0; }
.habit-title { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.habit-title span { flex: 1; font-size: 15px; font-weight: 500; }
.habit-title em { font-style: normal; font-size: 12px; color: var(--ink-soft); }
.cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cell {
  height: 42px; border-radius: 9px; border: 1.5px solid var(--line-soft); background: var(--empty);
  padding: 0; position: relative; transition: transform .08s;
}
.cell:active { transform: scale(.92); }
.cell.done { background: var(--done); border-color: var(--done); }
.cell.miss { background: var(--miss); border-color: var(--miss); }
.cell.off { background: var(--off); border-color: var(--off); }
.cell.today:not(.done):not(.miss):not(.off) { border: 2px solid var(--line); }
.cell svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; position: absolute; inset: 0; margin: auto; }
.cell.future { opacity: .55; }

.edit-row { display: flex; gap: 6px; }
.edit-row .icon-btn { width: 34px; height: 34px; }
.add-habit { display: block; width: 100%; margin: 4px 0 8px; padding: 10px; border: 1.5px dashed var(--line-soft); border-radius: 10px; background: transparent; color: var(--ink-soft); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-soft); margin: 2px 2px 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* tasks */
.add-task { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 14px; display: grid; gap: 8px; }
.add-task input, .add-task select, .sheet input, .sheet select, .field {
  width: 100%; border: 1px solid var(--line-soft); background: var(--paper); color: var(--ink);
  border-radius: 10px; padding: 11px 12px; font: inherit; min-height: 44px;
}
.add-task .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.primary { background: var(--line); color: #fff; border: 0; border-radius: 10px; padding: 12px; font-weight: 600; min-height: 44px; }
.task { display: flex; align-items: flex-start; gap: 12px; padding: 12px; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); margin-bottom: 8px; }
.task.done .t-title { text-decoration: line-through; color: var(--ink-soft); }
.check { flex: none; width: 26px; height: 26px; border: 2px solid var(--line); border-radius: 8px; background: transparent; padding: 0; position: relative; margin-top: 1px; }
.task.done .check { background: var(--done); border-color: var(--done); }
.task.done .check::after { content: ""; position: absolute; left: 7px; top: 2px; width: 6px; height: 12px; border: solid #fff; border-width: 0 2.6px 2.6px 0; transform: rotate(45deg); }
.t-main { flex: 1; min-width: 0; }
.t-title { font-weight: 500; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--empty); color: var(--ink-soft); }
.chip.urgent { background: var(--miss); color: #fff; }
.chip.high { background: var(--sun); color: #3d3200; }
.chip.late { background: transparent; color: var(--miss); border: 1px solid var(--miss); font-weight: 600; }
.chip.today { background: var(--line); color: #fff; }
.t-del { flex: none; width: 34px; height: 34px; border: 0; background: transparent; color: var(--ink-soft); font-size: 22px; line-height: 1; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin: 18px 2px 8px; }
.empty-note { text-align: center; color: var(--ink-soft); padding: 28px 12px; }

/* stats */
.big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 30px; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--ink-soft); }
.panel { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.panel h3 { font-size: 15px; margin-bottom: 10px; }
.bar-row { margin-bottom: 11px; }
.bar-row .lbl { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.bar-row .lbl b { font-weight: 700; }
.bar { height: 10px; background: var(--empty); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--done); }
.bar.health i { background: var(--done); }
.bar.money i { background: #d8a62a; }
.bar.growth i { background: #d9588f; }
.heat { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--empty); }
.heat i.l1 { background: color-mix(in srgb, var(--done) 30%, var(--empty)); }
.heat i.l2 { background: color-mix(in srgb, var(--done) 60%, var(--empty)); }
.heat i.l3 { background: var(--done); }
.heat i.bad { background: color-mix(in srgb, var(--miss) 55%, var(--empty)); }

/* edit sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 12, 25, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 30; }
.sheet { width: 100%; max-width: 640px; background: var(--card); border-radius: 18px 18px 0 0; padding: 16px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.sheet h3 { font-size: 18px; }
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet .ghost { background: transparent; border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px; min-height: 44px; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; gap: 4px;
  background: var(--card); border-top: 1px solid var(--line-soft);
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
}
.tabbar button { flex: 1; max-width: 200px; border: 0; background: transparent; display: grid; justify-items: center; gap: 2px; font-size: 12px; color: var(--ink-soft); padding: 6px 0; border-radius: 10px; }
.tabbar button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--line); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (min-width: 700px) {
  .cell { height: 38px; }
}

/* 12 weeks */
.score b, .stat b.ok { color: var(--done); }
.range.score { margin-top: 1px; }
.weeks-wrap { position: relative; }
.weeks { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 130px; position: relative; z-index: 1; }
.wk { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; min-width: 0; }
.wk .col { width: 100%; height: 100px; display: flex; align-items: flex-end; background: var(--empty); border-radius: 6px; overflow: hidden; }
.wk .col i { display: block; width: 100%; background: #d8a62a; border-radius: 6px 6px 0 0; }
.wk .col i.hit { background: var(--done); }
.wk small { font-size: 11px; color: var(--ink-soft); }
.wk em { font-style: normal; font-size: 10px; color: var(--ink-soft); height: 12px; }
.wk.now small { color: var(--line); font-weight: 700; }
.wk.now .col { outline: 2px solid var(--line); }
.target { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--line); z-index: 2; font-size: 10px; color: var(--line); text-align: right; pointer-events: none; line-height: 1; }
.goal { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.goal-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.goal-title { font-size: 17px; font-weight: 600; }
.goal-note { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.goal-stats { display: flex; gap: 16px; font-size: 14px; margin: 8px 0 2px; color: var(--ink-soft); }
.goal-stats b { color: var(--ink); }
.tactics { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.tactics li { margin: 2px 0; }
.tactics li.none { list-style: none; margin-left: -18px; color: var(--ink-soft); }
.panel textarea { width: 100%; border: 1px solid var(--line-soft); background: var(--paper); color: var(--ink); border-radius: 10px; padding: 10px 12px; font: inherit; resize: none; }
.tabbar button { font-size: 11px; }

.results { margin-top: 10px; display: grid; gap: 8px; }
.result { display: block; width: 100%; text-align: left; background: var(--paper); border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; }
.r-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 6px; }
.r-title { font-weight: 500; }
.result .bar { position: relative; overflow: visible; height: 10px; }
.result .bar i { background: var(--done); }
.result .bar i.behind { background: #d8a62a; }
.result .bar u { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--line); border-radius: 2px; text-decoration: none; }
.r-nums { font-size: 13px; margin-top: 6px; font-weight: 600; }
.r-nums span { font-weight: 400; color: var(--ink-soft); }
.add-result { background: transparent; border: 1px dashed var(--line-soft); border-radius: 10px; padding: 9px; color: var(--ink-soft); font-size: 14px; }
.lbl-s { display: grid; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.sheet input[type=number] { font-size: 18px; }

/* weekends = days off; done mark is a bonus "+" */
.cell.wknd { background: color-mix(in srgb, var(--off) 13%, var(--empty)); border-color: color-mix(in srgb, var(--off) 25%, var(--line-soft)); }
.cell.bonus { background: var(--bonus); border-color: var(--bonus); }
.bonus-n { color: var(--bonus); font-weight: 600; }
.heat i.wknd { background: color-mix(in srgb, var(--off) 13%, var(--empty)); }
.heat i.bonus { background: var(--bonus); }
.day.weekend i { color: var(--bonus); font-weight: 600; }
