:root {
    --primary-color: #8b4513;
    /* SaddleBrown */
    --secondary-color: #d2691e;
    /* Chocolate */
    --accent-color: #228b22;
    /* ForestGreen */
    --background-color: #f0e6d2;
    /* Linen */
    --card-bg: #fff;
    --text-color: #3e2723;
    --text-light: #f0e6d2;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.3);
    --font-main: 'Special Elite', cursive;
    --font-display: 'Rye', serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--background-color);
    background-image: url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%238b4513" fill-opacity="0.05"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    transition: background 0.5s ease;
}

/* Dedicated Game Screen Styles */
body.game-active {
    background-color: var(--background-color);
    /* Revert to default (white/linen) */
    background-image: url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%238b4513" fill-opacity="0.05"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
    /* Keep subtle pattern */
}

body.game-active .game-container {
    background: rgba(0, 0, 0, 0.2);
    /* Dark overlay for contrast */
    background-image: url('/static/felt-texture.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8);
    /* Inner shadow for depth */
    display: flex;
    flex-direction: column;
    /* Match landing page border */
    border: 2px solid var(--primary-color);
}

/* Game Info Footer */
#game-info-footer {
    margin-top: auto;
    /* Push to bottom of flex container */
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #3e2723;
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
    color: white;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-height: 150px;
    /* Increased height for 3 messages */
    max-height: 200px;
    overflow-y: auto;
}

#game-info-footer .game-status {
    margin-bottom: 5px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

#game-info-footer #turn-timer {
    margin: 0 auto;
}

/* Remove old order styles */
body.game-active #game-status,
body.game-active #message-area,
body.game-active #turn-timer {
    order: unset;
    z-index: auto;
}

/* On mobile, position them above the fixed player hand */
@media (max-width: 768px) {

    /* Adjust footer for mobile */
    #game-info-footer {
        margin-bottom: 20px;
        /* Standard margin */
    }
}

/* Wood texture for border (optional, using solid color for now or could use image) */
body.game-active .game-container::before {
    content: '';
    position: absolute;
    top: -15px;
    left: -15px;
    right: -15px;
    bottom: -15px;
    border: 2px solid #3e2723;
    border-radius: 20px;
    pointer-events: none;
    z-index: -1;
}

body.game-active .cover-art,
body.game-active h1,
body.game-active .creator-credit,
body.game-active img[src*="old-maid-cover.jpg"] {
    display: none !important;
}

.game-container {
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 1200px;
    min-height: 90vh;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    position: relative;
    backdrop-filter: blur(10px);
    border: 2px solid var(--primary-color);
}

/* Typography */
h1,
h2,
h3 {
    font-family: var(--font-display);
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 1rem;
}

h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* Game Setup & Lobby */
.game-section {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    text-align: center;
}

input,
select,
button {
    font-family: var(--font-main);
    font-size: 1.1rem;
    padding: 12px 20px;
    border-radius: 12px;
    border: 2px solid var(--primary-color);
    margin: 10px 0;
    width: 100%;
    transition: all 0.3s ease;
}

input,
select {
    background-color: white;
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%238b4513' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 16px;
    padding-right: 45px;
    cursor: pointer;
}

input:focus,
select:focus {
    border-color: var(--secondary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.2);
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover {
    background-color: #34495e;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

button.secondary {
    background-color: var(--secondary-color);
}

button.secondary:hover {
    background-color: #d35400;
}

/* Game Board */
#game-board {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex-grow: 1;
    max-width: 100%;
    justify-content: center;
    /* Center content vertically */
}

.game-status {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    /* Reduced margin */
    font-weight: 500;
    box-shadow: var(--shadow);
}

/* Opponents Area */
#opponents-section {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    /* Removed margin-bottom: auto to reduce space */
    padding: 1rem 0;
    /* Reduced padding */
    margin-bottom: 2rem;
    /* Fixed spacing instead of auto */
}

/* Turn Timer */
#turn-timer {
    background-color: var(--secondary-color);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    margin: 10px auto;
    width: fit-content;
    font-weight: bold;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

#turn-timer.warning {
    background-color: #e74c3c;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

/* Loader for Disconnect Modal */
.loader {
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.opponent {
    text-align: center;
    background: rgba(255, 255, 255, 0.5);
    padding: 1rem;
    border-radius: 15px;
    transition: transform 0.3s ease;
}

.opponent.active {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px var(--secondary-color);
    background: white;
}

.opponent-cards {
    display: flex;
    justify-content: center;
    margin-top: 10px;
    height: 100px;
    /* Fixed height for card backs */
}

.card-back-mini {
    width: 50px;
    height: 70px;
    background-color: #000080;
    /* Navy blue fallback */
    background-image: url('/static/card_back.png');
    /* Try to use the static file */
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    margin-left: -30px;
    /* Overlap effect */
    border: 1px solid white;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
    cursor: pointer;
}

.card-back-mini:first-child {
    margin-left: 0;
}

.card-back-mini:hover {
    transform: translateY(-10px);
    z-index: 10;
}

#player-section {
    background: rgba(255, 255, 255, 0.5);
    padding: 1rem;
    border-radius: 15px;
    margin: 1rem 0;
    border: none;
    width: 100%;
    text-align: center;
    position: relative;
    /* For shuffle button positioning */
    overflow: visible;
    /* Allow button to overhang */
}

/* Specific override for game active */
body.game-active #player-section {
    margin: 1rem 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.5);
    /* Match opponent transparency */
}

#shuffle-hand-btn {
    position: absolute;
    bottom: 10px;
    /* Bottom */
    right: 10px;
    /* Right */
    top: auto;
    /* Reset top */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    /* Circular */
    background-color: var(--secondary-color);
    color: white;
    border: none;
    cursor: pointer;
    font-family: var(--font-main);
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    padding: 0;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

#shuffle-hand-btn::after {
    content: 'Shuffle';
    position: absolute;
    bottom: 100%;
    right: 50%;
    transform: translateX(50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    white-space: nowrap;
    margin-bottom: 5px;
}

#shuffle-hand-btn:hover::after {
    opacity: 1;
}

#shuffle-hand-btn:hover {
    background-color: #d35400;
    transform: scale(1.05);
}

.player-hand {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 160px;
    perspective: 1000px;
}

.card {
    width: 100px;
    height: 140px;
    /* Standard card ratio */
    background-color: transparent;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: block;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    user-select: none;
}

.card img {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    object-fit: cover;
    display: block;
}

.card:hover {
    transform: translateY(-20px) scale(1.05);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.card.selected {
    transform: translateY(-30px);
    box-shadow: 0 0 15px var(--secondary-color);
}

/* Old Maid Special Styling */
.card.old-maid img {
    border: 5px solid white;
    border-radius: 8px;
    box-sizing: border-box;
}

/* Animations */
@keyframes deal {
    from {
        transform: translateY(-500px) rotate(720deg);
        opacity: 0;
    }

    to {
        transform: translateY(0) rotate(0);
        opacity: 1;
    }
}

.card.dealt {
    animation: deal 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px) rotate(-5deg);
    }

    75% {
        transform: translateX(5px) rotate(5deg);
    }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .game-container {
        padding: 0.5rem;
        /* Reduce padding */
        min-height: 100vh;
        border-radius: 0;
        justify-content: flex-start;
        /* Align to top to prevent squeezing */
    }

    h1 {
        font-size: 1.5rem;
        /* Smaller title */
        margin-bottom: 1rem;
    }

    /* Ensure Dad/Opponent section has space */
    #opponents-section {
        margin-top: 1rem;
        padding-top: 2rem;
        /* Space for Dad popup if needed */
    }

    .card {
        width: 70px;
        height: 105px;
        font-size: 1rem;
    }

    .card-center {
        font-size: 1.5rem;
    }

    #opponents-section {
        gap: 1rem;
        flex-wrap: wrap;
        /* Allow wrapping */
        justify-content: center;
        /* Center items */
        padding: 1rem;
    }

    .opponent {
        min-width: 100px;
        /* Allow smaller width */
        max-width: 45%;
        /* Ensure 2 per row on very small screens */
        flex-shrink: 1;
        /* Allow shrinking */
    }

    #player-section {
        position: relative;
        /* Unfix on mobile to allow scrolling to footer */
        bottom: auto;
        left: auto;
        right: auto;
        margin: 1rem 0;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.5);
        border: none;
        z-index: 1;
        width: 100%;
    }

    .player-hand {
        flex-wrap: wrap;
        justify-content: center;
        padding-bottom: 10px;
        min-height: 100px;
        /* Reduce height */
    }

    .card:hover {
        transform: translateY(-10px);
    }

    .card {
        width: 60px;
        /* Smaller cards */
        height: 90px;
        font-size: 1rem;
    }

    .card-back-mini {
        width: 40px;
        height: 60px;
        margin-left: -25px;
        /* Tighter overlap */
    }

    /* Adjust main content area to not be hidden by fixed player section */
    #game-board {
        padding-bottom: 180px;
    }
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 20px;
    max-width: 90%;
    width: 400px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Creator Credit */
.creator-credit {
    margin-top: 30px;
    padding: 20px;
    border-top: 2px solid var(--primary-color);
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
}

.creator-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.creator-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
}

.dad-avatar-mini {
    width: 40px;
    /* Reduced size */
    height: 40px;
    min-width: 40px;
    /* Prevent shrinking */
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    overflow: hidden;
    background: white;
    box-shadow: var(--shadow);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dad-avatar-mini img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.creator-text {
    text-align: left;
}

.creator-text p {
    margin: 0;
    color: var(--primary-color);
}

.license-text {
    font-size: 12px;
    font-style: italic;
    margin-top: 5px !important;
}

/* Dad Joke Styling - Dynamic */
/* Dad Message Panel - Permanent Horizontal Bar */
.dad-message-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    width: 100%;
    max-width: 500px;
    /* Limit width on large screens */
    margin-left: auto;
    margin-right: auto;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dad-message-text {
    background: white;
    padding: 10px 20px;
    border-radius: 15px;
    border: 2px solid var(--primary-color);
    box-shadow: var(--shadow);
    font-family: var(--font-main);
    color: var(--text-color);
    font-size: 1.1rem;
    flex-grow: 1;
    /* Expand horizontally */
    text-align: left;
    position: relative;
}

/* Speech bubble tail pointing left to avatar */
.dad-message-text::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -10px;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 10px 10px 0;
    border-color: transparent var(--primary-color) transparent transparent;
}

.dad-message-text::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -7px;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 8px 0;
    border-color: transparent white transparent transparent;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .dad-message-panel {
        width: 100%;
        padding: 0 10px;
        /* Ensure padding on small screens */
    }
}