:root {
  --bg: #f6f4fb;
  --surface: #ffffff;
  --text: #1f1d2b;
  --muted: #7a7690;
  --line: #e7e3f0;
  --accent: #ff5d8f;
  --accent-2: #7c5cff;
  --ok: #22c55e;
  --danger: #e5484d;
  --stage: #ecebf3;
  --shadow: 0 6px 20px rgba(40, 20, 80, .08);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131d; --surface: #201d2b; --text: #f2f0f8; --muted: #a29db8; --line: #322e42;
    --stage: #1b1925; --shadow: 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- home ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.2px; }
.brand img { border-radius: 8px; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px; line-height: 1;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }

.home-main { flex: 1; overflow-y: auto; padding: 12px 16px calc(84px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.tab-panel { max-width: 1100px; margin: 0 auto; }

.daily {
  display: flex; gap: 16px; align-items: center; padding: 14px; margin-bottom: 14px;
  border-radius: var(--radius); background: linear-gradient(135deg, #ff7aa2, #8f6bff); color: #fff;
  border: 0; width: 100%; text-align: left; box-shadow: var(--shadow);
}
.daily canvas { width: 96px; height: 96px; border-radius: 12px; background: #fff; image-rendering: pixelated; flex: none; object-fit: contain; }
.daily .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .9; }
.daily .title { font-size: 20px; font-weight: 800; margin: 2px 0 6px; }
.daily .go { display: inline-block; background: rgba(255,255,255,.22); padding: 6px 12px; border-radius: 999px; font-weight: 600; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 999px;
  font-weight: 600; font-size: 14px; color: var(--muted);
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.card {
  position: relative; border: 0; padding: 0; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; text-align: left; display: flex; flex-direction: column;
  transition: transform .12s ease;
}
.card:active { transform: scale(.97); }
.card .thumb { aspect-ratio: 1; display: grid; place-items: center; background: #fff; padding: 10px; }
.card canvas { width: 100%; height: 100%; image-rendering: pixelated; object-fit: contain; }
.card .meta { padding: 8px 10px 4px; display: flex; justify-content: space-between; gap: 6px; font-size: 13px; }
.card .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .size { color: var(--muted); flex: none; }
.card .bar { height: 4px; margin: 4px 10px 10px; background: var(--line); border-radius: 4px; overflow: hidden; }
.card .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.card .badge {
  position: absolute; top: 8px; right: 8px; background: var(--ok); color: #fff; border-radius: 999px;
  font-size: 12px; font-weight: 700; padding: 2px 8px;
}
.card .more {
  position: absolute; top: 6px; left: 6px; width: 30px; height: 30px; border-radius: 10px; border: 0;
  background: rgba(0,0,0,.45); color: #fff; font-size: 18px; line-height: 1; display: grid; place-items: center;
}
.sec-title { font-size: 17px; margin: 18px 0 10px; }
.sec-title:first-child { margin-top: 4px; }
.empty { color: var(--muted); margin: 0 0 8px; font-size: 14px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + var(--safe-b));
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none;
  color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 0;
}
.bottom-nav a.active { color: var(--accent); }

/* create */
.create { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.create .sec-title, .create > p { margin: 0; }
.file-drop {
  display: grid; place-items: center; min-height: 110px; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-weight: 600; cursor: pointer; text-align: center; padding: 12px;
}
.file-drop.drag { border-color: var(--accent); color: var(--accent); }
.file-drop input { display: none; }
.form-row { display: flex; gap: 12px; }
.form-row label, .field { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
select, .field input {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 15px; color: var(--text);
}
.preview-wrap { text-align: center; }
#create-preview { max-width: 100%; width: 320px; image-rendering: pixelated; background: #fff; border-radius: 12px; box-shadow: var(--shadow); }
#create-preview[width="1"] { display: none; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 16px; font-weight: 650;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- play ---------- */
.playbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--surface);
}
.play-title { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.2; min-width: 0; }
#play-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#play-progress { font-size: 12px; }
.progress-line { height: 3px; background: var(--line); }
.progress-line i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }
.stage { position: relative; flex: 1; background: var(--stage); overflow: hidden; touch-action: none; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.zoom-ctrl { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.zoom-ctrl .icon-btn { background: var(--surface); box-shadow: var(--shadow); font-weight: 700; }
@media (pointer: coarse) { .zoom-ctrl { display: none; } }

.tools { display: flex; align-items: center; gap: 14px; padding: 10px 18px 0; background: var(--surface); border-top: 1px solid var(--line); }
.tools-spacer { flex: 1; }
.boost {
  position: relative; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; box-shadow: 0 2px 6px rgba(40,20,80,.08); transition: transform .12s, box-shadow .12s;
}
.boost.active { box-shadow: 0 0 0 3px var(--accent-2); transform: scale(1.08); }
.boost.empty svg { opacity: .35; }
.boost .cnt {
  position: absolute; top: -4px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: #f97316; color: #fff; font-size: 12px; line-height: 20px; text-align: center; font-weight: 800;
}
.boost .cnt.inf { background: var(--accent-2); }
.done-bar { display: flex; justify-content: center; gap: 8px; padding: 8px; background: var(--surface); flex-wrap: wrap; }

.palette {
  display: flex; gap: 12px; overflow-x: auto; padding: 14px 16px calc(14px + var(--safe-b)); background: var(--surface);
  scrollbar-width: thin; scroll-behavior: smooth;
}
.swatch {
  --p: 0; flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; padding: 0; position: relative;
  background: var(--c); display: grid; place-items: center; font-weight: 800; font-size: 16px; color: var(--fg);
  transition: transform .12s ease;
}
.swatch::before { /* progress ring */
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  background: conic-gradient(var(--accent-2) calc(var(--p) * 1%), var(--line) 0);
  -webkit-mask: radial-gradient(circle, transparent 27px, #000 28px); mask: radial-gradient(circle, transparent 27px, #000 28px);
}
.swatch:first-child { margin-left: auto; }
.swatch:last-child { margin-right: auto; }
.swatch.light { box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch.sel { transform: scale(1.12); }
.swatch.sel::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--text);
}
.swatch.done { opacity: .45; }
.swatch.done span { display: none; }
.swatch.done::after { content: "✓"; position: static; border: 0; font-size: 20px; }

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 0; border-radius: 22px; padding: 20px; width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow-y: auto;
}
dialog::backdrop { background: rgba(20, 10, 40, .45); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 6px; font-size: 22px; }
#dlg-complete { text-align: center; }
#complete-canvas { width: 100%; max-width: 320px; aspect-ratio: 1; image-rendering: pixelated; margin: 8px 0 12px; background: #fff; border-radius: 12px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .btn { flex: 1; }
.switch { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.act-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: rgba(25, 20, 40, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }

/* collections / mystery / new */
.badge-new {
  position: absolute; top: 8px; right: 8px; background: #fde047; color: #713f12; border-radius: 6px;
  font-size: 11px; font-weight: 800; padding: 1px 6px; font-style: italic;
}
.card.mystery .thumb { background: linear-gradient(135deg, #fff1f5, #f3e8ff); }
.card.mystery canvas { visibility: hidden; }
.card.mystery .thumb::after {
  content: "?"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 64px; font-weight: 900;
  color: transparent; background: linear-gradient(135deg, #ef476f, #ffd166, #06d6a0, #118ab2) text; -webkit-background-clip: text;
  aspect-ratio: 1; height: auto;
}
.card .thumb { position: relative; }
.col-card .count { position: absolute; left: 10px; bottom: 58px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.col-head { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.col-head h2 { margin: 0; font-size: 18px; flex: 1; }
.col-head .muted { font-size: 13px; }
.reward { margin: 10px 0 0; font-weight: 700; color: var(--accent-2); min-height: 1em; }
