:root {
  --bg: #151a2d;
  --bg2: #1b2139;
  --card: rgba(255, 255, 255, 0.055);
  --card-solid: #222943;
  --card-hi: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef0fa;
  --muted: #9aa3c4;
  --mint: #7be0c3;
  --lav: #a99bff;
  --peach: #ffb38a;
  --sky: #7cc4ff;
  --rose: #ff8fa8;
  --sun: #ffd66e;
  --accent: var(--lav);
  --good: var(--mint);
  --bad: var(--rose);
  --warn: var(--sun);
  --radius: 22px;
  --shadow: 0 10px 30px rgba(5, 8, 25, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f1fb;
    --bg2: #ebe8f8;
    --card: rgba(255, 255, 255, 0.75);
    --card-solid: #ffffff;
    --card-hi: rgba(255, 255, 255, 0.95);
    --line: rgba(40, 35, 90, 0.08);
    --text: #262a44;
    --muted: #7a7f9e;
    --mint: #2fb894;
    --lav: #7b68ee;
    --peach: #f08a55;
    --sky: #3d9be0;
    --rose: #e5577a;
    --sun: #d9a312;
    --shadow: 0 10px 30px rgba(70, 60, 140, 0.12);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f1fb; --bg2: #ebe8f8; --card: rgba(255,255,255,.75); --card-solid: #fff;
  --card-hi: rgba(255,255,255,.95); --line: rgba(40,35,90,.08); --text: #262a44; --muted: #7a7f9e;
  --mint: #2fb894; --lav: #7b68ee; --peach: #f08a55; --sky: #3d9be0; --rose: #e5577a; --sun: #d9a312;
  --shadow: 0 10px 30px rgba(70,60,140,.12); color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

/* soft floating background */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-orbs i { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .35; animation: float 18s ease-in-out infinite; }
.bg-orbs i:nth-child(1) { width: 280px; height: 280px; background: var(--lav); top: -80px; left: -60px; }
.bg-orbs i:nth-child(2) { width: 240px; height: 240px; background: var(--mint); top: 40%; right: -100px; animation-delay: -6s; opacity: .22; }
.bg-orbs i:nth-child(3) { width: 220px; height: 220px; background: var(--peach); bottom: -60px; left: 20%; animation-delay: -12s; opacity: .18; }
@keyframes float { 0%,100% { transform: translate(0,0); } 50% { transform: translate(20px,30px); } }
@media (prefers-reduced-motion: reduce) { .bg-orbs i { animation: none; } * { transition: none !important; animation: none !important; } }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) max(16px, calc((100% - 608px) / 2)) 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar-h { font-size: 22px; font-weight: 900; letter-spacing: -.2px; }
.avatar {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  font-weight: 900; color: #1a1d33; cursor: pointer;
  background: linear-gradient(135deg, var(--mint), var(--lav));
  box-shadow: 0 6px 16px rgba(123, 104, 238, .35);
}
.xpbar { width: 120px; height: 6px; border-radius: 6px; background: var(--line); margin-top: 4px; overflow: hidden; }
.xpbar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--lav)); border-radius: 6px; transition: width .5s; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; background: var(--card); font-size: 18px; border: 1px solid var(--line); }

.view { padding: 4px 16px calc(100px + var(--safe-b)); max-width: 640px; margin: 0 auto; }

/* bottom tab bar */
.tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(10px + var(--safe-b)); z-index: 6;
  max-width: 616px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px; border-radius: 24px;
  background: color-mix(in srgb, var(--card-solid) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0; border-radius: 18px; font-size: 11px; color: var(--muted); font-weight: 800; transition: background .2s, color .2s; }
.tabbar .ti { font-size: 20px; transition: transform .2s; }
.tabbar button.active { background: var(--card-hi); color: var(--text); }
.tabbar button.active .ti { transform: translateY(-2px) scale(1.12); }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.card.tap { cursor: pointer; transition: transform .15s; }
.card.tap:active { transform: scale(.985); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-h h3 { margin: 0; font-size: 17px; font-weight: 900; display: flex; align-items: center; gap: 8px; }
.card-h .more { color: var(--muted); font-size: 13px; font-weight: 800; }
.section-t { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 900; margin: 18px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* hero */
.hero { display: flex; align-items: center; gap: 16px; }
.hero h2 { margin: 0 0 2px; font-size: 20px; font-weight: 900; }
.ring { --p: 0; --c: var(--mint); width: 84px; height: 84px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0); position: relative; transition: --p .6s; }
.ring::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--card-solid); }
.ring b { position: relative; font-size: 20px; font-weight: 900; }
.ring.sm { width: 48px; height: 48px; }
.ring.sm::before { inset: 5px; }
.ring.sm b { font-size: 12px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 20px; font-weight: 900; margin-top: 2px; }
.big-num { font-size: 40px; font-weight: 900; letter-spacing: -1px; line-height: 1.1; background: linear-gradient(90deg, var(--mint), var(--sky)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 800; background: var(--card-hi); border: 1px solid var(--line); white-space: nowrap; }
.pill.good { color: var(--good); } .pill.bad { color: var(--bad); } .pill.warn { color: var(--warn); } .pill.lav { color: var(--lav); }

/* segmented / chips */
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); margin-bottom: 12px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 14px; font-weight: 800; color: var(--muted); font-size: 14px; transition: all .2s; }
.seg button.active { background: var(--card-hi); color: var(--text); box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-weight: 800; font-size: 14px; color: var(--muted); }
.chip.active { color: #1a1d33; background: linear-gradient(135deg, var(--mint), var(--sky)); border-color: transparent; }

/* day navigation */
.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.daynav button { width: 40px; height: 40px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 18px; font-weight: 900; }
.daynav .d { text-align: center; font-weight: 900; }
.daynav .d small { display: block; color: var(--muted); font-weight: 700; font-size: 12px; }

/* quick add */
.quick { display: flex; gap: 8px; margin-bottom: 12px; }
.quick input { flex: 1; min-width: 0; padding: 13px 16px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); outline: none; font-weight: 700; }
.quick input:focus { border-color: var(--lav); }
.quick button, .fab-inline { width: 50px; border-radius: 18px; background: linear-gradient(135deg, var(--lav), var(--sky)); color: #fff; font-size: 24px; font-weight: 900; box-shadow: 0 6px 16px rgba(123,104,238,.35); }

/* list items */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); transition: opacity .25s, transform .2s; }
.item.done { opacity: .5; }
.item.done .item-title { text-decoration: line-through; }
.item-body { flex: 1; min-width: 0; cursor: pointer; }
.item-title { font-weight: 800; overflow-wrap: anywhere; }
.item-sub { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.imp { color: var(--peach); font-weight: 900; }
.check { flex: none; width: 30px; height: 30px; border-radius: 10px; border: 2px solid var(--muted); display: grid; place-items: center; font-weight: 900; color: #1a1d33; transition: all .2s; }
.item.done .check { background: var(--mint); border-color: var(--mint); animation: pop .3s; }
@keyframes pop { 50% { transform: scale(1.25); } }
.item .amt { font-weight: 900; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-weight: 700; }
.empty .e { font-size: 38px; display: block; margin-bottom: 6px; }

/* progress */
.prog { height: 10px; border-radius: 10px; background: var(--line); overflow: hidden; margin-top: 8px; }
.prog span { display: block; height: 100%; border-radius: 10px; background: linear-gradient(90deg, var(--mint), var(--sky)); transition: width .5s; }
.prog.peach span { background: linear-gradient(90deg, var(--peach), var(--sun)); }
.focus-card { border: 1px solid color-mix(in srgb, var(--sun) 45%, transparent); }
.focus-card .item { background: transparent; border: 0; padding: 4px 0; }
.prog.bad span { background: linear-gradient(90deg, var(--rose), var(--peach)); }

/* buttons */
.btn { padding: 11px 16px; border-radius: 16px; font-weight: 800; background: var(--card-hi); border: 1px solid var(--line); font-size: 15px; }
.btn.primary { background: linear-gradient(135deg, var(--lav), var(--sky)); color: #fff; border: 0; box-shadow: 0 6px 16px rgba(123,104,238,.3); }
.btn.good { background: linear-gradient(135deg, var(--mint), var(--sky)); color: #10233a; border: 0; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 12px; }
.btn.block { display: block; width: 100%; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btns .btn { flex: 1; }

details.fold { margin-top: 10px; }
details.fold summary { cursor: pointer; color: var(--muted); font-weight: 800; padding: 8px 4px; list-style: none; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary::before { content: "▸ "; }
details.fold[open] summary::before { content: "▾ "; }

/* weekly plan */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week .wd { text-align: center; padding: 8px 0; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 12px; font-weight: 800; color: var(--muted); }
.week .wd b { display: block; font-size: 16px; color: var(--text); }
.week .wd.today { border-color: var(--lav); color: var(--lav); }
.week .wd.has b { color: var(--mint); }

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 10, 25, .5); backdrop-filter: blur(3px); animation: fade .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  max-height: 88dvh; overflow-y: auto; background: var(--card-solid); border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(18px + var(--safe-b)); animation: up .25s cubic-bezier(.2,.9,.3,1.1);
  border: 1px solid var(--line);
}
.sheet::before { content: ""; display: block; width: 44px; height: 5px; border-radius: 5px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 20px; font-weight: 900; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); font-weight: 800; margin: 0 0 6px 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 13px 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); outline: none; font-weight: 700; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--lav); }
.field textarea { min-height: 80px; resize: vertical; }
.wdpick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.wdpick label { position: relative; }
.wdpick input { position: absolute; opacity: 0; }
.wdpick span { display: block; text-align: center; padding: 10px 0; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-weight: 800; font-size: 13px; }
.wdpick input:checked + span { background: linear-gradient(135deg, var(--mint), var(--sky)); color: #10233a; border-color: transparent; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions .btn { text-align: left; padding: 14px 16px; }

/* toast */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(92px + var(--safe-b)); z-index: 30; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 18px;
  background: var(--card-solid); border: 1px solid var(--line); box-shadow: var(--shadow); animation: up .25s;
  font-weight: 800;
}
.toast .grow { min-width: 0; }
.toast button { color: var(--lav); font-weight: 900; }

/* xp float */
.xp-pop { position: fixed; z-index: 40; pointer-events: none; font-weight: 900; color: var(--mint); animation: xp 1s forwards; font-size: 15px; }
@keyframes xp { to { transform: translateY(-40px); opacity: 0; } }

.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); font-size: 12px; font-weight: 800; color: var(--muted); }
.badge .e { font-size: 28px; display: block; filter: grayscale(1); opacity: .4; }
.badge.on { color: var(--text); }
.badge.on .e { filter: none; opacity: 1; }
