:root {
  --bg: var(--tg-theme-bg-color, #10141c);
  --bg2: var(--tg-theme-secondary-bg-color, #181e29);
  --text: var(--tg-theme-text-color, #eef1f6);
  --muted: var(--tg-theme-hint-color, #8b95a7);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5484d;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px; line-height: 1.4;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
h1 { font-size: 30px; margin: 8px 0 4px; letter-spacing: -0.5px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

#app { max-width: 520px; margin: 0 auto; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); min-height: 100vh; }
.screen { display: none; animation: fade .18s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--bg2); color: var(--text);
  padding: 12px 14px; border-radius: var(--radius);
  font-size: 15px; font-weight: 600;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; padding: 16px; font-size: 16px; }

.home-head { text-align: center; padding: 18px 0 8px; }
.logo { display: flex; justify-content: center; gap: 6px; }
.logo-piece { width: 34px; height: 34px; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0,0,0,.25), 0 3px 8px rgba(0,0,0,.35); }
.logo-piece.w { background: radial-gradient(circle at 35% 30%, #fff, #d9d4c7); }
.logo-piece.b { background: radial-gradient(circle at 35% 30%, #5b5b5b, #111); margin-top: 10px; }

.profile-chip { display: flex; align-items: center; gap: 10px; background: var(--bg2); padding: 10px 12px; border-radius: var(--radius); margin: 14px 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.menu { display: grid; gap: 10px; }
.menu-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.back { background: none; border: 0; color: var(--accent); font-size: 16px; padding: 6px 2px; cursor: pointer; }

.levels { display: grid; gap: 10px; margin: 8px 0 18px; }
.level { text-align: left; border: 0; background: var(--bg2); color: var(--text); padding: 16px; border-radius: var(--radius); cursor: pointer; display: flex; flex-direction: column; gap: 2px; font-size: 16px; }
.level span { color: var(--muted); font-size: 13px; }
.level:active { transform: scale(0.98); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg2); border-radius: var(--radius); padding: 4px; }
.seg button { border: 0; background: none; color: var(--text); padding: 10px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); }

.wait-box { text-align: center; padding: 50px 10px; display: grid; gap: 18px; justify-items: center; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--bg2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* O'yinchi panellari */
.player-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px; }
.pb-left { display: flex; align-items: center; gap: 10px; }
.pb-dot { width: 22px; height: 22px; border-radius: 50%; }
.pb-dot.w { background: radial-gradient(circle at 35% 30%, #fff, #cfc9ba); }
.pb-dot.b { background: radial-gradient(circle at 35% 30%, #555, #0d0d0d); }
.pb-name { font-weight: 700; }
.pb-timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 8px; background: var(--bg2); min-width: 54px; text-align: center; }
.pb-timer:empty { display: none; }
.pb-timer.low { background: var(--danger); color: #fff; }
.player-bar.turn .pb-name::after { content: " • yurish"; color: var(--accent); font-weight: 600; font-size: 12px; }

.status { text-align: center; min-height: 22px; color: var(--muted); font-size: 13.5px; margin: 4px 0 8px; }
.game-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.game-actions .btn { padding: 11px 6px; font-size: 13.5px; }
.game-actions .btn[hidden] { display: none; }

/* Taxta */
.board-wrap { width: 100%; aspect-ratio: 1; border-radius: 10px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; position: relative; --light: #f0dab4; --dark: #a9744c; --hl: rgba(255, 221, 87, .45); --target: rgba(90, 220, 120, .85); }
.sq { position: relative; display: grid; place-items: center; }
.sq.l { background: var(--light); }
.sq.d { background: var(--dark); }
.sq.last { box-shadow: inset 0 0 0 100px var(--hl); }
.sq.sel { box-shadow: inset 0 0 0 3px #ffd84d, inset 0 0 0 100px rgba(255,216,77,.25); }
.sq.target::after { content: ""; width: 30%; height: 30%; border-radius: 50%; background: var(--target); box-shadow: 0 0 0 3px rgba(0,0,0,.15); }
.sq.movable .pc { box-shadow: 0 0 0 3px rgba(255,216,77,.9), inset 0 -5px 0 rgba(0,0,0,.25), 0 3px 6px rgba(0,0,0,.45); }
.coord { position: absolute; font-size: 9px; opacity: .55; left: 3px; top: 1px; color: var(--light); pointer-events: none; }

.pc { width: 78%; height: 78%; border-radius: 50%; position: relative; transition: transform .15s ease; box-shadow: inset 0 -5px 0 rgba(0,0,0,.25), 0 3px 6px rgba(0,0,0,.45); display: grid; place-items: center; }
.pc.dead { opacity: .3; transform: scale(.85); }
.pc.k::after { content: "♛"; font-size: 150%; line-height: 1; opacity: .9; }
.pc.w { background: radial-gradient(circle at 35% 30%, var(--w1, #ffffff), var(--w2, #d6cfbd)); color: var(--wk, #a1793f); }
.pc.b { background: radial-gradient(circle at 35% 30%, var(--b1, #5a5a5a), var(--b2, #0e0e0e)); color: var(--bk, #e2b955); }
.pc.pop { animation: pop .22s ease; }
@keyframes pop { 0% { transform: scale(.7); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* Taxta dizaynlari */
.board.board_green { --light: #eeeed2; --dark: #769656; }
.board.board_ocean { --light: #dfe9f3; --dark: #4b7399; }
.board.board_marble { --light: #f4f1ec; --dark: #8d8a86; }
.board.board_marble .sq.d { background: linear-gradient(135deg, #9a9692 0%, #7d7a77 45%, #a3a09b 55%, #7a7773 100%); }
.board.board_marble .sq.l { background: linear-gradient(135deg, #fbf9f6, #ebe6df); }
.board.board_night { --light: #2d3446; --dark: #141a28; --hl: rgba(120, 170, 255, .35); }
.board.board_night .sq.d { background: radial-gradient(circle at 50% 50%, #1b2336, #10151f); }
.board.board_samarqand { --light: #f3ead5; --dark: #1f6f8b; }
.board.board_samarqand .sq.d { background:
    radial-gradient(circle at 50% 50%, transparent 30%, rgba(255,255,255,.08) 31%, transparent 34%),
    conic-gradient(from 45deg, #1d6a86 0 25%, #237c9b 0 50%, #1d6a86 0 75%, #237c9b 0);
}
.board.board_samarqand .sq.l { background: radial-gradient(circle at 50% 50%, #f7efdc 40%, #ead9b3 100%); }

/* Dona dizaynlari */
.board.pieces_gold  { --w1: #ffe9a6; --w2: #c99a2e; --wk: #7a4f00; --b1: #c0392b; --b2: #5e0f0a; --bk: #ffd36b; }
.board.pieces_neon  { --w1: #b9fbff; --w2: #19c3d6; --wk: #003b45; --b1: #ff8bf1; --b2: #a1159b; --bk: #fff; }
.board.pieces_neon .pc { box-shadow: 0 0 10px currentColor, inset 0 -5px 0 rgba(0,0,0,.25); }
.board.pieces_emerald { --w1: #e9fff2; --w2: #9ed9b6; --wk: #0b5d34; --b1: #29a36a; --b2: #0a3d24; --bk: #e6ffef; }
.board.pieces_royal { --w1: #ffffff; --w2: #c8c8d8; --wk: #5b2bab; --b1: #6a3fc2; --b2: #24104a; --bk: #ffd86b; }
.board.pieces_royal .pc::before { content: ""; position: absolute; inset: 14%; border-radius: 50%; border: 2px solid rgba(255,216,107,.7); }

/* Do'kon */
.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.item { background: var(--bg2); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; }
.item .preview { aspect-ratio: 1; border-radius: 10px; overflow: hidden; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.item .name { font-weight: 700; font-size: 14px; }
.item .btn { padding: 9px; font-size: 13.5px; }
.item.equipped { box-shadow: 0 0 0 2px var(--accent); }

/* Maslahat paketlari */
.hint-packs { display: grid; gap: 8px; }
.hint-pack { display: flex; justify-content: space-between; align-items: center; background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; }
.hint-pack .btn { padding: 9px 14px; font-size: 13.5px; }

/* Homiy reklamasi */
.sponsor-slot:empty { display: none; }
.sponsor-slot { margin-top: 14px; }
.sponsor { display: flex; gap: 12px; align-items: center; background: var(--bg2); border-radius: var(--radius); padding: 10px; text-decoration: none; color: var(--text); text-align: left; position: relative; cursor: pointer; }
.sponsor img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; }
.sponsor .s-title { font-weight: 700; font-size: 14.5px; }
.sponsor .s-text { color: var(--muted); font-size: 13px; margin-top: 2px; }
.sponsor .s-cta { color: var(--accent); font-weight: 600; font-size: 13px; margin-top: 4px; }
.sponsor .s-tag { position: absolute; top: 6px; right: 8px; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.modal .sponsor { margin-bottom: 4px; }

/* Reyting */
.card { background: var(--bg2); border-radius: var(--radius); padding: 14px; }
.rules p { margin: 0 0 10px; }
.leaders { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.leaders li { display: flex; justify-content: space-between; background: var(--bg2); padding: 10px 12px; border-radius: 10px; }
.leaders li.me { box-shadow: 0 0 0 2px var(--accent); }
.leaders .pos { color: var(--muted); width: 28px; display: inline-block; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; margin-top: 10px; }
.stats b { display: block; font-size: 18px; }

/* Modal va toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal[hidden] { display: none; }
.modal-box { background: var(--bg); border-radius: 18px; padding: 22px; width: 100%; max-width: 360px; text-align: center; animation: fade .2s ease; }
.modal-box h2 { font-size: 22px; margin-bottom: 6px; }
.modal-actions { display: grid; gap: 8px; margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #000c; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; }
.toast[hidden] { display: none; }
