:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16161a);
  --muted: var(--tg-theme-hint-color, #8a8a94);
  --accent: var(--tg-theme-button-color, #3d6fb6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --empty: color-mix(in srgb, var(--text) 9%, transparent);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --radius: 12px;
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #0f0f12; --card: #1a1a1f; --text: #f1f1f4; --muted: #8b8b96; }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

#app { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(28px + env(safe-area-inset-bottom)); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 10px; }
.year-switch { display: flex; align-items: center; gap: 6px; }
.year-switch h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; margin: 0; min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; }
.icon-btn { width: 38px; height: 38px; border-radius: 8px; border: 0; background: var(--card); display: grid; place-items: center; font-size: 22px; line-height: 1; }
.icon-btn:disabled { opacity: .35; cursor: default; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 12px; }
.legend .tag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--card); border-radius: 8px; font-size: 13px; font-weight: 600; }
.legend .tag i { width: 10px; height: 10px; display: inline-block; }
.legend .add { border: 1px dashed var(--line); background: transparent; color: var(--muted); }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }

/* heatmap */
.heat-card { padding: 14px 0 14px; }
.heat-scroll { overflow-x: auto; padding: 0 14px 6px; scrollbar-width: none; }
.heat-scroll::-webkit-scrollbar { display: none; }
#heatmap svg { display: block; }
#heatmap .cell { cursor: pointer; }
#heatmap .future { cursor: default; }
#heatmap text { fill: var(--muted); font-size: 10px; font-family: inherit; font-weight: 600; }
.heat-actions { display: flex; gap: 8px; padding: 10px 14px 0; }

.btn { border: 0; border-radius: 8px; padding: 12px 16px; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-text); flex: 1; }
.btn.ghost { background: var(--empty); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; }

/* stats */
.stat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stat-head h2 { margin: 0; font-size: 17px; font-weight: 800; }
.seg { display: flex; background: var(--empty); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.big-row { display: flex; gap: 12px; }
.big { flex: 1; }
.big b { display: block; font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.big span { color: var(--muted); font-size: 13px; font-weight: 600; }
.bar { display: flex; height: 10px; border-radius: 2px; overflow: hidden; background: var(--empty); margin-top: 14px; }
.bar div { height: 100%; }
.sub { color: var(--muted); font-size: 13px; margin-top: 10px; }

.type-rows { display: flex; flex-direction: column; gap: 12px; }
.type-row .lbl-line { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.type-row .lbl-line span:last-child { font-variant-numeric: tabular-nums; }
.type-row .track { height: 8px; border-radius: 2px; background: var(--empty); overflow: hidden; }
.type-row .track div { height: 100%; }
.dot { width: 10px; height: 10px; display: inline-block; margin-right: 8px; vertical-align: 0; }

.empty-state { text-align: center; padding: 6px 0 2px; color: var(--muted); font-size: 14px; }

/* sheets */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .25s cubic-bezier(.2,.8,.2,1); z-index: 11; }
.sheet.on { transform: none; }
.grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 6px 0 12px; font-size: 19px; font-weight: 800; }
.sheet h3.mt { margin-top: 26px; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.day-head h3 { flex: 1; font-size: 18px; line-height: 1.25; }
.date-pick { position: relative; flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px;
  border-radius: 8px; background: var(--empty); font-size: 13px; font-weight: 700; color: var(--accent); cursor: pointer; overflow: hidden; }
.date-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.date-pick input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.lbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 8px; }

.entries { list-style: none; margin: 0; padding: 0; }
.entries li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--empty); border-radius: 8px; margin-bottom: 6px; font-weight: 600; }
.entries li .grow { flex: 1; }
.entries li .min { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.entries li button { border: 0; background: transparent; color: var(--danger); font-size: 20px; padding: 0 4px; line-height: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid transparent; background: var(--empty); border-radius: 8px; padding: 8px 12px; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.chip i { width: 12px; height: 12px; }
.chip.on { border-color: var(--text); }

.minutes-row { display: flex; gap: 8px; align-items: center; }
.minutes-row input { width: 86px; padding: 11px 12px; border-radius: 8px; border: 0; background: var(--empty); font-weight: 700; font-size: 16px; }
.quick { display: flex; gap: 6px; flex: 1; }
.quick button { flex: 1; border: 0; background: var(--empty); border-radius: 8px; padding: 11px 0; font-weight: 700; font-size: 14px; }
.quick button.on { background: var(--accent); color: var(--accent-text); }

.type-list { list-style: none; margin: 0 0 8px; padding: 0; }
.type-list li { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); font-weight: 600; }
.type-list li .grow { flex: 1; }
.type-list li button { border: 0; background: transparent; padding: 4px 6px; color: var(--muted); font-size: 14px; font-weight: 600; }
.type-list li button.del { color: var(--danger); }
.type-form input#typeName { width: 100%; padding: 12px 14px; border-radius: 8px; border: 0; background: var(--empty); font-weight: 600; font-size: 16px; margin-top: 8px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 12px; }
.swatches button { aspect-ratio: 1; border: 3px solid transparent; }
.swatches button.on { border-color: var(--text); }
.swatches label { aspect-ratio: 1; background: var(--empty); position: relative; overflow: hidden; border: 3px solid transparent; }
.swatches label.on { border-color: var(--text); }
.swatches label::after { content: '+'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: var(--muted); }
.swatches label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.row { display: flex; align-items: center; gap: 10px; font-weight: 600; flex-wrap: wrap; }
.row input[type=time] { border: 0; background: var(--empty); border-radius: 10px; padding: 8px 10px; font-weight: 700; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--empty); border-radius: 999px; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

#sharePreview { width: 100%; border-radius: 6px; display: block; background: var(--empty); min-height: 120px; }
.share-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--card);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw; text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* header actions */
.top-actions { display: flex; gap: 8px; }
#openSupport { color: #c05a55; }

/* support button on the main screen */
.btn.support { background: var(--card); color: var(--text); margin: 4px 0 0; }
.btn.support svg { color: #c05a55; }

/* author credits: on every screen */
.credits { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 13px; font-weight: 600; color: var(--muted); padding: 18px 0 2px; }
.credits.main { padding-top: 20px; }
.credits a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); cursor: pointer; }
.credits a:active { color: var(--text); }
.credits .app { color: var(--text); font-weight: 800; }

/* support sheet */
.support-lead { font-size: 14px; line-height: 1.45; margin: -4px 0 14px; }
.pay-block { background: var(--empty); border-radius: 8px; padding: 12px 14px; margin-bottom: 8px; }
.pay-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.pay-head b { font-size: 15px; }
.pay-head span { font-size: 12px; color: var(--muted); font-weight: 600; }
.pay-row { display: flex; align-items: center; gap: 10px; }
.pay-row code { flex: 1; font: 600 13px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; user-select: all; -webkit-user-select: all; }
.copy-btn { flex: none; border: 0; background: var(--card); color: var(--accent); border-radius: 6px; padding: 8px 10px; font-weight: 700; font-size: 13px; }
.copy-btn.done { color: #4f9a6b; }
.pay-block .btn.wide { margin-top: 6px; }
.qr { display: block; width: 168px; height: 168px; margin: 12px auto 2px; border-radius: 6px; background: #fff; }
.qr-note { text-align: center; font-size: 12px; color: var(--muted); }
.stars-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stars-row button { border: 2px solid transparent; background: var(--card); border-radius: 6px; padding: 10px 0; font-weight: 700; font-size: 14px; }
.stars-row button.on { border-color: var(--text); }

/* onboarding */
.onboarding { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) 0 calc(18px + env(safe-area-inset-bottom)); }
.ob-top { display: flex; justify-content: flex-end; padding: 0 16px; min-height: 36px; }
.ob-skip { border: 0; background: transparent; color: var(--muted); font-weight: 600; font-size: 15px; padding: 8px; }
.ob-track { flex: 1; display: flex; overflow: hidden; }
.ob-slide { flex: 0 0 100%; max-width: 100%; padding: 8px 28px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; transition: transform .3s cubic-bezier(.2,.8,.2,1); overflow-y: auto; }
.ob-slide h2 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin: 22px 0 6px; }
.ob-sub { color: var(--muted); font-size: 16px; font-weight: 600; margin: 0 0 22px; }
.ob-logo { display: block; width: 132px; height: 132px; }
.ob-points { list-style: none; padding: 0; margin: 0; text-align: left; display: flex; flex-direction: column; gap: 12px; max-width: 340px; }
.ob-points li { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; font-weight: 600; line-height: 1.4; }
.ob-points i { flex: none; width: 14px; height: 14px; margin-top: 3px; }
.ob-points i.split { background: linear-gradient(135deg, #4c7fbf 50%, #c56b88 50%); }
.ob-avatar { width: 112px; height: 112px; display: grid; place-items: center; background: var(--card); font-size: 40px; font-weight: 800; overflow: hidden; border-radius: 50%; }
.ob-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ob-handle { margin: 0 0 16px; color: var(--muted); font-weight: 700; }
.ob-about { font-size: 15px; line-height: 1.5; max-width: 340px; margin: 0 0 20px; }
.ob-links { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 340px; }
.ob-bottom { padding: 0 20px; max-width: 480px; width: 100%; margin: 0 auto; }
.ob-dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 4px; }
.ob-dots span { width: 6px; height: 6px; background: var(--line); }
.ob-dots span.on { background: var(--text); width: 18px; }
