:root {
  --bg: #11131c;
  --bg-2: #171a26;
  --panel: #1e2230;
  --panel-2: #262b3d;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f3f4fb;
  --muted: #a2a7bd;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --good: #34d399;
  --stage: #f7f8fc;
  --cell-empty: #e9edf4;
  --cell-num: #8a93a6;
  --radius: 16px;
  --dock-h: 96px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.screen { display: none; height: 100dvh; flex-direction: column; }
.screen.is-active { display: flex; }

/* ---------------- Gallery ---------------- */
.home-head {
  padding: 22px 20px 8px;
  text-align: center;
  background:
    radial-gradient(700px 240px at 50% -40%, rgba(124, 92, 255, 0.25), transparent 70%),
    var(--bg);
}
.home-title {
  font-size: clamp(1.6rem, 6vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #fff, #c9c2ff 60%, #8be9ff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.home-sub { color: var(--muted); margin-top: 6px; font-size: 0.95rem; }

.catbar {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 20px;
  scrollbar-width: none;
}
.catbar::-webkit-scrollbar { display: none; }
.cat {
  flex: 0 0 auto; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted);
  font: inherit; font-weight: 600; font-size: 0.85rem;
  padding: 8px 15px; border-radius: 999px; white-space: nowrap;
  transition: all 0.15s ease;
}
.cat.is-active { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #0b0a14; border-color: transparent; }

.gallery {
  flex: 1; overflow-y: auto; padding: 6px 16px 28px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 14px; align-content: start; grid-auto-rows: max-content;
}
.card {
  cursor: pointer; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; position: relative;
  display: flex; flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-3px); border-color: rgba(124,92,255,0.5); }
.card-thumb-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; background: var(--stage); }
.card-thumb { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.card-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 11px; gap: 6px; }
.card-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-badge { font-size: 0.7rem; color: var(--good); font-weight: 700; flex: 0 0 auto; }
.card-done { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--good); color: #06231a; display: grid; place-items: center; font-size: 14px; font-weight: 900;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3); }

/* ---------------- Play ---------------- */
.play-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.play-title { flex: 1; text-align: center; font-weight: 700; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-actions { display: flex; gap: 8px; }
.chip-btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.85rem; padding: 8px 13px; border-radius: 999px;
}
.chip-btn:hover { background: var(--panel-2); }
.round-btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; font-size: 1rem; display: grid; place-items: center;
}
.round-btn:hover { background: var(--panel-2); }

.progress { height: 5px; background: var(--panel); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.35s ease; }

.stage { position: relative; flex: 1; overflow: hidden; background: var(--stage); touch-action: none; }
#canvas { display: block; width: 100%; height: 100%; }

.zoom-hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(17,19,28,0.78); color: #fff; font-size: 0.74rem; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; pointer-events: none;
  opacity: 0; transition: opacity 0.4s ease;
}
.zoom-hint.show { opacity: 1; }

.zoom-ctrl { position: absolute; left: 12px; bottom: 14px; z-index: 4; display: flex; flex-direction: column; gap: 6px; }
.zoom-ctrl button {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(17, 19, 28, 0.82); backdrop-filter: blur(8px); color: #fff;
  font-size: 1.25rem; font-weight: 700; cursor: pointer; display: grid; place-items: center; line-height: 1;
}
.zoom-ctrl button:active { transform: scale(0.94); }

/* Win overlay */
.win { position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(10,11,18,0.55); backdrop-filter: blur(6px); }
.win.show { display: grid; animation: fade 0.3s ease; }
.win-card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  padding: 28px 32px; text-align: center; box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7); }
.win-emoji { font-size: 3rem; }
.win-title { font-size: 1.5rem; font-weight: 800; margin-top: 6px; }
.win-stars { font-size: 1.6rem; color: #ffd166; margin: 10px 0 18px; letter-spacing: 4px; }
.win-btns { display: flex; gap: 10px; justify-content: center; }
.btn { cursor: pointer; border: none; font: inherit; font-weight: 700; font-size: 0.95rem;
  padding: 11px 20px; border-radius: 999px; }
.btn-primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #0b0a14; }
.btn-ghost { background: var(--panel-2); color: var(--text); }

/* Palette dock */
.palette {
  height: var(--dock-h); flex: 0 0 auto; display: flex; gap: 10px; align-items: center;
  padding: 12px 14px; overflow-x: auto; overflow-y: hidden;
  background: var(--bg-2); border-top: 1px solid var(--line); scrollbar-width: none;
}
.palette::-webkit-scrollbar { display: none; }
.swatch {
  position: relative; flex: 0 0 auto; width: 60px; height: 70px; border-radius: 14px;
  cursor: pointer; border: 3px solid transparent; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  transition: transform 0.12s ease;
}
.swatch:active { transform: scale(0.94); }
.swatch-chip { width: 34px; height: 34px; border-radius: 9px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.swatch-num { font-size: 0.92rem; font-weight: 800; color: var(--text); }
.swatch.is-active { border-color: #fff; box-shadow: 0 0 0 3px var(--accent); }
.swatch.is-done .swatch-chip { opacity: 0.25; }
.swatch.is-done .swatch-num { color: var(--muted); }
.swatch-check { position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--good); color: #06231a; font-size: 12px; font-weight: 900; display: none; place-items: center; }
.swatch.is-done .swatch-check { display: grid; }
.swatch-count { position: absolute; bottom: 3px; font-size: 0.62rem; color: var(--muted); font-weight: 700; }
.swatch.is-done .swatch-count { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
