/* ==============================================
   Regicide - Card Game Styles
   ============================================== */

/* ---- Reset & Base ---- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0e17;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-surface: #1c2541;
    --gold: #c9a227;
    --gold-light: #e8c84a;
    --gold-dark: #a07f1d;
    --text-primary: #e0e0e0;
    --text-secondary: #8a8a9a;
    --text-muted: #5a5a6a;
    --red: #e74c3c;
    --red-dark: #c0392b;
    --green: #27ae60;
    --green-dark: #1e8449;
    --blue: #3498db;
    --blue-dark: #2471a3;
    --hp-green: #2ecc71;
    --hp-yellow: #f1c40f;
    --hp-red: #e74c3c;
    --shadow: rgba(0, 0, 0, 0.4);
    --card-width: 60px;
    --card-height: 84px;
    --radius: 6px;
    --transition: 0.3s ease;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--gold-dark); border-radius: 2px; }

/* ---- Main Menu ---- */
.main-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: radial-gradient(ellipse at center, var(--bg-secondary) 0%, var(--bg-primary) 70%);
    position: relative;
    overflow: hidden;
}

.main-menu.hidden { display: none; }

.menu-crown {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.menu-title {
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 0 0 30px rgba(201, 162, 39, 0.3);
    letter-spacing: 0.15em;
    margin-bottom: 0.25rem;
}

.menu-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    letter-spacing: 0.1em;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 280px;
}

.btn {
    padding: 12px 24px;
    font-family: inherit;
    font-size: 1rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    font-weight: bold;
    letter-spacing: 0.05em;
    position: relative;
    overflow: hidden;
    min-height: 44px;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--gold), var(--gold-dark));
    color: var(--bg-primary);
    box-shadow: 0 4px 15px rgba(201, 162, 39, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--gold-light), var(--gold));
    box-shadow: 0 6px 25px rgba(201, 162, 39, 0.5);
    transform: translateY(-2px);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--text-muted);
}

.btn-secondary:hover {
    border-color: var(--gold);
    color: var(--gold);
}

/* ---- Game Board ---- */
.game-board {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    height: 100vh;
    background: radial-gradient(ellipse at 50% 30%, #1a1a3e 0%, var(--bg-primary) 60%);
    position: relative;
}

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

/* ---- Top Bar ---- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(201, 162, 39, 0.15);
}

.game-stats {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
}

.stat {
    display: flex;
    align-items: center;
    gap: 3px;
    color: var(--text-secondary);
}

.stat-icon { font-size: 0.9rem; }
.stat-value { color: var(--gold); font-weight: bold; }

.joker-stat .stat-value {
    color: #9b59b6;
}

.turn-label {
    font-size: 0.85rem;
    font-weight: bold;
    padding: 3px 12px;
    border-radius: 20px;
    letter-spacing: 0.05em;
}

.turn-label.your-turn {
    background: rgba(39, 174, 96, 0.2);
    color: var(--green);
    border: 1px solid rgba(39, 174, 96, 0.3);
}

.turn-label.ai-turn {
    background: rgba(52, 152, 219, 0.2);
    color: var(--blue);
    border: 1px solid rgba(52, 152, 219, 0.3);
}

.turn-label.discard {
    background: rgba(231, 76, 60, 0.2);
    color: var(--red);
    border: 1px solid rgba(231, 76, 60, 0.3);
    animation: pulse 1.5s ease-in-out infinite;
}

.turn-label.gameover {
    background: rgba(231, 76, 60, 0.3);
    color: var(--red);
}

.turn-label.victory {
    background: rgba(201, 162, 39, 0.3);
    color: var(--gold);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.top-right-btns {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all var(--transition);
}

.btn-icon:hover {
    border-color: var(--gold);
    color: var(--gold);
}

/* ---- Game Area (middle) ---- */
.game-area {
    display: grid;
    grid-template-columns: 200px 1fr 280px;
    gap: 12px;
    padding: 12px;
    align-items: start;
    overflow: hidden;
}

/* Solo mode: hide AI hand and use 2-column layout */
.solo-mode .game-area {
    grid-template-columns: 1fr 280px;
}

.solo-mode .ai-hand-area {
    display: none;
}

/* AI Hand */
.ai-hand-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.ai-hand-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-bottom: 2px;
}

.ai-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: center;
    max-width: 180px;
}

.card-back {
    width: 32px;
    height: 45px;
    border-radius: 3px;
    background: linear-gradient(135deg, #2c3e6e, #1a2540);
    border: 1px solid var(--gold-dark);
    box-shadow: 0 2px 4px var(--shadow);
    position: relative;
    overflow: hidden;
}

.card-back::after {
    content: '♔';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gold-dark);
    font-size: 1rem;
    opacity: 0.5;
}

/* Enemy Area */
.enemy-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.enemy-card {
    width: 110px;
    height: 154px;
    border-radius: 8px;
    background: linear-gradient(135deg, #2a1f3e, #1a1230);
    border: 2px solid var(--gold);
    box-shadow: 0 0 20px rgba(201, 162, 39, 0.2), 0 6px 24px var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    transition: all var(--transition);
}

.enemy-card[data-rank="K"] {
    border-color: #ff6b6b;
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.3), 0 6px 24px var(--shadow);
}

.enemy-card[data-rank="Q"] {
    border-color: #a855f7;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.3), 0 6px 24px var(--shadow);
}

.enemy-rank {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--gold);
}

.enemy-card[data-rank="K"] .enemy-rank { color: #ff6b6b; }
.enemy-card[data-rank="Q"] .enemy-rank { color: #a855f7; }

.enemy-suit {
    font-size: 2rem;
}

.enemy-title {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: capitalize;
    letter-spacing: 0.05em;
}

.enemy-stats {
    width: 100%;
    max-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hp-bar-container {
    width: 100%;
    height: 20px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.hp-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--hp-green), #27ae60);
    border-radius: 10px;
    transition: width 0.5s ease;
}

.hp-bar-container:has(.hp-bar[style*="width: 5"]) .hp-bar,
.hp-bar-container:has(.hp-bar[style*="width: 4"]) .hp-bar,
.hp-bar-container:has(.hp-bar[style*="width: 3"]) .hp-bar {
    background: linear-gradient(90deg, var(--hp-yellow), #e67e22);
}

.hp-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.enemy-attack-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.shield-info { color: var(--blue); }
.effective-attack { color: var(--text-muted); font-size: 0.7rem; }

.enemy-empty {
    width: 110px;
    height: 154px;
    border-radius: 8px;
    border: 2px dashed var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Game Log */
.game-log-area {
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 100%;
    max-height: 500px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 8px;
    border: 1px solid rgba(201, 162, 39, 0.1);
}

.log-title {
    color: var(--text-secondary);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 4px;
    flex-shrink: 0;
}

#game-log {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    flex: 1;
    padding-right: 4px;
}

.log-entry {
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    line-height: 1.3;
}

.log-entry:last-child {
    color: var(--text-secondary);
    font-weight: bold;
}

/* ---- Player Hand (bottom) ---- */
.player-area {
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-top: 1px solid rgba(201, 162, 39, 0.1);
}

.player-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-align: center;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

#player-hand {
    display: flex;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
    padding: 2px 0;
}

.hand-empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 12px;
}

/* ---- Cards ---- */
.card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 5px;
    background: #f5f0e8;
    border: 2px solid #d4c5a9;
    box-shadow: 0 2px 6px var(--shadow);
    cursor: default;
    position: relative;
    transition: all 0.2s ease;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.card.clickable {
    cursor: pointer;
}

.card.clickable:hover {
    transform: translateY(-6px);
    box-shadow: 0 6px 16px var(--shadow);
    border-color: var(--gold);
}

.card.selected {
    transform: translateY(-10px);
    border-color: var(--gold);
    box-shadow: 0 6px 20px rgba(201, 162, 39, 0.4), 0 0 0 2px var(--gold);
}

.card.red { color: var(--red); }
.card.black { color: #2c3e50; }
.card.joker { color: #9b59b6; }

.card-corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.top-left { top: 3px; left: 4px; }
.bottom-right { bottom: 3px; right: 4px; transform: rotate(180deg); }

.card-rank {
    font-size: 0.75rem;
    font-weight: bold;
}

.card-suit-small {
    font-size: 0.65rem;
}

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

/* ---- Action Bar ---- */
.action-bar {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
}

.btn-play {
    padding: 8px 28px;
    font-size: 0.95rem;
    border-radius: var(--radius);
    border: none;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.05em;
    min-height: 44px;
}

.btn-play:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#play-btn {
    background: linear-gradient(135deg, var(--gold), var(--gold-dark));
    color: var(--bg-primary);
}

#play-btn:not(:disabled):hover {
    background: linear-gradient(135deg, var(--gold-light), var(--gold));
    box-shadow: 0 4px 15px rgba(201, 162, 39, 0.4);
}

#yield-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--text-muted);
}

#yield-btn:not(:disabled):hover {
    border-color: var(--gold);
    color: var(--gold);
}

#yield-btn.hidden { display: none; }

#joker-btn {
    background: linear-gradient(135deg, #9b59b6, #7d3c98);
    color: white;
}

#joker-btn:not(:disabled):hover {
    background: linear-gradient(135deg, #af7ac5, #9b59b6);
    box-shadow: 0 4px 15px rgba(155, 89, 182, 0.4);
}

/* ---- Message Bar ---- */
.message-bar {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(26, 26, 46, 0.95);
    border: 1px solid var(--gold);
    color: var(--gold-light);
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: bold;
    box-shadow: 0 8px 30px var(--shadow);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 100;
    max-width: 600px;
    text-align: center;
}

.message-bar.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---- Game Over Overlay ---- */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.game-over-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.victory-title {
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 0 0 40px rgba(201, 162, 39, 0.5);
}

.victory-gold {
    color: #FFD700 !important;
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.6) !important;
}

.victory-silver {
    color: #C0C0C0 !important;
    text-shadow: 0 0 40px rgba(192, 192, 192, 0.6) !important;
}

.victory-bronze {
    color: #CD7F32 !important;
    text-shadow: 0 0 40px rgba(205, 127, 50, 0.6) !important;
}

.defeat-title {
    font-size: 3rem;
    color: var(--red);
    text-shadow: 0 0 40px rgba(231, 76, 60, 0.5);
}

.game-over-message {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 400px;
    text-align: center;
    line-height: 1.6;
}

.game-over-buttons {
    display: flex;
    gap: 16px;
    margin-top: 16px;
}

/* ---- Rules Modal ---- */
.rules-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.rules-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.rules-content {
    background: var(--bg-secondary);
    border: 1px solid var(--gold-dark);
    border-radius: 12px;
    padding: 32px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    width: 90%;
}

.rules-content h2 {
    color: var(--gold);
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.rules-content h3 {
    color: var(--gold-light);
    font-size: 1.1rem;
    margin-top: 16px;
    margin-bottom: 8px;
}

.rules-content p,
.rules-content li {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 8px;
}

.rules-content ul {
    padding-left: 20px;
}

.rules-close {
    margin-top: 20px;
    display: flex;
    justify-content: center;
}

/* ---- Responsive ---- */
/* Tablet and smaller desktop (768px - 1024px) */
@media (max-width: 1024px) {
    .game-area {
        grid-template-columns: 160px 1fr 240px; /* Compact log panel for tablets */
        gap: 10px;
        padding: 10px;
    }
    
    .solo-mode .game-area {
        grid-template-columns: 1fr 240px;
    }
}

/* Tablet (600px - 900px) */
@media (max-width: 900px) {
    .game-area {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 10px;
        padding: 10px;
    }

    /* Solo mode on tablet: simpler layout */
    .solo-mode .game-area {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
    }

    .ai-hand-area { 
        order: -1;
        flex-direction: row; /* Switch to horizontal layout on tablet/mobile for better space usage */
        justify-content: center;
    }
    
    .game-log-area { 
        order: 3; 
        max-height: 150px;
    }
    
    /* Solo mode: log comes after enemy */
    .solo-mode .game-log-area { order: 2; }
    
    .enemy-card {
        width: 100px;
        height: 140px;
    }

    .enemy-rank { font-size: 2.2rem; }
    .enemy-suit { font-size: 1.8rem; }
    .enemy-title { font-size: 0.65rem; }

    :root {
        --card-width: 56px;
        --card-height: 78px;
    }

    .card-center { font-size: 1.4rem; }
    .card-rank { font-size: 0.7rem; }
    .card-suit-small { font-size: 0.6rem; }
    
    .menu-title { font-size: 2.8rem; }
    .menu-crown { font-size: 2.8rem; }
}

/* Mobile (320px - 600px) */
@media (max-width: 600px) {
    :root {
        --card-width: 48px;
        --card-height: 67px;
    }

    html, body {
        overflow-y: auto;
        height: auto;
    }

    .main-menu {
        min-height: 100vh;
        padding: 1.5rem;
    }

    .menu-crown { font-size: 2.5rem; }
    .menu-title { font-size: 2.2rem; }
    .menu-subtitle { font-size: 0.9rem; margin-bottom: 1.5rem; }
    
    .menu-buttons {
        width: 100%;
        max-width: 280px;
        gap: 0.8rem;
    }

    .btn {
        padding: 14px 24px;
        font-size: 1rem;
        min-height: 48px;
    }

    .game-board {
        height: auto;
        min-height: 100vh;
        grid-template-rows: auto 1fr auto auto;
    }

    .top-bar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px;
        justify-content: center;
    }

    .game-stats { 
        gap: 8px; 
        font-size: 0.7rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .stat-icon { font-size: 0.85rem; }

    .turn-label {
        font-size: 0.8rem;
        padding: 4px 12px;
        order: -1;
        flex-basis: 100%;
        text-align: center;
    }

    .top-right-btns {
        flex-basis: 100%;
        justify-content: center;
    }

    .game-area {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px;
    }

    .ai-hand-area {
        padding: 6px;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 6px;
    }

    .ai-hand-label { font-size: 0.7rem; }

    .ai-cards {
        max-width: 100%;
        gap: 2px;
    }

    .card-back {
        width: 28px;
        height: 39px;
    }

    .enemy-area {
        gap: 6px;
    }

    .enemy-card {
        width: 85px;
        height: 119px;
    }
    
    .enemy-rank { font-size: 1.8rem; }
    .enemy-suit { font-size: 1.5rem; }
    .enemy-title { font-size: 0.6rem; }

    .enemy-stats {
        max-width: 100%;
        width: 90%;
    }

    .hp-bar-container { height: 18px; }
    .hp-text { font-size: 0.7rem; }

    .enemy-attack-display {
        font-size: 0.7rem;
        gap: 4px;
    }

    .enemy-empty {
        width: 85px;
        height: 119px;
        font-size: 0.8rem;
    }

    .game-log-area {
        max-height: 120px;
        padding: 6px;
    }

    .log-title { font-size: 0.7rem; }

    .log-entry { 
        font-size: 0.68rem;
        line-height: 1.25;
    }

    .player-area {
        padding: 8px;
    }

    .player-label { 
        font-size: 0.65rem;
        margin-bottom: 4px;
    }

    #player-hand {
        gap: 3px;
    }

    .card-center { font-size: 1.2rem; }
    .card-rank { font-size: 0.65rem; }
    .card-suit-small { font-size: 0.55rem; }
    .top-left { top: 2px; left: 3px; }
    .bottom-right { bottom: 2px; right: 3px; }

    .action-bar {
        gap: 8px;
        padding: 8px;
        flex-wrap: wrap;
    }
    
    .btn-play {
        padding: 12px 24px;
        font-size: 0.95rem;
        min-height: 48px;
        flex: 1;
        min-width: 140px;
    }

    .message-bar {
        top: 50px;
        max-width: 90%;
        font-size: 0.85rem;
        padding: 8px 16px;
    }

    .victory-title,
    .defeat-title {
        font-size: 2.2rem;
    }

    .game-over-message {
        font-size: 1rem;
        max-width: 90%;
        padding: 0 16px;
    }

    .game-over-buttons {
        flex-direction: column;
        gap: 12px;
        width: 100%;
        max-width: 280px;
        padding: 0 16px;
    }

    .rules-content {
        padding: 20px;
        max-height: 85vh;
        width: 95%;
    }

    .rules-content h2 { font-size: 1.3rem; }
    .rules-content h3 { font-size: 1rem; }
    .rules-content p,
    .rules-content li { font-size: 0.85rem; }
}

/* Extra small mobile (320px - 375px) */
@media (max-width: 375px) {
    :root {
        --card-width: 46px;
        --card-height: 64px;
    }

    .menu-title { font-size: 2rem; }
    .menu-crown { font-size: 2.2rem; }

    .game-stats { font-size: 0.65rem; }

    .enemy-card {
        width: 75px;
        height: 105px;
    }

    .enemy-rank { font-size: 1.6rem; }
    .enemy-suit { font-size: 1.3rem; }

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

    #player-hand {
        gap: 3px; /* Increased gap to improve touch targets */
    }

    .btn-play {
        font-size: 0.9rem;
        padding: 10px 20px;
    }
}
