:root{
  --bg1:#241a66;--bg2:#5b21b6;--ink:#1d1640;--card:#fffdf7;--lime:#8fd827;--lime2:#5fae12;--mag:#e5308a;--tq:#19c6b8;--mut:#7a7399;
  font-size:clamp(11px, calc(min(2.1vh, 1.5vw) + 4px), 19px);
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;overflow:hidden;background:var(--bg1)}
body{font-family:"Trebuchet MS","Segoe UI",system-ui,-apple-system,Roboto,sans-serif;color:var(--ink);
  touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent;
  background:linear-gradient(150deg,var(--bg1),var(--bg2));}
#bgc{position:fixed;inset:0;width:100%;height:100%;display:block;pointer-events:none}
#bgfx{
  background-image:radial-gradient(circle at 12% 20%,#ffffff22 0 2px,transparent 3px),radial-gradient(circle at 80% 70%,#ffffff1a 0 2px,transparent 3px);
  background-size:46px 46px,64px 64px}
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer}
.scr{position:fixed;inset:0;display:none}
.scr.on{display:flex}

/* ---------- start ---------- */
#menu{align-items:center;justify-content:center;padding:.8rem}
.card{background:var(--card);border-radius:1.3rem;box-shadow:0 .5rem 0 #120c3d55,0 1rem 2.4rem #0006;border:3px solid var(--ink)}
.start{display:flex;align-items:center;gap:1.2rem;padding:1.2rem 1.6rem;max-width:56rem;width:100%;max-height:100%}
.pixi{width:13rem;height:auto;flex:0 0 auto;filter:drop-shadow(0 .4rem 0 #0002);animation:bob 2.6s ease-in-out infinite}
@keyframes bob{50%{transform:translateY(-.4rem) rotate(-2deg)}}
.startTxt{flex:1;min-width:0;display:flex;flex-direction:column;gap:.7rem}
h1{display:flex;flex-direction:column;line-height:1}
.t1{font-size:2.9rem;font-weight:900;letter-spacing:-.02em;color:var(--ink)}
.t2{font-size:1.35rem;font-weight:800;color:var(--mag);letter-spacing:.12em;text-transform:uppercase;margin-top:.2rem}
.intro{font-size:1rem;line-height:1.35;color:#3c355e}
.ctrls{display:flex;flex-wrap:wrap;gap:.35rem .9rem;font-size:.85rem;color:var(--mut)}
.ctrls span{white-space:nowrap}
.k{display:inline-block;background:#efeaff;border:2px solid #cfc6f5;border-bottom-width:3px;border-radius:.4rem;padding:0 .35rem;margin-right:.2rem;color:var(--ink);font-size:.8rem}
.startBtns{display:flex;gap:.7rem;flex-wrap:wrap;align-items:center}
.big{background:var(--lime);border:3px solid var(--ink);border-bottom-width:6px;border-radius:1rem;padding:.55rem 2.2rem;font-size:1.6rem;font-weight:900;color:var(--ink)}
.big:active,.mid:active{transform:translateY(2px);border-bottom-width:3px}
.mid{background:#fff;border:3px solid var(--ink);border-bottom-width:5px;border-radius:1rem;padding:.5rem 1.2rem;font-size:1.1rem;font-weight:800}
.progress{font-size:.85rem;color:var(--mut)}

/* ---------- browser ---------- */
#browse{align-items:stretch;justify-content:center;padding:.6rem}
.list{width:100%;max-width:62rem;display:flex;flex-direction:column;padding:.7rem;min-height:0}
.listHead{display:flex;align-items:center;gap:.5rem}
.tabs{flex:1;display:flex;gap:.35rem;overflow-x:auto;scrollbar-width:none;padding:.2rem}
.tabs::-webkit-scrollbar{display:none}
.tab{flex:0 0 auto;padding:.35rem .75rem;border-radius:.8rem;border:2px solid #d8d1f5;background:#f4f1ff;font-weight:800;font-size:.9rem;white-space:nowrap}
.tab small{display:block;font-size:.7rem;font-weight:700;color:var(--mut)}
.tab.on{background:var(--ink);color:#fff;border-color:var(--ink)}
.tab.on small{color:#c9c2ff}
.packInfo{font-size:.85rem;color:var(--mut);margin:.4rem .3rem}
.tiles{flex:1;min-height:0;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(6.4rem,1fr));gap:.6rem;padding:.3rem;align-content:start;touch-action:pan-y}
.tile{position:relative;aspect-ratio:1/1.12;border-radius:.9rem;border:3px solid var(--ink);border-bottom-width:5px;background:#f6f3ff;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:.2rem;padding:.35rem;font-weight:800}
.tile canvas{width:70%;aspect-ratio:1;image-rendering:pixelated;border-radius:.3rem}
.tile .q{width:70%;aspect-ratio:1;border-radius:.4rem;display:flex;align-items:center;justify-content:center;font-size:1.6rem;color:#b5abe6;
  background:repeating-linear-gradient(0deg,#e7e1ff 0 1px,transparent 1px 12.5%),repeating-linear-gradient(90deg,#e7e1ff 0 1px,transparent 1px 12.5%),#fff}
.tile .nm{font-size:.8rem;line-height:1.1;text-align:center}
.tile .st{position:absolute;top:.15rem;right:.3rem;font-size:.75rem;color:#f5a400;letter-spacing:-.1em}
.tile.done{background:#effbe0}
.tile.today{box-shadow:0 0 0 3px var(--mag)}
.tile .badge{position:absolute;top:-.5rem;left:50%;transform:translateX(-50%);background:var(--mag);color:#fff;font-size:.65rem;padding:.05rem .45rem;border-radius:.5rem;white-space:nowrap}
.tile.gen{background:linear-gradient(160deg,#fff,#e8fbf8)}

/* ---------- play ---------- */
#play{flex-direction:column}
#hud{display:flex;align-items:center;gap:.45rem;padding:.35rem .6rem;color:#fff;flex:0 0 auto}
#pTitle{font-weight:900;font-size:1.05rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:40vw}
.chip{background:#ffffff22;border-radius:.7rem;padding:.15rem .55rem;font-weight:800;font-size:.85rem;white-space:nowrap}
.chip.err{background:#ff5d8f33}
.chip.err.free{display:none}
.sp{flex:1}
.ib{width:2.3rem;height:2.3rem;border-radius:.75rem;background:#ffffff1f;color:#fff;font-size:1.25rem;font-weight:900;display:flex;align-items:center;justify-content:center;flex:0 0 auto}
.list .ib{background:#efeaff;color:var(--ink)}
.ib svg{width:1.35rem;height:1.35rem}
.snd .x{display:none}.snd.off .x{display:inline}.snd.off .w{display:none}
#stage{flex:1;min-height:0;position:relative}
#cv{position:absolute;inset:0;width:100%;height:100%;touch-action:none}
#tip{position:absolute;left:50%;bottom:.25rem;transform:translateX(-50%);background:#120c3dcc;color:#fff;font-size:.8rem;padding:.2rem .7rem;border-radius:.7rem;max-width:94%;text-align:center;pointer-events:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#tools{display:flex;gap:.5rem;justify-content:center;padding:.35rem .5rem .5rem;flex:0 0 auto;flex-wrap:wrap}
.grp{display:flex;gap:.3rem;background:#ffffff18;border-radius:1rem;padding:.25rem}
.grp:empty{display:none}
.tb{display:flex;flex-direction:column;align-items:center;justify-content:center;min-width:3.6rem;height:3.1rem;border-radius:.8rem;background:var(--card);color:var(--ink);border:2px solid var(--ink);border-bottom-width:4px;font-weight:800;font-size:.72rem;padding:0 .35rem}
.tb .sw{font-size:1.1rem;line-height:1.2;font-weight:900}
.tb.on{background:var(--lime);transform:translateY(1px)}
.fillsw{display:inline-block;width:1rem;height:1rem;background:var(--ink);border-radius:.2rem;margin:.1rem 0}
.crosssw{color:var(--mag)}
.tb.hint{background:#fff4c7}
.tb:disabled{opacity:.45}
.pc{min-width:2.6rem}
.pc .sw{display:inline-block;width:1.3rem;height:1.3rem;border-radius:.3rem;border:2px solid #0004}
/* landscape: tools on the right side */
body.side #play{flex-direction:column}
body.side #playRow{display:flex}
body.side #tools{position:absolute;right:.4rem;top:3rem;bottom:.4rem;flex-direction:column;justify-content:center;flex-wrap:nowrap;padding:0}
body.side .grp{flex-direction:column}
body.side #stage{margin-right:5rem}
body.side.pal5 #stage{margin-right:5rem}

/* ---------- dialog ---------- */
.dlgWrap{position:fixed;inset:0;background:#0d0833aa;display:flex;align-items:center;justify-content:center;padding:.6rem;z-index:20}
.dlgWrap[hidden]{display:none}
.dlg{background:var(--card);border:3px solid var(--ink);border-radius:1.2rem;max-width:34rem;width:100%;max-height:94vh;display:flex;flex-direction:column;box-shadow:0 .6rem 0 #0005;animation:pop .25s ease-out}
@keyframes pop{from{transform:scale(.85);opacity:0}}
.dlgBody{overflow-y:auto;padding:1rem 1.2rem .5rem;font-size:.95rem;line-height:1.4;min-height:0;touch-action:pan-y}
.dlgBody h2{font-size:1.4rem;font-weight:900;margin-bottom:.4rem}
.dlgBody p{margin:.35rem 0}
.dlgBody ul{margin:.3rem 0 .3rem 1.2rem}
.dlgFoot{display:flex;gap:.6rem;justify-content:center;padding:.6rem;flex-wrap:wrap;flex:0 0 auto}
.dlgFoot .big{font-size:1.2rem;padding:.4rem 1.6rem}
.dlgFoot .mid{font-size:1rem;padding:.35rem 1rem}
.winBox{display:flex;gap:1rem;align-items:center}
.winBox canvas{width:9rem;height:9rem;image-rendering:pixelated;border-radius:.6rem;border:3px solid var(--ink);background:#fff;flex:0 0 auto}
.stars{font-size:1.8rem;color:#f5a400;letter-spacing:.1em}
.stars .off{color:#ddd6f3}
.row{display:flex;align-items:center;justify-content:space-between;gap:.8rem;padding:.45rem 0;border-bottom:1px solid #eee8ff}
.sw2{width:3.2rem;height:1.8rem;border-radius:1rem;background:#d8d1f0;position:relative;flex:0 0 auto;border:2px solid var(--ink)}
.sw2::after{content:"";position:absolute;top:.15rem;left:.2rem;width:1.15rem;height:1.15rem;border-radius:50%;background:#fff;border:2px solid var(--ink);transition:left .15s}
.sw2.on{background:var(--lime)}
.sw2.on::after{left:1.5rem}
.row small{display:block;color:var(--mut);font-size:.78rem}

#toast{position:fixed;left:50%;top:3.2rem;transform:translateX(-50%);background:var(--mag);color:#fff;font-weight:800;padding:.35rem 1rem;border-radius:1rem;z-index:30;pointer-events:none;font-size:.95rem;white-space:nowrap}

/* ---------- short windows ---------- */
@media (max-height:560px){
  .pixi{width:9.5rem}
  .start{padding:.8rem 1.1rem;gap:.9rem}
  .t1{font-size:2.3rem}.t2{font-size:1.05rem}
  .startTxt{gap:.45rem}
  .big{font-size:1.35rem;padding:.4rem 1.8rem}
  .tb{height:2.7rem;min-width:3.2rem}
  .ib{width:2rem;height:2rem}
  #hud{padding:.25rem .5rem}
}
@media (max-height:400px){
  .pixi{width:7rem}
  .t1{font-size:1.9rem}
  .intro{font-size:.85rem}
  .tb .tl{display:none}
  .tb{height:2.3rem;min-width:2.5rem}
  #tip{display:none}
}
/* phone portrait */
@media (max-width:560px) and (min-height:561px){
  .start{flex-direction:column;text-align:center;padding:1rem}
  .pixi{width:10rem}
  .startBtns,.ctrls{justify-content:center}
  .t1{font-size:2.5rem}
  .tb{min-width:3.1rem;font-size:.66rem}
  #tools{gap:.3rem}
}
@media (max-width:560px) and (max-height:560px){ .pixi{display:none} }
