:root {
  --bg: #0b0b14;
  --bg2: #13131f;
  --card: #181826;
  --card2: #20202f;
  --line: #2a2a3c;
  --text: #f3f3f8;
  --muted: #9b9bb0;
  --faint: #6b6b80;
  --accent: #8b5cf6;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 20px;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, .6);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --bg: #f4f4f8; --bg2: #ebebf2; --card: #fff; --card2: #f1f1f6; --line: #e2e2ea; --text: #15151f; --muted: #5f5f72; --faint: #9090a2; --shadow: 0 10px 30px -14px rgba(30, 30, 60, .25); color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f4f4f8; --bg2: #ebebf2; --card: #fff; --card2: #f1f1f6; --line: #e2e2ea; --text: #15151f; --muted: #5f5f72; --faint: #9090a2; --shadow: 0 10px 30px -14px rgba(30, 30, 60, .25); color-scheme: light; }

.c-violet { --c1: #8b5cf6; --c2: #6d28d9; }
.c-blue   { --c1: #3b82f6; --c2: #1d4ed8; }
.c-cyan   { --c1: #06b6d4; --c2: #0e7490; }
.c-teal   { --c1: #14b8a6; --c2: #0f766e; }
.c-green  { --c1: #22c55e; --c2: #15803d; }
.c-lime   { --c1: #84cc16; --c2: #4d7c0f; }
.c-amber  { --c1: #f59e0b; --c2: #b45309; }
.c-orange { --c1: #f97316; --c2: #c2410c; }
.c-red    { --c1: #ef4444; --c2: #b91c1c; }
.c-pink   { --c1: #ec4899; --c2: #be185d; }
.c-slate  { --c1: #64748b; --c2: #334155; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.page {
  max-width: 680px; margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 100px) calc(var(--safe-l) + 16px);
}
.topbar { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.topbar h1 { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 0; flex: 1; }
.topbar h2 { font-size: 18px; font-weight: 700; margin: 0; flex: 1; text-align: center; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); color: var(--text); box-shadow: var(--shadow); transition: transform .15s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.ghost { background: transparent; box-shadow: none; }
.fab {
  position: fixed; right: calc(var(--safe-r) + 20px); bottom: calc(var(--safe-b) + 22px); z-index: 20;
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #2563eb); box-shadow: 0 12px 30px -8px rgba(99, 102, 241, .7);
  transition: transform .15s;
}
.fab .ico { width: 28px; height: 28px; stroke-width: 2.5; }
.fab:active { transform: scale(.9); }
@media (min-width: 720px) { .fab { right: calc(50% - 340px + 4px); } }

/* ---------- tabs & search ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin: 10px 0 16px; }
.seg { display: flex; flex: 1; background: var(--bg2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 7px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.seg .count { font-size: 12px; opacity: .6; margin-left: 3px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--bg2); border-radius: 12px; padding: 0 12px; margin-bottom: 14px; }
.search input { flex: 1; background: none; border: 0; outline: 0; padding: 10px 0; }
.search .ico { width: 18px; height: 18px; color: var(--faint); }

/* ---------- cards ---------- */
.list { display: grid; gap: 14px; }
@media (min-width: 640px) { .list { grid-template-columns: 1fr 1fr; } }
.card {
  position: relative; overflow: hidden; text-align: left; width: 100%;
  background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  transition: transform .15s; animation: pop .3s ease both;
}
.card:active { transform: scale(.98); }
.card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 80% at 0% 0%, color-mix(in srgb, var(--c1) 28%, transparent), transparent 60%);
}
.card > * { position: relative; }
.card-head { display: flex; gap: 12px; align-items: center; }
.bubble {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 26px; flex: none;
  background: linear-gradient(135deg, var(--c1), var(--c2)); box-shadow: 0 6px 16px -6px var(--c1);
}
.card-title { font-weight: 700; font-size: 17px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card-sub .ico { width: 13px; height: 13px; }
.pin-flag { position: absolute; top: 12px; right: 12px; color: var(--c1); }
.pin-flag .ico { width: 16px; height: 16px; fill: currentColor; }
.units { display: flex; gap: 6px; margin-top: 14px; }
.unit { flex: 1; min-width: 0; text-align: center; background: var(--card2); border-radius: 12px; padding: 8px 2px 6px; }
.unit b { display: block; font-size: 22px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.unit span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 2px; }
.unit.zero b { color: var(--faint); }
.status { margin-top: 12px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.status .tag { font-weight: 700; color: var(--c1); }
.bar { height: 5px; background: var(--card2); border-radius: 5px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--c1), var(--c2)); transition: width 1s linear; }
.card.past .units .unit b { color: var(--muted); }
.big-today { margin-top: 14px; font-size: 24px; font-weight: 800; text-align: center; padding: 10px; border-radius: 12px; background: linear-gradient(135deg, var(--c1), var(--c2)); color: #fff; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 64px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: 14px; font-weight: 700; background: var(--card2); color: var(--text);
  transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: linear-gradient(135deg, #8b5cf6, #2563eb); color: #fff; }
.btn.danger { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.btn.block { width: 100%; }
.btn .ico { width: 18px; height: 18px; }

/* ---------- detail ---------- */
.detail {
  min-height: 100dvh; color: #fff;
  background: radial-gradient(130% 90% at 20% 0%, var(--c1), var(--c2) 55%, #07070d 120%);
}
.detail .page { padding-bottom: calc(var(--safe-b) + 30px); }
.detail .icon-btn { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.hero { text-align: center; padding: 16px 0 6px; }
.hero .emoji { font-size: 84px; line-height: 1; filter: drop-shadow(0 10px 20px rgba(0, 0, 0, .3)); animation: float 4s ease-in-out infinite; }
.hero h1 { font-size: 30px; margin: 14px 0 4px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.hero .when { opacity: .85; font-size: 15px; }
.hero .lead { margin-top: 8px; font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; opacity: .8; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px; margin: 22px 0; }
.tiles[style*="repeat(4"] .tile b { font-size: clamp(28px, 9vw, 52px); }
.tile { background: rgba(255, 255, 255, .14); border-radius: 18px; padding: 16px 6px 12px; text-align: center; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.tile b { display: block; font-size: clamp(34px, 11vw, 52px); font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.tile span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; opacity: .8; margin-top: 6px; }
.detail .bar { background: rgba(255, 255, 255, .18); height: 8px; }
.detail .bar i { background: #fff; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12px; opacity: .8; margin-top: 6px; }
.notes { background: rgba(0, 0, 0, .2); border-radius: 16px; padding: 14px 16px; margin-top: 18px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin-top: 20px; }
.actions button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 16px; background: rgba(255, 255, 255, .14); color: #fff; font-size: 12.5px; font-weight: 600; }
.actions button:active { background: rgba(255, 255, 255, .25); }
.actions button.on .ico { fill: currentColor; }
.today-banner { font-size: clamp(40px, 14vw, 72px); font-weight: 900; text-align: center; margin: 26px 0; letter-spacing: -.03em; }
.detail.focus .topbar, .detail.focus .actions, .detail.focus .notes, .detail.focus .progress-wrap { display: none; }
.detail.focus .page { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; }

/* ---------- sheet (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5); animation: fade .2s ease both; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; max-height: calc(100dvh - var(--safe-t) - 20px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 18px calc(var(--safe-b) + 20px);
  animation: up .28s cubic-bezier(.2, .9, .3, 1) both; overscroll-behavior: contain;
}
@media (min-width: 720px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 24px; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; gap: 8px; position: sticky; top: -8px; background: var(--bg); padding: 6px 0 10px; z-index: 2; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; text-align: center; }
.sheet-head .txt-btn { min-width: 64px; font-weight: 700; color: var(--accent); padding: 8px 4px; }
.sheet-head .txt-btn:first-child { text-align: left; color: var(--muted); font-weight: 500; }
.sheet-head .txt-btn:last-child { text-align: right; }

.field { margin: 16px 0; }
.field > label, .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 7px 4px; text-transform: uppercase; letter-spacing: .05em; }
.input, select.input, textarea.input {
  width: 100%; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; outline: 0; appearance: none; -webkit-appearance: none;
  font-size: 16px; /* >=16px stops iOS zoom */
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 80px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
input[type="date"].input, input[type="time"].input { min-height: 48px; }
.preview { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 18px; padding: 12px; }
.preview .bubble { width: 56px; height: 56px; font-size: 32px; border-radius: 16px; }
.preview .p-title { font-weight: 700; }
.preview .p-sub { font-size: 13px; color: var(--muted); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 14px; padding: 10px 14px; margin-top: 8px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 31px; background: var(--line); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1.5px solid var(--line); font-size: 14px; font-weight: 600; color: var(--muted); }
.chip.on { background: color-mix(in srgb, var(--accent) 18%, var(--card)); border-color: var(--accent); color: var(--text); }
.templates { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.templates::-webkit-scrollbar { display: none; }
.templates .chip { white-space: nowrap; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--c1), var(--c2)); position: relative; }
.swatch.on::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2.5px solid var(--text); }

.icon-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 8px; scrollbar-width: none; }
.icon-tabs::-webkit-scrollbar { display: none; }
.icon-tabs button { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.icon-tabs button.on { background: var(--card2); color: var(--text); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; background: var(--card); border-radius: 16px; padding: 8px; }
.emoji-grid button { font-size: 26px; height: 46px; border-radius: 12px; }
.emoji-grid button.on { background: color-mix(in srgb, var(--accent) 25%, transparent); outline: 2px solid var(--accent); }
.emoji-custom { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.emoji-custom input { width: 90px; flex: none; text-align: center; font-size: 22px; padding: 6px; }
.emoji-custom small { color: var(--faint); font-size: 12.5px; }

/* ---------- settings ---------- */
.group { background: var(--card); border-radius: 18px; overflow: hidden; margin: 8px 0 22px; }
.group-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 0 16px; }
.item .btn .ico { color: inherit; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .ico { color: var(--accent); }
.item .grow { flex: 1; }
.item small { display: block; color: var(--muted); font-size: 13px; }
.item.danger, .item.danger .ico { color: var(--danger); }
.item .seg { flex: none; width: 210px; }
.hint { color: var(--muted); font-size: 13.5px; padding: 0 16px; line-height: 1.5; }
.form-msg { min-height: 20px; font-size: 14px; margin-top: 8px; color: var(--danger); }
.form-msg.ok { color: var(--ok); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: calc(var(--safe-t) + 20px) 24px calc(var(--safe-b) + 20px); background: radial-gradient(100% 60% at 50% 0%, rgba(139, 92, 246, .35), transparent 70%), var(--bg); }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-box img { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 20px 40px -12px rgba(99, 102, 241, .7); animation: float 5s ease-in-out infinite; }
.login-box h1 { font-size: 30px; margin: 20px 0 4px; letter-spacing: -.02em; }
.login-box p { color: var(--muted); margin: 0 0 26px; }
.login-box .input { text-align: center; margin-bottom: 12px; }
.shake { animation: shake .4s; }

/* ---------- install hint / toast ---------- */
.install {
  display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 16px; padding: 12px 14px; margin-bottom: 14px;
  border: 1px dashed color-mix(in srgb, var(--accent) 50%, transparent); font-size: 14px;
}
.install .grow { flex: 1; color: var(--muted); }
.install b { color: var(--text); }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 100;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; transition: all .25s;
  display: flex; gap: 12px; align-items: center; white-space: nowrap; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: var(--accent); font-weight: 800; }
.offline-pill { font-size: 12px; font-weight: 700; color: var(--bg); background: #f59e0b; border-radius: 999px; padding: 3px 10px; }

/* iOS installed app uses a translucent status bar with white text; in light
   mode give it a dark strip so the clock/battery stay readable. */
@media (display-mode: standalone) {
  :root[data-theme="light"] body::before { content: ""; position: fixed; top: 0; left: 0; right: 0; height: var(--safe-t); background: #15151f; z-index: 40; }
}
@media (display-mode: standalone) and (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) body::before { content: ""; position: fixed; top: 0; left: 0; right: 0; height: var(--safe-t); background: #15151f; z-index: 40; }
}

canvas.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 200; }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
