:root {
    --bg-felt: #4caf50;
    --felt-shadow: inset 0 0 100px rgba(0, 0, 0, 0.3);
    --gold: #fbbf24;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --tile-white: #fefce8;
    --border: rgba(255, 255, 255, 0.2);
    --wood-dark: #3e2723;
    --wood-light: #5d4037;
    --accent-1: #6366f1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #2c6e3c;
    background-image: radial-gradient(circle, #388e3c 0%, #1b5e20 100%);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
.main-header {
    background: rgba(0, 0, 0, 0.3);
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.logo {
    font-size: 1.2rem;
    font-weight: 800;
    color: white;
}

.logo span {
    color: var(--gold);
}

.game-stats {
    display: flex;
    gap: 30px;
    font-size: 0.8rem;
    font-weight: 600;
}

.stat-item .label {
    color: var(--text-dim);
    text-transform: uppercase;
    margin-right: 5px;
}

.mini-tile {
    width: 24px;
    height: 32px;
    background: #fdf6e3;
    border-radius: 4px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid #e0d0b0;
    vertical-align: middle;
}

.mini-tile.red {
    color: #f44336;
}

.mini-tile.black {
    color: #212121;
}

.mini-tile.blue {
    color: #2196f3;
}

.mini-tile.yellow {
    color: #fbc02d;
}

.stat-item {
    display: flex;
    align-items: center;
}

.stat-item .value {
    color: var(--gold);
}

/* Table Area */
.game-table {
    flex-grow: 1;
    position: relative;
    box-shadow: var(--felt-shadow);
}

/* Pill Player Tags */
.player-tag {
    position: absolute;
    display: flex;
    align-items: center;
    background: white;
    padding: 4px 15px 4px 5px;
    border-radius: 30px;
    color: #1a5e20;
    font-weight: 800;
    font-size: 0.9rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    z-index: 20;
    transition: 0.3s;
}

.player-tag img,
.player-tag .icon {
    width: 40px;
    height: 40px;
    background: #e0e0e0;
    border-radius: 50%;
    margin-right: 12px;
    border: 2px solid white;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}

.player-tag .icon {
    overflow: hidden;
}

.player-tag .icon i {
    font-size: 1.2rem;
}

/* Gender specific avatars */
.avatar-male {
    background: #bbdefb !important;
    color: #1976d2;
}

.avatar-female {
    background: #f8bbd0 !important;
    color: #c2185b;
}

.player-tag.self {
    background: #00c853;
    color: white;
    border: 2px solid white;
}

/* Active Player Styling - No Movement, Just Glow */
.player-tag.active {
    background: rgba(251, 191, 36, 0.25);
    border-color: #fbbf24;
    box-shadow: 0 0 25px rgba(251, 191, 36, 0.6), inset 0 0 10px rgba(251, 191, 36, 0.2);
}

.score-badge {
    background: rgba(0, 0, 0, 0.5);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    margin-left: 8px;
    font-weight: 800;
}

.winner-glow {
    animation: goldGlow 1.5s infinite alternate;
    border: 3px solid var(--gold) !important;
    background: #4a3b00 !important;
    color: white !important;
}

@keyframes goldGlow {
    from {
        box-shadow: 0 0 10px var(--gold);
    }

    to {
        box-shadow: 0 0 30px var(--gold), 0 0 50px #ff9800;
    }
}

.tag-top {
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
}

.tag-left {
    left: 40px;
    top: 50%;
    transform: translateY(-50%);
}

.tag-right {
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
}

.tag-bottom {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
}

/* Discard Piles */
.discard-pile {
    position: absolute;
    width: 60px;
    height: 80px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.3s;
}

#discard-p0 {
    right: 32%;
    bottom: 230px;
}

#discard-p3 {
    left: 32%;
    bottom: 230px;
}

#discard-p1 {
    right: 32%;
    top: 110px;
}

#discard-p2 {
    left: 32%;
    top: 110px;
}

.discard-pile.highlight-drop {
    background: rgba(251, 191, 36, 0.4);
    border: 2px solid var(--gold);
    transform: scale(1.1);
}

.draw-highlight {
    animation: pulse 1.5s infinite;
    border-color: var(--accent-1);
    background: rgba(99, 102, 241, 0.2);
}

/* Table Center Area */
.table-center {
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 20px;
    align-items: center;
}

.deck-card {
    width: 65px;
    height: 85px;
    background: #f5f5f5;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    border-bottom: 5px solid #bdbdbd;
    position: relative;
    cursor: pointer;
}

.tile-stack-visual {
    width: 100%;
    height: 100%;
    background: #e2e8f0;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.1);
}

.deck-badge {
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    background: #1b5e20;
    color: white;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 800;
    border: 2px solid #fbbf24;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    z-index: 30;
}

.indicator-card {
    width: 48px;
    height: 68px;
    background: #fdfce8;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 1);
    border-bottom: 6px solid #d1d5db;
    position: relative;
    user-select: none;
}

.indicator-face {
    font-size: 1.8rem;
    font-weight: 1000;
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.indicator-face .num {
    margin-top: -10px;
}

/* Istaka (User) */
.player-hand-container {
    background: rgba(0, 0, 0, 0.4);
    padding: 15px 10px;
    display: flex;
    justify-content: center;
    position: relative;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.istaka {
    background: #8d6e63;
    padding: 12px;
    border-radius: 12px;
    border: 6px solid #4e342e;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(0, 0, 0, 0.3);
}

.rack-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.slot {
    width: 46px;
    height: 64px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    transition: background 0.3s, border 0.3s;
}

/* Persistent Seating Places during drag */
.dragging-active .slot:empty {
    background: rgba(255, 255, 255, 0.1) !important;
    border: 2px dashed rgba(255, 255, 255, 0.5) !important;
}

.dragging-active #discard-p0 {
    border-color: rgba(251, 191, 36, 0.5);
    background: rgba(251, 191, 36, 0.1);
}

.tile {
    width: 46px;
    height: 64px;
    background: #fdfce8;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-bottom: 6px solid #d1d5db;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 1);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    cursor: grab;
    /* Default hand cursor */
}

.tile:active {
    cursor: grabbing;
    /* Grabbing cursor when clicked */
}

.tile.okey-real {
    border-color: #fbbf24;
}

.tile .number {
    font-size: 1.8rem;
    font-weight: 1000;
    line-height: 1;
    margin-top: -12px;
    letter-spacing: -1.5px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.symbol-well {
    width: 14px;
    height: 14px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.8);
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
}

.tile-heart {
    font-size: 0.5rem;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.3));
}

.tile.red,
.indicator-card.red {
    color: #f44336;
}

.tile.blue,
.indicator-card.blue {
    color: #2196f3;
}

.tile.black,
.indicator-card.black,
.tile.joker,
.indicator-card.joker {
    color: #1a1a1a;
}

.tile.yellow,
.indicator-card.yellow {
    color: #ffc107;
}

.tile-dragging {
    opacity: 0.8;
    cursor: grabbing !important;
    scale: 1.05;
    z-index: 1000;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.tile-dragging-source {
    opacity: 0.3 !important;
}

/* Flipped Okey Tile */
.tile.flipped {
    background: #e2e8f0 !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.1);
}

.tile.flipped .number,
.tile.flipped .symbol-well,
.tile.flipped .tile-heart {
    display: none !important;
}

.tile.flipped::after {
    content: '';
    width: 16px;
    height: 24px;
    border: 2px solid #cbd5e1;
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.group-selected {
    box-shadow: 0 0 15px #fbbf24, 0 0 5px #fbbf24 inset !important;
    border-color: #fbbf24 !important;
    transition: 0.2s;
}

[draggable="true"] {
    -webkit-user-drag: element;
}

/* Control Buttons - Repositioned next to Rack */
.side-controls {
    position: absolute;
    display: flex;
    flex-direction: row;
    /* Horizontal */
    gap: 8px;
    z-index: 60;
    background: rgba(0, 0, 0, 0.4);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
}

.controls-left {
    left: auto;
    right: 50%;
    margin-right: 430px;
    bottom: 30px;
}

.side-controls .btn-rect {
    padding: 10px 20px;
    font-size: 0.9rem;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.15);
}

.side-controls .btn-rect:hover {
    background: rgba(255, 255, 255, 0.25);
}

#finish-btn {
    background: #00c853 !important;
    color: white;
}

#toggle-sound {
    display: none !important;
}

.controls-right {
    right: auto;
    left: 50%;
    margin-left: 430px;
    bottom: 30px;
    flex-direction: row;
}

#sort-double {
    margin-top: 0 !important;
}

.btn-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
}

.btn-circle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.btn-rect {
    padding: 10px 20px;
    border-radius: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s;
    backdrop-filter: blur(5px);
}

.btn-rect:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(99, 102, 241, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

#win-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: #333;
    padding: 50px;
    border-radius: 30px;
    text-align: center;
    border: 1px solid var(--border);
}

.btn-primary {
    background: #00c853;
    color: white;
    padding: 15px 40px;
    border: none;
    border-radius: 30px;
    font-weight: 800;
    font-size: 1.1rem;
    cursor: pointer;
    margin-top: 20px;
}

/* MOBILE RESPONSIVENESS */
@media screen and (max-width: 900px) {

    /* 1. Scale down the Rack - Pulled in from edges */
    .player-hand-container {
        pointer-events: auto;
        transform: scale(0.50);
        /* Slightly smaller to pull away from edges */
        transform-origin: bottom center;
        width: 200%;
        /* 100 / 0.50 */
        margin-left: -50%;
        /* (200 - 100) / 2 */
        bottom: 60px;
        position: absolute;
    }

    /* 2. Reposition Control Buttons - UNDER the Rack */
    .controls-left {
        left: 50%;
        right: auto;
        margin-right: 0;
        transform: translateX(-50%);
        bottom: 10px;
        /* Under the rack */
        width: max-content;
        gap: 6px;
        flex-direction: row;
        z-index: 70;
    }

    .side-controls .btn-rect {
        padding: 5px 10px;
        /* Smaller */
        font-size: 0.7rem;
        height: 28px;
    }

    .side-controls {
        padding: 4px;
        background: rgba(0, 0, 0, 0.6);
    }

    .side-controls .btn-rect {
        padding: 6px 12px;
        /* Much smaller padding */
        font-size: 0.75rem;
        /* Smaller text */
        border-radius: 6px;
        height: 30px;
        display: flex;
        align-items: center;
    }

    /* 3. Adjust Discard Piles - Slightly smaller */
    #discard-p0 {
        right: 10px;
        bottom: 180px;
        transform: scale(0.65);
    }

    #discard-p3 {
        left: 10px;
        bottom: 180px;
        transform: scale(0.65);
    }

    #discard-p1 {
        right: 10px;
        top: 70px;
        transform: scale(0.65);
    }

    #discard-p2 {
        left: 10px;
        top: 70px;
        transform: scale(0.65);
    }

    .discard-pile {
        width: 50px;
        height: 70px;
    }

    /* 4. Center Table - Smaller */
    .table-center {
        top: 35%;
        transform: translate(-50%, -50%) scale(0.55);
        /* Even smaller */
    }

    /* 5. Player Tags */
    .player-tag {
        font-size: 0.7rem;
        padding: 2px 6px;
        transform: none;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }

    .player-tag img,
    .player-tag .icon {
        width: 24px;
        height: 24px;
        margin-right: 4px;
        border-width: 1px;
    }

    .tag-top {
        top: 50px;
        transform: translateX(-50%);
    }

    /* Vertical Tags */
    .tag-left {
        left: 5px;
        /* Pull in from edge */
        top: 45%;
        writing-mode: vertical-rl;
        transform: rotate(180deg) translateY(50%);
        border-radius: 8px;
        /* Fully rounded */
    }

    .tag-left img,
    .tag-left .icon {
        margin: 0 0 4px 0;
        transform: rotate(90deg);
    }

    .score-badge {
        margin: 4px 0 0 0;
        padding: 0 4px;
        font-size: 0.65rem;
    }

    .tag-right {
        right: 5px;
        /* Pull in from edge */
        top: 45%;
        writing-mode: vertical-rl;
        transform: translateY(-50%);
        border-radius: 8px;
        /* Fully rounded */
    }

    .tag-right img,
    .tag-right .icon {
        margin: 0 0 4px 0;
        transform: rotate(-90deg);
    }

    .tag-bottom {
        bottom: 190px;
        /* Lifted up */
        z-index: 50;
        left: 50%;
        transform: translateX(-50%);
        width: max-content;
    }

    /* 6. Header */
    .main-header {
        padding: 0 8px;
    }

    .logo {
        font-size: 0.9rem;
    }

    .game-stats {
        gap: 8px;
    }
}

/* LANDSCAPE MOBILE OPTIMIZATION */
@media screen and (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {

    /* 1. Scale down Rack Significantly - And Ensure Clickable */
    /* 1. Scale down Rack Significantly - And Ensure Clickable */
    .player-hand-container {
        pointer-events: auto;
        transform: scale(0.60);
        /* Wider (was 0.54) */
        transform-origin: bottom center;
        width: 166.6%;
        /* 100 / 0.60 */
        margin-left: -33.3%;
        /* (166.6 - 100) / 2 */
        bottom: 35px;
        /* Lifted */
        z-index: 80;
        position: absolute;
    }

    #exit-btn {
        padding: 4px 10px !important;
        font-size: 0.7rem !important;
    }

    /* 2. Move Controls to RIGHT SIDE VERTICALLY to avoid overlap */
    /* 2. Move Controls to LEFT SIDE and UP */
    .controls-left {
        left: 10px;
        right: auto;
        bottom: 60px;
        /* Moved left and up */
        top: auto;
        transform: scale(0.7);
        flex-direction: column;
        z-index: 90;
    }

    /* 3. Center Table - Tiny & Moved Up */
    .table-center {
        top: 35%;
        /* Moved up from 45% */
        transform: translate(-50%, -50%) scale(0.45);
    }

    /* 4. Side Discards - At the corners of the rack */
    /* 4. Side Discards - Aligned with opponents (70px from edge) & moved up */
    /* 4. Side Discards - Aligned with opponents (70px from edge) & moved up */
    #discard-p0 {
        right: 70px;
        bottom: 155px;
        /* Up */
        transform: scale(0.5);
    }

    #discard-p3 {
        left: 70px;
        bottom: 155px;
        /* Up */
        transform: scale(0.5);
    }

    /* Top corners */
    #discard-p1 {
        right: 70px;
        top: 10px;
        transform: scale(0.5);
    }

    #discard-p2 {
        left: 70px;
        top: 10px;
        transform: scale(0.5);
    }

    /* 5. Player Tags - Compact */
    .tag-top {
        top: 5px;
    }

    .tag-left {
        left: 5px;
        top: 40%;
    }

    .tag-right {
        right: 5px;
        top: 40%;
    }

    /* Hide bottom tag in landscape to save vertical space if needed, or make very small */
    .tag-bottom {
        bottom: 160px;
        /* Down slightly */
        transform: translateX(-50%) scale(0.8);
    }

    /* 6. Header - Slimmer */
    .main-header {
        height: 35px;
    }

    .logo,
    .game-stats {
        font-size: 0.7rem;
    }

    .mini-tile {
        width: 16px;
        height: 22px;
        font-size: 0.6rem;
    }

    .player-tag {
        padding: 2px 5px;
        font-size: 0.6rem;
    }

    .player-tag img,
    .player-tag .icon {
        width: 16px;
        /* Even smaller avatar */
        height: 16px;
        margin-right: 2px;
        border-width: 1px;
    }

    .score-badge {
        font-size: 0.55rem;
        padding: 0 2px;
        margin-left: 2px;
    }

    /* SETUP SCREEN LANDSCAPE OPTIMIZATION */
    /* SETUP SCREEN LANDSCAPE OPTIMIZATION - LOGICAL LAYOUT */
    #setup-screen>div {
        transform: scale(0.9);
        /* Moderate scale */
        width: 95% !important;
        max-width: 700px !important;
        padding: 20px !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        /* Two columns */
        gap: 20px;
        align-items: start;
        text-align: left;
    }

    /* Left Column Elements */
    #setup-screen i {
        display: block !important;
        font-size: 1.5rem !important;
        margin-bottom: 5px !important;
        grid-column: 1 / -1;
        /* Icon on top, centered? Or just hide it. Let's keep it minimal */
        display: none !important;
    }

    #setup-screen h1 {
        grid-column: 1 / -1;
        /* Title spans full width */
        font-size: 1.2rem !important;
        margin-bottom: 10px !important;
        text-align: center;
    }

    #setup-screen p {
        display: none !important;
    }

    /* Left Side Content */
    #player-name {
        grid-column: 1;
        width: 100% !important;
        margin-bottom: 0 !important;
        height: 100%;
        /* Fill height of row? */
        align-self: center;
    }

    /* Right Side Content */
    #setup-screen>div>div {
        /* Bot Names Container */
        grid-column: 2;
        width: 100%;
        margin-bottom: 0 !important;
    }

    /* Buttons - Full Width at bottom */
    #play-bot {
        grid-column: 1;
        width: 100% !important;
        margin: 0 !important;
    }

    #exit-main {
        grid-column: 2;
        width: 100% !important;
        margin: 0 !important;
    }

    #exit-main {
        margin-right: 0;
    }
}