:root {
  --bg: var(--tg-theme-bg-color, #f4f6fb);
  --text: var(--tg-theme-text-color, #1d1d1f);
  --muted: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: Vazirmatn, Tahoma, "Segoe UI", sans-serif; overflow: hidden; user-select: none; }
.screen { display: none; height: 100%; padding: 16px; }
.screen.active { display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; gap: 12px; text-align: center; }
h1 { margin: 0 0 4px; font-size: 30px; } h2 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); margin: 0; }
.big { font-size: 32px; font-weight: bold; margin: 0; }
.btn { width: 100%; max-width: 320px; padding: 14px; border: 0; border-radius: 12px; font: inherit; font-size: 17px;
  background: var(--card); color: var(--text); box-shadow: 0 1px 4px #0002; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.small { width: auto; padding: 12px 18px; }
.btn:active { transform: scale(.97); }
.row { display: flex; gap: 8px; width: 100%; max-width: 320px; }
.row input { flex: 1; min-width: 0; padding: 12px; border-radius: 12px; border: 1px solid #0002; font: inherit; font-size: 18px;
  text-align: center; letter-spacing: 4px; text-transform: uppercase; background: var(--card); color: var(--text); direction: ltr; }
.code { font-size: 40px; font-weight: bold; letter-spacing: 8px; margin: 0; direction: ltr; }
.slots { list-style: none; padding: 0; margin: 4px 0; width: 100%; max-width: 320px; }
.slots li { padding: 10px; margin: 6px 0; border-radius: 10px; background: var(--card); display: flex; gap: 8px; align-items: center; }
.slots li.empty { opacity: .5; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; }
.spinner { width: 42px; height: 42px; border: 4px solid #0001; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#screen-game { padding: 8px; gap: 6px; align-items: center; }
#board { width: 100%; max-width: min(96vw, 60vh); aspect-ratio: 1; flex: none; }
.tags { direction: ltr; display: flex; justify-content: space-between; width: 100%; max-width: min(96vw, 60vh); gap: 8px; }
.tag { flex: 1; padding: 6px 8px; border-radius: 10px; background: var(--card); font-size: 13px; display: flex; align-items: center; gap: 6px;
  border: 2px solid transparent; min-height: 36px; direction: rtl; overflow: hidden; white-space: nowrap; }
.tag.turn { border-color: var(--accent); box-shadow: 0 0 0 3px #2481cc33; }
.tag .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tag .timer { font-weight: bold; color: var(--accent); }
.tag.offline { opacity: .55; }
.controls { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 4px; }
#status { margin: 0; min-height: 22px; font-size: 15px; }
.dice { width: 76px; height: 76px; padding: 10px; font-size: 36px; border-radius: 18px; border: 0; background: var(--card); box-shadow: 0 2px 8px #0003; cursor: pointer; }
.dice:not(:disabled) { animation: pulse 1s ease-in-out infinite; outline: 3px solid var(--accent); }
.dice:disabled { opacity: .7; }
.dice.rolling { animation: shake .4s; }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes shake { 25% { transform: rotate(-15deg); } 75% { transform: rotate(15deg); } }
.piece { transition: transform .3s ease; }
.piece.can { cursor: pointer; animation: bob .7s ease-in-out infinite alternate; }
@keyframes bob { to { opacity: .55; } }
.overlay { position: fixed; inset: 0; background: #0008; display: flex; align-items: center; justify-content: center; }
.overlay.hidden, .toast.hidden { display: none; }
.card { background: var(--bg); padding: 20px; border-radius: 16px; width: 86%; max-width: 340px; text-align: center; }
.card ol { text-align: right; font-size: 17px; line-height: 2; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90%; }
.dice svg { width: 100%; height: 100%; display: block; }
