/* ── Та битгий уурлаарай — «Нар жаргах ширэнгэ» ───────────────────────────
   Самбар доороосоо дээш нар жаргах өнгөөр, могой нь гөлгөр градиент,
   чулуу нь тоглогчийн аватар. Тоо: Unbounded · Текст: Manrope */
:root {
  --bg: #0b1020;
  --bg-2: #141a33;
  --text: #f5f3ff;
  --dim: rgba(245, 243, 255, .6);
  --glass: rgba(255, 255, 255, .07);
  --glass-2: rgba(255, 255, 255, .12);
  --line: rgba(255, 255, 255, .12);
  --lime: #b6ff5c;
  --green: #0fbf7a;
  --gold: #ffc54d;
  --orange: #ff9f1c;
  --pc: #ffffff;           /* тухайн тоглогчийн өнгө (inline) */
  --num: "Unbounded", "Manrope", system-ui, sans-serif;
  --ui: "Manrope", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; border: 0; background: none; }
button { cursor: pointer; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--text); font-family: var(--ui); font-weight: 700;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
img, svg { -webkit-user-drag: none; }

.sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background: radial-gradient(120% 70% at 50% 110%, #3a1d5c 0%, transparent 60%), linear-gradient(180deg, #0b1020, #101634 60%, #1a1240); }
.sky i { position: absolute; border-radius: 50%; filter: blur(70px); }
.sky i:nth-child(1) { width: 70vmax; height: 70vmax; left: -25vmax; top: -25vmax; background: #0fbf7a; opacity: .22; animation: drift 18s ease-in-out infinite alternate; }
.sky i:nth-child(2) { width: 60vmax; height: 60vmax; right: -25vmax; top: 20vh; background: #ff6b3d; opacity: .16; animation: drift 21s ease-in-out infinite alternate-reverse; }
.sky i:nth-child(3) { width: 50vmax; height: 50vmax; left: 10vw; bottom: -30vmax; background: #7c3aed; opacity: .25; animation: drift 16s ease-in-out infinite alternate; }
body[data-screen="table"] .sky { background: radial-gradient(80% 55% at 50% 42%, #28554a 0%, #163b36 55%, #0b2529 100%); }
body[data-screen="table"] .sky i { display: none; }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.1); } }

main#app { position: relative; z-index: 1; width: 100%; max-width: 480px; height: 100%; margin: 0 auto;
  display: flex; flex-direction: column; padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); }
body[data-screen="table"] main#app { max-width: 540px; padding-left: 8px; padding-right: 8px; }
.screen { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }

/* Аватар */
.ava { position: relative; border-radius: 50%; display: grid; place-items: center; overflow: hidden; flex: none;
  font-family: var(--num); font-weight: 800; color: #fff; background: var(--pc); }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* Товч */
.cta { height: 58px; padding: 0 22px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 17px; font-weight: 800; background: #fff; color: var(--bg); box-shadow: 0 12px 30px rgba(0, 0, 0, .35); transition: transform .12s, background .2s, opacity .2s; }
.cta svg { width: 20px; height: 20px; }
.cta.on { background: var(--lime); color: #12300a; }
.cta.go { background: linear-gradient(135deg, var(--lime), var(--green)); color: #062a19; box-shadow: 0 12px 34px rgba(15, 191, 122, .4); }
.cta.wide { width: 100%; }
.cta:disabled { opacity: .3; pointer-events: none; }
.cta:active, .chip:active, .tile:active { transform: scale(.95); }
.chip { height: 42px; padding: 0 16px; border-radius: 16px; display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 800;
  background: var(--glass-2); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); transition: transform .12s; }
.chip svg { width: 18px; height: 18px; }
.hint { font-size: 13px; color: var(--dim); text-align: center; min-height: 18px; font-weight: 600; }

/* ═════ Өрөө ═════ */
.lobby { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.logo svg { width: 112px; height: 112px; filter: drop-shadow(0 12px 30px rgba(15, 191, 122, .35)); animation: bob 3s ease-in-out infinite; }
.logo b { font-family: var(--num); font-weight: 900; font-size: 27px; line-height: 1.08; text-align: center; letter-spacing: -.03em;
  background: linear-gradient(135deg, var(--lime), var(--gold) 60%, var(--orange)); -webkit-background-clip: text; background-clip: text; color: transparent; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.seats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; width: 100%; max-width: 340px; }
.seat { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.seat .ava { width: 62px; height: 62px; font-size: 22px; box-shadow: 0 0 0 3px rgba(255, 255, 255, .12), 0 10px 22px rgba(0, 0, 0, .4); }
.seat.ready .ava { box-shadow: 0 0 0 3px var(--lime), 0 10px 22px rgba(0, 0, 0, .4); }
.seat .nm { font-size: 12px; color: var(--dim); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat.me .nm { color: #fff; }
.seat .tick { position: absolute; top: 44px; right: calc(50% - 38px); width: 22px; height: 22px; border-radius: 50%; background: var(--lime); color: #12300a;
  border: 3px solid var(--bg); display: grid; place-items: center; transform: scale(0); transition: transform .25s cubic-bezier(.34, 1.56, .64, 1); }
.seat .tick svg { width: 11px; height: 11px; }
.seat.ready .tick { transform: scale(1); }
.seat .crown { position: absolute; z-index: 2; top: -13px; font-size: 15px; }
.seat .x { position: absolute; top: -4px; right: calc(50% - 40px); width: 22px; height: 22px; border-radius: 50%; background: var(--glass-2); font-size: 11px; display: grid; place-items: center; z-index: 2; }
.seat.empty .ava { background: transparent; border: 2px dashed rgba(255, 255, 255, .16); box-shadow: none; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 360px; }
.tile { position: relative; aspect-ratio: 1 / .95; border-radius: 26px; padding: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  font-size: 15.5px; line-height: 1.15; text-align: center; color: #fff; overflow: hidden; box-shadow: 0 14px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .35); transition: transform .12s; }
.tile::after { content: ''; position: absolute; width: 130%; height: 60%; left: -15%; top: -32%; border-radius: 50%; background: rgba(255, 255, 255, .14); }
.tile.inv { background: linear-gradient(150deg, #5b8cff, #7c3aed); }
.tile.bots { background: linear-gradient(150deg, #22c55e, #0f9a8a); }
.tile .tile-ic { width: 60px; height: 60px; border-radius: 20px; background: rgba(255, 255, 255, .2); display: grid; place-items: center; }
.tile .tile-ic svg { width: 32px; height: 32px; }
.tile:disabled { opacity: .4; }
.hall-bar { display: flex; gap: 10px; }
.hall-main { display: flex; gap: 10px; width: 100%; max-width: 360px; }
.hall-main .cta { flex: 1; }

/* ═════ Самбар ═════ */
.board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.board {
  position: relative; width: min(100%, var(--bw, 100%)); aspect-ratio: 1;
}
.cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(10, 1fr); }
.cell { position: relative; }
.cell.lit { animation: lit .5s ease-out; }
@keyframes lit { from { box-shadow: inset 0 0 0 3px #fff, 0 0 18px #fff; } }
.tokens, .fx { position: absolute; inset: 0; pointer-events: none; }
.tok {
  position: absolute; width: 7.6%; aspect-ratio: 1; transform: translate(-50%, -50%); z-index: 3;
  border-radius: 50%; padding: 0; background: var(--pc);
  box-shadow: 0 6px 12px rgba(0, 0, 0, .45), 0 0 0 2px #fff;
  transition: left .16s, top .16s, width .2s, transform .2s;
}
.tok .ava { width: 100%; height: 100%; font-size: clamp(9px, 2.6vw, 13px); box-shadow: none; }
.tok.me { z-index: 4; }
.tok.active { z-index: 5; transform: translate(-50%, -50%) scale(1.3); box-shadow: 0 6px 14px rgba(0, 0, 0, .5), 0 0 0 2px #fff, 0 0 0 4px var(--pc); animation: tokPulse 1.1s ease-in-out infinite; }
@keyframes tokPulse { 50% { box-shadow: 0 6px 14px rgba(0, 0, 0, .5), 0 0 0 2px #fff, 0 0 0 4px var(--pc), 0 0 0 10px color-mix(in srgb, var(--pc) 40%, transparent); } }
.burst { position: absolute; transform: translate(-50%, -50%) scale(.4); opacity: 0; z-index: 8; white-space: nowrap;
  font-family: var(--num); font-weight: 900; font-size: clamp(16px, 5vw, 24px); color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, .3), 0 0 18px var(--glow, #fff);
  transition: transform .4s cubic-bezier(.34, 1.56, .64, 1), opacity .25s; }
.burst.show { transform: translate(-50%, -140%) scale(1); opacity: 1; }
.bubble { position: absolute; transform: translate(-50%, -100%) scale(.6); opacity: 0; z-index: 9; max-width: 150px; padding: 7px 12px; border-radius: 14px 14px 14px 4px;
  background: #fff; color: var(--bg); font-size: 12.5px; font-weight: 800; transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), opacity .2s; box-shadow: 0 10px 24px rgba(0, 0, 0, .4); overflow-wrap: anywhere; text-align: center; }
.bubble.emoji { background: none; box-shadow: none; font-size: 32px; padding: 0; }
.bubble.show { transform: translate(-50%, -100%) scale(1); opacity: 1; }

/* ═════ Шоо + доод мөр ═════ */
.dock { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding-top: 14px; min-height: 112px; }
.me-chip { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-chip .ava { width: 40px; height: 40px; font-size: 15px; box-shadow: 0 0 0 2.5px var(--pc); }
.me-chip .tx { min-width: 0; display: flex; flex-direction: column; }
.me-chip .nm { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-chip .pos { font-family: var(--num); font-size: 18px; font-weight: 800; }
.me-chip .pos small { font-size: .55em; color: var(--dim); }
.dock-info { justify-self: end; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; }
.dock-info .turn { font-size: 13px; font-weight: 800; padding: 7px 12px; border-radius: 14px; background: var(--pc); color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .2); white-space: nowrap; }
.dock-info .wait { font-size: 12px; color: var(--dim); max-width: 120px; }
.chat-btn { width: 40px; height: 40px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); font-size: 18px; }

.dice { position: relative; width: 84px; height: 84px; perspective: 500px; border-radius: 22px; }
.dice::before { content: ''; position: absolute; inset: -10px; border-radius: 30px; border: 3px solid var(--pc); opacity: 0; box-shadow: 0 0 26px var(--pc); transition: opacity .3s; }
.dice.can::before { opacity: 1; animation: ring 1.3s ease-in-out infinite; }
.dice.can:active { transform: translateY(3px); }
@keyframes ring { 50% { opacity: .35; transform: scale(1.06); } }
.dice:disabled { cursor: default; }
.die {
  position: absolute; inset: 12px; transform-style: preserve-3d;
}
.die-cube { position: absolute; inset: 0; transform-style: preserve-3d; }
.die-face {
  position: absolute; inset: 0; border-radius: 10px; padding: 9px; backface-visibility: hidden;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  background: linear-gradient(145deg, #fffef6, #f4e7cc 65%, #d6bd92);
  border: 1px solid #bca47d;
  box-shadow: inset 0 2px 1px #fff, inset 0 -3px 2px #bca47d66;
}
.die-face[data-v="1"] { transform: translateZ(30px); }
.die-face[data-v="2"] { transform: rotateX(90deg) translateZ(30px); }
.die-face[data-v="3"] { transform: rotateY(90deg) translateZ(30px); }
.die-face[data-v="4"] { transform: rotateY(-90deg) translateZ(30px); }
.die-face[data-v="5"] { transform: rotateX(-90deg) translateZ(30px); }
.die-face[data-v="6"] { transform: rotateY(180deg) translateZ(30px); }
.die-face b { width: 10px; height: 10px; border-radius: 50%; place-self: center; visibility: hidden;
  background: #263b30; box-shadow: inset 0 2px 2px #071c16, 0 1px 0 #fff; }
.die-face[data-v="1"] b:nth-child(5) { visibility: visible; width: 14px; height: 14px; background: #c94a3c; box-shadow: inset 0 2px 2px #8f2922, 0 1px 0 #fff; }
.die-face[data-v="2"] b:is(:nth-child(3), :nth-child(7)),
.die-face[data-v="3"] b:is(:nth-child(3), :nth-child(5), :nth-child(7)),
.die-face[data-v="4"] b:is(:nth-child(1), :nth-child(3), :nth-child(7), :nth-child(9)),
.die-face[data-v="5"] b:is(:nth-child(1), :nth-child(3), :nth-child(5), :nth-child(7), :nth-child(9)),
.die-face[data-v="6"] b:is(:nth-child(1), :nth-child(3), :nth-child(4), :nth-child(6), :nth-child(7), :nth-child(9)) { visibility: visible; }

/* ═════ Үр дүн ═════ */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(6, 8, 18, .55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 456px; max-height: 100%; overflow-y: auto; border-radius: 30px; padding: 22px 16px 16px;
  background: linear-gradient(180deg, rgba(32, 28, 66, .97), rgba(14, 12, 30, .98)); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px; animation: up .4s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hero .ava { width: 86px; height: 86px; font-size: 32px; box-shadow: 0 0 0 4px var(--gold), 0 0 40px rgba(255, 197, 77, .6); }
.hero .k { font-size: 11px; letter-spacing: .4em; color: var(--dim); padding-left: .4em; }
.hero .big { font-family: var(--num); font-size: 26px; font-weight: 900; letter-spacing: -.03em; text-align: center; }
.ranks { display: flex; flex-direction: column; gap: 8px; }
.rk { display: grid; grid-template-columns: 22px 36px 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 18px; background: var(--glass); }
.rk.me { background: var(--glass-2); box-shadow: inset 0 0 0 1px var(--line); }
.rk.win { background: linear-gradient(90deg, rgba(255, 197, 77, .22), var(--glass)); }
.rk .pos { font-family: var(--num); font-size: 12px; color: var(--dim); text-align: center; }
.rk .ava { width: 36px; height: 36px; font-size: 13px; box-shadow: 0 0 0 2px var(--pc); }
.rk .nm { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk .sq { font-family: var(--num); font-size: 16px; }
.records { width: 100%; }
.tabs { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: var(--glass); margin-bottom: 8px; }
.tab { flex: 1; height: 34px; border-radius: 10px; font-size: 13px; color: var(--dim); }
.tab.on { background: #fff; color: var(--bg); }
.rec-list { display: flex; flex-direction: column; gap: 6px; min-height: 56px; }
.rec { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px; font-size: 13px; }
.rec.me { background: var(--glass-2); }
.rec .ava { width: 28px; height: 28px; font-size: 11px; }
.rec .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-empty { text-align: center; color: var(--dim); font-size: 13px; padding: 12px 0; font-weight: 600; }

/* Чат */
.chat { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 75; width: min(94vw, 420px); padding: 12px; border-radius: 22px;
  background: rgba(30, 26, 62, .97); border: 1px solid var(--line); box-shadow: 0 18px 40px rgba(0, 0, 0, .5); display: flex; flex-direction: column; gap: 10px; animation: up .22s; }
.chat-emojis { display: flex; justify-content: space-between; }
.chat-emojis button { font-size: 26px; width: 42px; height: 42px; border-radius: 12px; }
.chat-phrases { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-phrases button { padding: 8px 12px; border-radius: 14px; background: var(--glass); font-size: 13px; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; height: 42px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); padding: 0 12px; font-size: 16px; outline: none; -webkit-user-select: text; user-select: text; }
.chat-form button { width: 42px; height: 42px; border-radius: 14px; background: #fff; color: var(--bg); font-size: 18px; }

.toast { position: fixed; left: 50%; top: max(14px, env(safe-area-inset-top)); z-index: 95; transform: translate(-50%, -24px); opacity: 0; padding: 11px 18px; border-radius: 16px;
  background: #fff; color: var(--bg); font-size: 14px; font-weight: 800; box-shadow: 0 14px 34px rgba(0, 0, 0, .45); transition: transform .3s cubic-bezier(.3, 1.3, .4, 1), opacity .25s; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.offline { position: fixed; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 91; width: 34px; height: 34px; border-radius: 50%; background: rgba(0, 0, 0, .5); display: grid; place-items: center; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spinr .8s linear infinite; display: inline-block; }
@keyframes spinr { to { transform: rotate(360deg); } }

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

/* Тоглолтын нам гүм ширээ. */
body[data-screen="table"] { --text: #eceef0; --dim: #9aa1a8; --glass: #2a2e34; --glass-2: #343941; --line: #3f454d; --num: "Manrope", system-ui, sans-serif; }
body[data-screen="table"] .sky { background: #1d2025; }
body[data-screen="table"] main#app { max-width: 540px; padding: max(18px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom)); }
#table { gap: 12px; justify-content: center; }
#table .board-wrap { flex: 0 1 auto; }
.strip { display: flex; justify-content: center; gap: 6px; flex: none; }
.pl { flex: 1 1 0; max-width: 110px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px 8px; border-radius: 16px; background: #2a2e34; border: 1px solid transparent; }
.pl .ava { width: 52px; height: 52px; font-size: 19px; }
.pl .tx { max-width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.15; }
.pl .nm { font-size: 13px; color: #9aa1a8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl b { font: 700 18px var(--num); color: #eceef0; min-width: 2ch; }
.pl.turn { border-color: var(--pc); }
.board { border: 7px solid #ff6500; border-radius: 10px; background: url(/board.webp) center / cover; box-shadow: 0 12px 32px #0000004d; }
.credit { position: absolute; right: 0; top: calc(100% + 9px); font-size: 9px; color: #6b7076; }
.dock { border-top: 1px solid #3a4048; padding: 14px 4px 0; min-height: 0; height: 120px; }
.me-chip .ava { width: 34px; height: 34px; font-size: 12px; }
.me-chip .pos { font-size: 20px; }
.dock-info .turn { border-radius: 8px; background: #3a4048; color: #ffffff; font-size: 11px; text-shadow: none; padding: 6px 9px; }
.dock-info .wait { font-size: 11px; }
.go-btn { border: 0; border-radius: 16px; background: var(--pc); color: #fff; font: 800 20px var(--ui); padding: 16px 30px; cursor: pointer; animation: go-in .2s ease-out; }
.go-btn:disabled { opacity: .5; }
@keyframes go-in { from { transform: scale(.85); opacity: 0; } }
.chat-btn { border-radius: 10px; width: 36px; height: 36px; }
.dice::before { border: 1px solid #d9dde1; box-shadow: none; inset: -4px; border-radius: 23px; }
.die-face { background: #f7f7f5; border-color: #3a4048; box-shadow: inset 0 -2px 0 #dcdfe2; }
@media (max-height: 650px) { #table { gap: 7px; } .dock { height: 108px; padding-top: 6px; } }
/* Өргөн дэлгэц: самбар өндрөөрөө, тоглогчид ба шоо баруун талд */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  body[data-screen="table"] main#app { max-width: none; }
  #table { display: grid; grid-template-columns: min(calc(100dvh - 34px), calc(100vw - 388px)) 300px; grid-template-rows: 1fr auto auto 1fr; grid-template-areas: "board ." "board strip" "board dock" "board ."; justify-content: center; align-content: stretch; column-gap: 32px; row-gap: 16px; }
  #table .board-wrap { grid-area: board; min-height: 0; }
  .strip { grid-area: strip; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .pl { max-width: none; padding: 14px 6px 12px; }
  .pl .ava { width: 64px; height: 64px; font-size: 24px; }
  .pl .nm { font-size: 14px; }
  .pl b { font-size: 22px; }
  .dock { grid-area: dock; border-top: 0; padding: 8px 0 0; }
}
