/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-blue: #e9f0fe;
  --card-blue-foot: #dbe6fd;
  --card-peach: #fdf1e6;
  --card-peach-foot: #fae4cf;
  --card-green: #e8f6ec;
  --ink: #111318;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;
  --line: #e6e8ec;
  --accent: #4a6ff3;
  --accent-ink: #ffffff;
  --accent-soft: #eceffd;
  --danger: #e5484d;
  --good: #16a34a;
  --series-1: #4a6ff3;
  --series-2: #eb6834;
  --goal: #94a3b8;
  --radius: 20px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --card: #1a1d24;
    --card-blue: #1b2540;
    --card-blue-foot: #223058;
    --card-peach: #2b2219;
    --card-peach-foot: #3a2d1f;
    --card-green: #16281c;
    --ink: #f1f3f5;
    --ink-2: #a0a6b1;
    --ink-3: #6b7280;
    --line: #2a2f3a;
    --accent: #5b7cff;
    --accent-soft: #22304f;
    --danger: #f06a6e;
    --good: #34c76a;
    --series-1: #5b7cff;
    --series-2: #f0773f;
    --goal: #64748b;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
}
body.sheet-open { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.page { max-width: 560px; margin: 0 auto; padding: 8px 16px 24px; }
.muted { color: var(--ink-2); margin: 0; }
.error { color: var(--danger); margin: 0 0 12px; font-weight: 500; }
.empty { color: var(--ink-2); text-align: center; padding: 32px 0; margin: 0; }
.chev { opacity: .7; margin-left: 4px; }

/* ---------- headers ---------- */
.topbar { display: flex; align-items: center; justify-content: center; padding: 10px 0 14px; }
.greeting { display: flex; align-items: center; gap: 12px; padding: 10px 0 18px; }
.greeting .hello { color: var(--ink-2); font-size: .9rem; }
.greeting .name { font-weight: 700; font-size: 1.15rem; }
.section-title { font-size: 1.4rem; margin-bottom: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); }
.avatar.large { width: 64px; height: 64px; }
.avatar-fallback { display: grid; place-items: center; color: var(--accent); font-weight: 700; font-size: 1.1rem; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
  color: var(--ink);
}
.card.blue { background: var(--card-blue); }
.card.peach { background: var(--card-peach); }
.card.green { background: var(--card-green); }
.card.ghost {
  display: flex; align-items: center; justify-content: space-between;
  text-decoration: none; color: var(--ink-2); border: 1.5px dashed var(--line); background: transparent;
}

.metric { padding: 0; overflow: hidden; }
.metric-head { display: flex; align-items: baseline; justify-content: space-between; padding: 18px 20px 0; }
.metric .meta { color: var(--ink-2); font-size: .9rem; text-decoration: none; }
.metric-body { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 10px 20px 18px; }
.metric-main { min-width: 0; }
.big { font-size: 2.4rem; font-weight: 800; line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big .unit { font-size: 1.05rem; font-weight: 600; margin-left: 4px; color: var(--ink-2); }
.status { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: .92rem; color: var(--ink); }
.status-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); color: var(--card); font-size: 11px; font-weight: 700; }
.status-icon:empty { display: none; }
.spark { width: 132px; flex: 0 0 132px; }
.spark-chart { height: 72px; }
.spark-days { display: flex; justify-content: space-between; padding: 2px 4px 0; font-size: .75rem; color: var(--ink-3); letter-spacing: .02em; }
.spark-days span.now { color: var(--accent); font-weight: 700; }
.card.peach .spark-days span.now { color: var(--series-2); }
.metric-foot {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 14px 20px; border: 0; text-align: left; text-decoration: none; cursor: pointer;
  font-size: 1rem; color: var(--ink-2); background: var(--card-blue-foot);
}
.card.peach .metric-foot { background: var(--card-peach-foot); }
.progress { height: 6px; margin: 0 20px 18px; border-radius: 999px; background: rgba(0,0,0,.08); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--good); border-radius: inherit; transition: width .6s cubic-bezier(.2,.8,.2,1); }

/* ---------- buttons and fields ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 12px 18px; border: 0; border-radius: 14px;
  font-weight: 600; font-size: 1.05rem; text-decoration: none; cursor: pointer; background: var(--accent-soft); color: var(--accent);
}
.button.primary { background: var(--accent); color: var(--accent-ink); }
.button.secondary { background: var(--card); color: var(--ink); }
.button.block { width: 100%; }
.button.link { background: none; min-height: 44px; }
.button.danger { color: var(--danger); }
.button:disabled { opacity: .6; cursor: default; }
input[type="number"], input[type="datetime-local"] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 46px; width: 100%;
}
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: .9rem; color: var(--ink-2); margin-bottom: 6px; }
.settings h2 { margin-bottom: 14px; }
.profile { display: flex; align-items: center; gap: 14px; }
.profile .name { font-weight: 700; font-size: 1.1rem; }
.signout { margin-top: 8px; }

.row-field {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 6px 20px; min-height: 60px;
}
.row-field > span { font-weight: 600; }
.row-field input[type="datetime-local"] {
  flex: 1; min-width: 0; width: auto; border: 0; background: transparent; text-align: right;
  padding: 8px 0; color: var(--ink-2); font-size: .95rem;
}

/* ---------- segmented control ---------- */
.segmented { display: flex; background: var(--accent-soft); border-radius: 14px; padding: 4px; margin-bottom: 8px; }
.segmented > button, .segmented .seg-option {
  flex: 1; min-height: 42px; border: 0; border-radius: 11px; background: transparent;
  color: var(--ink-2); font-weight: 600; cursor: pointer; display: grid; place-items: center;
}
.segmented > button.active, .segmented .seg-option:has(input:checked) {
  background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.segmented .seg-option input { position: absolute; opacity: 0; pointer-events: none; }
.segmented.small { margin-bottom: 0; }

/* ---------- pager and tiles ---------- */
.pager, .cal-nav { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px 0 14px; }
.cal-nav { margin: 0 0 10px; }
.pager-btn {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink-2);
  font-size: 1.6rem; line-height: 1; border-radius: 50%; cursor: pointer;
}
.pager-btn:disabled { opacity: .3; cursor: default; }
.pager-label { min-width: 150px; text-align: center; font-weight: 600; font-size: 1.05rem; }
.chart-card { padding: 12px 6px 4px; }
.chart { min-height: 320px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--card); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile-label { color: var(--ink-2); font-size: .9rem; }
.tile-value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- calendar ---------- */
.calendar-card { padding: 14px 10px 10px; }
.cal-head, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head span { text-align: center; color: var(--ink-3); font-size: .85rem; padding-bottom: 6px; }
.cal-day {
  height: 56px; border: 0; background: transparent; padding: 4px 0 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; color: var(--ink); font-size: 1.05rem;
}
.cal-day:disabled { cursor: default; }
.cal-num { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.cal-day.muted { color: var(--ink-3); }
.cal-day.today .cal-num { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-day.selected .cal-num { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 3px; visibility: hidden; }
.cal-day.has-entry .cal-dot { visibility: visible; }
.day-title { color: var(--ink-2); font-size: .95rem; margin: 6px 4px 10px; }
.entry-card { padding: 14px 18px; }
.entry-head { display: flex; align-items: center; justify-content: space-between; color: var(--ink-2); font-size: .9rem; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; color: var(--ink-2); display: grid; place-items: center; cursor: pointer; border-radius: 50%; margin-right: -10px; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.entry-main { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.entry-edit { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 6px 0; cursor: pointer; color: var(--ink-2); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--tabbar-h); text-decoration: none; color: var(--ink-3); font-size: .72rem; font-weight: 500;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }
.tab-add {
  justify-self: center; align-self: center; width: 56px; height: 56px; margin-top: -24px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 6px 16px rgba(74,111,243,.35); transition: transform .15s;
}
.tab-add:active { transform: scale(.94); }
.tab-add svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); opacity: 0; transition: opacity .22s; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 24px 24px 0 0; padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
.sheet.open { transform: none; }
.sheet.dragging { transition: none; }
.sheet-handle { display: grid; place-items: center; padding: 8px 0 4px; touch-action: none; cursor: grab; }
.sheet-handle span { width: 40px; height: 5px; border-radius: 999px; background: var(--line); }
.sheet-title { text-align: center; margin: 4px 0 16px; font-size: 1.35rem; }
.sheet-card { padding: 16px 0 10px; }
.sheet-label { padding: 0 20px; font-weight: 600; font-size: 1.05rem; }
.ruler-value { display: flex; align-items: baseline; justify-content: center; gap: 4px; margin: 6px 0 2px; }
.ruler-number, .ruler-input { font-size: 2.4rem; font-weight: 800; line-height: 1.1; border: 0; background: transparent; color: var(--ink); padding: 0; font-variant-numeric: tabular-nums; }
.ruler-number { cursor: text; }
.ruler-input { width: 7ch; text-align: center; border-bottom: 2px solid var(--accent); border-radius: 0; min-height: 0; }
.ruler-unit { font-size: 1.1rem; font-weight: 600; color: var(--ink-2); }
.ruler-wrap { position: relative; }
.ruler {
  height: 104px; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
}
.ruler::-webkit-scrollbar { display: none; }
.ruler-track { display: flex; align-items: flex-end; height: 62px; margin-top: 10px; padding: 0 calc(50% - 4px); width: max-content; }
.tick { position: relative; flex: 0 0 8px; width: 8px; height: 22px; scroll-snap-align: center; }
.tick::before { content: ""; position: absolute; left: 3.5px; bottom: 0; width: 1px; height: 100%; background: var(--ink-3); opacity: .55; }
.tick-mid { height: 32px; }
.tick-major { height: 44px; }
.tick-major::before { width: 2px; left: 3px; background: var(--ink-2); opacity: .8; }
.tick-major::after {
  content: attr(data-label); position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  margin-top: 8px; font-size: .95rem; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.ruler-indicator { position: absolute; left: 50%; top: 2px; width: 3px; height: 72px; margin-left: -1.5px; border-radius: 2px; background: var(--accent); pointer-events: none; }
.ruler-indicator::after { content: ""; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 6px solid transparent; border-top: 8px solid var(--accent); }
.sheet .error { text-align: center; }

/* ---------- login ---------- */
.login { text-align: center; padding-top: 14vh; }
.login-icon { width: 84px; height: 84px; border-radius: 22px; margin-bottom: 14px; }
.login h1 { font-size: 1.8rem; margin-bottom: 6px; }
.login .muted { margin-bottom: 20px; }
.login .error { margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop, .progress-bar, .tab-add { transition: none; }
}
