:root {
  --bg: #f6f4fb;
  --surface: #ffffff;
  --surface-2: #efecf7;
  --ink: #1f1d2b;
  --ink-2: #6b6880;
  --line: rgba(31, 29, 43, 0.08);
  --brand: #7c4dff;
  --brand-2: #ff5fa2;
  --brand-3: #ffb84d;
  --good: #22c38e;
  --board-bg: #e8ebf2;
  --shadow: 0 6px 24px rgba(60, 40, 120, 0.10), 0 1px 3px rgba(60, 40, 120, 0.08);
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14131c;
    --surface: #1f1d2b;
    --surface-2: #2a2739;
    --ink: #f3f1fb;
    --ink-2: #a5a1bb;
    --line: rgba(255, 255, 255, 0.08);
    --board-bg: #1b1a25;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14131c;
  --surface: #1f1d2b;
  --surface-2: #2a2739;
  --ink: #f3f1fb;
  --ink-2: #a5a1bb;
  --line: rgba(255, 255, 255, 0.08);
  --board-bg: #1b1a25;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overscroll-behavior: none; }
body { position: fixed; inset: 0; overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

#app { position: absolute; inset: 0; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); transition: transform .32s cubic-bezier(.2,.8,.2,1), opacity .25s; }
#play { transform: translateX(100%); opacity: 0; pointer-events: none; }
#play.active { transform: none; opacity: 1; pointer-events: auto; }
#home.behind { transform: translateX(-18%); opacity: .4; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-t)) 16px 8px; }
.brand { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; display: flex; align-items: center; gap: 8px; }
.brand span { background: linear-gradient(90deg, var(--brand), var(--brand-2) 60%, var(--brand-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-dot { width: 26px; height: 26px; border-radius: 50%; background: conic-gradient(from 200deg, var(--brand), var(--brand-2), var(--brand-3), #3ddc97, #3fa9ff, var(--brand)); box-shadow: inset 0 0 0 6px var(--bg); }
.chips { display: flex; align-items: center; gap: 8px; }
.chip { display: flex; align-items: center; gap: 4px; background: var(--surface); padding: 6px 10px; border-radius: 99px; font-weight: 700; font-size: 14px; box-shadow: var(--shadow); }
.chip svg { width: 16px; height: 16px; }
.icon-btn { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); flex: none; transition: transform .12s; }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 22px; height: 22px; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(96px + var(--safe-b)); }

/* ---------- tab bar ---------- */
.tabbar { position: absolute; left: 12px; right: 12px; bottom: calc(10px + var(--safe-b)); display: flex; background: color-mix(in srgb, var(--surface) 88%, transparent); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-radius: 24px; box-shadow: var(--shadow); padding: 6px; max-width: 520px; margin: 0 auto; }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; border-radius: 18px; color: var(--ink-2); font-size: 12px; font-weight: 700; transition: background .2s, color .2s; }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); }

/* ---------- home content ---------- */
h2.section { font-size: 19px; margin: 22px 2px 10px; display: flex; align-items: center; justify-content: space-between; }
h2.section small { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.daily { position: relative; display: flex; gap: 14px; align-items: center; padding: 14px; border-radius: 24px; color: #fff; background: linear-gradient(120deg, #7c4dff, #ff5fa2 65%, #ffb84d); box-shadow: 0 10px 30px rgba(124, 77, 255, .35); overflow: hidden; width: 100%; text-align: left; }
.daily::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.12); }
.daily .thumb { width: 104px; height: 104px; border-radius: 18px; flex: none; background: #fff; overflow: hidden; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.daily .thumb img { width: 100%; height: 100%; object-fit: cover; }
.daily h3 { margin: 0 0 2px; font-size: 21px; }
.daily p { margin: 0; opacity: .9; font-size: 14px; }
.daily .go { display: inline-block; margin-top: 10px; background: #fff; color: #7c4dff; font-weight: 800; padding: 7px 14px; border-radius: 99px; font-size: 14px; }

.studio { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 8px; scrollbar-width: none; }
.studio::-webkit-scrollbar, .cats::-webkit-scrollbar, .palette::-webkit-scrollbar { display: none; }
.gen-btn { flex: none; width: 112px; padding: 12px 10px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); text-align: left; }
.gen-btn .gi { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; color: #fff; margin-bottom: 8px; }
.gen-btn b { display: block; font-size: 14px; }
.gen-btn small { color: var(--ink-2); font-size: 12px; font-weight: 600; }

.cats { display: flex; gap: 8px; overflow-x: auto; margin: 4px -16px 12px; padding: 2px 16px; scrollbar-width: none; }
.cats button { flex: none; padding: 8px 14px; border-radius: 99px; background: var(--surface); font-weight: 700; font-size: 14px; color: var(--ink-2); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.cats button.active { background: var(--ink); color: var(--bg); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { position: relative; aspect-ratio: 1; border-radius: var(--radius); background: #fff; overflow: hidden; box-shadow: var(--shadow); transition: transform .15s; }
.card:active { transform: scale(.96); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card img.fresh { filter: grayscale(1) contrast(.45) brightness(1.32); }
.card .bar { position: absolute; left: 10px; right: 10px; bottom: 10px; height: 6px; border-radius: 6px; background: rgba(0,0,0,.12); overflow: hidden; }
.card .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 6px; }
.card .done-badge { position: absolute; right: 8px; top: 8px; width: 28px; height: 28px; border-radius: 50%; background: var(--good); color: #fff; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.card .done-badge svg { width: 16px; height: 16px; }
.card .tag { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 99px; }
.card .del { position: absolute; right: 6px; bottom: 18px; width: 30px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.45); color: #fff; display: grid; place-items: center; }
.card .del svg { width: 16px; height: 16px; }

.hero { border-radius: 24px; padding: 22px 18px; background: var(--surface); box-shadow: var(--shadow); text-align: center; margin-top: 8px; }
.hero .art { width: 88px; height: 88px; margin: 0 auto 10px; border-radius: 26px; display: grid; place-items: center; background: linear-gradient(135deg, #3fa9ff, #7c4dff); color: #fff; }
.hero .art svg { width: 46px; height: 46px; }
.hero h3 { margin: 4px 0 6px; font-size: 21px; }
.hero p { margin: 0 auto 16px; color: var(--ink-2); max-width: 320px; line-height: 1.4; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 22px; border-radius: 16px; font-weight: 800; font-size: 16px; background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(124, 77, 255, .35); transition: transform .12s; }
.btn:active { transform: scale(.96); }
.btn.ghost { background: var(--surface-2); color: var(--ink); box-shadow: none; }
.btn.wide { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.empty { text-align: center; color: var(--ink-2); padding: 40px 20px; line-height: 1.5; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 6px; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--ink-2); font-size: 12px; font-weight: 700; }

/* ---------- play screen ---------- */
.playbar { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) 12px 8px; z-index: 2; }
.progress { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 4px; }
.progress-bar { flex: 1; height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2), var(--brand-3)); border-radius: 8px; transition: width .3s; }
#progress-text { font-weight: 800; font-size: 14px; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.badge-btn { position: relative; }
.badge-btn b { position: absolute; right: -4px; top: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand-2); color: #fff; font-size: 11px; display: grid; place-items: center; }
#peek-btn.on { background: var(--brand); color: #fff; }
#board-host { flex: 1; position: relative; overflow: hidden; background: var(--board-bg); touch-action: none; }
.board-canvas { position: absolute; inset: 0; touch-action: none; display: block; }

.palette-wrap { background: var(--surface); padding: 10px 0 calc(10px + var(--safe-b)); box-shadow: 0 -4px 20px rgba(0,0,0,.06); z-index: 2; }
.palette { display: flex; gap: 10px; overflow-x: auto; padding: 4px 14px; scroll-behavior: smooth; scrollbar-width: none; }
.sw { flex: none; position: relative; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; transition: transform .2s, width .3s, margin .3s, opacity .3s; }
.sw::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(var(--brand) calc(var(--p, 0) * 1%), var(--surface-2) 0); }
.sw i { position: absolute; inset: 4px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.sw span { position: relative; font-weight: 800; font-size: 17px; }
.sw.sel { transform: scale(1.12); }
.sw.sel::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2.5px solid var(--ink); }
.sw.done span { display: none; }
.sw.done::before { background: var(--good); }
.sw .check { position: relative; display: none; width: 24px; height: 24px; }
.sw.done .check { display: block; }
.sw.gone { width: 0; margin-right: -10px; opacity: 0; transform: scale(.3); pointer-events: none; }
.sw.nudge { animation: nudge .5s; }
@keyframes nudge { 0%,100% { transform: translateY(0); } 25% { transform: translateY(-10px) scale(1.1); } 50% { transform: translateY(0); } 75% { transform: translateY(-5px); } }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(15, 12, 30, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet-card { width: 100%; max-width: 560px; max-height: 92%; overflow-y: auto; background: var(--bg); border-radius: 26px 26px 0 0; padding: 10px 18px calc(20px + var(--safe-b)); animation: up .28s cubic-bezier(.2,.8,.2,1); }
.sheet-card::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; background: var(--ink-2); opacity: .3; }
.sheet h3 { margin: 4px 0 14px; font-size: 21px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.row { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px; border-bottom: 1px solid var(--line); font-weight: 700; }
.row small { display: block; color: var(--ink-2); font-weight: 600; font-size: 13px; margin-top: 2px; }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--surface-2); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); transition: transform .2s; }
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(20px); }
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin: 6px 0 14px; }
.seg button { flex: 1; padding: 9px 0; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--ink-2); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.label { font-weight: 800; font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.preview { position: relative; border-radius: 18px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; min-height: 220px; margin-bottom: 12px; }
.preview canvas, .preview img { max-width: 100%; max-height: 46vh; display: block; }
.preview .pv-spin { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.pv-toggle { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.55); color: #fff; padding: 6px 12px; border-radius: 99px; font-weight: 700; font-size: 13px; }
.meta-line { color: var(--ink-2); font-weight: 600; font-size: 13px; text-align: center; margin: -4px 0 12px; }

/* ---------- complete ---------- */
.complete { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 20px 18px calc(18px + var(--safe-b)); pointer-events: none; }
.complete .panel { pointer-events: auto; width: 100%; max-width: 460px; background: var(--surface); border-radius: 26px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); text-align: center; animation: up .45s cubic-bezier(.2,.9,.25,1.1); }
.complete h2 { margin: 2px 0 2px; font-size: 26px; }
.complete p { margin: 0 0 14px; color: var(--ink-2); font-weight: 600; }
.complete .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.complete .actions .btn { padding: 12px 10px; font-size: 15px; }
.complete .actions .btn.wide { grid-column: 1 / -1; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 35; }

/* ---------- misc ---------- */
.toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translate(-50%, -20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 86vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading { position: fixed; inset: 0; z-index: 45; display: grid; place-content: center; justify-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.loading p { font-weight: 700; color: var(--ink-2); }
.spinner { width: 46px; height: 46px; border-radius: 50%; background: conic-gradient(var(--brand), var(--brand-2), var(--brand-3), transparent 75%); -webkit-mask: radial-gradient(circle, transparent 15px, #000 16px); mask: radial-gradient(circle, transparent 15px, #000 16px); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.about { color: var(--ink-2); font-size: 13px; line-height: 1.5; margin-top: 16px; text-align: center; }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .scroll { padding-left: max(16px, calc((100vw - 1100px) / 2)); padding-right: max(16px, calc((100vw - 1100px) / 2)); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
