/* General Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3d5a80;
    --primary-light: rgba(61, 90, 128, 0.08);
    --primary-dark: #2c4363;
    --secondary-color: #5d89bf;
    --secondary-dark: #4a7ab2;
    --accent-color: #43aa8b;
    --accent-dark: #389178;
    --warning-color: #f8961e;
    --warning-dark: #e98610;
    --danger-color: #ef5350;
    --danger-dark: #d32f2f;
    --text-color: #343a40;
    --bg-color: #f0f7ff;
    --table-bg-color: #43aa8b;
    --white: #fff;
    --card-width: 85px;
    --card-height: 120px;
    --card-border-radius: 8px;
    --shadow-sm: 0 2px 5px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 3px 8px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 5px 15px rgba(0, 0, 0, 0.2);
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

body {
    font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    overflow-x: hidden;
    max-width: 100vw;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    width: 100%;
}

.hidden {
    display: none !important;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(61, 90, 128, 0.2);
    flex-wrap: wrap;
    background-color: rgba(240, 247, 255, 0.9);
}

header h1 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    color: var(--primary-color);
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(61, 90, 128, 0.1);
}

.game-info {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

#deck-count {
    font-weight: bold;
    font-size: 0.9rem;
    background-color: var(--primary-color);
    color: var(--white);
    padding: 5px 10px;
    border-radius: 15px;
    box-shadow: var(--shadow-sm);
}

/* Buttons */
button {
    padding: 8px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.primary-btn {
    background-color: var(--primary-color);
    color: var(--white);
    font-weight: 600;
    padding: 8px 16px;
    font-size: 1rem;
}

.primary-btn:hover {
    background-color: var(--primary-dark);
}

.secondary-btn {
    background-color: var(--secondary-color);
    color: var(--white);
    font-weight: 600;
}

.small-btn {
    padding: 4px 8px;
    font-size: 0.85rem;
    background-color: var(--secondary-color);
    color: var(--white);
}

/* Стили для кнопок действий */
.action-btn {
    background-color: var(--accent-color);
    color: var(--white);
    margin: 0;
    padding: 12px 0;
    width: 48%;
    font-weight: 600;
    border-radius: 6px;
}

.action-btn:hover {
    background-color: var(--accent-dark);
}

#rules-btn {
    background-color: var(--warning-color);
    color: var(--white);
    font-size: 1.1rem;
    padding: 5px 10px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#rules-btn:hover {
    background-color: var(--warning-dark);
}

#restart-btn, #new-game-btn {
    background-color: var(--danger-color);
    color: var(--white);
    font-size: 0.9rem;
    padding: 5px 10px;
}

#restart-btn:hover, #new-game-btn:hover {
    background-color: var(--danger-dark);
}

/* Game Sections */
.game-section {
    background: none;
    padding: 0;
    margin: 0;
    box-shadow: none;
    transition: all var(--transition-normal);
}

.game-section h2 {
    color: var(--primary-color);
    margin-bottom: 10px;
    text-align: center;
    font-size: clamp(1.3rem, 4vw, 1.5rem);
}

/* Game Setup */
#game-setup {
    background-color: #fff;
    border-radius: 12px;
    padding: 15px;
    margin: 10px;
    box-shadow: var(--shadow-lg);
}

.game-options {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.option-group {
    width: 100%;
    max-width: 500px;
}

.option-group h3 {
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: clamp(1rem, 3vw, 1.1rem);
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    transition: all var(--transition-fast);
    padding: 6px 8px;
    border-radius: 6px;
}

.radio-group label:hover {
    background-color: var(--bg-color);
}

.radio-group input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
}

/* Computer mode difficulty section */
.computer-mode-section {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.difficulty-group {
    flex-direction: row;
    gap: 12px;
    flex-wrap: wrap;
}

.difficulty-label {
    flex: 1;
    min-width: 200px;
    padding: 0 !important;
}

.difficulty-label input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.difficulty-option {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border: 2px solid #ddd;
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    background-color: #fff;
    width: 100%;
}

.difficulty-label input[type="radio"]:checked + .difficulty-option {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
}

.difficulty-label:hover .difficulty-option {
    border-color: var(--secondary-color);
    background-color: var(--bg-color);
}

.diff-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--primary-color);
}

.diff-desc {
    font-size: 0.8rem;
    color: #666;
}

/* Multiplayer Section */
.multiplayer-section {
    width: 100%;
    max-width: 500px;
    margin-top: 10px;
    border-top: 1px solid #e0e0e0;
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Online tabs */
.online-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0;
}

.online-tab {
    flex: 1;
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    box-shadow: none;
    transition: all var(--transition-fast);
    margin-bottom: -2px;
}

.online-tab:hover {
    color: var(--primary-color);
    transform: none;
    box-shadow: none;
}

.online-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Online panels */
.online-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 8px;
}

.online-panel .primary-btn {
    width: 100%;
    margin-top: 4px;
}

/* Online format selection */
.online-format-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.format-label {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.95rem;
    margin: 0;
}

.online-format-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.format-option {
    flex: 1;
    min-width: 100px;
    cursor: pointer;
    padding: 0 !important;
}

.format-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.format-option-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 8px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: #fff;
    transition: all var(--transition-fast);
    text-align: center;
    width: 100%;
}

.format-option input[type="radio"]:checked + .format-option-inner {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
}

.format-option:hover:not(.format-soon) .format-option-inner {
    border-color: var(--secondary-color);
    background-color: var(--bg-color);
}

.format-soon {
    opacity: 0.5;
    cursor: not-allowed;
}

.format-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary-color);
}

.format-desc {
    font-size: 0.75rem;
    color: #888;
}

/* Room info after creation */
.room-created-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--accent-color);
    text-align: center;
    margin: 0;
}

.room-code-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.share-label {
    font-size: 0.85rem;
    color: #666;
    margin: 4px 0 0;
    text-align: center;
}

.input-group {
    margin-bottom: 10px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.input-group input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all var(--transition-normal);
}

.input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(61, 90, 128, 0.2);
    outline: none;
}

.option-card button {
    width: 100%;
    margin-top: 5px;
}

/* Room Info */
.room-info {
    background-color: rgba(67, 170, 139, 0.1);
    border: 1px solid var(--accent-color);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.room-code {
    font-size: clamp(1.2rem, 3vw, 1.4rem);
    font-weight: bold;
    color: var(--primary-color);
    background-color: var(--primary-light);
    padding: 5px 10px;
    border-radius: 6px;
    display: inline-block;
    margin: 5px 0;
    letter-spacing: 1px;
}

.share-link {
    display: flex;
    margin: 12px 0;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.share-link input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-right: none;
    font-size: 0.9rem;
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.share-link button {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* ── Opponents container ─────────────────────────────────────── */
.opponents-container {
    display: flex;
    flex-direction: row;
    gap: 12px;
    justify-content: center;
    align-items: flex-start;
    padding: 8px 8px 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Wrapper: square + fan below */
.opponent-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Dynamic sizing based on opponent count */
.opp-count-1 .opponent-wrapper { flex: 0 0 auto; }
.opp-count-1 .opponent-square { width: 90px; height: 72px; }
.opp-count-1 .opp-fan-card { width: 28px; height: 38px; }

.opp-count-2 .opponent-wrapper { flex: 0 0 auto; }
.opp-count-2 .opponent-square { width: 78px; height: 64px; }
.opp-count-2 .opp-fan-card { width: 24px; height: 33px; }

.opp-count-3 .opponent-wrapper { flex: 0 0 auto; }
.opp-count-3 .opponent-square { width: 68px; height: 56px; }
.opp-count-3 .opp-fan-card { width: 20px; height: 28px; }

.opponent-square {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    border: 2px solid rgba(61, 90, 128, 0.25);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.95);
    width: 90px;
    height: 72px;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    position: relative;
}

.opponent-square.active-turn {
    border-color: #43aa8b;
    box-shadow: 0 0 0 3px rgba(67, 170, 139, 0.4), 0 0 16px rgba(67, 170, 139, 0.35);
}

/* Team indicators for 2v2 */
.opponent-square.same-team::before {
    content: 'Союзник';
    position: absolute;
    top: -9px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.55rem;
    background: #43aa8b;
    color: #fff;
    padding: 1px 5px;
    border-radius: 4px;
    white-space: nowrap;
}

.opponent-square.enemy-team::before {
    content: 'Соперник';
    position: absolute;
    top: -9px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.55rem;
    background: #ef5350;
    color: #fff;
    padding: 1px 5px;
    border-radius: 4px;
    white-space: nowrap;
}

/* Collected count badge - top right corner of square */
.opp-collected-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* Emoji avatar in opponent square */
.opp-emoji {
    font-size: 1.4rem;
    line-height: 1;
    margin-bottom: 2px;
}

/* Opponent name at the bottom of the square */
.opponent-sq-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    line-height: 1.2;
}

.opponent-sq-name.waiting {
    font-size: 0.6rem;
    color: #aaa;
    font-style: italic;
}

/* Fan of card backs below the square */
.opp-card-fan {
    position: relative;
    height: 42px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-width: 60px;
}

.opp-fan-card {
    position: absolute;
    width: 28px;
    height: 38px;
    border-radius: 3px;
    background: url('/images/cards/card_back.png') center/cover no-repeat;
    border: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    transform-origin: 50% 100%;
    top: 0;
    left: 50%;
    margin-left: -14px;
}

/* ── Player bottom area ──────────────────────────────────────── */
.player-bottom-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px 0;
}

.player-bottom-header h3 {
    font-size: 0.9rem;
    color: var(--primary-color);
    margin: 0;
}

.collected-badge {
    font-size: 0.8rem;
    color: #555;
    background: rgba(61, 90, 128, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
}

/* ── Results dynamic ─────────────────────────────────────────── */

.results-dynamic {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    table-layout: auto;
}

.results-table th {
    background: var(--primary-color);
    color: #fff;
    padding: 5px 4px;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.75rem;
}

.results-table td {
    padding: 5px 4px;
    border-bottom: 1px solid #eee;
    text-align: center;
    white-space: nowrap;
}

.results-table tr:nth-child(even) td {
    background: var(--bg-color);
}

.results-table tr.results-winner td {
    background: rgba(67, 170, 139, 0.15);
    font-weight: 600;
}

.results-table tr.results-you td {
    font-style: italic;
}

.yes-badge {
    display: inline-block;
    background: #43aa8b;
    color: #fff;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.75rem;
}

.no-badge {
    color: #aaa;
    font-size: 0.8rem;
}

.game-winner-block {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    margin: 12px 0;
    color: var(--primary-color);
}

/* Waiting banner shown while not all players have joined */
.waiting-banner {
    background: rgba(61, 90, 128, 0.08);
    border: 1px dashed var(--primary-color);
    border-radius: 10px;
    padding: 12px 16px;
    text-align: center;
    color: var(--primary-color);
    font-size: 0.95rem;
}

.bottom-player {
    padding: 4px 0 8px;
}

.waiting-message {
    margin-top: 12px;
    color: var(--primary-color);
    font-style: italic;
    font-weight: 500;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.7; }
    to { opacity: 1; }
}

/* ОПТИМИЗИРОВАННЫЙ ИГРОВОЙ СТОЛ */
#game-board {
    padding: 0;
    background: none;
    box-shadow: none;
    margin: 0;
}

/* Основной игровой контейнер */
.game-layout {
    display: flex;
    flex-direction: column;
    background-color: var(--table-bg-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin: 0;
    padding: 0;
    position: relative;
    height: calc(100vh - 100px);
    max-height: 700px;
}

/* Улучшенная зона карт */
.player-area {
    padding: 5px;
    margin: 0;
    border: none;
    background: none;
    box-shadow: none;
    position: relative;
    z-index: 2;
}

/* Имена игроков */
.player-area h3 {
    margin: 2px 0 5px;
    color: rgba(255, 255, 255, 0.9);
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Области верхнего и нижнего игрока — без фоновых блоков, единое полотно */
.top-player {
    padding: 5px 10px;
}

/* Нижний игрок — абсолютно у нижнего края, карты наполовину скрыты */
.bottom-player {
    position: absolute;
    bottom: calc(var(--card-height) * 1.4375 * -0.45);
    left: 0;
    right: 0;
    z-index: 15;
    padding: 0 10px;
}

/* Активная область игрока */
.player-area.active h3 {
    color: #fff;
    font-weight: 600;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* Игровой стол в центре */
.game-table {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 10px;
    min-height: 200px;
}

/* Карты на столе - приподняты выше */
.table-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    align-content: flex-start;
    width: 100%;
    height: 100%;
    padding: 15px 10px 50px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    margin-top: 10px;
}

.table-cards::-webkit-scrollbar {
    width: 4px;
}

.table-cards::-webkit-scrollbar-track {
    background: transparent;
}

.table-cards::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

/* Карты в руке — веер */
.hand {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 165px;
    min-height: 165px;
    margin: 0;
    overflow: visible;
}

/* Карты веера — абсолютное позиционирование с поворотом */
.hand .card {
    position: absolute;
    bottom: 0;
    transform-origin: 50% 140%;
    transform: translateX(var(--fan-offset, 0px)) rotate(var(--fan-angle, 0deg));
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* translateY ДО rotate — карта поднимается строго вверх, сохраняя угол */
.hand .card:hover {
    transform: translateX(var(--fan-offset, 0px)) translateY(-16px) rotate(var(--fan-angle, 0deg)) !important;
    z-index: 30 !important;
}

.hand .card.selected {
    transform: translateX(var(--fan-offset, 0px)) translateY(-32px) rotate(var(--fan-angle, 0deg)) !important;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
    border: 2px solid var(--warning-color);
    z-index: 50 !important;
}

.hand .card.selected:hover {
    transform: translateX(var(--fan-offset, 0px)) translateY(-32px) rotate(var(--fan-angle, 0deg)) !important;
}

/* Карты игрока (нижняя рука) — на 43.75% крупнее (1.25 * 1.15) */
.hand .own-card {
    width: calc(var(--card-width) * 1.4375);
    height: calc(var(--card-height) * 1.4375);
}

.hand .own-card .card-value {
    font-size: 1.725rem;
}

.hand .own-card .card-suit {
    font-size: 1.4375rem;
}

.hand .own-card .card-center {
    font-size: 2.99rem;
}

/* Карты противника — уменьшены на 55% */
.hand .opponent-card {
    width: calc(var(--card-width) * 0.45);
    height: calc(var(--card-height) * 0.45);
    cursor: default;
}

.hand .opponent-card .card-value {
    font-size: 0.58rem;
    margin-bottom: 0;
}

.hand .opponent-card .card-suit {
    font-size: 0.5rem;
}

.hand .opponent-card .card-center {
    font-size: 0.85rem;
}

/* Рука противника (верхняя) — маленькие карты в веере */
.top-player .hand {
    height: calc(var(--card-height) * 0.65);
    min-height: calc(var(--card-height) * 0.65);
    pointer-events: none;
}

/* Рука игрока (нижняя) — позиционирована абсолютно, нижняя половина скрыта overflow:hidden */
.bottom-player .hand {
    height: calc(var(--card-height) * 1.4375);
    min-height: calc(var(--card-height) * 1.4375);
}


/* Последняя взятка - перемещена в левый угол */
#last-taken {
    --lt-card-w: 55px;
    --lt-card-h: 77px;
    --lt-gap: 4px;
    position: absolute;
    left: 10px;
    bottom: calc(var(--card-height) * 1.4375 * 0.5 + 55px);
    width: calc(var(--lt-card-w) * 2 + var(--lt-gap) + 16px);
    max-height: 45vh;
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 255, 255, 0.93);
    border-radius: 8px;
    padding: 8px;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    font-size: 0.85rem;
}

#last-taken h4 {
    color: var(--primary-color);
    margin-bottom: 5px;
    text-align: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.last-taken-cards {
    display: grid;
    grid-template-columns: repeat(2, var(--lt-card-w));
    justify-content: center;
    gap: var(--lt-gap);
    margin: 5px 0;
    overflow-y: auto;
    max-height: calc(var(--lt-card-h) + var(--lt-gap));
    scrollbar-width: thin;
    scrollbar-color: rgba(61, 90, 128, 0.3) transparent;
}

.last-taken-cards::-webkit-scrollbar { width: 3px; }
.last-taken-cards::-webkit-scrollbar-thumb { background: rgba(61, 90, 128, 0.3); border-radius: 3px; }

.last-taken-cards .card {
    width: var(--lt-card-w) !important;
    height: var(--lt-card-h) !important;
    transform: none !important;
    margin: 0;
    padding: 0;
}

.last-taken-by {
    margin-top: 5px;
    text-align: center;
    font-weight: 600;
    color: var(--primary-color);
    padding: 3px;
    background-color: var(--primary-light);
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Счетчики карт */
.collected-cards {
    text-align: center;
    position: relative;
    height: 25px;
}

.collected-count {
    position: absolute;
    right: 5px;
    background-color: var(--primary-color);
    color: var(--white);
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Элементы управления игрой - оптимизированы для мобильных */
.game-controls {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 5px 10px 10px;
    background-color: var(--bg-color);
}

/* Сообщение о ходе */
.game-message {
    width: 100%;
    text-align: center;
    font-weight: 600;
    color: var(--primary-color);
    background-color: rgba(61, 90, 128, 0.1);
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

/* Зона кнопок всегда в одну строку */
.button-container {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

/* Обе кнопки всегда имеют одинаковую ширину */
#discard-card-btn, #confirm-selection-btn {
    width: 48%;
    padding: 10px 5px;
    font-size: 0.95rem;
}

/* Карты на столе — на 10% крупнее базового размера (шрифты оставляем базовые) */
.table-cards .card {
    width: calc(var(--card-width) * 1.10);
    height: calc(var(--card-height) * 1.10);
}

/* Стили карт */
.card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: var(--card-border-radius);
    background-color: var(--white);
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0;
    font-weight: bold;
    border: 1px solid rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: inherit;
    pointer-events: none;
    user-select: none;
}

.card.back {
    padding: 0;
    border: 2px solid #293f5c;
    overflow: hidden;
}

.card.selected {
    transform: translateY(-8px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.25);
    border: 2px solid var(--warning-color);
    z-index: 5;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 2;
}

.card.selected:hover {
    transform: translateY(-8px);
}

.card-top, .card-bottom {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    height: auto;
    min-height: 25px;
    line-height: 1;
}

.card-bottom {
    align-items: flex-end;
    transform: rotate(180deg);
}

/* Улучшенное отображение значения карты */
.card-value {
    font-size: 1.3rem;
    line-height: 1;
    margin-bottom: 1px;
    display: block;
}

/* Улучшенное отображение масти */
.card-suit {
    font-size: 1.1rem;
    line-height: 1;
    display: block;
    height: auto;
    transform: scale(1.1); /* Немного увеличиваем масть */
}

/* Исправляем цвета мастей */
.card.hearts, .card.diamonds {
    color: var(--danger-color);
}

.card.clubs, .card.spades {
    color: var(--text-color);
}

/* Центральная масть - увеличенного размера и с правильным позиционированием */
.card-center {
    position: absolute;
    top: 50%;
    left: 66%;
    transform: translate(-50%, -50%);
    font-size: 2.2rem;
    line-height: 1;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Дополнительные стили для маленьких экранов */
@media (max-width: 480px) {
    .card-value {
        font-size: 1.1rem;
    }

    .card-suit {
        font-size: 0.9rem;
    }

    .card-center {
        font-size: 1.8rem;
    }
}

/* Lobby player list */
.lobby-player-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0;
}

.lobby-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
}

.lobby-player-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.lobby-player-connected {
    background: rgba(67, 170, 139, 0.15);
    color: #2d8a6e;
}

.lobby-player-waiting {
    background: rgba(61, 90, 128, 0.08);
    color: #999;
    font-style: italic;
}

.lobby-kick-btn {
    margin-left: auto;
    background: #ef5350;
    color: #fff;
    border: none;
    border-radius: 4px;
    width: 22px;
    height: 22px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.lobby-kick-btn:hover {
    background: #d32f2f;
}

/* Game Results */
#game-results {
    background-color: var(--white);
    border-radius: 10px;
    padding: 15px;
    margin: 10px;
    box-shadow: var(--shadow-lg);
    overflow-x: hidden;
}

.results-container {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin: 10px 0;
}

.player-results {
    flex: 1;
    background-color: var(--primary-light);
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    min-width: 250px;
}

.player-results h3 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.result-details p {
    margin-bottom: 8px;
    font-size: 0.95rem;
    padding: 4px 0;
    border-bottom: 1px solid #eee;
}

.total-score {
    margin-top: 12px;
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--primary-color);
    border-top: 2px solid #ddd;
    padding-top: 8px;
}

#game-winner {
    text-align: center;
    font-size: 1.3rem;
    font-weight: bold;
    margin: 15px 0;
    color: var(--accent-color);
    padding: 10px;
    background-color: rgba(67, 170, 139, 0.1);
    border-radius: 8px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(3px);
}

.modal-content {
    background-color: var(--white);
    margin: 10% auto;
    padding: 15px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    position: relative;
}

.close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 22px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.close:hover {
    color: #333;
}

.rules-content {
    margin-top: 20px;
}

.rules-content h3 {
    margin: 15px 0 10px;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.rules-content ul, .rules-content ol {
    margin-left: 18px;
    margin-bottom: 12px;
}

.rules-content li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Notification */
.notification {
    position: fixed;
    bottom: 15px;
    right: 15px;
    padding: 10px 15px;
    background-color: var(--primary-color);
    color: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s, transform 0.3s;
    font-weight: 600;
    max-width: 300px;
    font-size: 0.9rem;
}

.notification.error {
    background-color: var(--danger-color);
}

.notification.success {
    background-color: var(--accent-color);
}

.notification.hidden {
    opacity: 0;
    transform: translateY(30px);
    pointer-events: none;
}

/* Мобильная версия - коррекция для "Последней взятки" */
@media (max-width: 768px) {
    :root {
        --card-width: 70px;
        --card-height: 100px;
    }

    header {
        padding: 5px 10px;
    }

    /* Оптимизация расположения кнопок для мобильных устройств */
    .game-controls {
        padding: 10px;
    }

    /* Добавляем контейнер для кнопок */
    .button-container {
        display: flex;
        justify-content: space-between;
        width: 100%;
    }

    /* Стили для кнопок на мобильных */
    #discard-card-btn, #confirm-selection-btn {
        width: 48%;
        padding: 10px 5px;
        font-size: 0.9rem;
    }

    /* Сжимаем карты на мобильных устройствах */
    .card-value {
        font-size: 1.1rem;
    }

    .card-suit {
        font-size: 0.9rem;
    }

    .card-center {
        font-size: 1.6rem;
    }

    .hand {
        height: 148px;
        min-height: 148px;
    }

    /* Последняя взятка — мобилка 768 */
    #last-taken {
        --lt-card-w: 50px;
        --lt-card-h: 70px;
        width: calc(var(--lt-card-w) * 2 + var(--lt-gap) + 14px);
        padding: 6px;
        left: 5px;
        bottom: calc(var(--card-height) * 1.4375 * 0.5 + 55px);
        font-size: 0.8rem;
    }

    #last-taken h4 {
        font-size: 0.85rem;
        margin-bottom: 3px;
    }

    .last-taken-by {
        font-size: 0.75rem;
        margin-top: 3px;
    }

    /* Карты на столе поднимаем еще выше на мобильных устройствах */
    .table-cards {
        padding: 40px 10px 10px;
        margin-top: 35px; /* Дополнительное смещение вниз */
    }

    /* Модальное окно на весь экран */
    .modal-content {
        width: 100%;
        height: 100%;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
    }

    .game-layout {
        height: calc(100vh - 120px);
    }

    .results-container {
            flex-direction: column;
            gap: 10px;
        }

        .player-results {
            min-width: auto;
            width: 100%;
        }

        #game-results {
            padding: 10px;
            width: 100%;
            margin: 0;
            box-sizing: border-box;
        }

}

/* Для очень маленьких экранов дополнительная оптимизация */
@media (max-width: 480px) {
    :root {
        --card-width: 60px;
        --card-height: 85px;
        --card-border-radius: 6px;
    }

    .card.selected {
        transform: translateY(-5px);
    }

    .card:hover {
        transform: translateY(-2px);
    }

    .card.selected:hover {
        transform: translateY(-5px);
    }

    .hand {
        height: 132px;
        min-height: 132px;
    }

    /* Ещё плотнее упаковываем элементы */
    .table-cards {
        gap: 3px;
    }

    .collected-count {
        width: 22px;
        height: 22px;
        font-size: 0.75rem;
    }

    .game-layout {
        height: calc(100vh - 100px);
    }

    /* Дополнительное смещение для блока "Последняя взятка" */
    /* Последняя взятка — мобилка 480 */
    #last-taken {
        --lt-card-w: 45px;
        --lt-card-h: 63px;
        width: calc(var(--lt-card-w) * 2 + var(--lt-gap) + 12px);
        font-size: 0.75rem;
        padding: 5px;
    }

    /* Еще больше поднимаем карты на столе */
    .table-cards {
        padding: 5px 5px 70px;
        margin-top: 25px;
    }

    /* Opponent squares smaller on small screens */
    .opp-count-1 .opponent-square { width: 80px; height: 64px; }
    .opp-count-2 .opponent-square { width: 68px; height: 56px; }
    .opp-count-2 .opp-fan-card { width: 20px; height: 28px; }
    .opp-count-3 .opponent-square { width: 58px; height: 48px; }
    .opp-count-3 .opp-fan-card { width: 16px; height: 22px; }
    .opp-count-3 .opp-card-fan { height: 28px; }
    .opponent-sq-name { font-size: 0.6rem; }
    .opp-collected-badge { font-size: 0.5rem; min-width: 15px; height: 15px; }
    .opponents-container { gap: 6px; padding: 4px 4px 0; }
}

/* Добавляем HTML-код для контейнера кнопок */
.button-container {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

/* ── Winner celebration ─────────────────────────────────────── */
.winner-container {
    position: relative;
    border-radius: 12px;
    padding: 20px 15px;
    text-align: center;
    overflow: hidden;
    margin-bottom: 20px;
    background: linear-gradient(135deg, rgba(46,213,115,0.15), rgba(30,144,255,0.15), rgba(255,71,87,0.1));
    border: 2px solid rgba(46,213,115,0.3);
}

.winner-glow {
    position: absolute;
    inset: -50%;
    background: conic-gradient(from 0deg, transparent, rgba(255,215,0,0.15), transparent, rgba(46,213,115,0.15), transparent);
    animation: winner-spin 4s linear infinite;
    z-index: 0;
}

@keyframes winner-spin {
    to { transform: rotate(360deg); }
}

.winner-text {
    position: relative;
    z-index: 2;
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #2ed573, #1e90ff, #ffa502, #ff4757);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: winner-gradient 3s ease infinite, winner-pulse 1.5s ease-in-out infinite;
}

@keyframes winner-gradient {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes winner-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.confetti-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 1;
}

.confetti-piece {
    position: absolute;
    top: -10px;
    animation: confetti-fall linear forwards;
    will-change: transform;
}

.confetti-rect {
    width: 8px;
    height: 14px;
    background: var(--color);
    border-radius: 2px;
}

.confetti-circle {
    width: 8px;
    height: 8px;
    background: var(--color);
    border-radius: 50%;
}

.confetti-strip {
    width: 3px;
    height: 16px;
    background: var(--color);
    border-radius: 1px;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-10px) translateX(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    80% {
        opacity: 1;
    }
    100% {
        transform: translateY(180px) translateX(var(--drift)) rotate(var(--rot)) scale(0.5);
        opacity: 0;
    }
}

/* Стили для отображения общего счета */
.total-score-info {
    margin: 12px auto;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    max-width: 90%;
    width: 100%;
}

.total-score-info h3 {
    text-align: center;
    margin-top: 0;
    font-size: 14px;
    color: #343a40;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 6px;
    margin-bottom: 8px;
}

.score-row {
    display: flex;
    justify-content: space-around;
    margin: 8px 0;
    font-size: 13px;
    font-weight: bold;
}

.score-target {
    text-align: center;
    font-style: italic;
    color: #6c757d;
    margin-top: 8px;
    font-size: 12px;
}

.match-winner {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    color: #28a745;
    margin-top: 12px;
    padding: 6px;
    border-radius: 4px;
    background-color: #d4edda;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.03);
    }
    100% {
        transform: scale(1);
    }
}

/* Стили для диалогового окна подтверждения выхода */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.dialog-box {
    background-color: #fff;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    max-width: 90%;
    width: 300px;
    margin: 0 15px;
}

.dialog-content h3 {
    margin-top: 0;
    color: #333;
    font-size: 16px;
}

.dialog-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
}

.dialog-btn {
    padding: 8px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    min-width: 80px;
    font-size: 14px;
}

.confirm-btn {
    background-color: #d9534f;
    color: white;
}

.confirm-btn:hover {
    background-color: #c9302c;
}

.cancel-btn {
    background-color: #5cb85c;
    color: white;
}

.cancel-btn:hover {
    background-color: #449d44;
}

/* Стили для отображения номера раунда в игре */
.round-indicator {
    position: absolute;
    top: 5px;
    left: 5px;
    transform: none;
    background-color: rgba(52, 58, 64, 0.8);
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    z-index: 10;
}

/* Счёт — часть хедера, никакого floating */
.game-score-display {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    background-color: rgba(61, 90, 128, 0.12);
    border: 1px solid rgba(61, 90, 128, 0.2);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    order: -1;
}

.game-score-display .score-title {
    font-weight: bold;
    margin-bottom: 3px;
    font-size: 11px;
}

.game-score-display .score-value {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.game-score-display .score-value span {
    margin: 0;
    white-space: nowrap;
}

/* Добавим медиа-запрос для экранов больше 480px */
@media screen and (min-width: 480px) {
    .total-score-info {
        padding: 12px;
        border-radius: 8px;
    }

    .total-score-info h3 {
        font-size: 16px;
        padding-bottom: 8px;
    }

    .score-row {
        font-size: 16px;
        margin: 12px 0;
    }

    .score-target {
        font-size: 14px;
        margin-top: 10px;
    }

    .match-winner {
        font-size: 18px;
        margin-top: 15px;
        padding: 8px;
        border-radius: 5px;
    }

    .round-indicator {
        position: absolute;
        top: 5px;
        right: 10px;
        left: auto;
        transform: none;
        background-color: rgba(52, 58, 64, 0.8);
        color: white;
        padding: 3px 8px;
        border-radius: 12px;
        font-weight: bold;
        font-size: 12px;
        box-shadow: 0 1px 2px rgba(0,0,0,0.2);
        z-index: 10;
    }

}


/* Скрываем поле "Дополнительные очки" */
.result-details p:nth-last-child(2) {
    display: none;
}

/* Сдвигаем индикатор раунда чтобы не перекрывал карты */
@media screen and (max-width: 768px) {
    .round-indicator {
        top: 5px;
        left: 10px;
        transform: none;
    }
}

/* =========================================
   ВСТРАИВАНИЕ ЭКРАНА — ПЛАНШЕТЫ И ДЕСКТОП (769px+)
   ========================================= */
@media screen and (min-width: 769px) {
    body {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .container {
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    #game-board {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .game-layout {
        flex: 1;
        height: auto;
        max-height: none;
    }

    #game-setup {
        flex: 1;
        overflow-y: auto;
    }

    .game-controls {
        flex-shrink: 0;
    }
}

/* =========================================
   ПЛАНШЕТЫ (768px – 1024px)
   ========================================= */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    :root {
        --card-width: 80px;
        --card-height: 112px;
    }

    .game-layout {
        border-radius: 12px;
        margin: 5px;
    }

    .hand {
        height: 180px;
        min-height: 180px;
    }

    .bottom-player .hand {
        height: calc(var(--card-height) * 1.4375);
        min-height: calc(var(--card-height) * 1.4375);
    }

    .top-player .hand {
        height: calc(var(--card-height) * 0.65);
        min-height: calc(var(--card-height) * 0.65);
    }

    #last-taken {
        --lt-card-w: 55px;
        --lt-card-h: 77px;
        width: calc(var(--lt-card-w) * 2 + var(--lt-gap) + 16px);
        max-height: 35vh;
    }

    .round-indicator {
        right: 10px;
        left: auto;
        top: 5px;
        transform: none;
    }

    .table-cards {
        max-width: 600px;
    }
}

/* =========================================
   ДЕСКТОП (1024px+)
   ========================================= */
@media screen and (min-width: 1025px) {
    :root {
        --card-width: 90px;
        --card-height: 126px;
    }

    .container {
        max-width: 1200px;
        margin: 0 auto;
        height: 100%;
    }

    .game-layout {
        border-radius: 16px;
        margin: 8px;
        box-shadow: var(--shadow-lg);
    }

    .hand {
        height: 200px;
        min-height: 200px;
    }

    .bottom-player .hand {
        height: calc(var(--card-height) * 1.4375);
        min-height: calc(var(--card-height) * 1.4375);
    }

    .top-player .hand {
        height: calc(var(--card-height) * 0.65);
        min-height: calc(var(--card-height) * 0.65);
    }

    .game-table {
        min-height: 280px;
    }

    .table-cards {
        max-width: 700px;
        gap: 8px;
    }

    #last-taken {
        --lt-card-w: 60px;
        --lt-card-h: 84px;
        width: calc(var(--lt-card-w) * 2 + var(--lt-gap) + 16px);
        max-height: 40vh;
    }

    .round-indicator {
        right: 10px;
        left: auto;
        top: 5px;
        transform: none;
    }

    /* Карты на столе крупнее */
    .table-cards .card {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    }

    /* Ховер-эффекты заметнее */
    .hand .card:hover {
        transform: translateX(var(--fan-offset, 0px)) translateY(-20px) rotate(var(--fan-angle, 0deg)) !important;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    }

    header {
        padding: 10px 20px;
    }

    .game-controls {
        padding: 15px 20px;
    }
}

/* =========================================
   БЛОКИРОВКА ГОРИЗОНТАЛЬНОЙ ОРИЕНТАЦИИ (МОБИЛКИ)
   ========================================= */
#rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: #1b4332;
    z-index: 99999;
    justify-content: center;
    align-items: center;
}

.rotate-message {
    text-align: center;
    color: white;
}

.rotate-icon {
    font-size: 4rem;
    animation: rotate-phone 2s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes rotate-phone {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(90deg); }
    50% { transform: rotate(90deg); }
    75% { transform: rotate(0deg); }
}

.rotate-message p {
    font-size: 1.2rem;
    line-height: 1.6;
}

/* Показываем оверлей на телефонах в ландшафте.
   Телефон в ландшафте = маленькая высота (до 500px) + landscape.
   Планшеты/десктопы не попадают — у них высота больше. */
@media screen and (max-height: 500px) and (orientation: landscape) {
    #rotate-overlay {
        display: flex;
    }
}

