/* ============================================
   Palace Card Game - Game Styles
   ============================================ */

/* Game Page Layout */
.game-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.game-header {
    flex-shrink: 0;
}

.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-top: var(--header-height);
    position: relative;
    background: linear-gradient(180deg, #0c1322 0%, #1a2744 50%, #0f172a 100%);
    overflow: hidden;
}

/* Game Screens */
.game-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.game-screen.hidden {
    display: none;
}

/* Start Screen */
#start-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.start-content h1 {
    font-size: clamp(3rem, 10vw, 6rem);
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #fff, var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.start-content .tagline {
    font-size: 1.5rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.start-content .play-btn {
    margin-bottom: 1rem;
}

.start-content .secondary-btn {
    display: block;
}

/* Swap Screen */
#swap-screen {
    padding: 1rem;
    justify-content: center;
    align-items: center;
}

.swap-instructions {
    text-align: center;
    margin-bottom: 2rem;
}

.swap-instructions h2 {
    margin-bottom: 0.5rem;
}

.swap-instructions p {
    color: var(--text-muted);
}

.swap-area {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-bottom: 2rem;
    max-width: 600px;
    width: 100%;
}

.swap-section {
    text-align: center;
}

.swap-section h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

/* Game Over Screen */
#gameover-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.gameover-content h2 {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.gameover-content p {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.gameover-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

/* Main Game Screen */
#game-screen {
    padding: 0.25rem 0.5rem;
    justify-content: flex-start;
    gap: 0.25rem;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* Player Areas */
.opponent-area,
.player-area {
    flex-shrink: 0;
}

.player-area {
    display: flex;
    justify-content: center;
    align-items: center;
}

.player-label {
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0.25rem;
}

.player-cards,
.opponent-cards {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.opponent-cards {
    flex-direction: column-reverse;
}

.table-cards {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Card Rows */
.card-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-height: 70px;
}

.facedown-row {
    margin-bottom: -40px;
    z-index: 1;
}

.faceup-row {
    z-index: 2;
}

.hand-row {
    min-height: 90px;
    z-index: 3;
}

/* Opponent hand with overlapping cards */
#opponent-hand {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    position: relative;
    min-height: 70px;
}

#opponent-hand .card {
    margin-left: -30px;
    transition: transform 0.2s ease, margin-left 0.2s ease;
}

#opponent-hand .card:first-child {
    margin-left: 0;
}

/* Card Styles */
.card {
    width: 50px;
    height: 70px;
    background: white;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    cursor: default;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    user-select: none;
}

.card-face {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.55rem;
    line-height: 1;
    font-weight: 700;
}

.card-corner .card-suit {
    font-size: 0.6rem;
}

.card-corner.top-left {
    top: 4px;
    left: 5px;
}

.card-corner.bottom-right {
    bottom: 4px;
    right: 5px;
    transform: rotate(180deg);
}

.card.red {
    color: #dc2626;
}

.card.black {
    color: #1e293b;
}

.card-rank,
.card-suit {
    line-height: 1;
}

/* Card Back */
.card-back {
    background: linear-gradient(135deg, #1e40af, #3730a3);
    color: rgba(255,255,255,0.3);
    cursor: default;
}

.card-back-design {
    font-size: 0.75rem;
    text-align: center;
}

.card-debug-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6px 5px;
    color: rgba(255,255,255,0.9);
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.card-debug-label {
    font-size: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.75);
    margin-bottom: 0.15rem;
}

.card.debug-red .card-debug-overlay {
    color: #fecaca;
}

.card.debug-black .card-debug-overlay {
    color: #e2e8f0;
}

/* Playable Cards */
.card.playable {
    cursor: pointer;
}

.card.playable:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.4);
}

.card.selected {
    transform: translateY(-10px);
    box-shadow: 0 12px 24px rgba(16, 185, 129, 0.4);
    outline: 3px solid var(--secondary-color);
}

.card.swap-selected {
    transform: translateY(-8px);
    box-shadow: 0 10px 20px rgba(245, 158, 11, 0.4);
    outline: 3px solid var(--accent-color);
}

/* Face-down cards for player (clickable during endgame) */
.card.facedown-playable {
    cursor: pointer;
}

.card.facedown-playable:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.5);
}

/* Center Area */
.center-area {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 90px;
    width: 100%;
}

.center-layout {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
}

.debug-panel {
    grid-column: 1;
    justify-self: start;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-left: 0.25rem;
}

.debug-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.debug-toggle input {
    accent-color: var(--primary-light);
}

.debug-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin: 0;
}

.deck-pile-container {
    display: flex;
    gap: 3rem;
    align-items: center;
    grid-column: 2;
    justify-self: center;
}

.deck-area,
.pile-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.deck,
.pile {
    width: 60px;
    height: 84px;
    position: relative;
}

.deck .card,
.pile .card {
    position: absolute;
    top: 0;
    left: 0;
    width: 60px;
    height: 84px;
}

.deck .card-back-design {
    font-size: 0.875rem;
}

.deck-count,
.pile-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.pile-placeholder {
    width: 60px;
    height: 84px;
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dark);
    font-size: 0.75rem;
}

.twos-indicator {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--primary-color);
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.deck.empty .card {
    display: none;
}

/* Center Controls */
.center-controls {
    grid-column: 3;
    justify-self: start;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}

/* Game Message */
.game-message {
    min-height: 1.5rem;
    padding: 0.5rem 1rem;
    text-align: center;
    font-weight: 600;
    color: var(--text-color);
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
}

.game-message.success {
    background: rgba(16, 185, 129, 0.2);
    color: var(--secondary-color);
}

.game-message.error {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger-color);
}

.game-message.info {
    background: rgba(37, 99, 235, 0.2);
    color: var(--primary-light);
}

/* Control Buttons */
.control-btn {
    padding: 0.85rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 120px;
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pickup-btn {
    background: var(--bg-card);
    color: var(--text-color);
}

#pickup-btn:not(:disabled):hover {
    background: var(--bg-light);
}

#play-btn {
    background: linear-gradient(135deg, var(--secondary-color), var(--secondary-dark));
    color: white;
    min-width: 110px;
}

#play-btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Pile Cards Stack Effect */
.pile .card:nth-child(n+2) {
    display: none;
}

.pile.has-cards .pile-placeholder {
    display: none;
}

/* Animation Classes */
@keyframes dealCard {
    from {
        transform: translateY(-100px) rotate(-10deg);
        opacity: 0;
    }
    to {
        transform: translateY(0) rotate(0);
        opacity: 1;
    }
}

@keyframes playCard {
    from {
        transform: scale(1.3) translateY(-20px);
        opacity: 0;
    }
    50% {
        transform: scale(1.15) translateY(-10px);
        opacity: 0.7;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes playCardFromHand {
    from {
        transform: translateY(100px) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes playCardFromOpponent {
    from {
        transform: translateY(-100px) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes swapFlyIn {
    from {
        transform: translateY(40px) scale(0.9);
        opacity: 0;
    }
    60% {
        opacity: 0.85;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}


@keyframes pickupPile {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1) translateY(50px);
        opacity: 0;
    }
}

.card.dealing {
    animation: dealCard 0.3s ease-out;
}

.card.playing {
    animation: playCard 0.3s ease-out;
}

.card.playing-from-hand {
    animation: playCardFromHand 0.4s ease-out;
}

.card.playing-from-opponent {
    animation: playCardFromOpponent 0.4s ease-out;
}

.card.swap-fly-in {
    animation: swapFlyIn 0.45s ease-out both;
}

/* Flying Card Animation (hand/faceup to pile) */
.flying-card {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    transition: transform 0.35s ease-out, opacity 0.35s ease-out;
}

.flying-card.animate {
    transform: translate(var(--fly-to-x), var(--fly-to-y)) scale(1.05);
}

.flying-card.fade-out {
    opacity: 0;
}


/* Winner/Loser Styles */
.winner-title {
    color: var(--secondary-color);
}

.loser-title {
    color: var(--danger-color);
}

/* Responsive Game Layout */
@media (min-width: 768px) {
    #game-screen {
        padding: 1rem;
    }

    .card {
        width: 60px;
        height: 84px;
    }

    .card-row {
        min-height: 84px;
        gap: 0.5rem;
    }

    .hand-row {
        min-height: 100px;
    }

    #opponent-hand {
        min-height: 84px;
    }

    #opponent-hand .card {
        margin-left: -35px;
    }

    #opponent-hand .card:first-child {
        margin-left: 0;
    }

    .facedown-row {
        margin-bottom: -50px;
    }

    .card-corner {
        font-size: 0.65rem;
    }

    .card-corner .card-suit {
        font-size: 0.7rem;
    }

    .deck,
    .pile {
        width: 70px;
        height: 98px;
    }

    .deck .card,
    .pile .card {
        width: 70px;
        height: 98px;
    }

    .pile-placeholder {
        width: 70px;
        height: 98px;
    }

    .center-area {
        min-height: 140px;
    }

    .center-controls {
        gap: 0.75rem;
    }

    .control-btn {
        padding: 0.8rem 1.3rem;
        font-size: 1rem;
        min-width: 130px;
    }
}

@media (min-width: 1024px) {
    .card {
        width: 70px;
        height: 98px;
    }

    .card-row {
        min-height: 98px;
    }

    .hand-row {
        min-height: 120px;
    }

    #opponent-hand {
        min-height: 98px;
    }

    #opponent-hand .card {
        margin-left: -42px;
    }

    #opponent-hand .card:first-child {
        margin-left: 0;
    }

    .facedown-row {
        margin-bottom: -55px;
    }

    .card-corner {
        font-size: 0.75rem;
    }

    .card-corner .card-suit {
        font-size: 0.8rem;
    }

    .deck,
    .pile {
        width: 80px;
        height: 112px;
    }

    .deck .card,
    .pile .card {
        width: 80px;
        height: 112px;
    }

    .pile-placeholder {
        width: 80px;
        height: 112px;
    }

    .center-controls {
        gap: 1rem;
    }

    .control-btn {
        padding: 0.95rem 1.5rem;
        font-size: 1.05rem;
        min-width: 140px;
    }
}

/* Mobile Optimizations */
@media (max-width: 480px) {
    #game-screen {
        padding: 0.15rem 0.25rem;
        gap: 0.15rem;
    }

    .card {
        width: 38px;
        height: 53px;
    }

    .card-row {
        min-height: 53px;
        gap: 0.15rem;
    }

    .hand-row {
        min-height: 60px;
    }

    .facedown-row {
        margin-bottom: -32px;
    }

    .card-corner {
        font-size: 0.45rem;
    }

    .card-corner .card-suit {
        font-size: 0.5rem;
    }

    .deck,
    .pile {
        width: 44px;
        height: 62px;
    }

    .deck .card,
    .pile .card {
        width: 44px;
        height: 62px;
    }

    .pile-placeholder {
        width: 44px;
        height: 62px;
        font-size: 0.55rem;
    }

    .deck-pile-container {
        gap: 1.5rem;
    }

    .center-area {
        min-height: 70px;
        gap: 0.2rem;
    }

    .deck-count,
    .pile-count {
        font-size: 0.65rem;
    }

    .game-message {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        min-height: 1.25rem;
    }

    .center-controls {
        gap: 0.35rem;
    }

    .control-btn {
        padding: 0.5rem 0.6rem;
        font-size: 0.7rem;
        min-width: 70px;
    }

    .player-label {
        font-size: 0.7rem;
        padding: 0.15rem;
    }

    .player-cards,
    .opponent-cards {
        gap: 0.15rem;
    }

    #opponent-hand {
        min-height: 53px;
    }

    #opponent-hand .card {
        margin-left: -25px;
    }

    .card-back-design {
        font-size: 0.6rem;
    }

    .deck .card-back-design {
        font-size: 0.7rem;
    }

    .swap-area {
        gap: 1.5rem;
    }
}

/* Extra small height screens (landscape or short devices) */
@media (max-height: 600px) {
    #game-screen {
        padding: 0.1rem 0.25rem;
        gap: 0.1rem;
    }

    .card {
        width: 32px;
        height: 45px;
    }

    .card-row {
        min-height: 45px;
        gap: 0.1rem;
    }

    .hand-row {
        min-height: 50px;
    }

    .facedown-row {
        margin-bottom: -28px;
    }

    .card-corner {
        font-size: 0.4rem;
    }

    .card-corner .card-suit {
        font-size: 0.45rem;
    }

    .deck,
    .pile {
        width: 38px;
        height: 53px;
    }

    .deck .card,
    .pile .card {
        width: 38px;
        height: 53px;
    }

    .pile-placeholder {
        width: 38px;
        height: 53px;
        font-size: 0.5rem;
    }

    .center-area {
        min-height: 55px;
        gap: 0.12rem;
    }

    .game-message {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
        min-height: 1rem;
    }

    .center-controls {
        gap: 0.25rem;
    }

    .control-btn {
        padding: 0.45rem 0.5rem;
        font-size: 0.65rem;
        min-width: 65px;
    }

    .player-label {
        font-size: 0.6rem;
        padding: 0.1rem;
    }

    #opponent-hand {
        min-height: 45px;
    }

    #opponent-hand .card {
        margin-left: -20px;
    }
}
