* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root { --red: #e53935; --green: #2e9e48; --yellow: #f6b400; --blue: #1e6fd9; --bg1: #1b1446; --bg2: #3a1f7a; }
html, body { height: 100%; overflow: hidden; background: radial-gradient(circle at 50% 20%, var(--bg2), var(--bg1)); color: #fff; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); text-align: center; }

/* menu */
.brand h1 { font-size: 44px; font-weight: 900; letter-spacing: 1px; line-height: 1; text-shadow: 0 5px 0 rgba(0,0,0,.3); }
.brand h1 span { color: #ffd34e; display: block; font-size: 34px; letter-spacing: 6px; }
.brand p { opacity: .75; margin-top: 8px; }
.brand-dice { display: grid; grid-template-columns: repeat(2, 28px); gap: 6px; justify-content: center; margin-bottom: 14px; transform: rotate(45deg); }
.brand-dice i { width: 28px; height: 28px; border-radius: 7px; }
.brand-dice i:nth-child(1) { background: var(--red); } .brand-dice i:nth-child(2) { background: var(--green); }
.brand-dice i:nth-child(3) { background: var(--blue); } .brand-dice i:nth-child(4) { background: var(--yellow); }
.me { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.08); padding: 8px 12px; border-radius: 14px; width: min(300px, 100%); }
.me input, .joinrow input { flex: 1; min-width: 0; background: transparent; border: 0; color: #fff; font-size: 17px; font-weight: 600; outline: none; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #fff3 center/cover; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.btn { width: min(300px, 100%); border: 0; border-radius: 16px; padding: 15px; font-size: 19px; font-weight: 800; color: #fff; cursor: pointer; transition: transform .1s; }
.btn:active { transform: scale(.96); }
.btn.green { background: linear-gradient(#45c96a, #1f9a45); box-shadow: 0 5px 0 #13702f; }
.btn.blue { background: linear-gradient(#4b93f0, #1e63c4); box-shadow: 0 5px 0 #11468f; }
.btn.yellow { background: linear-gradient(#ffcf3f, #f0a500); box-shadow: 0 5px 0 #b77b00; color: #3b2500; }
.btn.ghost { background: rgba(255,255,255,.14); box-shadow: none; }
.btn.small { font-size: 16px; padding: 11px; }
.codebox { display: flex; flex-direction: column; gap: 8px; width: min(300px, 100%); }
.joinrow { display: flex; gap: 8px; background: rgba(255,255,255,.08); border-radius: 14px; padding: 4px 4px 4px 14px; }
.joinrow .btn { width: auto; padding: 10px 18px; }
.status { font-size: 13px; opacity: .6; min-height: 18px; }

/* searching / room */
.spinner { width: 64px; height: 64px; border-radius: 50%; border: 6px solid #fff2; border-top-color: #ffd34e; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.roomcode { font-size: 20px; background: rgba(255,255,255,.1); padding: 10px 20px; border-radius: 14px; }
.roomcode b { color: #ffd34e; font-size: 30px; letter-spacing: 4px; margin-left: 8px; }
.hint { opacity: .75; font-size: 14px; max-width: 300px; }
.roomplayers { display: flex; flex-direction: column; gap: 6px; width: min(300px, 100%); }
.roomplayers div { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,.08); font-weight: 600; }

/* game */
#game { justify-content: flex-start; gap: 8px; }
.topbar { width: min(560px, 100%); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.12); color: #fff; font-size: 18px; cursor: pointer; }
.turnmsg { font-weight: 700; font-size: 16px; }
.prow { width: min(560px, 100%); display: flex; justify-content: space-between; gap: 8px; }
.pcard { flex: 1; max-width: 48%; min-height: 64px; display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 14px; background: rgba(255,255,255,.06); position: relative; opacity: .45; transition: opacity .2s, box-shadow .2s; }
.pcard:empty { visibility: hidden; }
.pcard[data-corner="1"], .pcard[data-corner="2"] { flex-direction: row-reverse; text-align: right; }
.pcard.active { opacity: 1; box-shadow: 0 0 0 3px var(--c), 0 0 18px var(--c); background: rgba(255,255,255,.12); }
.pcard.present { opacity: .85; }
.pcard .avatar { width: 42px; height: 42px; border: 3px solid var(--c); }
.pcard .info { flex: 1; min-width: 0; }
.pcard .pname { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .tag { font-size: 11px; opacity: .7; }
.pcard .timer { height: 4px; border-radius: 2px; background: #fff2; margin-top: 4px; overflow: hidden; }
.pcard .timer i { display: block; height: 100%; background: var(--c); width: 0; }
.dice { width: 46px; height: 46px; flex: none; border-radius: 10px; background: #fff; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 6px; box-shadow: 0 4px 0 #bbb; visibility: hidden; }
.pcard.active .dice { visibility: visible; }
.dice.can { cursor: pointer; animation: bounce .7s ease infinite alternate; box-shadow: 0 4px 0 #bbb, 0 0 0 3px #ffd34e; }
.dice.rolling { animation: shake .12s linear infinite; }
@keyframes bounce { to { transform: translateY(-5px); } }
@keyframes shake { 50% { transform: rotate(14deg) scale(1.05); } }
.dice b { width: 8px; height: 8px; border-radius: 50%; background: #222; place-self: center; visibility: hidden; }
.dice b.on { visibility: visible; }
.bubble { position: absolute; top: -26px; font-size: 34px; animation: float 1.6s ease forwards; pointer-events: none; z-index: 5; }
@keyframes float { 0% { transform: scale(.3); } 20% { transform: scale(1.2); } 30% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }

.boardwrap { width: min(560px, 100%, calc(100dvh - 270px)); aspect-ratio: 1; flex: none; }
#board { width: 100%; height: 100%; display: block; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.emojis { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.emojis button { font-size: 22px; width: 42px; height: 42px; border-radius: 12px; border: 0; background: rgba(255,255,255,.1); cursor: pointer; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(10,6,30,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.card { background: linear-gradient(#3b2b8a, #24195c); border-radius: 22px; padding: 26px 20px; width: min(340px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.crown { font-size: 54px; }
#adMock { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; z-index: 50; }
#toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.85); padding: 10px 18px; border-radius: 12px; z-index: 60; font-size: 15px; max-width: 90%; text-align: center; }

@media (max-height: 700px) { .brand h1 { font-size: 36px; } .brand-dice { display: none; } .pcard { min-height: 54px; } }
