:root {
  --bg: #0a0a0f;
  --card: #15151c;
  --card-2: #1d1d26;
  --line: #262631;
  --text: #f4f4f6;
  --muted: #8d8d9b;
  --danger: #ff5a5f;
  --ok: #34d399;
  --accent: #ff6a00;
  --accent-light: #ffc46b;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:disabled { opacity: .35; cursor: default; }
input { -webkit-user-select: text; user-select: text; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 12px 16px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 12px; }
.row.gap { gap: 8px; }
.label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.num, .streak-num, .big, .unlock-days, .road-pct, .count-val, .ring span { font-family: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif; font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot-flame { width: 44px; height: 56px; border-radius: 50% 50% 46% 46% / 62% 62% 38% 38%; background: linear-gradient(0deg, #ff6a00, #ffc46b); animation: flicker 1.2s ease-in-out infinite; }
.shell { padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 96px); max-width: 560px; margin: 0 auto; }
.view { animation: fade .18s ease-out; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 2px 14px; }
.topbar h1 { margin: 0; font-size: 28px; line-height: 1.1; letter-spacing: -.02em; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 4px 8px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(var(--safe-bottom) + 6px);
  background: rgba(14, 14, 20, .82); backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--text); }
.tab.on svg { color: var(--accent); filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 60%, transparent)); }

/* ---------- cards & bits ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin-bottom: 12px; }
.stat .big { font-size: 34px; font-weight: 800; margin: 4px 0 2px; letter-spacing: -.02em; }
.bar { height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bar.big { height: 12px; margin: 12px 0 8px; }
.bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-light)); transition: width .35s cubic-bezier(.2, .8, .2, 1); }
.primary { display: block; width: 100%; padding: 15px 18px; border-radius: 14px; font-weight: 700; color: #fff; background: linear-gradient(180deg, var(--accent-light), var(--accent)); box-shadow: 0 6px 24px -8px var(--accent); }
.primary:active { transform: scale(.98); }
.ghost { display: block; width: 100%; padding: 13px 16px; border-radius: 14px; font-weight: 600; background: var(--card-2); margin-top: 8px; }
.danger { color: var(--danger); }
.small-btn { width: auto; display: inline-block; padding: 9px 14px; margin: 0; font-size: 14px; border-radius: 11px; }
.link-btn { display: inline-block; margin-top: 6px; color: var(--accent-light); font-weight: 700; }
.icon-btn { min-width: 34px; height: 34px; padding: 0 10px; border-radius: 10px; background: var(--card-2); font-size: 14px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chip { padding: 7px 11px; border-radius: 99px; background: var(--card-2); border: 1px solid var(--line); font-size: 14px; font-weight: 600; }
.banner { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin-bottom: 12px; border-radius: 14px; background: var(--card-2); border: 1px solid var(--line); font-size: 14px; }
.banner span { flex: 1; }
.banner.broken { border-color: #4a3a2a; background: #1f1812; }
.banner .x { color: var(--muted); padding: 2px 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 2px; }

/* ---------- today ---------- */
.ring { position: relative; width: 52px; height: 52px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring-bg { stroke: var(--card-2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s cubic-bezier(.2, .8, .2, 1); }
.ring span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800; }
.ring small { font-size: 9px; margin-top: 3px; }

.hero { text-align: center; padding: 8px 0 18px; }
.flame-wrap { position: relative; display: inline-block; }
.flame-wrap::after { content: ""; position: absolute; left: 50%; bottom: 4%; width: 70%; height: 30%; transform: translateX(-50%); background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 55%, transparent), transparent); filter: blur(14px); z-index: -1; }
.state-out .flame-wrap::after, .state-empty .flame-wrap::after { display: none; }
.flame { display: block; overflow: visible; }
.flame.lit .flame-body { transform-origin: 50% 100%; animation: flicker 2.6s ease-in-out infinite; }
.flame.lit .flame-core { animation: core 1.7s ease-in-out infinite; transform-origin: 50% 100%; }
.flame.out .flame-core { opacity: .25; }
.flame.risk .flame-body { animation: risk 1.1s steps(2, jump-none) infinite, flicker 1.3s ease-in-out infinite; }
.streak-num { font-size: 76px; line-height: 1; font-weight: 800; letter-spacing: -.04em; margin-top: -6px; }
.streak-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; margin-top: 2px; }
.status { margin: 12px auto 0; max-width: 320px; color: #c9c9d3; font-size: 15px; }
.state-rescue .status { color: #ffcf8a; }

.next .next-days { font-weight: 800; }
.reward { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--card-2); font-weight: 600; }
.goal-line { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.goal-line b { color: var(--text); }
.legend p { margin: 6px 0 0; color: var(--muted); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; margin: 6px 0 4px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.seg button, .seg label span { display: block; padding: 8px 10px; border-radius: 9px; text-align: center; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on, .seg input:checked + span { background: var(--card-2); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg.locked { opacity: .6; }
.dot { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: #ff9f43; vertical-align: middle; }

.habits { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.habit { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color .2s, background .2s; }
.habit.done { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.habit-tap { display: flex; align-items: center; gap: 12px; width: 100%; padding: 16px; text-align: left; }
.habit-tap:active .box { transform: scale(.88); }
.box { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; border: 2px solid #3a3a48; color: transparent; transition: all .18s cubic-bezier(.2, .8, .2, 1); }
.box svg { width: 20px; height: 20px; }
.done .box { border-color: transparent; color: #fff; background: linear-gradient(180deg, var(--accent-light), var(--accent)); animation: pop .3s cubic-bezier(.2, .8, .2, 1.4); }
.emoji { font-size: 20px; flex: none; }
.name { font-weight: 600; font-size: 16px; flex: 1; min-width: 0; }
.habit.count { padding: 14px 16px; }
.count-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.count-val { font-size: 22px; font-weight: 800; white-space: nowrap; }
.count-val small { font-size: 13px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.steps { display: flex; gap: 8px; margin-top: 12px; }
.step { flex: 1; height: 40px; border-radius: 12px; background: var(--card-2); font-weight: 700; font-size: 15px; }
.step:active { background: #2a2a36; transform: scale(.96); }
.step.fill { color: var(--accent-light); }
.empty h2 { margin: 0 0 6px; }
.empty p { margin: 0 0 10px; color: var(--muted); }
.preset-list { margin: 0 0 14px; padding-left: 18px; color: #c9c9d3; line-height: 1.8; }

/* ---------- journey ---------- */
.road { text-align: center; }
.road-pct { font-size: 56px; font-weight: 800; letter-spacing: -.03em; line-height: 1; background: linear-gradient(180deg, var(--accent-light), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.road-label { color: var(--muted); margin: 6px 0 18px; }
.road-label b { color: var(--text); }
.road-track { position: relative; height: 14px; border-radius: 99px; background: var(--card-2); margin: 0 6px; }
.road-fill { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-light)); }
.road-mark { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--bg); border: 2px solid #4a4a58; }
.road-mark.hit { border-color: #fff; background: var(--accent-light); }
.road-axis { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--muted); }
.ladder { position: relative; margin: 6px 0 12px; }
.rung { display: flex; gap: 14px; padding: 14px 16px; margin-bottom: 8px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); opacity: .65; }
.rung.next { opacity: 1; border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.rung.reached { opacity: 1; }
.rung-icon { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--card-2); }
.rung-days { font-weight: 800; font-size: 17px; }
.rung-reward { margin-top: 2px; }
.rung-meta { margin-top: 4px; font-size: 13px; color: var(--muted); }
.target { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--accent); }
.lock { width: 12px; height: 10px; border-radius: 3px; background: #4a4a58; position: relative; margin-top: 5px; }
.lock::before { content: ""; position: absolute; left: 2px; top: -7px; width: 8px; height: 8px; border: 2px solid #4a4a58; border-bottom: 0; border-radius: 6px 6px 0 0; box-sizing: border-box; }

/* ---------- stats ---------- */
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 4px; margin: 14px 0 10px; }
.cell { display: block; aspect-ratio: 1; border-radius: 4px; background: var(--card-2); }
.cell.none { background: #121218; }
.cell.future { background: transparent; }
.cell.miss { background: #262631; }
.cell.partial { background: color-mix(in srgb, var(--accent) calc(var(--a, .4) * 100%), #262631); }
.cell.perfect { background: linear-gradient(180deg, var(--accent-light), var(--accent)); }
.cell.today { outline: 2px solid var(--text); outline-offset: 1px; }
.cell.sel { outline: 2px solid var(--accent-light); outline-offset: 1px; }
.legend { display: inline-flex; gap: 4px; }
.legend .cell { width: 12px; height: 12px; }
.detail { min-height: 18px; }
.hstat { position: relative; }
.hstat .hname { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.hstat .rate { font-size: 22px; font-weight: 800; }
.hstat .bar { margin: 10px 0 8px; }
.hstat.weak { border-color: #4a3a2a; }
.weak-tag { position: absolute; top: -9px; right: 14px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: #3a2a18; color: #ffb36b; }

/* ---------- settings ---------- */
.list { padding: 0; overflow: hidden; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-row.column { flex-direction: column; align-items: stretch; gap: 10px; }
.list-row:last-child { border-bottom: 0; }
.list-row .hname { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.stack { display: flex; flex-direction: column; min-width: 0; }
.stack .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: flex; gap: 6px; flex: none; }
.add-row { display: block; width: 100%; padding: 14px 16px; text-align: left; font-weight: 700; color: var(--accent-light); }
.add-row.inline { width: auto; padding: 0; }
.add-row.danger { color: var(--danger); }
.ms-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.ms-row input, .list-row input[type="time"], .field input { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; outline: none; min-width: 0; }
.ms-row input:focus, .field input:focus { border-color: var(--accent); }
.ms-days { width: 68px; text-align: center; font-weight: 700; }
.ms-reward { flex: 1; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: #3a3a48; position: relative; flex: none; transition: background .2s; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }
.archived { margin: 0 4px; color: var(--muted); font-size: 14px; }
.archived summary { cursor: pointer; padding: 4px 0 8px; }
.archived div { display: flex; gap: 6px; padding: 4px 0; }
.build { margin-top: 24px; }

/* ---------- overlay ---------- */
#overlay { position: fixed; inset: 0; z-index: 30; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); opacity: 0; transition: opacity .2s; }
#overlay.open .backdrop { opacity: 1; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; padding: 10px 18px calc(var(--safe-bottom) + 18px); background: #17171f; border-radius: 22px 22px 0 0; border-top: 1px solid var(--line); transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1); max-width: 560px; margin: 0 auto; }
#overlay.open .sheet { transform: none; }
.grabber { width: 38px; height: 5px; border-radius: 99px; background: #3a3a48; margin: 0 auto 10px; }
.sheet h2 { margin: 0 0 12px; }
.presets { justify-content: flex-start; margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input { color: var(--text); font-size: 16px; font-weight: 500; padding: 12px; }
.field.grow { flex: 1; }
.emoji-field input { width: 64px; text-align: center; font-size: 20px; padding: 9px; }
.habit-form .seg { margin-bottom: 12px; }
.habit-form .primary { margin-top: 14px; }
.modal { position: absolute; left: 50%; top: 50%; width: min(340px, calc(100% - 32px)); transform: translate(-50%, -46%) scale(.94); opacity: 0; transition: all .3s cubic-bezier(.2, .8, .2, 1.2); }
#overlay.open .modal { transform: translate(-50%, -50%); opacity: 1; }
.unlock { text-align: center; padding: 26px 22px 22px; border-radius: 26px; background: radial-gradient(120% 70% at 50% 0%, color-mix(in srgb, var(--accent) 30%, #17171f), #17171f); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); }
.unlock .flame { margin: 0 auto; }
.unlock-days { font-size: 64px; font-weight: 800; line-height: 1; margin-top: -4px; }
.unlock-label { font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.unlock p { margin: 14px 0; font-weight: 600; }
.unlock-reward { margin: 0 0 18px; padding: 12px; border-radius: 14px; background: rgba(255, 255, 255, .06); }
.unlock-reward b { display: block; font-size: 18px; margin-top: 2px; }

#toast { position: fixed; left: 50%; top: calc(var(--safe-top) + 10px); z-index: 40; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 14px; background: #24242e; border: 1px solid #33333f; font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: drop .25s cubic-bezier(.2, .8, .2, 1.2); }
#toast.error { background: #2a1518; border-color: #4d2329; color: #ffb3b6; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; display: none; }
#confetti.on { display: block; }

/* ---------- login ---------- */
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(340px, 100%); text-align: center; }
.login .flame { margin: 0 auto 6px; }
.login h1 { margin: 6px 0 4px; font-size: 32px; letter-spacing: -.02em; }
.login p { margin: 0 0 22px; }
.login input[type="password"] { width: 100%; padding: 15px 16px; margin-bottom: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); outline: none; font-size: 17px; }
.login input[type="password"]:focus { border-color: var(--accent); }
.login .error { color: var(--danger); margin-top: 14px; }

@keyframes flicker {
  0%, 100% { transform: scale(1, 1) skewX(0deg); }
  25% { transform: scale(1.02, .97) skewX(-1.5deg); }
  50% { transform: scale(.98, 1.03) skewX(1deg); }
  75% { transform: scale(1.01, .99) skewX(-.5deg); }
}
@keyframes core { 0%, 100% { transform: scale(1); opacity: .95; } 50% { transform: scale(.94, 1.06); opacity: .8; } }
@keyframes risk { 0% { opacity: 1; } 100% { opacity: .55; } }
@keyframes pop { 0% { transform: scale(.6); } 100% { transform: scale(1); } }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
