:root {
  --bg-0: #05040a;
  --bg-1: #0d0a1a;
  --bg-2: #1d1533;
  --glass: rgba(22, 16, 40, 0.72);
  --glass-2: rgba(40, 30, 70, 0.55);
  --line: rgba(217, 180, 106, 0.22);
  --line-2: rgba(255, 255, 255, 0.08);
  --gold: #e9bf62;
  --gold-2: #ffd98a;
  --text: #f3eefc;
  --muted: #a99fc4;
  --t0: #3d7bff;
  --t1: #18c47c;
  --t2: #ff3d5e;
  --red-ink: #b81d3c;
  --black-ink: #1d2240;
  --radius: 18px;
  --card-w: 70px;
  --card-h: 98px;
  --ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Cinzel", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ui);
  color: var(--text);
  background: radial-gradient(ellipse 90% 70% at 50% 30%, #2b1d4f 0%, var(--bg-1) 55%, var(--bg-0) 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
input, select, button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 50;
  background: var(--bg-1); transition: opacity .6s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid rgba(233, 191, 98, .2); border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.screen { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.screen > * { pointer-events: auto; }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
}

.muted { color: var(--muted); }

/* ---------- товч ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 12px; cursor: pointer;
  background: var(--glass-2); border: 1px solid var(--line-2);
  font-weight: 700; letter-spacing: .01em;
  transition: transform .15s, background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { background: rgba(70, 55, 120, .6); border-color: var(--line); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, #ffdf94, #d7a242);
  color: #2a1906; border-color: #ffe6ac;
  box-shadow: 0 8px 26px rgba(233, 191, 98, .32), inset 0 1px 0 rgba(255, 255, 255, .6);
}
.btn.primary:hover { background: linear-gradient(180deg, #ffe7ab, #e0ae50); }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 20px; font-size: 1.05rem; }
.btn.small { padding: 7px 12px; font-size: .85rem; border-radius: 10px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  background: var(--glass); border: 1px solid var(--line); font-size: 1.25rem;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

/* ---------- нүүр ---------- */
#home { display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.home-card {
  width: min(420px, 100%); padding: 28px 24px 20px; display: flex; flex-direction: column; gap: 18px;
  animation: rise .7s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.97); } }
.logo-wrap { text-align: center; }
.logo {
  font-family: var(--serif); font-weight: 800; font-size: clamp(2.2rem, 9vw, 3rem);
  margin: 6px 0 0; letter-spacing: .14em;
  background: linear-gradient(180deg, #fff3cf 10%, #e9bf62 55%, #a8772a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgba(233, 191, 98, .35));
}
.tag { margin: 4px 0 0; color: var(--muted); letter-spacing: .2em; font-size: .8rem; text-transform: uppercase; }
.logo-chips { display: flex; justify-content: center; gap: 6px; }
.logo-chips i {
  width: 22px; height: 22px; border-radius: 50%; display: block;
  border: 3px dashed rgba(255, 255, 255, .85);
  animation: bob 2.4s ease-in-out infinite;
}
.logo-chips i:nth-child(2) { animation-delay: .15s; }
.logo-chips i:nth-child(3) { animation-delay: .3s; }
.logo-chips i:nth-child(4) { animation-delay: .45s; }
.logo-chips i:nth-child(5) { animation-delay: .6s; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.c0 { background: var(--t0); box-shadow: 0 0 14px var(--t0); }
.c1 { background: var(--t1); box-shadow: 0 0 14px var(--t1); }
.c2 { background: var(--t2); box-shadow: 0 0 14px var(--t2); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.field input, .join-row input, select {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-2);
  background: rgba(0, 0, 0, .3); color: var(--text); outline: none; font-size: 1rem; font-weight: 600;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .join-row input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(233, 191, 98, .18); }
.block { display: flex; flex-direction: column; gap: 10px; }
.block h3, .settings h3 { margin: 0; font-size: .75rem; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); font-weight: 800; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: .3em; text-align: center; font-family: var(--serif); font-weight: 700; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick-btn { flex-direction: column; gap: 2px; padding: 12px 6px; }
.quick-btn b { font-family: var(--serif); font-size: 1rem; }
.quick-btn small { color: var(--muted); font-weight: 600; font-size: .72rem; }

/* ---------- лобби ---------- */
#lobby { display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.lobby-card {
  width: min(980px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 22px; display: flex; flex-direction: column; gap: 18px;
  animation: rise .5s cubic-bezier(.2, .9, .3, 1.2) both;
}
.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.room-code {
  font-family: var(--serif); font-weight: 800; font-size: 2.4rem; letter-spacing: .25em; line-height: 1.1;
  color: var(--gold-2); text-shadow: 0 0 24px rgba(233, 191, 98, .4);
}
.head-actions { display: flex; gap: 8px; }
.lobby-body { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
.settings { display: flex; flex-direction: column; gap: 14px; }
.layout-group { display: flex; flex-direction: column; gap: 6px; }
.group-label { font-size: .8rem; color: var(--muted); font-weight: 700; }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }
.lay {
  padding: 8px 10px; border-radius: 10px; cursor: pointer; font-family: var(--serif); font-weight: 700; font-size: .85rem;
  background: rgba(0, 0, 0, .25); border: 1px solid var(--line-2); transition: all .2s;
}
.lay small { display: block; font-family: var(--ui); font-size: .65rem; color: var(--muted); font-weight: 600; }
.lay.on { border-color: var(--gold); background: rgba(233, 191, 98, .16); box-shadow: 0 0 0 1px var(--gold) inset; }
.lay:disabled { cursor: default; }
.lay:disabled:not(.on) { opacity: .5; }
.setting-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.setting-row label { display: flex; flex-direction: column; gap: 6px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.setting-row select { padding: 9px 10px; font-size: .9rem; }
.hint { margin: 0; font-size: .8rem; color: var(--muted); }

.teams { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-content: start; }
.team {
  border-radius: 14px; padding: 12px; background: rgba(0, 0, 0, .25);
  border: 1px solid color-mix(in srgb, var(--tc) 45%, transparent);
  box-shadow: inset 0 0 40px color-mix(in srgb, var(--tc) 12%, transparent);
}
.team h4 { margin: 0 0 10px; display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.team h4 .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--tc); box-shadow: 0 0 12px var(--tc); border: 2px dashed rgba(255, 255, 255, .7); }
.seat {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; margin-bottom: 6px;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line-2); min-height: 44px;
}
.seat.me { border-color: var(--tc); background: color-mix(in srgb, var(--tc) 16%, transparent); }
.seat .nm { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .nm.empty { color: var(--muted); font-weight: 500; font-style: italic; }
.seat .tag-s { font-size: .7rem; color: var(--muted); }
.seat .x { width: 26px; height: 26px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, .06); cursor: pointer; }
.seat .off { width: 8px; height: 8px; border-radius: 50%; background: #777; }
.spectators { font-size: .85rem; color: var(--muted); }
.lobby-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.lobby-foot p { margin: 0; flex: 1; }

/* ---------- тоглолт ---------- */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px; pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.scores { flex: 1; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.score {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border-radius: 999px;
  background: var(--glass); border: 1px solid color-mix(in srgb, var(--tc) 60%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-weight: 800; font-size: .85rem;
}
.score.mine { box-shadow: 0 0 0 2px var(--tc), 0 0 22px color-mix(in srgb, var(--tc) 50%, transparent); }
.score .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--tc); border: 2px dashed rgba(255, 255, 255, .8); }
.score .pips { display: flex; gap: 3px; }
.score .pips i { width: 9px; height: 9px; border-radius: 3px; background: rgba(255, 255, 255, .15); transform: rotate(45deg); }
.score .pips i.on { background: var(--gold); box-shadow: 0 0 8px var(--gold); }

.players {
  position: absolute; left: 12px; top: 70px; display: flex; flex-direction: column; gap: 6px;
  max-height: calc(100dvh - 300px); overflow-y: auto; width: 210px; scrollbar-width: none;
}
.players::-webkit-scrollbar { display: none; }
.pl {
  position: relative; display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--line-2); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: border-color .25s, box-shadow .25s, transform .25s; overflow: hidden;
}
.pl.turn { border-color: var(--tc); box-shadow: 0 0 0 1px var(--tc), 0 0 24px color-mix(in srgb, var(--tc) 45%, transparent); transform: translateX(4px); }
.pl .av {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--tc); border: 2px dashed rgba(255, 255, 255, .8); font-size: .75rem; font-weight: 800;
}
.pl .who { flex: 1; min-width: 0; }
.pl .who b { display: block; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl .who small { color: var(--muted); font-size: .7rem; }
.pl .cnt { font-size: .75rem; font-weight: 800; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.pl .cnt::before { content: ""; width: 9px; height: 12px; border-radius: 2px; background: linear-gradient(135deg, #e9bf62, #8d6223); }
.pl .tbar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--tc); width: 0; }
.pl.off { opacity: .55; }
.pl .react { position: absolute; right: 8px; top: 50%; font-size: 1.6rem; animation: pop 1.6s ease-out forwards; pointer-events: none; }
@keyframes pop {
  0% { transform: translateY(-50%) scale(.2); opacity: 0; }
  15% { transform: translateY(-50%) scale(1.25); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(-140%) scale(1); opacity: 0; }
}

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(5, 4, 10, .75) 35%);
  pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.status-row { display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.status {
  padding: 7px 16px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line-2);
  font-weight: 700; font-size: .9rem; text-align: center; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.status.mine { border-color: var(--gold); color: var(--gold-2); animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 24px rgba(233, 191, 98, .45); } }
.timer { width: 180px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.timer i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #ff9f5a); border-radius: 4px; }
.timer.low i { background: #ff4d6d; }

.hand-row { display: flex; align-items: flex-end; gap: 14px; max-width: 100%; }
.hand { display: flex; gap: 6px; padding-top: 18px; overflow-x: auto; scrollbar-width: none; max-width: calc(100vw - 110px); }
.hand::-webkit-scrollbar { display: none; }
.pile { width: calc(var(--card-w) * .8); height: calc(var(--card-h) * .8); position: relative; flex: none; }
.pile .card { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-6deg); pointer-events: none; }
.pile:empty { border: 2px dashed var(--line); border-radius: 10px; }

.card {
  position: relative; width: var(--card-w); height: var(--card-h); flex: none; border-radius: 10px; cursor: pointer; padding: 0;
  background: linear-gradient(180deg, #fffaf0, #e7d7b8); border: 1px solid #fff4d6;
  box-shadow: 0 8px 18px rgba(0, 0, 0, .45), inset 0 0 0 3px rgba(201, 164, 92, .35);
  transition: transform .22s cubic-bezier(.2, .9, .3, 1.3), box-shadow .2s, filter .2s;
  color: var(--black-ink); fill: currentColor; stroke: currentColor; overflow: hidden;
}
.card.red { color: var(--red-ink); }
.card .idx { position: absolute; left: 6px; top: 4px; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.card .idx b { font-family: var(--serif); font-weight: 800; font-size: 1.25rem; letter-spacing: -.04em; }
.card .pip { width: 14px; height: 14px; margin-top: 2px; }
.card .big { position: absolute; right: 7px; bottom: 9px; width: 52%; height: auto; opacity: .95; }
.card .big path { stroke: none; }
.card.jack .big { opacity: 1; }
.card.wild .jack-art { fill: #c9a45c; }
.card.cut .jack-art { fill: none; stroke: var(--red-ink); }
.card .badge {
  position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); font-size: .58rem; font-weight: 800; letter-spacing: .04em;
  padding: 2px 6px; border-radius: 6px; background: #2a1d4a; color: var(--gold-2); white-space: nowrap; text-transform: uppercase;
}
.card.cut .badge { background: var(--red-ink); color: #fff; }
.card .dead-tag {
  display: none; position: absolute; inset: auto 0 38% 0; text-align: center; font-size: .62rem; font-weight: 800;
  background: rgba(20, 14, 34, .85); color: #ffb3c0; padding: 3px 0; transform: rotate(-12deg) scale(1.15); letter-spacing: .08em; text-transform: uppercase;
}
.card.dead { filter: saturate(.3) brightness(.8); }
.card.dead .dead-tag { display: block; }
.hand .card:hover { transform: translateY(-8px); }
.hand .card.sel { transform: translateY(-16px) scale(1.05); box-shadow: 0 0 0 3px var(--gold), 0 14px 30px rgba(233, 191, 98, .45); }
.hand .card.new { animation: deal .5s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes deal { from { transform: translateY(60px) rotate(8deg); opacity: 0; } }
.hand.wait .card { filter: brightness(.82); }
.hand.wait .card.dead { filter: saturate(.3) brightness(.65); }

.actions-row { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.reacts { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line-2); }
.reacts button { width: 32px; height: 28px; border: 0; background: transparent; cursor: pointer; border-radius: 999px; font-size: 1.05rem; transition: transform .15s; }
.reacts button:hover { transform: scale(1.25); background: rgba(255, 255, 255, .06); }

.banner {
  position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); pointer-events: none; text-align: center;
  font-family: var(--serif); font-weight: 800; font-size: clamp(1.6rem, 6vw, 3.2rem); letter-spacing: .08em; opacity: 0;
  text-shadow: 0 0 30px var(--bc, var(--gold)), 0 4px 0 rgba(0, 0, 0, .4); color: #fff; white-space: nowrap;
}
.banner small { display: block; font-family: var(--ui); font-size: .38em; letter-spacing: .2em; color: var(--gold-2); text-transform: uppercase; }
.banner.show { animation: banner 2.2s cubic-bezier(.2, .9, .3, 1.2) forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

.menu {
  position: absolute; left: 12px; top: 62px; padding: 12px; display: flex; flex-direction: column; gap: 6px; width: 240px;
  animation: rise .25s ease-out both;
}
.menu .btn { justify-content: flex-start; }
.menu-code { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; padding: 2px 4px 6px; }
.menu-code b { color: var(--gold-2); font-family: var(--serif); letter-spacing: .2em; }

/* ---------- цонх ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(5, 4, 10, .55); }
.modal-card { position: relative; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; animation: rise .4s cubic-bezier(.2, .9, .3, 1.2) both; }
.modal-card h2 { margin: 0 0 12px; font-family: var(--serif); color: var(--gold-2); }
.close { position: absolute; right: 12px; top: 12px; width: 34px; height: 34px; border-radius: 10px; border: 0; background: rgba(255, 255, 255, .06); cursor: pointer; }
.rules-card ol { padding-left: 20px; display: flex; flex-direction: column; gap: 10px; line-height: 1.5; font-size: .92rem; }
.over-card { text-align: center; overflow: hidden; }
.over-card h2 { font-size: clamp(1.6rem, 6vw, 2.3rem); margin-top: 8px; text-shadow: 0 0 30px var(--tc, var(--gold)); color: #fff; }
.over-burst { width: 90px; height: 90px; margin: 0 auto; border-radius: 50%; background: var(--tc, var(--gold)); border: 6px dashed rgba(255, 255, 255, .85); box-shadow: 0 0 60px var(--tc, var(--gold)); animation: spin 6s linear infinite; }
.over-team { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 14px 0; }
.over-team span { padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, .06); font-weight: 700; font-size: .85rem; }
.over-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -140%); z-index: 60; padding: 11px 18px; border-radius: 12px;
  background: rgba(20, 14, 34, .95); border: 1px solid var(--line); font-weight: 700; font-size: .9rem; transition: transform .35s cubic-bezier(.2, .9, .3, 1.2);
  max-width: calc(100vw - 32px); text-align: center; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- гар утас ---------- */
@media (max-width: 760px) {
  :root { --card-w: 50px; --card-h: 70px; }
  .lobby-body { grid-template-columns: 1fr; }
  .lobby-card { padding: 16px; }
  .room-code { font-size: 2rem; }
  .players {
    left: 0; right: 0; top: 60px; width: auto; flex-direction: row; overflow-x: auto; padding: 0 12px; max-height: none;
  }
  .pl { flex: none; padding: 5px 8px; gap: 6px; }
  .pl.turn { transform: translateY(2px); }
  .pl .av { width: 22px; height: 22px; }
  .pl .who b { max-width: 80px; font-size: .78rem; }
  .pl .who small { display: none; }
  .card .idx b { font-size: .95rem; }
  .card .pip { width: 10px; height: 10px; }
  .card .badge { font-size: .5rem; padding: 1px 4px; }
  .hand { gap: 4px; max-width: calc(100vw - 70px); }
  .hand-row { gap: 8px; }
  .score { padding: 4px 9px 4px 6px; font-size: .75rem; }
  .icon-btn { width: 38px; height: 38px; font-size: 1.05rem; }
  .status { font-size: .8rem; padding: 6px 12px; }
  .reacts button { width: 28px; }
  .menu { top: 104px; }
}
@media (max-width: 380px) {
  :root { --card-w: 44px; --card-h: 62px; }
  .pile { display: none; }
  .hand { max-width: calc(100vw - 24px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
