/* Цвета — из темы Telegram (--tg-theme-*), запасные — для браузера */
:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
    --text: var(--tg-theme-text-color, #111111);
    --hint: var(--tg-theme-hint-color, #8a8f98);
    --accent: var(--tg-theme-button-color, #2f7ff5);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --danger: var(--tg-theme-destructive-text-color, #e5484d);
    --red: #ef4444;
    --yellow: #facc15;
    --board: #2456d6;
    --hole: var(--bg);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

h1 { font-size: 22px; margin: 4px 0 0; text-align: center; }

.muted { color: var(--hint); text-align: center; }

/* Игроки */
.players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.player {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-radius: 14px; background: var(--bg2);
    border: 2px solid transparent; transition: border-color .2s, transform .2s;
    min-width: 0; min-height: 64px;
}
.player.right { flex-direction: row-reverse; text-align: right; }
.player.active { border-color: var(--accent); transform: scale(1.03); }
.player .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .you { font-size: 12px; color: var(--hint); font-weight: 400; }
.vs { color: var(--hint); font-weight: 700; font-size: 13px; }

.chip { width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.chip.c0 { background: var(--red); }
.chip.c1 { background: var(--yellow); }

/* Поле «4 в ряд» */
.board {
    --cols: 7;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: 6px;
    padding: 8px;
    background: var(--board);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(36, 86, 214, .25);
}
.col { display: grid; grid-template-rows: repeat(6, 1fr); gap: 6px; border-radius: 12px; cursor: pointer; }
.col.playable:active, .col.playable:hover { background: rgba(255,255,255,.12); }
.cell {
    aspect-ratio: 1; border-radius: 50%; background: var(--hole);
    box-shadow: inset 0 3px 6px rgba(0,0,0,.25); position: relative; overflow: hidden;
}
.cell .disc {
    position: absolute; inset: 0; border-radius: 50%;
    box-shadow: inset 0 -4px 0 rgba(0,0,0,.18);
}
.cell .disc.c0 { background: var(--red); }
.cell .disc.c1 { background: var(--yellow); }
.cell .disc.drop { animation: drop var(--t, .4s) cubic-bezier(.45, 0, .7, 1.25); }
.cell .disc.win { animation: pulse 1s ease-in-out infinite; box-shadow: 0 0 0 3px #fff inset; }

@keyframes drop { from { transform: translateY(calc(var(--rows, 6) * -118%)); } to { transform: translateY(0); } }
@keyframes pulse { 50% { transform: scale(.82); } }

/* Статус и кнопки */
.status { text-align: center; font-weight: 600; min-height: 24px; }
.status.win { color: var(--accent); font-size: 18px; }

.btn {
    display: block; width: 100%; padding: 14px; border: 0; border-radius: 12px;
    background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--danger); font-weight: 500; padding: 8px; }
.btn:disabled { opacity: .5; }

.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    background: rgba(0,0,0,.8); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
    animation: fade 2.4s forwards; pointer-events: none; max-width: 90vw; text-align: center;
}
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

.loader {
    margin: 40vh auto 0; width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--bg2); border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { margin-top: 20vh; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.empty .big { font-size: 56px; }
