:root {
  --bg: #f2f2f7; --card: #ffffff; --fill: rgba(120,120,128,.12); --fill-strong: rgba(120,120,128,.2);
  --text: #000; --muted: #8e8e93; --sep: rgba(60,60,67,.14);
  --accent: #f05a28; --danger: #ff3b30; --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --fill: rgba(120,120,128,.24); --fill-strong: rgba(120,120,128,.36);
          --text: #fff; --muted: #98989f; --sep: rgba(84,84,88,.5); --accent: #ff7d42; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
       -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
#app { height: 100dvh; max-width: 640px; margin: 0 auto; position: relative; overflow: hidden; }
#screen { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 32px); }
.pushed { animation: slideIn .32s cubic-bezier(.2,.8,.2,1); }
@keyframes slideIn { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }

/* top bars */
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin-bottom: 4px; }
.circle-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--card); display: grid; place-items: center;
              box-shadow: 0 1px 6px rgba(0,0,0,.12); font-size: 20px; }
.circle-btn svg { width: 22px; height: 22px; }
.title { font-size: 34px; font-weight: 800; letter-spacing: -.5px; margin: 6px 4px 0; }
.subtitle { font-size: 20px; font-weight: 500; color: var(--muted); margin: 0 4px 14px; }
.nav-title { font-weight: 600; font-size: 17px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.summary { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 56px; height: 56px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring .bg { stroke: color-mix(in srgb, var(--accent) 16%, transparent); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s cubic-bezier(.2,.8,.2,1); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.summary h2 { font-size: 17px; font-weight: 600; } .summary p { color: var(--muted); font-size: 15px; }

.habit { display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer; }
.hicon { --c: var(--accent); width: var(--s, 48px); height: var(--s, 48px); flex: none; border-radius: calc(var(--s, 48px) * .3);
         background: color-mix(in srgb, var(--c) 16%, transparent); display: grid; place-items: center; font-size: calc(var(--s, 48px) * .5); }
.info { flex: 1; min-width: 0; }
.info h3 { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.streak { color: var(--muted); font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; }
.streak .flame { filter: none; } .streak.zero .flame { filter: grayscale(1) opacity(.5); }
.dots { width: 36px; height: 46px; display: grid; place-items: center; color: var(--muted); font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.check { --c: var(--accent); width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
         background: color-mix(in srgb, var(--c) 14%, transparent); border: 2px solid color-mix(in srgb, var(--c) 50%, transparent);
         color: color-mix(in srgb, var(--c) 70%, transparent); transition: transform .15s; }
.check:active { transform: scale(.88); }
.check svg { width: 22px; height: 22px; }
.check.done { background: var(--c); border-color: var(--c); color: #fff; }
.check.pop { animation: pop .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { 0% { transform: scale(.7); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* empty state */
.empty { text-align: center; padding: 64px 28px; display: grid; gap: 14px; justify-items: center; }
.empty .blob { width: 112px; height: 112px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 14%, transparent); display: grid; place-items: center; font-size: 52px; }
.empty h2 { font-size: 22px; font-weight: 700; } .empty p { color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px; border-radius: 999px;
       background: var(--accent); color: #fff; font-weight: 600; }
.btn.block { width: 100%; } .btn.tint { background: var(--c, var(--accent)); }
.btn.soft { background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent); color: var(--c, var(--accent)); min-height: 40px; padding: 0 16px; }
.btn.plain { background: var(--fill); color: var(--text); }
.btn.danger { background: var(--fill); color: var(--danger); }
.btn:disabled { opacity: .4; }
.link { color: var(--accent); font-weight: 500; }

/* detail */
.head { display: flex; align-items: center; gap: 16px; margin: 8px 0 16px; }
.head h1 { font-size: 24px; font-weight: 800; overflow-wrap: anywhere; } .head p { color: var(--muted); font-size: 15px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px; } .stat .ic { font-size: 22px; }
.stat b { display: block; font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 6px; }
.stat b small { font-size: 15px; font-weight: 500; color: var(--muted); } .stat span { color: var(--muted); font-size: 13px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head h3 { font-size: 17px; font-weight: 700; } .cal-nav { display: flex; gap: 8px; }
.cal-nav button { width: 32px; height: 32px; border-radius: 50%; background: var(--fill); color: var(--accent); font-size: 18px; }
.cal-nav button:disabled { color: var(--muted); opacity: .5; }
.grid7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px 4px; text-align: center; }
.dow { font-size: 12px; font-weight: 600; color: var(--muted); }
.day { aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-size: 16px; font-variant-numeric: tabular-nums; }
.day.done { background: var(--c); color: #fff; font-weight: 700; }
.day.today:not(.done) { box-shadow: inset 0 0 0 2px var(--c); }
.day.future { color: var(--muted); opacity: .45; } .day:disabled { cursor: default; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 10px; }
.heat { display: flex; gap: 4px; } .heat div { flex: 1; display: grid; gap: 4px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--fill); display: block; }
.heat i.on { background: var(--c); } .heat i.none { background: transparent; }
.card h3.sec { font-size: 17px; font-weight: 700; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: baseline; }
.note { background: var(--fill); border-radius: 14px; padding: 12px; margin-bottom: 8px; text-align: left; width: 100%; display: block; }
.note small { display: block; color: var(--muted); font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.note p { white-space: pre-wrap; overflow-wrap: anywhere; }

/* sheets */
.layer { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.35); animation: fade .2s; }
.layer.closing { opacity: 0; transition: opacity .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; background: var(--bg); border-radius: 26px 26px 0 0;
         padding: 8px 16px calc(var(--safe-bottom) + 24px); animation: up .32s cubic-bezier(.2,.8,.2,1); }
.layer.closing .sheet { transform: translateY(40px); transition: transform .2s; }
@keyframes up { from { transform: translateY(60px); opacity: .6; } }
.sheet-bar { display: flex; align-items: center; justify-content: space-between; min-height: 52px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.sheet-bar h2 { font-size: 17px; font-weight: 600; } .sheet-bar button { font-weight: 500; color: var(--accent); min-width: 64px; }
.sheet-bar button.strong { font-weight: 700; text-align: right; } .sheet-bar button:disabled { color: var(--muted); }
.group { background: var(--card); border-radius: 18px; padding: 4px 16px; margin-bottom: 8px; }
.group.pad { padding: 14px 16px; }
.label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .3px; margin: 16px 16px 6px; }
.footnote { color: var(--muted); font-size: 13px; margin: 6px 16px 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--sep); }
.row:last-child { border-bottom: 0; }
.row input[type=text], .row input[type=number], .row input[type=time], .row input[type=url], .row input[type=password] {
  border: 0; background: transparent; text-align: right; outline: none; min-width: 0; flex: 1; }
.name-row { display: flex; align-items: center; gap: 14px; padding: 8px 0; }
.name-row input { border: 0; background: none; outline: none; font-size: 20px; font-weight: 500; flex: 1; min-width: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 0; }
.sw { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; font-weight: 700; }
.sw:not(.sel) span { display: none; }
.emojis { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; padding: 12px 0; }
.emojis button { height: 46px; border-radius: 12px; background: var(--fill); font-size: 24px; }
.emojis button.sel { box-shadow: inset 0 0 0 2px var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); }
textarea.note-input { width: 100%; min-height: 160px; border: 0; background: transparent; outline: none; resize: vertical; padding: 10px 0; }
.switch { appearance: none; width: 51px; height: 31px; border-radius: 999px; background: var(--fill-strong); position: relative; transition: background .2s; flex: none; }
.switch::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,.25); transition: transform .2s; }
.switch:checked { background: #34c759; } .switch:checked::after { transform: translateX(20px); }
.menu { display: grid; gap: 8px; }
.menu .group { padding: 0; overflow: hidden; margin: 0; }
.menu button { width: 100%; text-align: left; padding: 15px 18px; display: flex; gap: 12px; align-items: center; border-bottom: 1px solid var(--sep); }
.menu button:last-child { border-bottom: 0; } .menu button.danger { color: var(--danger); } .menu .cancel { text-align: center; justify-content: center; font-weight: 600; background: var(--card); border-radius: 18px; border: 0; }
.menu-title { text-align: center; color: var(--muted); font-size: 13px; padding: 4px 0 8px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--fill); font-size: 13px; color: var(--muted); }
.status { color: var(--muted); font-size: 14px; margin: 4px 16px 12px; }
.status.ok { color: #34c759; } .status.bad { color: var(--danger); }

/* milestone */
.ms { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0,0,0,.55); animation: fade .25s; padding: 24px; }
.ms-card { width: min(340px, 100%); background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
           border-radius: 32px; padding: 28px; text-align: center; display: grid; gap: 14px; animation: msIn .55s cubic-bezier(.2,1.5,.4,1); position: relative; z-index: 1; }
@keyframes msIn { from { transform: scale(.75); opacity: 0; } }
.ms-flame { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; font-size: 62px; background: color-mix(in srgb, var(--c) 18%, transparent); animation: flame 1.2s ease-in-out infinite alternate; }
@keyframes flame { to { transform: scale(1.08) rotate(3deg); } }
.ms-num { font-size: 64px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; } .ms p { color: var(--muted); }
.confetti { position: absolute; left: 50%; top: 42%; width: 9px; height: 15px; border-radius: 2px; background: var(--c); opacity: 0;
            animation: burst 1.7s cubic-bezier(.1,.7,.3,1) forwards; }
@keyframes burst { 0% { opacity: 1; transform: translate(0,0) rotate(0); } 100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); } }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } .ms-flame, .pushed, .check.pop { animation: none; } }

[hidden] { display: none !important; }
