:root {
  --bg: #14143a; --p1: #4b1f7e; --p2: #2d0f55; --edge: #b79cf0; --text: #fff; --muted: #c9b8ee;
  --red: #e1131d; --green: #2bad28; --blue: #2f84e8; --yellow: #f0a516; --gold: #ffc826;
  --board: #232979;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  background: var(--bg) url(../assets/bg.png) center/cover fixed; color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; user-select: none; -webkit-user-select: none;
  display: flex; justify-content: center;
}
button { font: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; }
.hidden { display: none !important; }
#app { width: 100%; max-width: 480px; min-height: 100%; position: relative; }
.screen { display: none; min-height: 100vh; padding: max(10px, env(safe-area-inset-top)) 16px 24px; flex-direction: column; gap: 12px; animation: fade .25s; }
.screen.active { display: flex; }
.screen.center { align-items: center; justify-content: center; text-align: center; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }
h1 { margin: 0; font-size: 20px; letter-spacing: 1px; text-shadow: 0 2px 0 #3a1380; }
h2 { margin: 6px 4px 0; font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; } .center-t { text-align: center; }

.panel { background: linear-gradient(180deg, var(--p1), var(--p2)); border: 1.5px solid var(--edge); border-radius: 16px;
  box-shadow: 0 0 18px rgba(150,90,255,.3), inset 0 2px 0 rgba(255,255,255,.18); padding: 14px; }
button.panel { text-align: left; }
.logo { width: 70%; max-width: 300px; margin: 0 auto; display: block; -webkit-mask-image: radial-gradient(ellipse 68% 66% at 50% 50%, #000 62%, transparent 100%);
  mask-image: radial-gradient(ellipse 68% 66% at 50% 50%, #000 62%, transparent 100%); animation: float 4s ease-in-out infinite; }
.logo.big { width: 78%; max-width: 340px; }
@keyframes float { 50% { transform: translateY(-6px); } }
.loader { width: 200px; height: 10px; border-radius: 9px; background: #2d0f55; border: 1px solid var(--edge); overflow: hidden; margin: 14px 0 6px; }
.loader i { display: block; height: 100%; width: 40%; background: linear-gradient(90deg, #46b814, #8be04a); border-radius: 9px; animation: load 1.1s ease-in-out infinite; }
@keyframes load { from { margin-left: -40%; } to { margin-left: 100%; } }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; }
.round { width: 48px; height: 50px; padding: 0; border: 0; background: none; transition: transform .12s; }
.round img { width: 100%; height: 100%; }
.round:active { transform: scale(.9); }
.helpimg { object-fit: contain; }
.coins { display: flex; align-items: center; gap: 6px; background: #2d0f55; border: 1.5px solid var(--edge); border-radius: 22px; padding: 6px 8px 6px 12px; font-weight: 800; }
.coins button { width: 24px; height: 24px; border-radius: 50%; border: 0; background: #46b814; color: #fff; font-weight: 900; line-height: 1; }
.mode-title { height: 38px; }

/* gradient buttons made from game sprites */
.gbtn, .rbtn { position: relative; border: 0; padding: 0; background: none; width: 100%; max-width: 340px; align-self: center; transition: transform .12s, filter .12s; }
.gbtn img, .rbtn img { width: 100%; display: block; }
.gbtn span, .rbtn span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 900; letter-spacing: 2px; text-shadow: 0 2px 0 rgba(0,0,0,.45); }
.gbtn:hover, .rbtn:hover { filter: brightness(1.1); } .gbtn:active, .rbtn:active { transform: scale(.96); }
.gbtn:disabled, .rbtn:disabled { filter: grayscale(.8) brightness(.7); cursor: not-allowed; }
.gbtn.sm span, .rbtn.sm span { font-size: 16px; } .gbtn.sm, .rbtn.sm { max-width: 150px; }

/* auth */
.auth-card { display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 6px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 12px; }
.tab { flex: 1; padding: 9px 4px; border: 0; background: none; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tab.on { background: linear-gradient(180deg, #7b45d6, #4b1f7e); color: #fff; box-shadow: 0 0 10px rgba(180,120,255,.5); }
.seg { margin: 0 4px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
input { background: #1b0c3a; border: 1.5px solid #6a43b0; border-radius: 10px; padding: 12px; color: #fff; font-size: 16px; width: 100%; outline: none; user-select: text; }
input:focus { border-color: var(--gold); }
.pw { position: relative; } .pw button { position: absolute; right: 6px; top: 6px; border: 0; background: none; font-size: 18px; padding: 6px; }
.err { color: #ff8a8a; min-height: 18px; margin: 0; font-size: 13px; }

/* home */
.profile { display: flex; align-items: center; gap: 12px; width: 100%; }
.avatar { position: relative; width: 58px; height: 58px; flex: none; }
.avatar .face { position: absolute; inset: 5px; width: calc(100% - 10px); height: calc(100% - 10px); border-radius: 12px; background: linear-gradient(160deg, #9c7cf0, #5a2ea6); object-fit: cover; padding: 3px; }
.avatar .ring { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.avatar.xl { width: 96px; height: 96px; margin: 0 auto; }
.pi { min-width: 0; } .name { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--muted); }
.online { margin-left: auto; text-align: right; display: grid; font-size: 11px; color: var(--muted); }
.online b { font-size: 20px; color: #fff; } .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #888; } .dot.up { background: #3ee05a; box-shadow: 0 0 6px #3ee05a; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode { text-align: center !important; padding: 14px 8px 12px; transition: transform .12s, box-shadow .12s; }
.mode.on { box-shadow: 0 0 0 3px var(--gold), 0 0 24px rgba(255,200,38,.45); } .mode:active { transform: scale(.97); }
.mode .title { height: 38px; max-width: 92%; } .mode .tokens { display: flex; justify-content: center; margin: 8px 0 4px; } .mode .tokens img { width: 28px; margin: 0 -2px; }
.mode p { margin: 0; font-size: 12px; color: var(--muted); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { text-align: center !important; padding: 12px 4px !important; font-size: 13px; } .tile b { display: block; font-size: 22px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px; }
.item .grow { flex: 1; min-width: 0; } .item .t { font-weight: 800; } .item .s { font-size: 12px; color: var(--muted); }
.fee { font-weight: 900; color: var(--gold); } .win { color: #6dff7a; } .loss { color: #ff8a8a; }
.item .gbtn { max-width: 96px; } .item .gbtn span { font-size: 15px; }
.rankno { width: 30px; text-align: center; font-weight: 900; font-size: 18px; color: var(--gold); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.pcard { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.statrow { display: grid; grid-template-columns: repeat(3, 1fr); } .statrow b { display: block; font-size: 22px; } .statrow small { color: var(--muted); }
.avgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.avgrid button { aspect-ratio: 1; border-radius: 14px; border: 2px solid transparent; background: linear-gradient(160deg, #9c7cf0, #5a2ea6); padding: 6px; }
.avgrid button.on { border-color: var(--gold); box-shadow: 0 0 14px rgba(255,200,38,.6); } .avgrid img { width: 100%; }

/* ---------------- game screen ---------------- */
#s-game { padding: max(6px, env(safe-area-inset-top)) 10px 10px; gap: 6px; height: 100vh; min-height: 0; }
.game-bar { min-height: 44px; } .game-bar .round { width: 42px; height: 44px; }
.gtitle { text-align: center; display: grid; justify-items: center; } .gtitle img { height: 30px; } .gtitle small { color: var(--gold); font-weight: 800; font-size: 12px; }
.gright { display: flex; }
.clock { text-align: center; font-size: 13px; color: var(--muted); margin-top: -4px; } .clock b { color: #fff; font-size: 16px; }
.prow { display: flex; justify-content: space-between; min-height: 76px; gap: 8px; }
.pn { display: flex; align-items: center; gap: 8px; transition: opacity .3s, transform .2s; position: relative; }
.pn.right { flex-direction: row-reverse; text-align: right; }
.pn.off { opacity: .35; }
.pav { position: relative; width: 58px; height: 58px; border-radius: 50%; flex: none; padding: 4px;
  background: conic-gradient(var(--tc, #4ade80) calc(var(--p, 0) * 1%), rgba(255,255,255,.12) 0); }
.pn.turn .pav { box-shadow: 0 0 14px var(--pc); }
.pav .in { width: 100%; height: 100%; border-radius: 50%; background: var(--pc); border: 3px solid var(--pc); display: grid; place-items: center; overflow: hidden; box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
.pav img { width: 86%; height: 86%; }
.pinfo { display: grid; gap: 2px; min-width: 0; }
.pname { font-size: 12px; font-weight: 800; max-width: 86px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: rgba(0,0,0,.35); border-radius: 8px; padding: 2px 8px; }
.lives { font-size: 11px; letter-spacing: 2px; min-height: 14px; } .lives .x { color: #ff6b6b; } .lives .o { color: rgba(255,255,255,.3); }
.pscore { font-size: 12px; color: var(--gold); font-weight: 800; }
.dice { width: 56px; height: 56px; border-radius: 12px; background: rgba(0,0,0,.28); border: 2px solid var(--pc); display: grid; place-items: center; flex: none; opacity: 0; transform: scale(.7); transition: .2s; }
.dice img { width: 80%; }
.pn.turn .dice { opacity: 1; transform: scale(1); }
.dice.mine { cursor: pointer; animation: pulse 0.9s infinite; }
.dice.rolling img { animation: roll .5s linear infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,200,38,.0), 0 0 18px var(--gold); transform: scale(1.1); } }
@keyframes roll { 0% { transform: rotate(0) scale(.8); } 50% { transform: rotate(180deg) scale(1.15); } 100% { transform: rotate(360deg) scale(.8); } }
.dice.pop img { animation: pop .35s; } @keyframes pop { 0% { transform: scale(1.8); } 100% { transform: scale(1); } }
.tap { position: absolute; bottom: -14px; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 900; color: var(--gold); letter-spacing: 1px; animation: blink 1s infinite; } @keyframes blink { 50% { opacity: .3; } }
.emote { position: absolute; width: 52px; height: 52px; top: -14px; animation: emote 2.2s forwards; pointer-events: none; z-index: 5; } .emote img { width: 100%; }
@keyframes emote { 0% { transform: scale(.2); opacity: 0; } 12% { transform: scale(1.2); opacity: 1; } 20% { transform: scale(1); } 85% { opacity: 1; } 100% { transform: translateY(-14px); opacity: 0; } }

#board-wrap { position: relative; align-self: center; width: var(--bs, 340px); height: var(--bs, 340px); }
#board { position: absolute; inset: 0; border-radius: 14px; background: var(--board); border: 3px solid #8e6fe0; box-shadow: 0 0 22px rgba(140,90,255,.5), inset 0 0 30px rgba(0,0,0,.35); overflow: visible; }
.yard { position: absolute; width: 40%; height: 40%; border-radius: 12px 12px 12px 12px; }
.yard .box { position: absolute; inset: 14%; border-radius: 14px; background: #fff; box-shadow: inset 0 0 10px rgba(0,0,0,.2); }
.yspot { position: absolute; width: 11%; aspect-ratio: 1; border-radius: 50%; background: rgba(0,0,0,.12); transform: translate(-50%, -50%); }
.cell { position: absolute; background: #fff; border: 1.5px solid var(--board); border-radius: 6px; background-clip: padding-box; }
.cell.star::after { content: ""; position: absolute; inset: 18%; background: url(../assets/star.png) center/contain no-repeat; opacity: .75; filter: invert(.1); }
.cell.c0 { background: var(--red); } .cell.c1 { background: var(--green); } .cell.c2 { background: var(--blue); } .cell.c3 { background: var(--yellow); }
.cell.c0.star::after, .cell.c1.star::after, .cell.c2.star::after, .cell.c3.star::after { filter: none; opacity: .95; }
.tri { position: absolute; }
.tok { position: absolute; left: 0; top: 0; width: 0; height: 0; transition: transform .17s linear; pointer-events: none; will-change: transform; }
.tok img { position: absolute; width: var(--tw); left: calc(var(--tw) / -2); bottom: calc(var(--tw) * -0.18); filter: drop-shadow(0 3px 2px rgba(0,0,0,.45)); transform-origin: 50% 100%; transition: transform .17s; }
.tok.hop img { animation: hop .17s; } @keyframes hop { 50% { transform: translateY(-28%) scale(1.12); } }
.tok.go { pointer-events: auto; cursor: pointer; z-index: 999 !important; }
.tok.go img { animation: bob .6s ease-in-out infinite; filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 10px var(--gold)); }
@keyframes bob { 50% { transform: translateY(-14%) scale(1.15); } }
.tok.home img { opacity: .95; }
.overlay { position: absolute; inset: 0; border-radius: 14px; background: rgba(20,10,60,.82); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; z-index: 2000; padding: 16px; }
.overlay .big { font-size: 64px; font-weight: 900; color: var(--gold); text-shadow: 0 4px 0 #6a1b9a; animation: pop .5s; }
.overlay .seats { display: flex; gap: 10px; justify-content: center; margin: 6px 0; }
.seatc { width: 54px; height: 54px; border-radius: 50%; border: 2px dashed var(--edge); display: grid; place-items: center; background: rgba(255,255,255,.06); }
.seatc.f { border-style: solid; background: #5a2ea6; } .seatc img { width: 80%; }
.banner { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%) scale(.6); opacity: 0; font-size: 24px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 #6a1b9a, 0 0 14px #c06cff; z-index: 1500; pointer-events: none; white-space: nowrap; background: rgba(40,10,90,.75); border: 1.5px solid var(--edge); padding: 6px 18px; border-radius: 14px; }
.banner.show { animation: banner 1.2s forwards; } @keyframes banner { 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 25% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70%) scale(1); } }
.emoji-bar { display: flex; justify-content: center; }
.emoji-btn { display: flex; align-items: center; gap: 8px; background: linear-gradient(180deg, var(--p1), var(--p2)); border: 1.5px solid var(--edge); border-radius: 22px; padding: 4px 16px 4px 8px; font-weight: 700; }
.emoji-btn img { width: 30px; }

/* modals */
.modal-bg { position: fixed; inset: 0; background: rgba(8,4,30,.78); display: flex; align-items: center; justify-content: center; z-index: 5000; animation: fade .2s; padding: 16px; }
.modal { position: relative; width: 100%; max-width: 380px; padding: 52px 22px 24px; text-align: center; color: #fff;
  background: url(../assets/popup.png) center/100% 100% no-repeat; max-height: 88vh; overflow: auto; }
.modal .mt { position: absolute; left: 50%; top: -6px; transform: translateX(-50%); height: 40px; }
.modal .x { position: absolute; right: 6px; top: -6px; width: 42px; border: 0; background: none; padding: 0; } .modal .x img { width: 100%; }
.modal p { margin: 8px 0; line-height: 1.45; } .modal .btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.modal .btns button { flex: 1; max-width: 150px; }
.modal ul { text-align: left; padding-left: 20px; font-size: 14px; line-height: 1.5; margin: 6px 0; }
.setrow { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid rgba(255,255,255,.1); } .setrow:last-child { border: 0; }
.setrow img.ic { width: 34px; } .setrow .lbl { flex: 1; text-align: left; font-weight: 800; } .setrow button { border: 0; background: none; padding: 0; width: 82px; } .setrow button img { width: 100%; }
.emogrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; } .emogrid button { background: rgba(255,255,255,.08); border: 1px solid var(--edge); border-radius: 12px; padding: 4px; } .emogrid img { width: 100%; }
/* result */
.res { padding-top: 30px; } .res .rib { width: 78%; margin: -64px auto 6px; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.res .glow { position: absolute; inset: -20px; background: url(../assets/glow.png) center/contain no-repeat; opacity: .5; pointer-events: none; }
.rrow { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.3); border: 1.5px solid #6a43b0; border-radius: 14px; padding: 8px 10px; margin: 8px 0; text-align: left; }
.rrow.me { border-color: var(--gold); box-shadow: 0 0 14px rgba(255,200,38,.35); } .rrow.w { background: linear-gradient(90deg, rgba(255,200,38,.28), rgba(0,0,0,.3)); }
.rrow .rk { width: 30px; } .rrow .rn { flex: 1; min-width: 0; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .rrow .amt { font-weight: 900; color: var(--gold); }
.rrow .pa { width: 40px; height: 40px; border-radius: 50%; background: #5a2ea6; padding: 4px; } .rrow .pa img { width: 100%; }
.res .big { font-size: 26px; font-weight: 900; margin: 4px 0; color: var(--gold); }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 30px); opacity: 0; background: #2d0f55; border: 1.5px solid var(--edge); padding: 10px 18px; border-radius: 12px; transition: all .25s; pointer-events: none; font-size: 14px; max-width: 90%; text-align: center; z-index: 9000; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.netbar { position: fixed; top: 0; left: 0; right: 0; background: #b3261e; text-align: center; padding: 6px; font-size: 13px; font-weight: 700; z-index: 9500; }
.confetti { position: fixed; top: -20px; width: 10px; height: 14px; z-index: 6000; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@media (max-height: 700px) { .prow { min-height: 64px; } .pav { width: 50px; height: 50px; } .dice { width: 46px; height: 46px; } }

.round.q { border-radius: 50%; width: 44px; height: 44px; margin: 3px 2px; font-size: 24px; font-weight: 900; color: #fff;
  background: radial-gradient(circle at 35% 30%, #8e6fe0, #3a1a7a 70%); border: 2px solid #b79cf0; box-shadow: 0 0 10px rgba(150,90,255,.5); text-shadow: 0 2px 0 #2a0f5a; }
.yard.off .box { display: none; }
.dice .q { font-size: 28px; font-weight: 900; color: rgba(255,255,255,.5); }

.modal.res { overflow: visible; margin-top: 80px; padding-top: 48px; }
.res .rib { width: 82%; margin: -118px auto 4px; }

.pn { min-width: 0; } .pinfo { min-width: 0; }
#s-game.p4 .pav { width: 48px; height: 48px; padding: 3px; }
#s-game.p4 .dice { width: 42px; height: 42px; }
#s-game.p4 .pn { gap: 6px; } #s-game.p4 .pname { max-width: 62px; font-size: 11px; padding: 2px 6px; }
#s-game.p4 .prow { min-height: 62px; }

.pbtn { align-self: center; width: 100%; max-width: 340px; padding: 12px; font-weight: 900; letter-spacing: 1px; border-radius: 14px; border: 1.5px solid var(--edge);
  background: linear-gradient(180deg, #7b45d6, #4b1f7e); box-shadow: 0 0 14px rgba(150,90,255,.45), inset 0 2px 0 rgba(255,255,255,.2); }
.pbtn:active { transform: scale(.97); }
.fcard { display: flex; flex-direction: column; gap: 10px; } .fcard h3 { margin: 0; font-size: 15px; letter-spacing: 1px; }
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip { padding: 10px 0; border-radius: 12px; border: 1.5px solid #6a43b0; background: rgba(0,0,0,.25); font-weight: 800; }
.chip.on { border-color: var(--gold); box-shadow: 0 0 12px rgba(255,200,38,.5); background: rgba(255,200,38,.15); }
#f-code { text-align: center; font-size: 26px; font-weight: 900; letter-spacing: 8px; text-transform: uppercase; }
.roomcode { font-size: 38px; font-weight: 900; letter-spacing: 8px; color: var(--gold); text-shadow: 0 3px 0 #6a1b9a; background: rgba(0,0,0,.35); border: 2px dashed var(--edge); border-radius: 14px; padding: 6px 16px; }
.overlay .row { display: flex; gap: 8px; } .overlay .row button { max-width: 130px; }
