[hidden] { display: none !important; }
:root {
  --ink: #0d0f1e; --ink2: #151935; --panel: rgba(28, 32, 64, 0.72); --line: rgba(167, 139, 250, 0.28);
  --text: #f3efe6; --dim: #a9a6c4; --teal: #2dd4bf; --teal2: #7cf0dd; --violet: #a78bfa; --coral: #ff6b6b; --gold: #fde047;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); overflow: hidden; }
body { background: radial-gradient(120% 80% at 10% -10%, #2a1f5c 0%, transparent 55%), radial-gradient(110% 80% at 110% 110%, #0f4a4a 0%, transparent 55%), var(--ink); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; }

/* drifting background tiles */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.sky i { position: absolute; width: 26px; height: 26px; border-radius: 7px; opacity: 0.16; background: linear-gradient(135deg, var(--teal), var(--violet)); animation: drift 26s linear infinite; }
.sky i:nth-child(odd) { width: 16px; height: 16px; animation-duration: 34s; }
.sky i:nth-child(3n) { background: none; border: 2px solid var(--violet); }
.sky i:nth-child(1) { left: 6%; animation-delay: -2s; } .sky i:nth-child(2) { left: 18%; animation-delay: -14s; }
.sky i:nth-child(3) { left: 29%; animation-delay: -7s; } .sky i:nth-child(4) { left: 41%; animation-delay: -21s; }
.sky i:nth-child(5) { left: 52%; animation-delay: -4s; } .sky i:nth-child(6) { left: 63%; animation-delay: -17s; }
.sky i:nth-child(7) { left: 74%; animation-delay: -10s; } .sky i:nth-child(8) { left: 85%; animation-delay: -25s; }
.sky i:nth-child(9) { left: 94%; animation-delay: -12s; } .sky i:nth-child(10) { left: 12%; animation-delay: -30s; }
.sky i:nth-child(11) { left: 47%; animation-delay: -28s; } .sky i:nth-child(12) { left: 69%; animation-delay: -1s; }
@keyframes drift { from { transform: translateY(110vh) rotate(0deg); } to { transform: translateY(-15vh) rotate(320deg); } }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; z-index: 1; padding-top: var(--safe-t); }
.screen.active { display: flex; animation: screenIn 0.35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; min-height: 52px; }
.top .left, .top .right { display: flex; align-items: center; gap: 6px; min-width: 44px; }
.top .right { justify-content: flex-end; }
.top h2 { font-size: 18px; font-weight: 800; letter-spacing: 0.02em; }
.icon { width: 40px; height: 40px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 18px; font-weight: 800; display: grid; place-items: center; transition: transform 0.12s, background 0.2s; }
.icon:active { transform: scale(0.92); }
.icon.back { font-size: 28px; line-height: 1; padding-bottom: 3px; }
.chip { padding: 9px 16px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-weight: 700; font-size: 14px; transition: transform 0.12s, background 0.2s, border-color 0.2s; }
.chip:active { transform: scale(0.95); }
.chip.primary { background: linear-gradient(135deg, var(--teal), #8b5cf6); border-color: transparent; color: #0b0d1a; }
.chip.on { background: rgba(45, 212, 191, 0.2); border-color: var(--teal); color: var(--teal2); }

/* home */
#home { overflow-y: auto; }
.hero { text-align: center; padding: 4px 16px 10px; }
#logo-art { width: 116px; height: 116px; filter: drop-shadow(0 8px 26px rgba(45, 212, 191, 0.35)); }
.logo { font-size: clamp(38px, 11vw, 60px); font-weight: 900; letter-spacing: 0.06em; line-height: 1; margin-top: 6px; background: linear-gradient(90deg, var(--text), #d9d4ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo b { background: linear-gradient(90deg, var(--teal), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { color: var(--dim); margin: 6px 0 0; font-size: 15px; }
.modes { display: grid; gap: 10px; padding: 8px 16px; max-width: 520px; width: 100%; margin: 0 auto; }
.mode { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 16px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); position: relative; overflow: hidden; transition: transform 0.15s, border-color 0.2s; animation: rise 0.5s backwards cubic-bezier(.2, .9, .3, 1.2); }
.mode:nth-child(2) { animation-delay: 0.05s; } .mode:nth-child(3) { animation-delay: 0.1s; } .mode:nth-child(4) { animation-delay: 0.15s; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
.mode:hover { border-color: var(--violet); }
.mode:active { transform: scale(0.97); }
.mode::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.07) 50%, transparent 70%); transform: translateX(-100%); animation: sheen 5s infinite; }
@keyframes sheen { 0%, 70% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.mode .mi { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; flex: none; background: linear-gradient(135deg, rgba(45, 212, 191, 0.25), rgba(167, 139, 250, 0.25)); }
.mode.daily .mi { background: linear-gradient(135deg, #f59e0b, #ec4899); color: #fff; }
.mode.continue .mi { background: linear-gradient(135deg, var(--teal), #8b5cf6); color: #0b0d1a; }
.mode b { display: block; font-size: 17px; }
.mode small { display: block; color: var(--dim); font-size: 13px; margin-top: 2px; }
.mode em { margin-left: auto; font-style: normal; color: var(--teal2); font-size: 22px; font-weight: 900; }
.quick { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 6px 16px; }
.stats { text-align: center; color: var(--dim); font-size: 13px; padding-bottom: calc(16px + var(--safe-b)); }

/* packs */
.scroll { overflow-y: auto; flex: 1; padding: 0 14px calc(20px + var(--safe-b)); }
.pack { max-width: 720px; margin: 8px auto 18px; padding: 14px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); }
.pack-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pack-head h3 { font-size: 18px; }
.pack-head span { color: var(--dim); font-size: 13px; }
.pack p { color: var(--dim); margin: 4px 0 10px; font-size: 14px; }
.pack .bar, .gen-box .bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin-bottom: 12px; }
.pack .bar i, .gen-box .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--violet)); transition: width 0.4s; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.thumb { padding: 8px; border-radius: 14px; background: rgba(0, 0, 0, 0.25); border: 1px solid transparent; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform 0.15s, border-color 0.2s; }
.thumb:hover { border-color: var(--violet); }
.thumb:active { transform: scale(0.95); }
.thumb canvas { width: 72px; height: 72px; image-rendering: pixelated; }
.thumb small { font-size: 12px; color: var(--dim); text-align: center; }
.thumb.solved small { color: var(--teal2); }
.thumb .q { font-size: 11px; color: var(--violet); }

/* custom */
.custom-body { max-width: 560px; margin: 0 auto; width: 100%; }
.preview-wrap { position: relative; display: grid; place-items: center; padding: 6px 0 4px; }
#shape-preview { width: 170px; height: 170px; }
.dims { position: absolute; bottom: 4px; right: calc(50% - 110px); font-weight: 800; font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.custom-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); margin: 14px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips .chip { padding: 8px 13px; font-size: 13.5px; }
.slider { display: grid; grid-template-columns: 60px 1fr 34px; align-items: center; gap: 10px; margin-top: 10px; }
.slider label { color: var(--dim); font-size: 14px; }
.slider output { font-weight: 800; text-align: right; }
input[type="range"] { width: 100%; accent-color: var(--teal); height: 28px; }
.toggle { display: flex; align-items: center; gap: 10px; margin: 12px 0 2px; font-size: 15px; }
.toggle small { color: var(--dim); }
.toggle input { width: 20px; height: 20px; accent-color: var(--teal); }
.big-btn { display: block; width: 100%; margin: 20px 0 8px; padding: 16px; border-radius: 16px; font-size: 18px; font-weight: 900; color: #0b0d1a; background: linear-gradient(135deg, var(--teal), #8b5cf6); box-shadow: 0 10px 30px rgba(45, 212, 191, 0.25); transition: transform 0.12s; }
.big-btn:active { transform: scale(0.97); }
.fine { color: var(--dim); font-size: 12.5px; text-align: center; }

/* game */
.game-top { min-height: 50px; padding: 6px 8px; }
.title-block { text-align: center; min-width: 0; flex: 1; }
.title-block h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-block small { color: var(--dim); font-size: 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 15px; min-width: 44px; text-align: right; color: var(--teal2); }
.progress { height: 3px; margin: 0 10px; background: rgba(255, 255, 255, 0.06); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--violet)); transition: width 0.3s; }
.board-wrap { flex: 1; position: relative; min-height: 0; margin: 4px 2px 0; }
#board { position: absolute; inset: 0; touch-action: none; outline: none; display: block; }
.pause-cover { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(13, 15, 30, 0.92); backdrop-filter: blur(8px); z-index: 3; text-align: center; }
.pause-cover b { font-size: 26px; display: block; }
.pause-cover .big-btn { width: 200px; }
.inspector { min-height: 26px; padding: 3px 12px; font-size: 13.5px; color: var(--dim); text-align: center; white-space: nowrap; overflow-x: auto; }
.inspector b { color: var(--text); }
.inspector .sep { color: var(--violet); padding: 0 4px; }
.inspector .done { color: var(--teal2); }
.toolbar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 14px; padding: 6px 8px calc(8px + var(--safe-b)); background: linear-gradient(180deg, transparent, rgba(13, 15, 30, 0.8)); }
.tools { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.tool { width: 58px; height: 52px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: background 0.2s, transform 0.12s; }
.tool small { font-size: 10.5px; color: var(--dim); font-weight: 700; }
.tool .sw { width: 22px; height: 22px; display: grid; place-items: center; font-size: 17px; font-weight: 900; }
.tool .sw.fill { border-radius: 6px; background: linear-gradient(135deg, var(--teal), var(--violet)); }
.tool.active { background: rgba(45, 212, 191, 0.2); box-shadow: inset 0 0 0 1.5px var(--teal); }
.tool.active small { color: var(--teal2); }
.tool:active { transform: scale(0.92); }
.acts { display: flex; gap: 4px; }
.act { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 19px; font-weight: 800; transition: transform 0.12s, opacity 0.2s; }
.act:active { transform: scale(0.9); }
.act:disabled { opacity: 0.35; }
.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%) translateY(20px); max-width: min(92vw, 460px); padding: 10px 16px; border-radius: 14px; background: rgba(28, 32, 64, 0.96); border: 1px solid var(--violet); font-size: 14px; text-align: center; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* generation */
.gen-cover { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(8, 9, 20, 0.8); backdrop-filter: blur(6px); }
.gen-box { width: min(86vw, 320px); padding: 22px; border-radius: 22px; background: var(--ink2); border: 1px solid var(--line); text-align: center; display: grid; gap: 14px; justify-items: center; }
.gen-box .bar { width: 100%; margin: 0; }
.gen-grid { display: grid; grid-template-columns: repeat(5, 18px); gap: 4px; }
.gen-grid i { width: 18px; height: 18px; border-radius: 5px; background: rgba(255, 255, 255, 0.08); animation: genPulse 1.2s infinite; }
@keyframes genPulse { 0%, 100% { background: rgba(255, 255, 255, 0.08); transform: scale(0.9); } 50% { background: var(--teal); transform: scale(1); } }

/* dialogs */
.dlg { border: 1px solid var(--line); border-radius: 22px; background: var(--ink2); color: var(--text); padding: 20px; max-width: min(92vw, 440px); width: 100%; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); }
.dlg::backdrop { background: rgba(5, 6, 14, 0.7); backdrop-filter: blur(4px); }
.dlg[open] { animation: pop 0.32s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes pop { from { opacity: 0; transform: scale(0.88) translateY(10px); } }
.dlg h2 { font-size: 22px; margin-bottom: 8px; }
.dlg p, .dlg li { color: #d6d3ea; font-size: 14.5px; line-height: 1.45; }
.dlg ul { padding-left: 18px; }
.dlg i.bar { color: var(--violet); font-style: normal; font-weight: 900; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.menu-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.help-demo { display: flex; align-items: center; gap: 10px; justify-content: center; margin: 10px 0; }
.help-demo .hc { font-weight: 900; font-size: 15px; } .help-demo .hc i { color: var(--violet); font-style: normal; }
.help-demo .hr { display: flex; gap: 2px; }
.help-demo .hr b, .help-demo .hr s, .help-demo .hr u { width: 18px; height: 18px; border-radius: 4px; display: block; }
.help-demo .hr b { background: linear-gradient(135deg, var(--teal), var(--violet)); animation: pop 0.5s backwards; }
.help-demo .hr s { background: rgba(255, 255, 255, 0.07); }
.help-demo .hr u { width: 12px; background: none; }
.result { text-align: center; overflow: hidden; }
.result #res-art { width: 180px; height: 180px; image-rendering: pixelated; margin: 4px auto 6px; display: block; filter: drop-shadow(0 10px 24px rgba(167, 139, 250, 0.35)); animation: artIn 0.8s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes artIn { from { transform: scale(0.4) rotate(-8deg); opacity: 0; } }
.result h2 { font-size: 30px; background: linear-gradient(90deg, var(--gold), #fb7185, var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.res-name { margin: 0; font-weight: 700; }
.res-stats { display: flex; justify-content: center; gap: 22px; margin: 12px 0 4px; }
.res-stats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.res-stats small { color: var(--dim); font-size: 12px; }
.badges { min-height: 20px; font-size: 13.5px; color: var(--teal2); }
.result .actions { justify-content: center; }
.burst { position: absolute; inset: -40%; background: conic-gradient(from 0deg, transparent 0 10deg, rgba(253, 224, 71, 0.08) 10deg 20deg, transparent 20deg 40deg, rgba(167, 139, 250, 0.08) 40deg 50deg, transparent 50deg 70deg); animation: spin 18s linear infinite; pointer-events: none; z-index: -1; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 900px) {
  .toolbar { gap: 10px 22px; }
  .tool { width: 66px; }
}
@media (max-height: 640px) {
  .tool { height: 44px; } .tool small { display: none; } .act { width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .sky { display: none; }
}
