:root {
  --bg: #f5f3ff;
  --ink: #1e1b3a;
  --muted: #6e6a92;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-brd: rgba(60, 50, 140, 0.10);
  --p1: #ff4d6d;
  --p1-hi: #ffb3c1;
  --p1-lo: #b5173f;
  --p2: #ffc23d;
  --p2-hi: #fff0b8;
  --p2-lo: #d9890b;
  --board-a: #5b5cf6;
  --board-b: #3027b8;
  --cell: max(40px, min(76px, calc((100vw - 56px) / 7), calc((100dvh - 330px) / 7.4)));
  --rimw: calc(var(--cell) * 0.2);
  --hole: calc(var(--cell) * 0.4);
  --disc: calc(var(--cell) * 0.78);
  --radius: 22px;
  font-family: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100dvh; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }

/* ---------- background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(1200px 700px at 50% -10%, #ffffff 0%, transparent 60%), linear-gradient(180deg, #f8f6ff, #efedfb); }
.blob { position: absolute; width: 46vmax; height: 46vmax; border-radius: 50%; filter: blur(100px); opacity: .22; animation: drift 22s ease-in-out infinite alternate; }
.b1 { background: var(--p1); left: -16vmax; top: 20vh; }
.b2 { background: var(--p2); right: -18vmax; top: 45vh; opacity: .28; animation-delay: -7s; }
.b3 { background: #8b7dff; left: 30vw; top: -30vmax; opacity: .2; animation-delay: -12s; }
@keyframes drift { to { transform: translate(6vmax, -5vmax) scale(1.15); } }

/* ---------- header ---------- */
.top { display: flex; justify-content: center; padding: 18px 16px 6px; }
.logo { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 20px; letter-spacing: .2px; }
.logo-discs { display: inline-flex; }
.logo-discs i { width: 16px; height: 16px; border-radius: 50%; margin-left: -4px; box-shadow: 0 0 0 2px var(--bg); }
.logo-discs i:first-child { margin-left: 0; }
.logo-discs .p1, .avatar.p1 i { background: radial-gradient(circle at 35% 30%, var(--p1-hi), var(--p1) 50%, var(--p1-lo)); }
.logo-discs .p2 { background: radial-gradient(circle at 35% 30%, var(--p2-hi), var(--p2) 50%, var(--p2-lo)); }

.view { width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 16px 32px; display: flex; flex-direction: column; align-items: center; }

/* ---------- cards / buttons / fields ---------- */
.card { background: linear-gradient(180deg, rgba(255,255,255,.92), rgba(255,255,255,.78)); border: 1px solid var(--glass-brd);
  border-radius: var(--radius); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 30px 70px -30px rgba(60, 40, 160, .28), 0 2px 6px rgba(60, 40, 160, .05), inset 0 1px 0 #fff; }

.btn { border: 0; border-radius: 14px; padding: 12px 20px; font-weight: 700; letter-spacing: .2px; transition: transform .15s ease, box-shadow .2s ease, background .2s ease, opacity .2s; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, #ff5e7e, #ff8a4c 55%, #ffc23d); color: #1a0d14;
  box-shadow: 0 10px 30px -8px rgba(255, 94, 126, .6), inset 0 1px 0 rgba(255,255,255,.45); }
.btn.primary:hover { box-shadow: 0 14px 36px -8px rgba(255, 94, 126, .8), inset 0 1px 0 rgba(255,255,255,.45); transform: translateY(-1px); }
.btn.ghost { background: var(--glass); border: 1px solid var(--glass-brd); }
.btn.ghost:hover { background: #fff; box-shadow: 0 6px 18px -8px rgba(60,40,160,.3); }
.btn.big { width: 100%; padding: 16px; font-size: 17px; }
.btn.small { padding: 8px 14px; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 8px; width: 100%; text-align: left; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
input { width: 100%; background: #fff; border: 1px solid var(--glass-brd); border-radius: 14px; padding: 14px 16px; font-size: 16px; outline: none; transition: border-color .2s, box-shadow .2s; }
input:focus { border-color: rgba(255, 140, 120, .7); box-shadow: 0 0 0 4px rgba(255, 94, 126, .15); }
input::placeholder { color: #a9a5c6; }

/* ---------- lobby ---------- */
.lobby-card { margin-top: 6vh; width: 100%; max-width: 440px; padding: 34px 28px; display: flex; flex-direction: column; gap: 18px; text-align: center; animation: rise .6s cubic-bezier(.2,.9,.3,1.2) both; }
.lobby-card h1 { margin: 0; font-size: clamp(30px, 6vw, 40px); line-height: 1.08; font-weight: 800; letter-spacing: -.5px; }
.grad { background: linear-gradient(90deg, var(--p1), #ff8a4c, var(--p2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { margin: 0; color: var(--muted); font-size: 16px; }
.divider { display: flex; align-items: center; gap: 12px; color: #9a96b8; font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--glass-brd); }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.97); } }

/* ---------- players ---------- */
.players { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 6px; }
.vs { font-weight: 800; color: #aaa6c8; font-size: 13px; letter-spacing: 2px; }
.player { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 18px; background: var(--glass); border: 1px solid var(--glass-brd);
  transition: box-shadow .3s, border-color .3s, transform .3s, background .3s; min-width: 0; }
.player.p2 { justify-content: flex-end; }
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: rgba(60,50,140,.07); }
.avatar i { width: 26px; height: 26px; border-radius: 50%; }
.player.p1 .avatar i { background: radial-gradient(circle at 35% 30%, var(--p1-hi), var(--p1) 50%, var(--p1-lo)); }
.player.p2 .avatar i { background: radial-gradient(circle at 35% 30%, var(--p2-hi), var(--p2) 50%, var(--p2-lo)); }
.pinfo { min-width: 0; flex: 1; }
.pinfo.right { text-align: right; }
.pname { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 16px; }
.pinfo.right .pname { justify-content: flex-end; }
.pname .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #cfcce3; transition: background .3s, box-shadow .3s; }
.player.online .dot { background: #22c56b; box-shadow: 0 0 0 3px rgba(34, 197, 107, .18); }
.ptag { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .5px; text-transform: uppercase; min-height: 15px; }
.pscore { font-size: 28px; font-weight: 800; min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; }
.player.empty .name { color: #a9a5c6; font-weight: 500; }
.player.turn.p1 { border-color: rgba(255, 77, 109, .7); box-shadow: 0 0 0 4px rgba(255, 77, 109, .14), 0 12px 40px -12px rgba(255, 77, 109, .7); background: #fff4f6; }
.player.turn.p2 { border-color: rgba(255, 194, 61, .7); box-shadow: 0 0 0 4px rgba(255, 194, 61, .14), 0 12px 40px -12px rgba(255, 194, 61, .7); background: #fffaeb; }
.player.turn .avatar i { animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px) scale(1.06); } }
.score-pop { animation: pop .5s cubic-bezier(.3,1.8,.5,1); }
@keyframes pop { 40% { transform: scale(1.6); } }

/* ---------- status ---------- */
.status { margin: 16px 0 8px; font-size: clamp(18px, 4vw, 22px); font-weight: 700; text-align: center; min-height: 30px; transition: color .3s; }
.status.p1 { color: #e0244f; }
.status.p2 { color: #c27a00; }
.status .hint { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* ---------- board ---------- */
.stage { position: relative; isolation: isolate; display: flex; justify-content: center; width: 100%; }
.board-area { position: relative; z-index: 0; isolation: isolate; display: flex; flex-direction: column; align-items: center; transition: filter .4s, opacity .4s; }
.board-area.dim { visibility: hidden; }
.ghost-row { display: grid; grid-template-columns: repeat(7, var(--cell)); height: var(--cell); margin-bottom: calc(var(--rimw) + 6px); }
.ghost-row .g { display: grid; place-items: center; }
.ghost-row .g i { width: var(--disc); height: var(--disc); border-radius: 50%; opacity: 0; transform: translateY(8px) scale(.9); transition: opacity .15s, transform .15s; }
.ghost-row .g.show i { opacity: 1; transform: none; }
.ghost-row.p1 i { background: radial-gradient(circle at 35% 30%, var(--p1-hi), var(--p1) 50%, var(--p1-lo)); box-shadow: 0 8px 24px -6px var(--p1); }
.ghost-row.p2 i { background: radial-gradient(circle at 35% 30%, var(--p2-hi), var(--p2) 50%, var(--p2-lo)); box-shadow: 0 8px 24px -6px var(--p2); }

.board { position: relative; width: calc(var(--cell) * 7); height: calc(var(--cell) * 6); }
.board::before { content: ''; position: absolute; inset: calc(-1 * var(--rimw)); border-radius: calc(var(--rimw) + 12px);
  box-shadow: 0 40px 70px -24px rgba(48, 39, 184, .55), 0 12px 24px -12px rgba(48, 39, 184, .35); }
.slots, .discs, .cols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(7, var(--cell)); grid-template-rows: repeat(6, var(--cell)); }
.slots .s { display: grid; place-items: center; }
.slots .s::before { content: ''; width: calc(var(--hole) * 2); height: calc(var(--hole) * 2); border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #f4f2ff, #dcd8f3); box-shadow: inset 0 6px 10px rgba(30, 20, 110, .45); }

.frame { position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(165deg, var(--board-a), var(--board-b));
  background-size: calc(100% + 2 * var(--rimw)) calc(100% + 2 * var(--rimw));
  background-position: calc(-1 * var(--rimw)) calc(-1 * var(--rimw));
  -webkit-mask: radial-gradient(circle, transparent var(--hole), #000 calc(var(--hole) + .5px)) 0 0 / var(--cell) var(--cell) repeat;
          mask: radial-gradient(circle, transparent var(--hole), #000 calc(var(--hole) + .5px)) 0 0 / var(--cell) var(--cell) repeat; }
.frame::after { content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0) calc(var(--hole) + 1px), rgba(255,255,255,.22) calc(var(--hole) + 2px), rgba(255,255,255,0) calc(var(--hole) + 5px)) 0 0 / var(--cell) var(--cell) repeat; }
.rim { position: absolute; inset: calc(-1 * var(--rimw)); padding: var(--rimw); border-radius: calc(var(--rimw) + 12px); pointer-events: none;
  background: linear-gradient(165deg, var(--board-a), var(--board-b));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); }
.rim::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 2px 0 rgba(255,255,255,.28), inset 0 -3px 0 rgba(0,0,0,.25); }
.feet { display: flex; justify-content: space-between; width: calc(var(--cell) * 7 + var(--rimw) * 4); margin-top: calc(var(--rimw) - 2px); }
.feet i { width: calc(var(--cell) * .9); height: calc(var(--rimw) * .9); border-radius: 0 0 10px 10px; background: linear-gradient(180deg, var(--board-b), #1d1680); }

.discs .cell { display: grid; place-items: center; }
.disc { width: var(--disc); height: var(--disc); border-radius: 50%; position: relative; will-change: transform; }
.disc::after { content: ''; position: absolute; inset: 17%; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); box-shadow: inset 0 2px 4px rgba(0,0,0,.2); }
.disc.p1 { background: radial-gradient(circle at 35% 28%, var(--p1-hi), var(--p1) 45%, var(--p1-lo) 100%); box-shadow: inset 0 -5px 10px rgba(0,0,0,.28), inset 0 3px 6px rgba(255,255,255,.35); }
.disc.p2 { background: radial-gradient(circle at 35% 28%, var(--p2-hi), var(--p2) 45%, var(--p2-lo) 100%); box-shadow: inset 0 -5px 10px rgba(0,0,0,.22), inset 0 3px 6px rgba(255,255,255,.45); }
.disc.drop { animation: drop var(--dur, .5s) cubic-bezier(.45, 0, 1, 1) both, settle .35s ease-out var(--dur, .5s); }
@keyframes drop { from { transform: translateY(calc(-1 * var(--fall))); } to { transform: translateY(0); } }
@keyframes settle { 30% { transform: translateY(calc(var(--cell) * -.12)); } 60% { transform: translateY(0); } 80% { transform: translateY(calc(var(--cell) * -.03)); } }
.board.over .disc:not(.win) { filter: saturate(.35) brightness(.8) opacity(.55); transition: filter .6s .4s; }
.disc.win { animation: winpulse 1.2s ease-in-out infinite .5s; z-index: 1; }
.disc.win::after { border-color: rgba(255,255,255,.9); box-shadow: 0 0 12px rgba(255,255,255,.8), inset 0 0 8px rgba(255,255,255,.6); }
@keyframes winpulse { 50% { transform: scale(1.08); filter: brightness(1.25); } }

.cols { top: calc(-1 * (var(--cell) + var(--rimw) + 6px)); grid-template-rows: 1fr; z-index: 5; }
.cols button { background: none; border: 0; padding: 0; border-radius: 14px; -webkit-tap-highlight-color: transparent; }
.cols button:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: -2px; }
.cols.disabled button { cursor: default; }
.cols:not(.disabled) button:hover { background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.02)); }

/* ---------- invite overlay ---------- */
.invite { position: absolute; z-index: 10; inset: 0; margin: auto; height: fit-content; width: min(420px, calc(100vw - 32px)); padding: 28px 24px; text-align: center; background: #fff; animation: rise .5s cubic-bezier(.2,.9,.3,1.2) both; }
.invite h2 { margin: 14px 0 6px; font-size: 22px; }
.invite p { margin: 0 0 18px; color: var(--muted); }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; font-size: 14px; padding: 12px 14px; color: #4a4670; background: #f6f5fc; }
.invite .btn.small { margin-top: 12px; }
.pulse-ring { position: relative; width: 54px; height: 54px; margin: 0 auto; display: grid; place-items: center; }
.pulse-ring::before, .pulse-ring::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--p1); animation: ring 2s ease-out infinite; }
.pulse-ring::after { animation-delay: 1s; }
.pulse-ring i { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--p1-hi), var(--p1) 50%, var(--p1-lo)); }
@keyframes ring { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }

/* ---------- below board ---------- */
.below { margin-top: 22px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
#rematchBtn { padding: 14px 34px; font-size: 17px; animation: rise .4s both; }
.reactions { display: flex; gap: 6px; padding: 6px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-brd); }
.reactions button { background: none; border: 0; font-size: 22px; width: 42px; height: 42px; border-radius: 50%; transition: transform .15s, background .15s; }
.reactions button:hover { background: #f1effc; transform: translateY(-2px) scale(1.12); }
.draws { color: var(--muted); font-size: 13px; }

/* ---------- modal / toast / floaters ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(235, 232, 252, .55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(6px); }
.modal-card { width: 100%; max-width: 400px; padding: 30px 26px; display: flex; flex-direction: column; gap: 16px; text-align: center; animation: rise .4s cubic-bezier(.2,.9,.3,1.2) both; }
.modal-card h2 { margin: 0; font-size: 26px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; z-index: 60; pointer-events: none;
  padding: 12px 18px; border-radius: 14px; background: #1e1b3a; color: #fff; border: 0; font-weight: 600; transition: opacity .25s, transform .25s; box-shadow: 0 20px 50px -20px rgba(30, 20, 90, .6); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.floaters { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.floater { position: absolute; bottom: -40px; font-size: 42px; animation: floatUp 2.6s cubic-bezier(.2,.6,.4,1) forwards; filter: drop-shadow(0 6px 12px rgba(60,40,160,.25)); }
@keyframes floatUp { 0% { transform: translateY(0) scale(.6); opacity: 0; } 15% { opacity: 1; transform: translateY(-15vh) scale(1.1); } 100% { transform: translateY(-75vh) translateX(var(--dx, 0)) scale(.9) rotate(var(--rot, 0deg)); opacity: 0; } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 45; }

.shake { animation: shake .5s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

@media (max-width: 520px) {
  .player { padding: 8px; gap: 6px; }
  .avatar { width: 30px; height: 30px; }
  .avatar i { width: 20px; height: 20px; }
  .pname { font-size: 14px; }
  .pscore { font-size: 22px; min-width: 18px; }
  .ptag { font-size: 10px; }
  .vs { font-size: 11px; }
  .reactions { gap: 0; padding: 4px; }
  .reactions button { width: 36px; height: 36px; font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- music toggle (shared by all games) ---------- */
.music-btn { position: fixed; left: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 30; width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--glass-brd);
  background: rgba(255,255,255,.85); font-size: 20px; box-shadow: 0 8px 22px -10px rgba(60,40,160,.45); backdrop-filter: blur(6px); transition: transform .15s, opacity .2s; }
.music-btn:hover { transform: translateY(-2px); }
.music-btn.off, .icon-btn.off, .gicon.off { opacity: .45; position: relative; }
.music-btn.off::after, .icon-btn.off::after, .gicon.off::after { content: ''; position: absolute; left: 9px; right: 9px; top: 50%; height: 2.5px; border-radius: 2px; background: #e11d48; transform: rotate(-35deg); }
