:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.1);
    
    --card-width: min(180px, 18vw);
    --card-height: calc(var(--card-width) * 1.4);
    --card-red: #ef4444;
    --card-black: #1e293b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #fdfdfd;
    background-image: url('table_setting.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: #1e293b;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Prevent vertical jumping */
    padding-top: 8vh;
    padding-bottom: 5vh;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    text-align: center;
}

h1 {
    font-size: 4.5rem;
    font-weight: 800;
    color: #1e3a8a;
    margin-bottom: 0.5rem;
    text-align: center;
}

.subtitle {
    color: #475569;
    font-size: 1.6rem;
}

.game-area {
    display: flex;
    gap: 3rem;
    align-items: flex-start;
    justify-content: center;
}

/* Grid */
.grid-container {
    display: grid;
    grid-template-columns: repeat(3, var(--card-width));
    grid-template-rows: repeat(3, var(--card-height));
    gap: 1.5rem;
    perspective: 1000px;
}

.pile {
    width: var(--card-width);
    height: var(--card-height);
    position: relative;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s;
    transform-style: preserve-3d;
}

.pile::after {
    /* Subtle placeholder outline when empty or for positioning */
    content: '';
    position: absolute;
    inset: 0;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    z-index: -1;
}

.pile:hover:not(.disabled):not(.active) {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.pile.active {
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 0 0 3px var(--accent-primary), 0 15px 30px rgba(59, 130, 246, 0.3);
}

.pile.disabled {
    cursor: not-allowed;
    opacity: 0.6;
    filter: grayscale(0.5);
}

/* Card Styling */
.card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0.5rem;
    backface-visibility: hidden;
    transform-origin: center;
    user-select: none;
}

.card-back {
    background: linear-gradient(135deg, #1e3a8a, #3b82f6);
    background-image: radial-gradient(circle at center, #2563eb 0%, #1e3a8a 100%);
    border: 4px solid white;
    transform: rotateY(180deg);
}

.card-back::after {
    content: '♠♥♦♣';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.2);
    font-size: 2rem;
    text-align: center;
    line-height: 1.2;
}

/* Red X for eliminated piles */
.red-x {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5rem;
    font-weight: 800;
    color: var(--danger);
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
    z-index: 10;
    animation: stampX 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes stampX {
    0% { transform: scale(3); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Card Ranks and Suits */
.card-top { align-self: flex-start; text-align: left; }
.card-bottom { align-self: flex-end; text-align: right; transform: rotate(180deg); }
.card .rank { font-size: 1.2rem; font-weight: 800; line-height: 1; }
.card .suit { font-size: 1.2rem; line-height: 1; }

.suit-hearts, .suit-diamonds { color: var(--card-red); }
.suit-spades, .suit-clubs { color: var(--card-black); }

/* Sidebar */
.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.deck-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    justify-content: space-between;
}

.deck-area {
    text-align: center;
    flex: 1;
}

.deck-area h2 {
    font-size: 1.8rem;
    color: #334155;
    margin-bottom: 1rem;
}

.deck-visual {
    width: var(--card-width);
    height: var(--card-height);
    margin: 0 auto;
    position: relative;
    border-radius: 12px;
    box-shadow: -2px -2px 0 #0f172a, -4px -4px 0 #1e293b, -6px -6px 0 #334155;
    transition: transform 0.2s;
}

.deck-visual .card {
    transform: rotateY(0); /* Ensure back is visible when in deck visual */
}

.deck-visual:hover {
    transform: translate(2px, 2px);
    box-shadow: -1px -1px 0 #0f172a, -2px -2px 0 #1e293b, -3px -3px 0 #334155;
}

.deck-count {
    margin-top: 1.5rem;
    font-size: 1.4rem;
    color: #475569;
}

.deck-count span {
    font-weight: 800;
    color: #0f172a;
}

/* Glass Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2.2rem;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
}

.controls-area, .game-over-area {
    width: 100%;
    height: auto; 
    min-height: 240px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.controls-area h3, .game-over-area h3, .stats-area h3 {
    margin-bottom: 0.8rem;
    font-size: 1.8rem;
    color: #1e293b;
}

.controls-area p, .stats-area p {
    font-size: 1.3rem;
    color: #475569;
    margin-bottom: 1.5rem;
}

.highlight {
    color: #2563eb;
    font-weight: 800;
}

.buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.btn {
    padding: 1.2rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-weight: 800;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.btn-higher {
    background-color: var(--success);
}
.btn-higher:hover { background-color: #16a34a; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4); }

.btn-lower {
    background-color: var(--danger);
}
.btn-lower:hover { background-color: var(--danger-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4); }

.btn-primary {
    background-color: var(--accent-primary);
    width: 100%;
}
.btn-primary:hover { background-color: var(--accent-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4); }

.sub-text {
    margin-top: 1rem;
    font-size: 1.1rem;
    color: #64748b;
}

#game-over-message {
    margin-bottom: 1.5rem;
    color: #475569;
    font-size: 1.4rem;
}

/* Animations */
.anim-deal {
    animation: dealCard 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes dealCard {
    from { 
        transform: translate(200px, -200px) scale(0.5); 
        opacity: 0; 
    }
    to { 
        transform: translate(0, 0) scale(1); 
        opacity: 1; 
    }
}

.anim-flip {
    animation: flipCard 0.6s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes flipCard {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(90deg) scale(1.1); }
    100% { transform: rotateY(0deg) scale(1); }
}

.anim-shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Media Queries */
@media (max-width: 900px) {
    body {
        padding: 0;
        margin: 0;
        height: 100vh;
        height: 100dvh;
        overflow: hidden; /* NO SCROLLING */
        align-items: center;
        background-attachment: scroll;
    }
    
    .app-container {
        padding: 0.5rem;
        gap: 0.5rem;
        height: 100%;
        max-height: 100dvh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    header { margin-top: 0.5rem; }
    h1 { font-size: 2rem; margin-bottom: 0; }
    .subtitle { font-size: 1rem; margin-bottom: 0; }

    .game-area {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
        flex: 1;
        justify-content: center;
    }
    
    .grid-container {
        --card-width: 21vw;
        --card-height: calc(var(--card-width) * 1.4);
        gap: 2vw;
    }
    
    .sidebar {
        width: 100%;
        max-width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Deck area compaction */
    .deck-row {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 1.5rem;
    }
    .deck-visual, .deck-area h2 { display: none; }
    .deck-area { text-align: left; flex: unset; }
    .deck-count { margin-top: 0; font-size: 1.2rem; }

    /* Stats Area compaction */
    .stats-area {
        padding: 0.5rem 1rem;
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    .stats-area h3, .stats-area p {
        margin: 0;
        font-size: 1.2rem;
    }

    .glass-panel { padding: 0.5rem; border-radius: 12px; }
    
    .controls-area, .game-over-area {
        height: auto;
        min-height: auto;
    }
    .controls-area h3, .controls-area p { display: none; }
    .controls-area .buttons {
        flex-direction: row;
        justify-content: center;
        gap: 1rem;
    }

    .btn { font-size: 1.5rem; padding: 0.8rem; flex: 1; }
    
    .global-controls {
        margin-top: 0;
        padding-bottom: 0.5rem;
    }
    .global-controls .btn { padding: 0.5rem 1rem; font-size: 1rem; }

    .card .rank, .card .suit { font-size: 0.9rem; }
    .center-symbol.giant { font-size: 2.5rem; }
    
    /* Overlays */
    .title-logo { font-size: 2.5rem; }
    .title-content { padding: 1.5rem; }
    
    .floating-message { font-size: 3rem; white-space: normal; text-align: center; width: 90%; }
    
    .modal-content { padding: 1rem; }
    
    .btn-mute { top: 5px; right: 5px; width: 40px; height: 40px; font-size: 1.2rem; }
}

/* Global Controls */
.global-controls {
    text-align: center;
    margin-top: 2rem;
}

.btn-secondary {
    background-color: #475569;
    padding: 0.8rem 2rem;
    font-size: 1.1rem;
}

.btn-secondary:hover {
    background-color: #334155;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-mute {
    position: absolute;
    top: 20px;
    right: 20px;
    background: white;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 2rem;
    cursor: pointer;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-mute:hover {
    transform: scale(1.1);
}

/* Pip Layouts */
.card-center {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    padding: 28px 16px; /* Dynamically fit within the card without overlapping the corner numbers */
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.center-symbol {
    font-size: 2.5rem;
    text-align: center;
    margin: auto;
}

.center-symbol.giant {
    font-size: 6rem;
    line-height: 1;
}

.face-card {
    font-size: 3.2rem;
    font-weight: 800;
    font-family: serif;
}

.pips {
    width: 100%;
    height: 100%;
    display: grid;
}

.pip {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    line-height: 1;
}

.upside-down {
    transform: rotate(180deg);
}

.col-1 {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 1fr);
}

.col-1 .pip:nth-child(1) { grid-row: 1; }
.col-1 .pip:nth-child(2) { grid-row: 2; }
.col-1 .pip:nth-child(3) { grid-row: 3; }

.col-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.col-2-with-center {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}
.col-2-with-center .center-pip {
    grid-column: 1 / span 2;
    grid-row: 2;
}

.col-2-3row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}

.col-2-3row .top-center-pip {
    grid-column: 1 / span 2;
    grid-row: 1 / span 2;
    align-self: center;
}

.col-2-3row .bottom-center-pip {
    grid-column: 1 / span 2;
    grid-row: 2 / span 2;
    align-self: center;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    padding: 3rem;
}

.modal-content h2 {
    color: #1e3a8a;
    margin-bottom: 1.5rem;
    text-align: center;
}

.btn-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 2.5rem;
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
}

.btn-close:hover { color: #ef4444; }

.cards-grid {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    padding-top: 10px;
    padding-bottom: 20px;
}

.value-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cards-grid .card {
    position: relative;
    width: 60px;
    height: 84px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.cards-grid .card .rank, .cards-grid .card .suit { font-size: 0.8rem; }
.cards-grid .card .center-symbol.giant { font-size: 2.5rem; }
.col-2-4row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr 1fr;
}

.col-2-4row .center-pip {
    grid-column: 1 / span 2;
    grid-row: 2 / span 2;
    align-self: center;
}

.col-2-4row .top-center-pip {
    grid-column: 1 / span 2;
    grid-row: 1 / span 2;
    align-self: end;
}

.col-2-4row .bottom-center-pip {
    grid-column: 1 / span 2;
    grid-row: 3 / span 2;
    align-self: start;
}

/* Title Screen */
.title-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: inherit;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.title-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(8px);
    z-index: -1;
}

.title-content {
    padding: 4rem;
    max-width: 800px;
}

.title-logo {
    font-size: 5rem;
    background: linear-gradient(to right, #1e3a8a, #dc2626, #22c55e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
}

.btn-play {
    font-size: 2rem;
    padding: 1.5rem 3rem;
    margin-top: 2rem;
    border-radius: 50px;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    box-shadow: 0 10px 20px rgba(34, 197, 94, 0.3);
}

.app-container {
    display: none; /* Hidden by default until play is clicked */
}

/* Floating Message */
.floating-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 6rem;
    font-weight: 800;
    font-family: serif;
    color: white;
    text-shadow: 0 5px 30px rgba(0,0,0,0.8), 0 2px 10px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    z-index: 3000;
    white-space: nowrap;
}

.floating-message.show {
    animation: popInOut 2.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popInOut {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    10% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    20% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}
