/* remi.css */
:root {
    --remi-tile-bg: #fdfaf1;
    --remi-tile-text: #333;
    --remi-bg-main: #0a4d25;
    --remi-table-gradient: radial-gradient(circle at 50% 50%, #177a3d 0%, #0a4d25 100%);
    --remi-hand-wood: #4d2d18;
    --remi-glass-bg: rgba(0, 0, 0, 0.4);
    --remi-glass-border: rgba(255, 255, 255, 0.1);
    --remi-slot-bg: rgba(255, 255, 255, 0.02);
    --remi-slot-border: rgba(255, 255, 255, 0.1);
    --remi-text: #ffffff;

    /* Tile Colors */
    --remi-clr-red: #e74c3c;
    --remi-clr-blue: #3498db;
    --remi-clr-black: #2c3e50;
    --remi-clr-yellow: #f39c12;
    --remi-clr-joker: #9b59b6;
}

body.dark-theme.remi-body {
    --remi-tile-bg: #1a1a1a;
    --remi-tile-text: #ffffff;

    /* Darker background for dark theme */
    --remi-bg-main: #02140a;
    --remi-table-gradient: radial-gradient(circle at 50% 50%, #052c14 0%, #02140a 100%);

    --remi-hand-wood: #3a2210;
    --remi-glass-bg: rgba(0, 0, 0, 0.2);
    --remi-glass-border: rgba(255, 255, 255, 0.1);
    --remi-slot-bg: rgba(0, 0, 0, 0.1);
    --remi-slot-border: rgba(255, 255, 255, 0.1);
    --remi-text: #e0e0e0;

    /* Tile Colors for Dark Mode - "black" becomes white */
    --remi-clr-red: #ff5e57;
    --remi-clr-blue: #48dbfb;
    --remi-clr-black: #ffffff;
    --remi-clr-yellow: #feca57;
    --remi-clr-joker: #d291ff;
}


body.remi-body {
    background-color: var(--remi-bg-main);
    background-image: var(--remi-table-gradient);
    font-family: 'Outfit', sans-serif;
    color: var(--remi-text);
    min-height: 100vh;
    overflow-x: hidden; /* Prevent global horizontal scroll */
}

.glass-panel {
    background: var(--remi-glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--remi-glass-border);
    border-radius: 20px;
}

.remi-hand {
    background: var(--remi-hand-wood);
    padding: 15px;
    border-radius: 10px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.4);
    min-height: 160px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 900px;
}

.hand-row {
    display: grid;
    grid-template-columns: repeat(20, 42px);
    gap: 4px;
    padding: 10px;
    min-height: 70px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow-x: auto;
    user-select: none;
    -webkit-user-select: none;
}

.tile-slot {
    width: 40px;
    height: 55px;
    border: 1px dashed var(--remi-slot-border);
    border-radius: 5px;
    background: var(--remi-slot-bg);
    position: relative;
    /* Removed overflow:hidden to allow selected tiles to pop up */
}

.tile {
    width: 40px;
    height: 55px;
    background: var(--remi-tile-bg);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--remi-tile-text);
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.1s, box-shadow 0.1s;
    position: relative;
    z-index: 10;
    touch-action: none;
}

.tile span {
    pointer-events: none; /* Prevents text-selection ghosts on drag */
}

.tile:active {
    cursor: grabbing;
}

.tile.dragging {
    opacity: 0.5;
}

.tile.selected {
    border: 3px solid #2ecc71 !important;
    transform: translateY(-10px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
}

.tile.tile-back {
    background: linear-gradient(135deg, #d4d4d4 0%, #a5a5a5 100%);
    border: 2px solid #fff;
    box-shadow: 2px 2px 0px #777;
    background-image: radial-gradient(circle, #888 1px, transparent 1px);
    background-size: 4px 4px;
}

.tile.tile-back.small,
.tile.small {
    width: 32px;
    height: 48px;
    font-size: 1rem;
}

.tile.tile-red {
    color: var(--remi-clr-red);
}

.tile.tile-blue {
    color: var(--remi-clr-blue);
}

.tile.tile-black {
    color: var(--remi-clr-black);
}

.tile.tile-yellow {
    color: var(--remi-clr-yellow);
}

.tile.tile-joker {
    color: var(--remi-clr-joker);
}

.tile.mini {
    width: 22px;
    height: 32px;
    font-size: 0.75rem;
    border-radius: 3px;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.tile.mini span {
    transform: scale(0.9);
}

/* --- LAYOUT OPTIMIZAT --- */

.remi-body .remi-wrapper {
    max-width: 100vw;
    margin: 0 auto;
    padding-top: 120px !important;
    overflow-x: hidden; /* Locks page to viewport width */
    /* Spatiu sub navbar - CLEARANCE FIXED */
}

.remi-body .remi-table {
    display: grid;
    grid-template-areas:
        ". top ."
        "left center right"
        ". bottom .";
    grid-template-columns: 200px 1fr 200px;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
    align-items: center;
    min-height: calc(100vh - 140px);
}

.remi-body .opp-top {
    grid-area: top;
    display: flex;
    justify-content: center;
    margin-bottom: 5px;
}

.remi-body .opp-left {
    grid-area: left;
    display: flex;
    justify-content: center;
    transform: rotate(90deg);
    margin-left: -40px;
}

.remi-body .opp-right {
    grid-area: right;
    display: flex;
    justify-content: center;
    transform: rotate(-90deg);
    margin-right: -40px;
}

.remi-body .player-area {
    grid-area: bottom;
    display: flex;
    justify-content: center;
    margin-top: 5px;
}

.remi-body .table-center {
    grid-area: center;
    min-height: 380px;
    display: flex;
    flex-direction: column;
    padding: 1.5rem !important;
}

/* Central Stacks */
.remi-body .deck-stacks-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    /* Closer together */
    flex-wrap: wrap;
    margin: 15px 0;
    min-height: 80px;
    max-width: 90%;
    /* Keep it centered and grouped */
    margin-left: auto;
    margin-right: auto;
}

.remi-body .stack-pile {
    position: relative;
    width: 45px;
    height: 60px;
    cursor: pointer;
}

.remi-body .stack-count {
    position: absolute;
    bottom: -28px;
    /* Slightly lower */
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    color: var(--remi-text);
    font-weight: 800;
    white-space: nowrap;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.remi-body .stack-pile.single-stack {
    width: 60px;
    height: 80px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.remi-body .stack-pile.single-stack:hover {
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.4);
}

.remi-body .stack-pile.active-stack {
    filter: drop-shadow(0 0 8px rgba(255, 193, 7, 0.4));
    cursor: grab;
    transition: transform 0.2s;
}

.remi-body .stack-pile.active-stack:hover {
    transform: translateY(-5px) scale(1.05);
    filter: drop-shadow(0 0 12px rgba(255, 193, 7, 0.6));
}

/* Opponent Hands - Wood Rack Style */
.remi-body .opponent-hand {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
    background: var(--remi-hand-wood);
    padding: 10px;
    border-radius: 8px;
    position: relative;
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6), 0 5px 15px rgba(0, 0, 0, 0.4);
    min-width: 160px;
    max-width: 280px;
}

.remi-body .opponent-info {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 0.8rem;
    font-weight: 800;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 10px;
    border-radius: 10px;
}

.discard-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    border-radius: 12px;
    transition: background 0.2s;
}

#discard-pile-visual {
    width: 40px;
    height: 55px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 1px dashed rgba(255, 255, 255, 0.2);
}

.remi-body .opponent-tile-back {
    width: 25px;
    height: 38px;
    background: linear-gradient(135deg, #eee 0%, #aaa 100%);
    border: 1px solid #fff;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
}

.remi-body .melded-container {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 140px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
    padding: 1rem;
    border-radius: 12px;
    overflow-y: auto;
    overflow-x: auto;
}

.atu-area {
    background: rgba(255, 193, 7, 0.05);
    padding: 8px;
    border-radius: 12px;
    border: 1px dashed rgba(255, 193, 7, 0.2);
}

.x-small {
    font-size: 0.65rem;
    letter-spacing: 0.5px;
}

.glow-purple {
    box-shadow: 0 0 15px rgba(155, 89, 182, 0.6) !important;
    border: 2px solid #9b59b6 !important;
}

.discard-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

@media (max-width: 1200px) {
    .remi-body .remi-table {
        grid-template-columns: 150px 1fr 150px;
    }
}

@media (max-width: 992px) {
    .remi-body .remi-table {
        grid-template-columns: 1fr;
        grid-template-areas:
            "top"
            "center"
            "left"
            "right"
            "bottom";
        gap: 10px;
    }

    .remi-body .opp-left,
    .remi-body .opp-right {
        display: flex;
        transform: none;
        margin: 2px 0;
        justify-content: center;
    }

    .remi-body .opp-left {
        grid-area: left;
    }

    .remi-body .opp-right {
        grid-area: right;
    }

    .remi-body .opponent-hand {
        max-width: 100%;
        width: 100%;
    }
}

@media (max-width: 600px) {
    .remi-body .remi-wrapper {
        padding-top: 105px !important; /* Increased to push top opponent below Navbar */
        padding-left: 5px;
        padding-right: 5px;
    }

    .remi-body .remi-table {
        grid-template-areas: 
            "top" 
            "center" 
            "left" 
            "right" 
            "bottom";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto;
        gap: 6px;
        justify-items: center;
        width: 100%;
        margin: 0 auto;
    }

    .remi-body .table-center {
        min-height: auto;
        padding: 0.4rem !important;
        width: 100%;
        max-width: 100vw;
        display: flex;
        flex-direction: column;
        align-items: center;
        box-sizing: border-box;
    }

    .remi-body .deck-stacks-grid {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 4px;
        width: 100%;
        margin: 4px auto;
        flex-wrap: wrap;
    }

    .remi-body .stack-pile {
        width: 22px;
        height: 32px;
    }

    .remi-body .stack-count {
        bottom: -15px;
        font-size: 0.6rem;
    }

    .remi-body .hand-row {
        grid-template-columns: repeat(20, 42px);
        gap: 4px;
        padding: 5px;
        min-height: 70px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
        padding-bottom: 12px; /* Space for scrollbar */
    }

    /* Fat scrollbar for touch-friendly scrolling */
    .remi-body .hand-row::-webkit-scrollbar {
        height: 14px;
        display: block;
    }
    .remi-body .hand-row::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.3);
        border-radius: 6px;
    }
    .remi-body .hand-row::-webkit-scrollbar-thumb {
        background: #1abc9c;
        border-radius: 6px;
        border: 1px solid rgba(0,0,0,0.5);
    }

    .remi-body .tile, .remi-body .tile-slot {
        width: 40px !important;
        height: 55px !important;
        font-size: 1.2rem !important;
    }

    .remi-body .discard-area {
        padding: 4px;
        min-width: 50px;
    }

    .remi-body #discard-pile-visual {
        width: 32px;
        height: 48px;
    }

    .remi-body .board-controls {
        gap: 3px !important;
        margin-bottom: 5px !important;
    }

    .remi-body .board-controls .btn {
        padding: 0.25rem 0.4rem;
        font-size: 0.65rem;
    }

    .remi-body .opponent-tile-back {
        width: 14px;
        height: 22px;
    }

    .remi-body .opponent-info {
        top: -16px;
        font-size: 0.6rem;
        padding: 1px 6px;
    }

    .remi-body .melded-container {
        min-height: 40px;
        padding: 4px;
        gap: 4px;
        padding-bottom: 10px;
    }

    .remi-body .melded-container::-webkit-scrollbar {
        height: 10px;
        display: block;
    }
    .remi-body .melded-container::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 5px;
    }
    .remi-body .melded-container::-webkit-scrollbar-thumb {
        background: rgba(26, 188, 156, 0.7);
        border-radius: 5px;
    }

    .remi-body .remi-hand {
        min-height: 100px;
        padding: 4px;
        width: 98vw;
        max-width: 600px;
    }

    .remi-body .opponent-hand {
        padding: 4px;
        min-width: 120px;
        max-width: 90vw;
        transform: scale(0.85);
        transform-origin: center;
        margin-bottom: 15px;
    }

    .remi-body #turn-indicator {
        font-size: 1rem !important;
        text-align: center;
        width: 100%;
        margin-bottom: 5px;
    }

    .remi-body .badge {
        font-size: 0.6rem;
        padding: 2px 4px;
    }
}

/* --- MOBILE DRAG & DROP SUPPORT --- */
.remi-body .tile {
    touch-action: none;
    /* Prevent scrolling when dragging */
}

.dragging-ghost {
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    opacity: 0.85;
    transform: scale(1.1);
    transition: none !important;
}

/* --- FIX HORIZONTAL SCROLL ON MOBILE --- */
@media (max-width: 480px) {
    .remi-body .remi-wrapper {
        padding-top: 100px !important; /* Increased for mobile portrait */
        padding-left: 2px !important;
        padding-right: 2px !important;
        overflow-x: hidden;
    }

    .remi-body .remi-table {
        grid-template-columns: 1fr;
        width: 100%;
        margin: 0;
    }

    .remi-body .hand-row {
        grid-template-columns: repeat(20, 42px);
        gap: 4px;
        padding: 6px;
        min-height: 70px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        box-sizing: border-box;
        padding-bottom: 12px; /* Extra room for fat scrollbar */
    }

    /* Fat touch-friendly scrollbar for mobile */
    .remi-body .hand-row::-webkit-scrollbar {
        height: 14px;
        display: block;
    }
    .remi-body .hand-row::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.4);
        border-radius: 7px;
    }
    .remi-body .hand-row::-webkit-scrollbar-thumb {
        background: #1abc9c;
        border-radius: 7px;
        border: 2px solid rgba(0,0,0,0.5);
    }

    .remi-body .stack-pile {
        width: 25px;
        height: 35px;
    }

    .remi-body .opponent-hand {
        min-width: 80px;
        padding: 4px;
    }

    .remi-body .opponent-tile-back {
        width: 8px;
        height: 14px;
    }

    .remi-body .table-center {
        padding: 0.75rem !important;
    }

    .remi-body .atu-area #atu-tile-visual .tile,
    .remi-body .discard-area #discard-pile-visual .tile {
        width: 32px !important;
        height: 44px !important;
        font-size: 1rem !important;
        display: flex !important;
    }

    .remi-body .atu-area {
        padding: 4px;
    }
    
    .remi-body .x-small {
        font-size: 0.55rem;
    }

    .remi-body .table-center .d-flex.align-items-center.gap-3 {
        gap: 10px !important;
        justify-content: center;
    }
}

/* Specific fix for ultra-narrow screens (e.g. iPhone SE) */
@media (max-width: 380px) {
    .remi-body .table-center {
        padding: 0.4rem !important;
    }

    .remi-body #turn-indicator {
        font-size: 0.85rem;
    }

    .remi-body .board-controls {
        display: flex;
        flex-wrap: wrap !important;
        justify-content: center;
        gap: 2px !important;
        width: 100%;
    }

    .remi-body .board-controls .btn {
        padding: 0.3rem 0.4rem !important;
        font-size: 0.65rem !important;
        flex: 1 1 auto;
        min-width: 60px;
    }
}

/* --- REMI MODAL ENHANCEMENTS --- */
.remi-modal .modal-content {
    background-color: #1a1d21 !important; /* Force dark background even on white themes */
    background-image: linear-gradient(145deg, #23272d, #1a1d21);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    color: #ffffff !important;
}

.remi-modal .modal-header, 
.remi-modal .modal-body, 
.remi-modal .modal-footer {
    color: #ffffff !important;
}

.remi-modal h4,
.remi-modal h5,
.remi-modal h6,
.remi-modal p,
.remi-modal li,
.remi-modal div:not(.tile):not(.tile-slot) {
    color: #ffffff !important;
}

.remi-modal .text-white-50 {
    color: rgba(255, 255, 255, 0.7) !important;
}

/* Ensure tiles in modals maintain their specific colors and readable background */
.remi-modal .tile {
    background-color: #fdfaf1 !important; /* Force light background for tiles in modals for clarity */
    color: inherit;
}

.remi-modal .tile.tile-black { color: #2c3e50 !important; }
.remi-modal .tile.tile-red { color: #e74c3c !important; }
.remi-modal .tile.tile-blue { color: #3498db !important; }
.remi-modal .tile.tile-yellow { color: #f39c12 !important; }
.remi-modal .tile.tile-joker { color: #9b59b6 !important; }

.remi-modal .modal-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem 1.5rem 1rem;
}

.remi-modal .modal-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 1.5rem 1.5rem;
}

.remi-modal .btn-close-white {
    filter: invert(1) grayscale(100%) brightness(200%);
}

@media (max-width: 576px) {
    .remi-modal .modal-dialog {
        display: flex;
        align-items: center;
        min-height: calc(100% - 1rem);
        margin: 0.5rem auto;
        pointer-events: none;
        width: calc(100% - 1rem);
    }


    .remi-modal .modal-content {
        margin: auto;
        pointer-events: auto;
    }
}

.pulse-warning {
    animation: pulsate-warning 2.5s infinite;
}

@keyframes pulsate-warning {

    0%,
    100% {
        opacity: 0.7;
    }

    50% {
        opacity: 1;
        color: #ffc107;
    }
}