:root {
  --bg: #0f1115;
  --card: #181b22;
  --card-2: #20242d;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #8b93a3;
  --accent: #4ade80;
  --accent-ink: #062b12;
  --water: #38bdf8;
  --warn: #f87171;
  --gold: #fbbf24;
  --rest: #64748b;
  --mood: #c084fc;
  --sleep: #818cf8;
  --radius: 14px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --card-2: #eef0f3;
    --line: #dde1e7;
    --text: #14171c;
    --muted: #677084;
    --accent: #16a34a;
    --accent-ink: #ffffff;
    --water: #0284c7;
    --warn: #dc2626;
    --gold: #d97706;
    --rest: #94a3b8;
    --mood: #9333ea;
    --sleep: #4f46e5;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 22px; margin: 0; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 22px; padding: 6px 8px; }

main { padding: 12px 16px 24px; max-width: 560px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; color: var(--muted);
  font-size: 10.5px; padding: 8px 0 10px; white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button span { font-size: 16px; }
.tabs button.on { color: var(--accent); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 28px; font-weight: 700; white-space: nowrap; }
.center { text-align: center; }

.datebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.datebar strong { font-size: 16px; }

button.btn, .btn {
  appearance: none; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); border-radius: 10px; padding: 10px 14px; font-size: 15px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.water { background: var(--water); color: #fff; border-color: transparent; }
.btn.danger { color: var(--warn); }
.btn.ghost { background: none; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 2px 6px; }

input, select {
  font-size: 16px; /* prevents iOS zoom */
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
}
label.f { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label.f input { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.bar { height: 10px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.water > i { background: var(--water); }
.bar.over > i { background: var(--warn); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

.ex-title { font-weight: 700; margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; }
.set { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-variant-numeric: tabular-nums; }
.pr-badge { color: var(--gold); font-size: 12px; font-weight: 700; margin-left: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card-2); color: var(--text); border-radius: 99px; padding: 6px 12px; font-size: 14px; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cal button {
  aspect-ratio: 1; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); border-radius: 8px; font-size: 13px; padding: 0;
}
.cal button.train { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.cal button.rest { background: var(--rest); color: #fff; border-color: transparent; }
.cal button.today { outline: 2px solid var(--text); outline-offset: 1px; }
.cal .blank { visibility: hidden; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--card-2); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .pt { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 11px; }

.empty { color: var(--muted); text-align: center; padding: 18px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  font-weight: 600; font-size: 14px; transition: .25s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.gold { background: var(--gold); color: #1a1200; }

/* ---- v2: sections, forms, daily ---- */
.seg { display: flex; gap: 2px; padding: 3px; background: var(--card-2); border: 1px solid var(--line); border-radius: 11px; }
.seg button { border: 0; background: none; color: var(--muted); font: 700 15px system-ui, -apple-system, sans-serif; padding: 7px 20px; border-radius: 8px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.vh { font-size: 24px; margin: 4px 0 12px; }

textarea {
  font: inherit; font-size: 16px; width: 100%; padding: 10px 12px; border-radius: 10px; resize: vertical;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text); margin-top: 4px;
}
label.f textarea { display: block; }
div.f { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input[type=time], input[type=date], select { min-height: 44px; -webkit-appearance: none; appearance: none; }
input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin: 0; }
input[type=search] { -webkit-appearance: none; appearance: none; }
[hidden] { display: none !important; }

.pills { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.pills.q5 { grid-template-columns: repeat(5, 1fr); }
.pills label { position: relative; }
.pills input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pills span {
  display: block; text-align: center; padding: 10px 0; border-radius: 8px; font-weight: 700; font-size: 14px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text); font-variant-numeric: tabular-nums;
}
.pills input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.pills.mood input:checked + span { background: var(--mood); color: #fff; }
.pills.prod input:checked + span { background: var(--water); color: #fff; }
.pills.sleep input:checked + span { background: var(--sleep); color: #fff; }
.pills input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 1px; }

.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.mini .stat { border: 1px solid var(--line); text-align: left; color: var(--text); font: inherit; width: 100%; }
.mini button.stat b::after { content: ' ›'; color: var(--muted); font-weight: 400; }

details summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: '✎ '; }

.bar.prot { height: 6px; margin-top: 2px; }
.bar.prot > i { background: var(--gold); }
.bar.sleep > i { background: var(--sleep); }

.glance li { cursor: pointer; }
.glance li > span:first-child { color: var(--muted); font-size: 13px; width: 78px; flex: none; }
.glance li .grow { font-size: 14px; }

.rem .rem-time { min-width: 68px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rem.overdue .rem-time { color: var(--warn); font-weight: 700; }
.rem.done .rem-title { text-decoration: line-through; color: var(--muted); }

.note-text { white-space: pre-wrap; word-break: break-word; }
.day-h { display: block; background: none; border: 0; padding: 0; margin: 0 0 4px; color: var(--muted); font: 700 13px system-ui, -apple-system, sans-serif; }

.score { min-width: 30px; text-align: center; font-weight: 700; border-radius: 8px; padding: 3px 0; color: #fff; font-variant-numeric: tabular-nums; }
.score.mood { background: var(--mood); }
.score.prod { background: var(--water); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.mood { background: var(--mood); }
.legend i.prod { background: var(--water); }

.chart .goal { stroke: var(--muted); stroke-dasharray: 4 4; }
.chart .b-accent { fill: var(--accent); }
.chart .b-water { fill: var(--water); }
.chart .b-sleep { fill: var(--sleep); }
.chart .ln.mood { stroke: var(--mood); }
.chart .ln.prod { stroke: var(--water); }
.chart .pt.mood { fill: var(--mood); }
.chart .pt.prod { fill: var(--water); }
.chart text.sel { fill: var(--text); font-weight: 700; }

/* ---- v3: quotes + interactions ---- */
/* press feedback on everything tappable */
.btn, .chip, .x, .icon-btn, .tabs button, .seg button, .mini .stat, .pills span, .cal button,
.glance li, .list li[data-act], .day-h, .stepper button {
  transition: transform .12s ease, opacity .12s ease, background-color .2s ease, color .2s ease;
}
.btn:active, .chip:active, .x:active, .icon-btn:active, .tabs button:active, .seg button:active,
.mini .stat:active, .pills span:active, .cal button:active, .stepper button:active { transform: scale(.94); opacity: .85; }
.glance li:active, .list li[data-act]:active { opacity: .6; }
.tabs button.on span { display: inline-block; animation: pop .3s ease; }

/* screen change animation */
#view.enter { animation: fadeUp .22s ease-out; }
#view.enter.from-right { animation: fromRight .22s ease-out; }
#view.enter.from-left { animation: fromLeft .22s ease-out; }
#view.enter .bar > i, #view.enter .mini-bar > i { animation: grow .7s cubic-bezier(.2,.8,.2,1); }
#view.enter .chart rect { animation: rise .6s cubic-bezier(.2,.8,.2,1) both; transform-origin: bottom; transform-box: fill-box; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }
@keyframes fromRight { from { opacity: 0; transform: translateX(24px); } }
@keyframes fromLeft { from { opacity: 0; transform: translateX(-24px); } }
@keyframes grow { from { width: 0; } }
@keyframes rise { from { transform: scaleY(0); } }
@keyframes pop { 50% { transform: scale(1.3); } }

/* tap the date to pick any day */
.date-tap { position: relative; display: inline-block; cursor: pointer; overflow: hidden; vertical-align: top; }
.date-tap .caret { font-size: 11px; color: var(--muted); }
.date-tap input.date-pick { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; min-height: 0; opacity: 0; padding: 0; margin: 0; border: 0; cursor: pointer; }

/* +/- steppers under workout fields */
.stepper { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: -2px 0 10px; }
.stepper button {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 8px; padding: 6px 0; font-size: 18px; font-weight: 700; line-height: 1;
}

/* quote card */
.greet { margin: -4px 0 10px; color: var(--muted); font-weight: 600; }
.quote { background: linear-gradient(135deg, color-mix(in srgb, var(--mood) 16%, var(--card)), var(--card) 70%); }
.quote-text {
  margin: 0 0 10px; font: italic 19px/1.45 "Iowan Old Style", Georgia, "Times New Roman", serif;
  cursor: pointer; animation: fadeUp .35s ease-out;
}
.quote cite { font-style: normal; font-size: 13px; color: var(--muted); }
.quote-actions { gap: 0; }
.quote-actions .icon-btn { font-size: 20px; padding: 4px 8px; }
.icon-btn.heart.fav { color: var(--warn); animation: pop .35s ease; }

/* water mini bar inside the day log */
.mini-bar { display: block; height: 5px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin-top: 5px; max-width: 170px; }
.mini-bar > i { display: block; height: 100%; background: var(--water); border-radius: 99px; }

/* toast with Undo */
#toast { display: flex; align-items: center; gap: 14px; justify-content: center; }
#toast.act { pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 800; font-size: 14px; padding: 2px 4px; }
#toast.gold button { color: #1a1200; }

/* confetti burst */
.confetti {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); z-index: 50; pointer-events: none;
  font-size: 18px; font-weight: 800; animation: burst 1.2s cubic-bezier(.15,.7,.3,1) forwards;
}
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, #view.enter, #view.enter * { animation: none !important; transition: none !important; }
}
.quote details summary::before { content: '♥ '; color: var(--warn); }
