/* ===== Сброс и переменные ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f172a;
    --bg-2: #1e293b;
    --surface: #273449;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #22c55e;
    --primary-dark: #16a34a;
    --danger: #ef4444;
    --accent: #f59e0b;
    --border: #334155;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(0,0,0,.35);
}

html, body { height: 100%; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: radial-gradient(circle at 20% 0%, #1e293b 0%, var(--bg) 55%);
    color: var(--text);
    line-height: 1.45;
    overflow: hidden;               /* приложение, а не документ */
}

.screen { display: none; width: 100%; height: 100dvh; overflow: auto; }
.screen.active { display: flex; flex-direction: column; }

/* ===== Общие компоненты ===== */
.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px 20px;
    border: 0;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .12s ease, filter .12s ease;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #052e16; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-primary:active, .btn-secondary:active { transform: scale(.97); }
.btn-link {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: .9rem;
    cursor: pointer;
    padding: 8px 4px;
    text-decoration: underline;
    text-underline-offset: 3px;
}

input {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text);
    font-size: 1.05rem;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }

.error { color: var(--danger); font-size: .9rem; margin-top: 10px; text-align: center; }
.hint  { color: var(--muted); font-size: .9rem; margin-bottom: 10px; }

/* ===== Экран авторизации ===== */
#screen-auth {
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: rgba(30, 41, 59, .82);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 32px 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}

.logo { text-align: center; margin-bottom: 24px; }
.logo h1 {
    font-size: 1.9rem;
    letter-spacing: .04em;
    margin-top: 8px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#auth-step-phone, #auth-step-code { display: flex; flex-direction: column; gap: 12px; }
#auth-step-code [hidden] { display: none; }

/* ===== Экран лобби ===== */
.topbar,
.game-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: rgba(30,41,59,.7);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#screen-lobby { padding: 0; }
.lobby-card {
    margin: auto;
    width: calc(100% - 32px);
    max-width: 420px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow);
}
.lobby-card h2 { font-size: 1.25rem; }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .12em; text-align: center; }
.join-row .btn-secondary { width: auto; padding-inline: 20px; }

/* ===== Экран игры ===== */
#screen-game { overflow: hidden; }

.game-layout {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    min-height: 0;
    overflow: hidden;
}

/* ----- Поле ----- */
.board {
    --cell: min(9vw, 8.5vh, 74px);
    display: grid;
    grid-template-columns: repeat(11, var(--cell));
    grid-template-rows: repeat(11, var(--cell));
    gap: 2px;
    margin: 12px;
    align-self: center;
    justify-self: center;
    position: relative;
    background: #0b1220;
    border-radius: 12px;
    padding: 4px;
    box-shadow: 0 0 0 1px var(--border), var(--shadow);
}

.board .cell {
    background: var(--surface);
    border-radius: 6px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 3px;
    font-size: clamp(7px, 1.1vw, 11px);
    text-align: center;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    transition: filter .12s ease;
}
.board .cell:active { filter: brightness(1.25); }

/* Цветовые полосы групп */
.cell[data-group="brown"]  { border-top: 5px solid #92400e; }
.cell[data-group="cyan"]   { border-top: 5px solid #06b6d4; }
.cell[data-group="pink"]   { border-top: 5px solid #ec4899; }
.cell[data-group="orange"] { border-top: 5px solid #f97316; }
.cell[data-group="red"]    { border-top: 5px solid #ef4444; }
.cell[data-group="yellow"] { border-top: 5px solid #eab308; }
.cell[data-group="green"]  { border-top: 5px solid #22c55e; }
.cell[data-group="blue"]   { border-top: 5px solid #3b82f6; }

.cell .cell-name {
    font-weight: 600;
    line-height: 1.1;
    max-height: 2.4em;
    overflow: hidden;
}
.cell .cell-price { color: var(--muted); font-size: .85em; }

/* Фишки игроков */
.token {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,.85);
    box-shadow: 0 0 6px rgba(0,0,0,.5);
    position: absolute;
}
.token.red    { background: #ef4444; }
.token.blue   { background: #3b82f6; }
.token.green  { background: #22c55e; }
.token.orange { background: #f97316; }

.tokens-wrap {
    position: absolute;
    bottom: 2px;
    right: 2px;
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ----- Панель игрока ----- */
.player-panel {
    background: rgba(15, 23, 42, .65);
    border-left: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    min-height: 0;
}

.money-box {
    background: var(--bg-2);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}
.money-box .label { color: var(--muted); font-size: .85rem; }
.money-box .value { font-size: 1.6rem; font-weight: 700; color: var(--primary); }

.dice-box {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--muted);
}
.die {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,.3);
}
#dice-sum { font-weight: 700; color: var(--accent); }

.actions { display: flex; flex-direction: column; gap: 8px; }
.actions .btn-primary,
.actions .btn-secondary { padding: 12px 14px; font-size: .95rem; }

.players-list { display: flex; flex-direction: column; gap: 8px; }
.player-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-2);
    border-radius: 10px;
    font-size: .9rem;
}
.player-row .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.player-row.active { outline: 1px solid var(--primary); }
.player-row .p-money { margin-left: auto; font-weight: 600; color: var(--primary); }
.player-row .p-money.broke { color: var(--danger); }

.event-feed {
    flex: 1;
    min-height: 80px;
    overflow-y: auto;
    font-size: .82rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* ===== Мобильная адаптация ===== */
@media (max-width: 900px) {
    .game-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }

    .board {
        --cell: min(8.5vw, 7.5vh, 62px);
        margin: 6px;
    }
    .board .cell { font-size: clamp(6px, 1.6vw, 9px); border-radius: 4px; }

    .player-panel {
        border-left: 0;
        border-top: 1px solid var(--border);
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
        gap: 10px;
        padding: 10px 12px;
        max-height: 42vh;
    }
    .money-box, .dice-box, .actions, .players-list, .event-feed {
        grid-column: span 1;
    }
    .actions { grid-column: span 2; flex-direction: row; }
    .actions > * { flex: 1; }
    .event-feed { grid-column: span 2; max-height: 100px; }
}

@media (max-width: 480px) {
    .board { --cell: min(8vw, 6.8vh, 52px); gap: 1px; padding: 3px; }
    .auth-card { padding: 24px 18px; }
    .logo h1 { font-size: 1.5rem; }
}