:root {
  --bg: #12141a;
  --card: #1c1f28;
  --card2: #252937;
  --line: #2f3443;
  --text: #f2f3f7;
  --muted: #9aa1b5;
  --accent: #ff7a1a;
  --accent2: #ffb35c;
  --good: #2ecc71;
  --bad: #ff4d4d;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); color: var(--text); min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none;
  /* To'liq ekranda: tepadagi soat/kamera va Telegram tugmalari ostida qolmaslik uchun xavfsiz chegaralar */
  padding-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  padding-bottom: var(--tg-safe-area-inset-bottom, 0px); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select { font: inherit; color: var(--text); background: var(--card2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; font-size: 16px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.screen { max-width: 560px; margin: 0 auto; padding: 16px 16px 32px; }
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 16px; }

.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; font-weight: 700; font-size: 17px;
  background: var(--card2); text-align: center; }
.btn.primary { background: linear-gradient(180deg, var(--accent2), var(--accent)); color: #1a0d00; }
.btn:active { transform: scale(.98); }

.logo { font-size: 38px; font-weight: 900; letter-spacing: 2px; }
.logo span { color: var(--accent); }

/* Ro'yxatdan o'tish */
.reg { display: flex; flex-direction: column; gap: 10px; padding-top: 40px; }
.reg .logo { text-align: center; }
.reg p { text-align: center; margin-bottom: 14px; }
.reg label { font-size: 14px; color: var(--muted); margin-top: 6px; }
.ac { position: relative; }
.sugg { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--card2);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; z-index: 5; }
.sugg button { display: block; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sugg button:last-child { border-bottom: 0; }
.sugg button small { color: var(--muted); }
.sugg .other { color: var(--accent2); }
.picked { background: rgba(255,122,26,.1); border: 1px solid rgba(255,122,26,.35); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.err { color: var(--bad); min-height: 20px; text-align: center; font-size: 14px; }

/* Bosh sahifa */
.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.profile .main { flex: 1; min-width: 0; }
/* Avatar: Telegram rasmi, bo'lmasa bosh harf */
.av { position: relative; width: 36px; height: 36px; border-radius: 50%; flex: none; overflow: hidden;
  background: linear-gradient(135deg, var(--accent2), var(--accent)); display: inline-grid; place-items: center; }
.av::before { content: attr(data-i); font-weight: 900; color: #1a0d00; font-size: 15px; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.av.lg { width: 48px; height: 48px; }
.av.lg::before { font-size: 20px; }
.av.xl { width: 76px; height: 76px; margin: 0 auto; }
.av.xl::before { font-size: 32px; }
.avwrap { position: relative; flex: none; display: inline-flex; }
.avwrap .dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%;
  background: #6b7287; border: 2px solid var(--card); }
.avwrap .dot.on { background: var(--good); }
.online { color: var(--good); }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--card2); font-size: 18px; flex: none; }
.row.mine { background: rgba(255,122,26,.08); }
.lvl.sm { width: 22px; height: 22px; font-size: 11px; border-width: 2px; vertical-align: middle; }
.lvl.sm.cal { font-size: 7px; }
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 4px; }
.theme { background: var(--card2); border-radius: 14px; padding: 10px; border: 2px solid transparent; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 8px; }
.theme.active { border-color: var(--accent); }
.sw { display: grid; grid-template-columns: 1fr 1fr; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; }
.pname { font-weight: 800; font-size: 18px; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; }
.conn.on { background: var(--good); }
.tabs { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; padding: 10px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tabs button.active { background: var(--card2); color: var(--text); }

.games { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gcard { background: var(--card); border-radius: 16px; padding: 16px 14px; text-align: left; position: relative;
  border: 1px solid var(--line); min-height: 128px; display: flex; flex-direction: column; }
.gcard .gi { font-size: 34px; line-height: 1; margin-bottom: 10px; }
.gcard .gn { font-weight: 800; }
.gcard .gt { font-size: 13px; color: var(--muted); margin-top: auto; padding-top: 8px; }
.gcard .lvl { position: absolute; top: 12px; right: 12px; }
.gcard.soon { opacity: .45; }
.gcard.soon .gt { color: var(--accent2); }

/* FACEIT uslubidagi daraja nishoni */
.lvl { --c: #cfcfcf; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--c); color: var(--c); font-weight: 900; font-size: 14px; background: rgba(0,0,0,.25); flex: none; }
.lvl.big { width: 64px; height: 64px; font-size: 28px; border-width: 5px; }
.lvl.cal { --c: #6b7287; font-size: 10px; border-style: dashed; }
.lvl.big.cal { font-size: 16px; }

/* Reyting */
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; }
.chips button { padding: 8px 14px; border-radius: 999px; background: var(--card); white-space: nowrap; font-weight: 600; font-size: 14px; }
.chips button.active { background: var(--accent); color: #1a0d00; }
.list { background: var(--card); border-radius: 16px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .rk { width: 26px; text-align: center; font-weight: 800; color: var(--muted); flex: none; }
.row .rk.top { color: var(--accent2); }
.row .main { flex: 1; min-width: 0; }
.row .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .val { font-weight: 800; text-align: right; }
.row.dim { opacity: .5; }
.note { font-size: 12px; color: var(--muted); padding: 10px 4px; line-height: 1.5; }
.empty { padding: 28px 14px; text-align: center; color: var(--muted); }

/* Navbat */
.queue .big-icon { font-size: 64px; }
.queue .qt { font-size: 22px; font-weight: 800; }
.queue .timer { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--accent2); }

/* O'yin */
.game { padding: 4px 3px 24px; max-width: 640px; }
.pbar { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.pbar .main { flex: 1; min-width: 0; }
.pbar .nm { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbar .sub { font-size: 12px; color: var(--muted); }
.clock { font-variant-numeric: tabular-nums; font-weight: 900; font-size: 24px; padding: 6px 12px; border-radius: 10px;
  background: var(--card); min-width: 92px; text-align: center; }
.clock.active { background: #f2f3f7; color: #12141a; }
.clock.low { background: var(--bad); color: #fff; }

.board { --bw: min(calc(100vw - 6px), 620px); width: var(--bw); height: var(--bw); margin: 0 auto; position: relative;
  border-radius: 4px; overflow: hidden; touch-action: none; }

.status { text-align: center; padding: 10px; min-height: 42px; font-weight: 600; }
.status.warn { color: var(--accent2); }
.actions { display: flex; gap: 10px; padding: 0 6px; }
.actions .btn { font-size: 15px; padding: 12px; }
.moves { padding: 12px 8px; font-size: 13px; color: var(--muted); line-height: 1.7; word-spacing: 2px; }
.moves b { color: var(--text); font-weight: 600; }

/* Modal oynalar */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 24px 16px 28px; text-align: center;
  display: flex; flex-direction: column; gap: 10px; animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { font-size: 28px; }
.sheet .reason { color: var(--muted); margin-bottom: 6px; }
.sheet .rating { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 8px 0 12px; }
.delta { font-size: 26px; font-weight: 900; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.promo { display: flex; gap: 10px; justify-content: center; }
.promo button { width: 68px; height: 68px; background: var(--card2); border-radius: 12px; position: relative; }
.promo .pc { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(0,0,0,.85);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 30; max-width: 90vw; }
.toast.show { opacity: 1; }
.link { color: var(--muted); font-size: 13px; padding: 6px; text-decoration: underline; }

.actions .full-btn { flex: 0 0 52px; font-size: 22px; padding: 8px 0; }
.brand-logo { width: 132px; height: 132px; margin: 0 auto; display: block; filter: drop-shadow(0 8px 24px rgba(255,122,26,.25)); }
.reg .brand-logo { margin-bottom: 4px; }
.gcard .excl { font-size: 11px; color: var(--accent2); margin-top: 4px; font-weight: 700; }

/* Karvon o'rgatuvchisi */
.tut { gap: 12px; }
.tut-dots { display: flex; gap: 6px; justify-content: center; }
.tut-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tut-dots i.on { background: var(--accent); width: 22px; border-radius: 4px; }
.tut-d { color: var(--text); font-size: 15px; line-height: 1.55; text-align: left; }
.tut-d .c0 { color: #b8bcc6; } .tut-d .c1 { color: #6fa8e8; } .tut-d .c2 { color: #f2b544; }
.tut-nav { display: flex; gap: 10px; }
.tut-nav .btn:first-child:not(.primary) { flex: 0 0 64px; }
.mb-row { display: flex; gap: 10px; justify-content: center; align-items: center; }
.mb-row .mini-board { width: 30%; }
.mini-board { display: grid; grid-template-columns: repeat(var(--n), 1fr); width: min(62vw, 230px); margin: 0 auto; border-radius: 6px; overflow: hidden;
  box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.mb-sq { position: relative; aspect-ratio: 1; }
.mb-sq.l { background: var(--light-sq); } .mb-sq.d { background: var(--dark-sq); }
.mb-sq.dot::after { content: ""; position: absolute; left: 35%; top: 35%; width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 85, 30, .6); }
.mb-sq.cap::before { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 3px solid rgba(200, 30, 30, .75); z-index: 2; }
.mb-pc { position: absolute; inset: 6%; background: center / contain no-repeat url('/pieces/disc/w.svg'); display: grid; place-items: center; font-size: 140%; }
.mb-pc.b { background-image: url('/pieces/disc/b.svg'); }
.mb-pc .pw { position: absolute; right: -4%; top: -4%; min-width: 46%; height: 40%; border-radius: 99px; display: grid; place-items: center;
  font: 800 10px system-ui, sans-serif; color: #1a1a1a; border: 1.5px solid rgba(0,0,0,.35); }
.mb-pc .pw.p0 { background: #b8bcc6; } .mb-pc .pw.p1 { background: #6fa8e8; } .mb-pc .pw.p2 { background: #f2b544; }
.mb-big { font-size: 64px; text-align: center; }
.actions .help-btn { flex: 0 0 52px; font-size: 20px; padding: 8px 0; }
.profile-edit { text-align: left; min-width: 0; }
.profile-edit .edit-ic { font-size: 13px; opacity: .6; }
.city-picker { display: flex; flex-direction: column; gap: 10px; }
.city-picker label { font-size: 14px; color: var(--muted); margin-top: 6px; }

/* Lobby */
.lobby-stats { display: flex; justify-content: space-around; background: var(--card); border-radius: 12px; padding: 10px; margin-bottom: 12px; font-size: 14px; }
.lobby-stats b { font-size: 16px; }
.seek .seek-g { font-size: 22px; width: 26px; text-align: center; flex: none; }
.seek .seek-btn { width: auto; flex: none; padding: 8px 14px; font-size: 14px; }
.seek .seek-btn:disabled { opacity: .5; }
.seek .lock { color: var(--bad); }
.tabs button { font-size: 14px; padding: 10px 4px; }
.lv-custom { display: flex; gap: 8px; align-items: center; justify-content: center; }
.lv-custom select { width: 80px; }
.sheet .chips { flex-wrap: wrap; overflow: visible; }

/* Telefon yotqizilganda (balandlik kichik): taxta chapda va ekran balandligi bo'yicha katta, qolgani o'ngda */
@media (orientation: landscape) and (max-height: 560px) {
  .game { max-width: none; display: grid; grid-template-columns: auto minmax(210px, 1fr); grid-template-rows: auto auto auto auto 1fr;
    column-gap: 12px; align-items: start; padding: 4px 8px; }
  .game .board { grid-column: 1; grid-row: 1 / span 5; --bw: min(calc(100vh - 12px), 620px); margin: 0; }
  /* Narda: haqiqiy taxtadek keng; ustunlar balandligi ekran balandligidan */
  .game .board.nd { --bw: min(calc(100vw - 236px), 1000px); --hh: calc((100vh - 96px) / 2); }
  .game .board.nd .die { max-width: 50px; max-height: 50px; }
  .game .board.nd .nd-mid { min-height: 0; padding: 0 6px; }
  .game #opp { grid-column: 2; grid-row: 1; }
  .game #me { grid-column: 2; grid-row: 2; }
  .game .status { grid-column: 2; grid-row: 3; }
  .game .actions { grid-column: 2; grid-row: 4; }
  .game .moves { grid-column: 2; grid-row: 5; max-height: 30vh; overflow-y: auto; }
}
.rotate-hint { text-align: center; font-size: 13px; color: var(--muted); padding: 2px 8px 6px; }
@media (orientation: landscape) and (max-height: 560px) { .rotate-hint { display: none; } }

/* Narda: telefon tik bo'lsa ham ekran 90° buriladi (yotqizilgan ko'rinish).
   Taxta butun ekranni egallaydi; o'yinchilar, soat va tugmalar — tepada ingichka bitta qatorda.
   Burilganda telefonning tepasi (Telegram tugmalari, kamera) chap tomonga tushadi — u yerga joy qoldiramiz. */
#app.force-land { position: fixed; top: 0; left: 0; width: 100vh; height: 100vw; overflow: hidden; background: var(--bg);
  transform-origin: top left; transform: translateX(100vw) rotate(90deg);
  padding-left: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 4px); }
#app.force-land .game { max-width: none; height: 100%; display: grid; grid-template-columns: 1fr 1fr auto auto;
  grid-template-rows: 44px 1fr; column-gap: 8px; row-gap: 4px; align-items: center; padding: 2px 6px 4px; }
#app.force-land .game .board.nd { grid-column: 1 / -1; grid-row: 2; margin: 0 auto; align-self: start;
  --bw: calc(100vh - var(--tg-safe-area-inset-top, 0px) - var(--tg-content-safe-area-inset-top, 0px) - 24px);
  --hh: calc((100vw - 44px - 92px) / 2); }
#app.force-land .game .board.nd .die { max-width: 48px; max-height: 48px; }
#app.force-land .game .board.nd .nd-mid { min-height: 0; padding: 0 6px; }
#app.force-land .game #opp { grid-column: 1; grid-row: 1; }
#app.force-land .game #me { grid-column: 2; grid-row: 1; }
#app.force-land .game .status { grid-column: 3; grid-row: 1; min-height: 0; padding: 0 4px; font-size: 13px; max-width: 30vh; }
#app.force-land .game .actions { grid-column: 4; grid-row: 1; padding: 0; }
#app.force-land .game .actions .btn { flex: 0 0 40px; padding: 6px 0; font-size: 16px; }
#app.force-land .game #resignBtn { flex: 0 0 auto; padding: 6px 10px; font-size: 13px; }
#app.force-land .pbar { padding: 0; gap: 6px; min-width: 0; }
#app.force-land .pbar .av { width: 28px; height: 28px; }
#app.force-land .pbar .sub { display: none; }
#app.force-land .pbar .nm { font-size: 13px; }
#app.force-land .clock { font-size: 17px; min-width: 64px; padding: 3px 8px; }
#app.force-land .moves, #app.force-land .rotate-hint { display: none; }
