:root {
  --pink: #ff5fa2; --violet: #7c6cff; --teal: #12c9b0; --sun: #ffc83d; --ink: #3b2a5a; --soft: #8a7aa8;
  --me: #ff5fa2; --opp: #2bb8ff;
  --cell: 28px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink); background: linear-gradient(160deg, #ffe3f1 0%, #e4ddff 45%, #d6f4ff 100%);
  overflow-x: hidden; user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg i { position: absolute; border-radius: 50%; filter: blur(30px); opacity: .55; animation: drift 18s ease-in-out infinite alternate; }
.bg i:nth-child(1) { width: 260px; height: 260px; background: #ffb3d9; left: -60px; top: 5%; }
.bg i:nth-child(2) { width: 220px; height: 220px; background: #b9f0e6; right: -50px; top: 25%; animation-delay: -4s; }
.bg i:nth-child(3) { width: 300px; height: 300px; background: #ffe6a0; left: 20%; bottom: -80px; animation-delay: -8s; }
.bg i:nth-child(4) { width: 180px; height: 180px; background: #c9b8ff; right: 10%; bottom: 20%; animation-delay: -2s; }
.bg i:nth-child(5) { width: 140px; height: 140px; background: #a8dcff; left: 5%; bottom: 35%; animation-delay: -6s; }
@keyframes drift { to { transform: translate(40px, -50px) scale(1.15); } }

#app { max-width: 560px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); min-height: 100%; display: flex; flex-direction: column; }
.card { background: rgba(255,255,255,.78); backdrop-filter: blur(10px); border-radius: 28px; padding: 20px; box-shadow: 0 10px 30px rgba(124,108,255,.18); }
h1 { margin: 0; font-size: 2.3rem; line-height: 1; letter-spacing: -.5px; }
h1 span { background: linear-gradient(90deg, var(--pink), var(--violet), var(--teal)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: var(--soft); margin: 6px 0 0; font-weight: 600; }
.logo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; width: 74px; margin: 0 auto 10px; }
.logo b { aspect-ratio: 1; border-radius: 8px; background: hsl(calc(var(--i) * 40), 90%, 65%); animation: pop 2.4s ease-in-out infinite; animation-delay: calc(var(--i) * .15s); }
.logo b.off { visibility: hidden; }
@keyframes pop { 0%, 60%, 100% { transform: scale(1); } 30% { transform: scale(.7) rotate(8deg); } }

label.f { display: block; font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--soft); margin: 16px 0 6px; }
input.txt { width: 100%; font: inherit; font-weight: 800; font-size: 1.15rem; padding: 13px 16px; border: 3px solid #e6dcff; border-radius: 18px; background: #fff; color: var(--ink); outline: none; user-select: text; -webkit-user-select: text; }
input.txt:focus { border-color: var(--violet); }
input.code { text-align: center; letter-spacing: .4em; text-transform: uppercase; font-size: 1.5rem; }
.row { display: flex; gap: 10px; }
.avatars { display: flex; gap: 6px; flex-wrap: wrap; }
.avatars button { font-size: 1.6rem; width: 46px; height: 46px; border-radius: 16px; border: 3px solid transparent; background: #fff; cursor: pointer; }
.avatars button.on { border-color: var(--pink); transform: scale(1.1); background: #fff0f7; }
.sizes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sizes button { padding: 10px 0; border-radius: 16px; border: 3px solid #e6dcff; background: #fff; font: inherit; font-weight: 900; color: var(--ink); cursor: pointer; }
.sizes button small { display: block; font-weight: 700; color: var(--soft); font-size: .68rem; }
.sizes button.on { border-color: var(--violet); background: #f1eeff; }

.btn { display: block; width: 100%; font: inherit; font-weight: 900; font-size: 1.15rem; color: #fff; border: 0; border-radius: 20px; padding: 15px; margin-top: 14px; cursor: pointer;
  background: linear-gradient(90deg, var(--pink), var(--violet)); box-shadow: 0 6px 0 #b24b9a, 0 12px 20px rgba(124,108,255,.3); transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #b24b9a; }
.btn.teal { background: linear-gradient(90deg, var(--teal), #2bb8ff); box-shadow: 0 6px 0 #0c8f9c, 0 12px 20px rgba(18,201,176,.3); }
.btn.teal:active { box-shadow: 0 1px 0 #0c8f9c; }
.btn.ghost { background: #fff; color: var(--violet); box-shadow: 0 5px 0 #e0d6ff; }
.btn:disabled { filter: grayscale(.6); opacity: .6; }
.or { text-align: center; color: var(--soft); font-weight: 800; margin: 18px 0 2px; }
.err { color: #d6336c; font-weight: 800; min-height: 1.3em; margin: 10px 0 0; text-align: center; }

.center { text-align: center; }
.bigcode { font-size: 3.4rem; font-weight: 900; letter-spacing: .18em; margin: 8px 0 0 .18em; background: linear-gradient(90deg, var(--pink), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; user-select: text; -webkit-user-select: text; }
.wait { display: inline-flex; gap: 6px; margin-top: 18px; }
.wait i { width: 12px; height: 12px; border-radius: 50%; background: var(--pink); animation: bounce 1s infinite; }
.wait i:nth-child(2) { background: var(--sun); animation-delay: .15s; } .wait i:nth-child(3) { background: var(--teal); animation-delay: .3s; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-12px); } }

/* game */
.race { display: grid; gap: 8px; margin-bottom: 10px; }
.lane { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: 8px; background: rgba(255,255,255,.7); border-radius: 20px; padding: 6px 10px 6px 6px; }
.lane .av { font-size: 1.7rem; text-align: center; transition: transform .3s; }
.lane .nm { display: flex; justify-content: space-between; font-weight: 900; font-size: .85rem; }
.lane .nm em { font-style: normal; color: var(--soft); }
.lane .bar { height: 14px; border-radius: 9px; background: #efe8ff; overflow: hidden; margin-top: 3px; }
.lane .bar b { display: block; height: 100%; width: 0; border-radius: 9px; transition: width .35s cubic-bezier(.3,1.4,.5,1); background: linear-gradient(90deg, var(--c1), var(--c2)); }
.lane.me { --c1: #ff5fa2; --c2: #ffa24d; } .lane.opp { --c1: #2bb8ff; --c2: #12c9b0; }
.lane.pulse .av { animation: hop .5s; } @keyframes hop { 40% { transform: translateY(-8px) scale(1.2); } }
.hud { display: flex; justify-content: space-between; align-items: center; font-weight: 900; margin: 2px 4px 8px; }
.hud .time { font-variant-numeric: tabular-nums; font-size: 1.3rem; }
.hud .pill { background: rgba(255,255,255,.75); border-radius: 14px; padding: 4px 12px; font-size: .85rem; }

.stage { position: relative; display: flex; justify-content: center; }
.board { display: grid; grid-template-columns: auto repeat(var(--n), var(--cell)); background: rgba(255,255,255,.85); padding: 8px; border-radius: 22px; box-shadow: 0 10px 30px rgba(124,108,255,.2); touch-action: none; }
.board.hidden { filter: blur(9px); pointer-events: none; }
.cc, .rc { font-weight: 900; font-size: calc(var(--cell) * .5); color: var(--ink); display: flex; line-height: 1.05; }
.cc { flex-direction: column; justify-content: flex-end; align-items: center; padding-bottom: 3px; text-align: center; }
.rc { justify-content: flex-end; align-items: center; gap: calc(var(--cell) * .2); padding-right: 6px; height: var(--cell); }
.cc span:nth-child(odd), .rc span:nth-child(odd) { color: var(--violet); } .cc span:nth-child(even), .rc span:nth-child(even) { color: #e0409a; }
.cc.ok, .rc.ok { opacity: .28; text-decoration: line-through; }
.cell { width: var(--cell); height: var(--cell); border-radius: calc(var(--cell) * .24); background: #f4efff; border: 2px solid #fff; display: grid; place-items: center; font-size: calc(var(--cell) * .6); color: #b9a9d8; font-weight: 900; transition: background .12s, transform .12s; }
.cell.alt { background: #ece4ff; }
.cell.f { background: var(--fill); border-color: color-mix(in srgb, var(--fill) 70%, #fff); animation: stamp .16s; }
.cell.x::after { content: "✕"; }
.cell.gr { border-right-color: #b7a6f5; } .cell.gb { border-bottom-color: #b7a6f5; }
.cell.solved { animation: wave .8s both; animation-delay: calc(var(--d) * 28ms); }
@keyframes stamp { 0% { transform: scale(.6); } 70% { transform: scale(1.08); } }
@keyframes wave { 0% { transform: scale(1); } 40% { transform: scale(1.25) rotate(6deg); } 100% { transform: scale(1); } }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.tool { border: 3px solid transparent; background: rgba(255,255,255,.8); border-radius: 18px; font: inherit; font-weight: 900; padding: 11px; font-size: 1rem; color: var(--ink); cursor: pointer; }
.tool.on { border-color: var(--violet); background: #f1eeff; }
.tool i { display: inline-block; width: 18px; height: 18px; border-radius: 6px; background: var(--pink); vertical-align: -3px; margin-right: 6px; }
.tool.x i { background: none; font-style: normal; color: var(--soft); text-align: center; line-height: 18px; width: auto; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; pointer-events: none; }
.count { font-size: 9rem; font-weight: 900; color: #fff; text-shadow: 0 8px 0 var(--pink), 0 14px 30px rgba(124,108,255,.6); animation: zoom 1s infinite; }
@keyframes zoom { 0% { transform: scale(.4); opacity: 0; } 25% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); opacity: .9; } }
.result { pointer-events: auto; background: rgba(255,255,255,.94); backdrop-filter: blur(8px); border-radius: 30px; padding: 22px 24px; text-align: center; width: min(88vw, 380px); box-shadow: 0 20px 60px rgba(124,108,255,.45); animation: rise .45s cubic-bezier(.3,1.5,.5,1); }
.result h2 { margin: 0; font-size: 2.2rem; } .result .big { font-size: 4rem; }
.result .scores { font-weight: 900; font-size: 1.1rem; margin: 6px 0; } .result p { margin: 4px 0; color: var(--soft); font-weight: 700; }
@keyframes rise { from { transform: translateY(60px) scale(.8); opacity: 0; } }
.link { background: none; border: 0; color: var(--soft); font: inherit; font-weight: 800; margin-top: 12px; cursor: pointer; text-decoration: underline; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 16px; font-weight: 800; z-index: 9; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 8; width: 100%; height: 100%; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.install { margin-top: 16px; padding: 12px 14px; border-radius: 18px; background: #f3f0ff; font-weight: 700; font-size: .9rem; line-height: 1.35; text-align: center; color: var(--ink); }
.install p { margin: 0; } .install p + p { margin-top: 6px; }
