/* My Ludo — UI */
:root {
  --bg0: #070b1f; --bg1: #0b1026; --bg2: #151b45;
  --surface: rgba(255,255,255,.055); --surface2: rgba(255,255,255,.09); --line: rgba(255,255,255,.09); --line2: rgba(255,255,255,.16);
  --text: #eef2ff; --muted: #98a2d3; --dim: #6b75a8;
  --gold1: #fde68a; --gold2: #f5b70a; --gold3: #d48806;
  --ok: #10b981; --bad: #ef4444;
  --c0: #ef4444; --c1: #22c55e; --c2: #f5b70a; --c3: #3b82f6;
  --r-lg: 22px; --r-md: 16px; --r-sm: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --ease: cubic-bezier(.22,.9,.3,1);
  --board: min(calc(100vw - 20px), calc(100dvh - 222px), 620px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Cairo", "Segoe UI", Tahoma, system-ui, sans-serif;
  color: var(--text); background: var(--bg1);
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.bg-glow { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: radial-gradient(120% 90% at 50% -10%, var(--bg2), var(--bg1) 55%, var(--bg0)); }
.bg-glow i { position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(80px); opacity: .22; animation: drift 22s ease-in-out infinite alternate; }
.bg-glow i:nth-child(1) { background: #6d28d9; top: -25vmax; right: -20vmax; }
.bg-glow i:nth-child(2) { background: #0ea5e9; bottom: -30vmax; left: -25vmax; animation-delay: -8s; opacity: .16; }
.bg-glow i:nth-child(3) { background: #f59e0b; top: 40%; left: 40%; width: 30vmax; height: 30vmax; opacity: .07; animation-delay: -14s; }
@keyframes drift { to { transform: translate(4vmax, 3vmax) scale(1.08); } }

#app { min-height: 100dvh; max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom); }
.screen { display: none; padding: 12px 4px 28px; }
.screen.active { display: block; animation: enter .38s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(10px) scale(.99); } }

/* ---------- common ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; margin-bottom: 12px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.card-h { font-weight: 800; margin-bottom: 12px; display: flex; gap: 6px; align-items: center; }
.muted { color: var(--muted); font-size: .88rem; }
.center { text-align: center; justify-content: center; }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row > * { flex: 1; }
.btn { border: 0; border-radius: var(--r-md); padding: 13px 16px; font-weight: 800; transition: transform .15s var(--ease), filter .2s, box-shadow .2s, background .2s; position: relative; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.gold { background: linear-gradient(180deg, var(--gold1) -40%, var(--gold2) 45%, var(--gold3)); color: #2a1a00; box-shadow: 0 8px 22px rgba(245,183,10,.28), inset 0 1px 0 rgba(255,255,255,.55); }
.btn.gold:hover { filter: brightness(1.06); }
.btn.glass { background: var(--surface2); border: 1px solid var(--line); }
.btn.glass:hover { background: rgba(255,255,255,.13); }
.btn.small { padding: 9px 14px; font-size: .88rem; border-radius: var(--r-sm); }
.btn.wide { width: 100%; margin-top: 14px; }
.btn.copied { background: var(--ok) !important; color: #fff !important; }
.link { background: none; border: 0; color: var(--gold2); font-weight: 700; font-size: .85rem; padding: 4px; }
.icon-btn { width: 42px; height: 42px; flex: none; border-radius: 14px; border: 1px solid var(--line); background: var(--surface2); display: grid; place-items: center; font-size: 1.05rem; position: relative; transition: background .2s, transform .15s; }
.icon-btn:active { transform: scale(.93); }
.icon-btn.copied { background: var(--ok); }
input { width: 100%; padding: 12px 14px; border-radius: var(--r-sm); border: 1px solid var(--line2); background: rgba(0,0,0,.28); outline: none; font-size: 16px; transition: border-color .2s; }
input:focus { border-color: var(--gold2); }
.seg { display: flex; background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); padding: 9px 6px; border-radius: 10px; font-weight: 700; font-size: .9rem; transition: background .2s, color .2s; white-space: nowrap; }
.seg button.on { background: linear-gradient(180deg, rgba(255,255,255,.2), rgba(255,255,255,.1)); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; background: var(--surface2); border: 1px solid var(--line); font-size: .78rem; font-weight: 700; white-space: nowrap; }
.chip.magic { background: linear-gradient(90deg, rgba(168,85,247,.35), rgba(236,72,153,.3)); border-color: rgba(236,72,153,.35); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: rgba(255,255,255,.16); transition: background .25s; }
.switch i::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); transition: transform .3s var(--ease); }
.switch input:checked + i { background: linear-gradient(90deg, #a855f7, #ec4899); }
.switch input:checked + i::after { transform: translateX(-20px); }
.switch input:disabled + i { opacity: .5; }

/* ---------- home ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 22px; }
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 46px; height: 46px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; transform: rotate(-10deg); filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
.mark i { border-radius: 7px; }
.mark i:nth-child(1) { background: linear-gradient(135deg, #fca5a5, var(--c0)); }
.mark i:nth-child(2) { background: linear-gradient(135deg, #86efac, var(--c1)); }
.mark i:nth-child(3) { background: linear-gradient(135deg, #93c5fd, var(--c3)); }
.mark i:nth-child(4) { background: linear-gradient(135deg, #fde68a, var(--c2)); }
.word { display: flex; flex-direction: column; line-height: 1.1; }
.word b { font-size: 1.55rem; font-weight: 900; direction: ltr; letter-spacing: .3px; background: linear-gradient(90deg, #fff, #c7d2fe); -webkit-background-clip: text; background-clip: text; color: transparent; }
.word small { color: var(--muted); font-size: .74rem; font-weight: 600; }
.profile { display: flex; align-items: center; gap: 8px; background: var(--surface2); border: 1px solid var(--line); border-radius: 99px; padding: 4px 6px 4px 12px; max-width: 48%; cursor: text; }
.profile .pav { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #2a1a00; background: linear-gradient(135deg, var(--gold1), var(--gold2)); }
.profile input { border: 0; background: none; padding: 4px 0; font-weight: 700; font-size: 15px; min-width: 0; }
.profile .pen { color: var(--dim); font-size: .85rem; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 10px; font-weight: 800; color: #dfe4ff; }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.mode-cards button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-lg); padding: 14px 6px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; transition: transform .2s var(--ease), border-color .2s, background .2s, box-shadow .2s; }
.mode-cards .mi { width: 46px; height: 46px; display: grid; place-items: center; font-size: 1.5rem; border-radius: 14px; background: rgba(255,255,255,.07); transition: transform .3s var(--ease); }
.mode-cards b { font-size: 1rem; }
.mode-cards small { color: var(--muted); font-size: .72rem; line-height: 1.35; text-align: center; }
.mode-cards button.on { border-color: rgba(245,183,10,.7); background: linear-gradient(180deg, rgba(245,183,10,.16), rgba(245,183,10,.04)); box-shadow: 0 8px 24px rgba(245,183,10,.12); transform: translateY(-2px); }
.mode-cards button.on .mi { transform: scale(1.08) rotate(-6deg); background: rgba(245,183,10,.18); }
.magic-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); cursor: pointer; margin-bottom: 18px; transition: border-color .25s, background .25s; }
.magic-card .mc-ic { width: 42px; height: 42px; flex: none; border-radius: 13px; display: grid; place-items: center; font-size: 1.3rem; background: linear-gradient(135deg, rgba(168,85,247,.4), rgba(236,72,153,.35)); }
.magic-card .mc-txt { flex: 1; display: flex; flex-direction: column; line-height: 1.35; }
.magic-card small { color: var(--muted); font-size: .76rem; }
.magic-card:has(input:checked) { border-color: rgba(236,72,153,.5); background: linear-gradient(90deg, rgba(168,85,247,.14), rgba(236,72,153,.08)); }
.magic-card.small { margin: 10px 0 0; padding: 8px 12px; }
.magic-card.small .mc-ic { width: 34px; height: 34px; font-size: 1.05rem; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.xl { display: flex; align-items: center; gap: 12px; padding: 16px; text-align: right; border-radius: var(--r-lg); }
.btn.xl .bi { width: 44px; height: 44px; flex: none; display: grid; place-items: center; font-size: 1.35rem; border-radius: 14px; background: rgba(255,255,255,.18); }
.btn.gold.xl .bi { background: rgba(255,255,255,.35); }
.btn.xl b { display: block; font-size: 1.05rem; }
.btn.xl small { display: block; font-weight: 600; font-size: .74rem; opacity: .75; }
.actions-row .btn.xl { flex-direction: column; text-align: center; gap: 6px; padding: 14px 8px; }
.foot { text-align: center; color: var(--dim); font-size: .74rem; margin-top: 22px; }
.dev-credit { display: flex; align-items: center; justify-content: center; gap: 7px; width: max-content; margin: 10px auto 4px; padding: 5px 14px 5px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .78rem; text-decoration: none; transition: border-color .2s, color .2s; }
.dev-credit:hover { color: #fff; border-color: var(--gold2); }
.dev-credit img { border-radius: 50%; }
.dev-credit b { color: var(--gold2); font-weight: 800; letter-spacing: .3px; }

/* ---------- sheets ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(3,6,20,.6); backdrop-filter: blur(3px); z-index: 30; animation: fadeIn .25s; }
@keyframes fadeIn { from { opacity: 0; } }
.sheet { position: fixed; left: 50%; bottom: 0; width: min(560px, 100%); transform: translate(-50%, 105%); z-index: 31; background: linear-gradient(180deg, #1a2150, #10153a); border: 1px solid var(--line2); border-bottom: 0; border-radius: 26px 26px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); transition: transform .38s var(--ease); box-shadow: 0 -20px 50px rgba(0,0,0,.45); }
.sheet.open { transform: translate(-50%, 0); }
.sheet .grab { width: 42px; height: 5px; border-radius: 9px; background: rgba(255,255,255,.22); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 8px; text-align: center; font-size: 1.15rem; }
.sheet .sheet-chips { margin-bottom: 14px; }
.field-l { font-size: .82rem; color: var(--muted); font-weight: 700; margin: 12px 4px 6px; }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick { border: 1px solid var(--line2); background: var(--surface2); border-radius: var(--r-lg); padding: 18px 8px; display: flex; flex-direction: column; gap: 2px; transition: transform .15s, background .2s, border-color .2s; }
.pick b { font-size: 1.25rem; }
.pick small { color: var(--muted); }
.pick:hover { border-color: rgba(245,183,10,.6); background: rgba(245,183,10,.1); }
.pick:active { transform: scale(.97); }
.or { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: .8rem; margin: 16px 0 4px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line2); }
.row.join input { flex: 1.5; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; min-height: 46px; }
.topbar .title { flex: 1; min-width: 0; text-align: center; font-weight: 800; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.topbar .title > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chips.mini { justify-content: center; margin-top: 2px; gap: 4px; }
.chips.mini .chip { font-size: .64rem; padding: 0 7px; }
.voice-ctl { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; padding: 3px; }
.ctl { width: 46px; height: 42px; border: 0; border-radius: 12px; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; position: relative; transition: background .2s; }
.ctl .ic { font-size: 1rem; line-height: 1; }
.ctl .lb { font-size: .56rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.ctl.on { background: rgba(16,185,129,.22); }
.ctl.on .lb { color: #6ee7b7; }
.ctl.off { background: rgba(239,68,68,.18); }
.ctl.off .lb { color: #fca5a5; }
.ctl.off::after { content: ""; position: absolute; left: 13px; right: 13px; top: 15px; height: 2.5px; background: #fca5a5; transform: rotate(-40deg); border-radius: 2px; }
.ctl.speak { box-shadow: 0 0 0 2px #34d399 inset; }

/* ---------- search ---------- */
#search { text-align: center; }
.radar { position: relative; width: 180px; height: 180px; margin: 26px auto 18px; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(245,183,10,.5); animation: ping 2.4s var(--ease) infinite; }
.radar span:nth-child(2) { animation-delay: .8s; } .radar span:nth-child(3) { animation-delay: 1.6s; }
@keyframes ping { from { transform: scale(.35); opacity: 1; } to { transform: scale(1.1); opacity: 0; } }
.radar-core { position: absolute; inset: 50px; border-radius: 50%; display: grid; place-items: center; font-size: 2.2rem; background: radial-gradient(circle at 35% 30%, #2b347a, #141a45); border: 1px solid var(--line2); box-shadow: 0 0 40px rgba(245,183,10,.25); animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.search-h { margin: 6px 0 2px; font-size: 1.3rem; }
.search-sub { color: var(--muted); margin: 0 0 12px; font-size: .9rem; }
.search-timer { font-size: 1.6rem; font-weight: 900; letter-spacing: 2px; margin: 12px 0; direction: ltr; color: var(--gold1); font-variant-numeric: tabular-nums; }
.slots { display: flex; justify-content: center; gap: 14px; margin: 10px 0 8px; flex-wrap: wrap; }
.slot { width: 64px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .74rem; color: var(--muted); }
.slot .sa { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 1.2rem; border: 2px dashed var(--line2); color: var(--dim); }
.slot.filled .sa { border: 2px solid transparent; color: #111; animation: popIn .4s var(--ease); }
.slot .nm { max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes popIn { from { transform: scale(.4); opacity: 0; } }

/* ---------- lobby ---------- */
.code-card { text-align: center; }
.code-row { display: flex; align-items: center; justify-content: center; gap: 12px; direction: ltr; }
.code { font-size: 2.3rem; font-weight: 900; letter-spacing: 9px; margin: 2px 0 8px; background: linear-gradient(180deg, var(--gold1), var(--gold2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.share-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.members { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); animation: enter .3s var(--ease); }
.members li:last-child { border: 0; }
.av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #111; flex: none; background: #a5b4fc; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.members .nm { flex: 1; font-weight: 700; }
.members .tag { font-size: .7rem; padding: 2px 9px; border-radius: 99px; background: var(--surface2); color: var(--muted); font-weight: 700; }
.members li.empty { opacity: .45; }
.members li.empty .av { background: transparent; border: 2px dashed var(--line2); color: var(--dim); box-shadow: none; }
.members .kick { background: none; border: 0; color: #fca5a5; font-size: 1rem; }
#lobbyChips { margin-top: 10px; }

/* ---------- game ---------- */
#game.screen { padding-top: 6px; }
.game-top .title #gameTitle { font-size: .95rem; }
.table { width: var(--board); margin: 0 auto; }
.prow { display: flex; justify-content: space-between; gap: 8px; height: 64px; }
.prow.top { margin-bottom: 8px; } .prow.bottom { margin-top: 8px; }
.panel { flex: 1; max-width: 49%; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); position: relative; transition: background .3s, box-shadow .3s, transform .3s var(--ease); visibility: hidden; }
.panel.show { visibility: visible; }
.panel[data-corner="1"], .panel[data-corner="2"] { flex-direction: row-reverse; text-align: right; }
.panel.turn { background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.06)); box-shadow: 0 0 0 1.5px var(--pc) inset, 0 8px 22px rgba(0,0,0,.25); transform: translateY(-1px); }
.panel.out { opacity: .6; }
.panel .avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; position: relative;
  background: conic-gradient(var(--pc) calc(var(--p, 1) * 360deg), rgba(255,255,255,.1) 0); }
.panel .avatar b { width: 39px; height: 39px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff8, transparent 45%), var(--pc); display: grid; place-items: center; color: #111; font-weight: 900; border: 2.5px solid var(--bg1); }
.panel .avatar.speak::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2.5px solid #34d399; animation: speak 1s ease-in-out infinite; }
@keyframes speak { 50% { transform: scale(1.08); opacity: .4; } }
.panel .info { min-width: 0; flex: 1; }
.panel .pname { font-weight: 800; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel .psub { font-size: .7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel .rank { position: absolute; top: -10px; font-size: 1.3rem; filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }
.panel[data-corner="0"] .rank, .panel[data-corner="3"] .rank { left: -6px; }
.panel[data-corner="1"] .rank, .panel[data-corner="2"] .rank { right: -6px; }
.panel .badges { position: absolute; bottom: -8px; display: flex; gap: 3px; }
.panel[data-corner="0"] .badges, .panel[data-corner="3"] .badges { left: 42px; }
.panel[data-corner="1"] .badges, .panel[data-corner="2"] .badges { right: 42px; }
.panel .badges span { background: #141a45; border: 1px solid var(--line2); border-radius: 99px; padding: 0 6px; font-size: .72rem; line-height: 1.5; }
/* dice: a glossy gem in the player's colour with white pips */
.dice { width: 46px; height: 46px; flex: none; border-radius: 12px; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 7px; gap: 1px; position: relative; overflow: hidden;
  background: radial-gradient(circle at 28% 22%, rgba(255,255,255,.6), transparent 42%),
              linear-gradient(145deg, color-mix(in srgb, var(--pc, #6366f1) 70%, #fff), var(--pc, #6366f1) 50%, color-mix(in srgb, var(--pc, #6366f1) 62%, #000));
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.22), inset 0 2px 0 rgba(255,255,255,.35), 0 6px 14px rgba(0,0,0,.35); visibility: hidden; transition: transform .2s var(--ease); }
.dice.vis { visibility: visible; animation: popIn .3s var(--ease); }
.dice i { border-radius: 50%; margin: 1px; transition: background .1s; position: relative; z-index: 1; }
.dice i.p { background: radial-gradient(circle at 38% 32%, #fff, #e2e8f0 60%, #94a3b8); box-shadow: 0 1px 1px rgba(0,0,0,.35); }
/* before rolling: a faint five-pip emblem, a centre star, and a light sweep */
.dice.idle i:nth-child(odd) { background: rgba(255,255,255,.28); }
.dice.idle i:nth-child(5) { background: none; }
.dice.idle::before { content: "★"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 17px; text-shadow: 0 1px 3px rgba(0,0,0,.4); z-index: 2; }
.dice.idle::after { content: ""; position: absolute; inset: -40%; background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,.55) 50%, transparent 60%); animation: diceShine 2.4s ease-in-out infinite; z-index: 3; }
@keyframes diceShine { 0% { transform: translateX(-60%); } 55%, 100% { transform: translateX(60%); } }
.dice.mine { cursor: pointer; animation: bob 1.1s ease-in-out infinite; box-shadow: inset 0 -3px 0 rgba(0,0,0,.22), inset 0 2px 0 rgba(255,255,255,.35), 0 0 0 3px var(--gold2), 0 8px 22px rgba(245,183,10,.55); }
.dice.golden { background: radial-gradient(circle at 28% 22%, rgba(255,255,255,.7), transparent 42%), linear-gradient(145deg, #fff3b0, #facc15 55%, #c98a10); }
.dice.golden i.p { background: radial-gradient(circle at 38% 32%, #78350f, #422006); }
.dice.golden.idle i:nth-child(odd) { background: rgba(120,53,15,.3); }
.dice.golden.idle i:nth-child(5) { background: none; }
.dice.golden.idle::before { color: #78350f; text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.dice.rolling { animation: roll .5s linear infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes roll { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(200deg) scale(.82); } 100% { transform: rotate(360deg) scale(1); } }
.bubble { position: absolute; bottom: calc(100% + 6px); background: #fff; color: #111; padding: 6px 12px; border-radius: 14px; font-size: .95rem; font-weight: 700; white-space: nowrap; z-index: 5; animation: popIn .25s var(--ease); box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.prow.top .bubble { bottom: auto; top: calc(100% + 6px); }

.board-wrap { position: relative; width: var(--board); height: var(--board); }
#board { width: 100%; height: 100%; display: block; filter: drop-shadow(0 18px 30px rgba(0,0,0,.5)); touch-action: manipulation; }
.tok { transition: transform .17s var(--ease); }
.tok.jump { transition: transform .5s cubic-bezier(.3,1.5,.6,1); }
.tok .hopper { transform-box: fill-box; transform-origin: 50% 80%; }
.tok.hop .hopper { animation: hop .17s ease-out; }
@keyframes hop { 40% { transform: translateY(-0.28px) scale(1.12); } }
.tok .ring { opacity: 0; }
.tok .jbadge { display: none; }
.tok.joint .jbadge { display: inline; }
.tok.can { cursor: pointer; }
.tok.can .ring { opacity: 1; animation: ringspin 2.2s linear infinite; transform-box: fill-box; transform-origin: center; }
.tok.can .hopper { animation: canbob .9s ease-in-out infinite; }
@keyframes ringspin { to { transform: rotate(360deg); } }
@keyframes canbob { 50% { transform: translateY(-0.1px); } }
.prop { pointer-events: none; }
.prop .glow { animation: glow 1.5s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes glow { 50% { opacity: .3; transform: scale(1.25); } }
.prop-pop { animation: proppop .55s ease forwards; transform-box: fill-box; transform-origin: center; }
@keyframes proppop { to { transform: scale(2.4); opacity: 0; } }
.toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.7); background: rgba(10,14,40,.9); border: 1px solid var(--line2); padding: 10px 20px; border-radius: 16px; font-weight: 800; opacity: 0; pointer-events: none; transition: opacity .2s, transform .3s var(--ease); white-space: nowrap; direction: rtl; box-shadow: var(--shadow); z-index: 4; }
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.joint-pick { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(10,14,40,.95); border: 1px solid var(--line2); border-radius: 18px; padding: 12px; z-index: 6; box-shadow: var(--shadow); text-align: center; animation: popIn .25s var(--ease); min-width: 220px; }
.joint-pick .jp-h { font-weight: 800; margin-bottom: 8px; font-size: .9rem; }
.joint-pick .row { margin-top: 0; }
.joint-pick .btn { padding: 10px 8px; font-size: .85rem; }
.gtoast { position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px); background: rgba(10,14,40,.95); border: 1px solid var(--line2); padding: 11px 18px; border-radius: 14px; opacity: 0; transition: .3s var(--ease); pointer-events: none; z-index: 60; max-width: 92vw; text-align: center; font-weight: 700; font-size: .9rem; box-shadow: var(--shadow); }
.gtoast.show { opacity: 1; transform: translateX(-50%); }
.emoji-pop { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: linear-gradient(180deg, #1a2150, #10153a); border: 1px solid var(--line2); border-radius: 20px; padding: 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; z-index: 30; width: min(360px, 94vw); box-shadow: var(--shadow); animation: popIn .22s var(--ease); }
.emoji-pop button { border: 0; background: var(--surface2); border-radius: 12px; padding: 9px 4px; font-size: .86rem; font-weight: 700; transition: background .15s, transform .1s; }
.emoji-pop button:active { transform: scale(.94); }
.emoji-pop button.e { font-size: 1.5rem; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(3,6,20,.72); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 40; padding: 16px; animation: fadeIn .25s; }
[hidden] { display: none !important; }
.modal { background: linear-gradient(180deg, #1c2456, #10153a); border: 1px solid var(--line2); border-radius: 26px; padding: 22px; width: min(400px, 100%); text-align: center; animation: popIn .35s var(--ease); box-shadow: 0 30px 60px rgba(0,0,0,.5); }
.modal h2 { margin: 4px 0 14px; }
.trophy { font-size: 3.2rem; line-height: 1; filter: drop-shadow(0 8px 18px rgba(245,183,10,.45)); animation: popIn .5s var(--ease); }
.ranks { list-style: none; padding: 0; margin: 0 0 6px; }
.ranks li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 7px; font-weight: 700; animation: enter .4s var(--ease) backwards; }
.ranks li:nth-child(2) { animation-delay: .08s; } .ranks li:nth-child(3) { animation-delay: .16s; } .ranks li:nth-child(4) { animation-delay: .24s; }
.ranks li.me { border-color: rgba(245,183,10,.55); background: rgba(245,183,10,.1); }
.ranks .medal { font-size: 1.4rem; width: 30px; }
.ranks .av { width: 28px; height: 28px; }
.rules-modal { text-align: right; max-height: 88dvh; display: flex; flex-direction: column; }
.rules-modal h2 { text-align: center; }
.rules-modal .seg button { font-size: .8rem; padding: 8px 2px; }
.rules-list { list-style: none; padding: 0; margin: 12px 0 0; overflow-y: auto; }
.rules-list li { display: flex; gap: 12px; padding: 11px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 7px; font-size: .88rem; line-height: 1.65; }
.rules-list li b { font-size: 1.35rem; flex: none; width: 32px; text-align: center; }
.rules-list li strong { display: block; color: var(--gold1); }

/* ---------- responsive ---------- */
@media (max-width: 400px) {
  .prow { height: 58px; }
  .panel { padding: 4px 6px; gap: 6px; border-radius: 15px; }
  .panel .avatar { width: 40px; height: 40px; } .panel .avatar b { width: 33px; height: 33px; font-size: .85rem; }
  .dice { width: 40px; height: 40px; padding: 6px; }
  .panel .pname { font-size: .78rem; }
  .ctl { width: 40px; } .ctl .lb { font-size: .5rem; }
  .icon-btn { width: 38px; height: 38px; border-radius: 12px; }
  .mode-cards small { font-size: .66rem; }
  .btn.xl small { display: none; }
}
@media (orientation: landscape) and (max-height: 540px) {
  :root { --board: min(calc(100dvh - 20px), 520px); }
  #app { max-width: none; }
  #game .table { display: grid; grid-template-columns: 180px var(--board) 180px; grid-template-rows: 1fr 1fr; width: auto; justify-content: center; gap: 8px 12px; }
  #game .prow { display: contents; }
  #game .board-wrap { grid-column: 2; grid-row: 1 / 3; }
  #game .panel { max-width: none; height: 64px; }
  #game .panel[data-corner="0"] { grid-column: 1; grid-row: 1; align-self: start; }
  #game .panel[data-corner="1"] { grid-column: 3; grid-row: 1; align-self: start; }
  #game .panel[data-corner="3"] { grid-column: 1; grid-row: 2; align-self: end; }
  #game .panel[data-corner="2"] { grid-column: 3; grid-row: 2; align-self: end; }
  #game .topbar { position: fixed; top: 6px; right: 8px; z-index: 10; margin: 0; flex-direction: column; min-height: 0; }
  #game .topbar .title { display: none; }
  #game .voice-ctl { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
