@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Outfit:wght@300;400;600;800&display=swap');

:root {
    --bg-dark: #070913;
    --bg-panel: rgba(15, 20, 38, 0.7);
    --bg-card: rgba(22, 28, 54, 0.95);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --neon-blue: #00d2ff;
    --neon-blue-glow: rgba(0, 210, 255, 0.4);
    --neon-red: #ff005b;
    --neon-red-glow: rgba(255, 0, 91, 0.4);
    
    /* Ultimate Card Glows */
    --gold: #ffd700;
    --gold-glow: rgba(255, 215, 0, 0.4);
    --purple: #bf00ff;
    --purple-glow: rgba(191, 0, 255, 0.4);
    --orange: #ff6a00;
    --orange-glow: rgba(255, 106, 0, 0.4);
    --green: #00ff66;
    --green-glow: rgba(0, 255, 102, 0.4);
    --teal: #00ffcc;
    --teal-glow: rgba(0, 255, 204, 0.4);
    
    --text-main: #f0f3ff;
    --text-muted: #8a96b3;
    
    --font-outfit: 'Outfit', sans-serif;
    --font-orbitron: 'Orbitron', sans-serif;
    
    --transition-speed: 0.3s;
}

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

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(0, 210, 255, 0.08) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(255, 0, 91, 0.08) 0, transparent 50%),
        radial-gradient(at 50% 50%, rgba(15, 20, 38, 0.5) 0, #070913 100%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-outfit);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: rgba(10, 12, 26, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-img {
    height: 48px;
    filter: drop-shadow(0 0 8px var(--neon-blue-glow));
}

.logo-text {
    font-family: var(--font-orbitron);
    font-weight: 900;
    font-size: 1.5rem;
    letter-spacing: 2px;
    background: linear-gradient(to right, var(--text-main), var(--neon-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 6px;
    font-family: var(--font-orbitron);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--neon-blue);
    box-shadow: 0 0 10px var(--neon-blue-glow);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--neon-blue), #0077ff);
    border: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.btn-primary:hover {
    box-shadow: 0 0 15px var(--neon-blue-glow);
    background: linear-gradient(135deg, #00e1ff, #0088ff);
}

.btn-danger {
    background: linear-gradient(135deg, var(--neon-red), #b3003b);
    border: none;
}

.btn-danger:hover {
    box-shadow: 0 0 15px var(--neon-red-glow);
    background: linear-gradient(135deg, #ff337e, #cc0044);
}

.btn-warning {
    background: linear-gradient(135deg, var(--orange), #cc5200);
    border: none;
}

.btn-warning:hover {
    box-shadow: 0 0 15px var(--orange-glow);
    background: linear-gradient(135deg, #ff8033, #e65c00);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Main Layout */
.app-container {
    display: flex;
    flex: 1;
    position: relative;
}

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    max-width: calc(100% - 380px); /* Leave room for debug log when open */
    transition: max-width var(--transition-speed);
}

.game-area.full-width {
    max-width: 100%;
}

/* Player Panels */
.player-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.player-panel.opponent {
    border-left: 4px solid var(--neon-red);
}

.player-panel.player {
    border-left: 4px solid var(--neon-blue);
}

.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-name-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 700;
}

.opponent .avatar {
    background: linear-gradient(135deg, var(--neon-red), #5c0022);
    border: 2px solid var(--neon-red);
    box-shadow: 0 0 10px var(--neon-red-glow);
}

.player .avatar {
    background: linear-gradient(135deg, var(--neon-blue), #004a5c);
    border: 2px solid var(--neon-blue);
    box-shadow: 0 0 10px var(--neon-blue-glow);
}

.player-title {
    font-family: var(--font-orbitron);
    font-weight: 700;
    letter-spacing: 1px;
}

.hp-container {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.hp-label {
    font-family: var(--font-orbitron);
    font-weight: 700;
    width: 60px;
    text-align: right;
}

.hp-bar-outer {
    background: rgba(0, 0, 0, 0.4);
    height: 16px;
    border-radius: 8px;
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.05);
    overflow: hidden;
    position: relative;
}

.hp-bar-inner {
    height: 100%;
    width: 100%;
    transition: width 0.5s ease-out;
}

.opponent .hp-bar-inner {
    background: linear-gradient(90deg, var(--neon-red), #ff6699);
    box-shadow: 0 0 10px var(--neon-red-glow);
}

.player .hp-bar-inner {
    background: linear-gradient(90deg, var(--neon-blue), #80e5ff);
    box-shadow: 0 0 10px var(--neon-blue-glow);
}

.status-badges {
    display: flex;
    gap: 10px;
}

.badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-orbitron);
}

.badge-warning {
    color: var(--gold);
    border-color: rgba(255, 215, 0, 0.3);
    background: rgba(255, 215, 0, 0.05);
}

/* Card Areas */
.cards-row {
    display: flex;
    gap: 12px;
    min-height: 160px;
    padding: 5px;
    overflow-x: auto;
    align-items: flex-end;
}

/* Card Object */
.card-wrapper {
    perspective: 1000px;
    transition: transform var(--transition-speed);
}

.card {
    width: 100px;
    height: 145px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    user-select: none;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    transition: all var(--transition-speed);
    cursor: pointer;
}

/* Selected Card State */
.card-wrapper.selected {
    transform: translateY(-20px) scale(1.05);
}

.card-wrapper.selected .card {
    border-color: var(--neon-blue);
    box-shadow: 0 0 20px var(--neon-blue-glow);
}

/* Card Glows based on Ranks */
.card.ace-card { border-color: var(--gold); box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.1), 0 3px 10px rgba(255, 215, 0, 0.2); }
.card.ace-card:hover { box-shadow: inset 0 0 15px rgba(255, 215, 0, 0.2), 0 0 15px var(--gold-glow); }

.card.king-card { border-color: var(--orange); box-shadow: inset 0 0 10px rgba(255, 106, 0, 0.1), 0 3px 10px rgba(255, 106, 0, 0.2); }
.card.king-card:hover { box-shadow: inset 0 0 15px rgba(255, 106, 0, 0.2), 0 0 15px var(--orange-glow); }

.card.queen-card { border-color: var(--green); box-shadow: inset 0 0 10px rgba(0, 255, 102, 0.1), 0 3px 10px rgba(0, 255, 102, 0.2); }
.card.queen-card:hover { box-shadow: inset 0 0 15px rgba(0, 255, 102, 0.2), 0 0 15px var(--green-glow); }

.card.jack-card { border-color: var(--teal); box-shadow: inset 0 0 10px rgba(0, 255, 204, 0.1), 0 3px 10px rgba(0, 255, 204, 0.2); }
.card.jack-card:hover { box-shadow: inset 0 0 15px rgba(0, 255, 204, 0.2), 0 0 15px var(--teal-glow); }

.card.joker-card { border-color: var(--purple); box-shadow: inset 0 0 10px rgba(191, 0, 255, 0.1), 0 3px 10px rgba(191, 0, 255, 0.2); }
.card.joker-card:hover { box-shadow: inset 0 0 15px rgba(191, 0, 255, 0.2), 0 0 15px var(--purple-glow); }

/* Regular Hover */
.card-wrapper:not(.selected):hover {
    transform: translateY(-8px) scale(1.02);
}

.card-wrapper:not(.selected):hover .card:not(.ace-card):not(.king-card):not(.queen-card):not(.jack-card):not(.joker-card) {
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 20px rgba(0, 210, 255, 0.15);
}

/* Card Front Content */
.card-corner {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: var(--font-orbitron);
    font-weight: 700;
    line-height: 1;
}

.card-corner.top-left {
    align-self: flex-start;
}

.card-corner.bottom-right {
    align-self: flex-end;
    transform: rotate(180deg);
}

.card-rank {
    font-size: 1.25rem;
}

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

.card-center {
    font-size: 2.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
}

.card-red {
    color: #ff3b30;
}

.card-white {
    color: var(--text-main);
}

/* Card Back */
.card-back {
    width: 100px;
    height: 145px;
    border-radius: 10px;
    background: repeating-linear-gradient(
        45deg,
        #0b0d1a,
        #0b0d1a 10px,
        #12162b 10px,
        #12162b 20px
    );
    border: 2px solid var(--neon-red);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5), 0 0 8px var(--neon-red-glow);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.card-back.interactive-target {
    border-color: var(--gold);
    box-shadow: 0 0 15px var(--gold-glow);
    cursor: pointer;
    animation: targetGlow 1.5s infinite alternate;
}

@keyframes targetGlow {
    0% { transform: scale(1); box-shadow: 0 0 10px var(--gold-glow); }
    100% { transform: scale(1.05); box-shadow: 0 0 25px var(--gold); border-color: #ffffff; }
}

.card-back::after {
    content: '';
    position: absolute;
    width: 60px;
    height: 60px;
    border: 1px solid rgba(255, 0, 91, 0.3);
    transform: rotate(45deg);
}

.card-back::before {
    content: 'BARRAGE';
    font-family: var(--font-orbitron);
    font-weight: 900;
    font-size: 0.65rem;
    letter-spacing: 2px;
    color: var(--neon-red);
    opacity: 0.8;
    text-shadow: 0 0 5px var(--neon-red-glow);
    transform: rotate(-45deg);
}

/* Battlefield Play Area */
.battlefield {
    flex: 1;
    background: rgba(10, 13, 28, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: grid;
    grid-template-columns: 1fr 120px 1fr;
    padding: 20px;
    min-height: 250px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
    position: relative;
    align-items: center;
}

.battle-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 15px;
    text-align: center;
}

.battle-side.player-side {
    border-right: 1px dashed rgba(255,255,255,0.05);
}

.battle-side.opponent-side {
    border-left: 1px dashed rgba(255,255,255,0.05);
}

.side-label {
    font-family: var(--font-orbitron);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.player-side .side-label {
    text-shadow: 0 0 8px var(--neon-blue-glow);
}

.opponent-side .side-label {
    text-shadow: 0 0 8px var(--neon-red-glow);
}

.played-cards {
    display: flex;
    gap: 10px;
    justify-content: center;
    min-height: 145px;
    width: 100%;
    align-items: center;
}

.card-placeholder {
    width: 100px;
    height: 145px;
    border-radius: 10px;
    border: 2px dashed rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    color: rgba(255,255,255,0.1);
    font-family: var(--font-orbitron);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.battle-vs {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: var(--font-orbitron);
    font-weight: 900;
    font-size: 1.8rem;
    color: var(--text-muted);
    gap: 5px;
}

.vs-glow {
    animation: vsPulse 2s infinite alternate;
}

@keyframes vsPulse {
    0% { color: var(--text-muted); text-shadow: none; }
    50% { color: var(--neon-blue); text-shadow: 0 0 10px var(--neon-blue-glow); }
    100% { color: var(--neon-red); text-shadow: 0 0 10px var(--neon-red-glow); }
}

.battle-action-desc {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.05);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Phase and Game Messages Overlay */
.battle-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    pointer-events: none;
    text-align: center;
    width: 100%;
}

.phase-alert {
    background: rgba(7, 9, 19, 0.9);
    border: 1px solid var(--neon-blue);
    box-shadow: 0 0 30px rgba(0, 210, 255, 0.2);
    padding: 15px 40px;
    border-radius: 8px;
    display: inline-block;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.phase-alert.show {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

.phase-alert-title {
    font-family: var(--font-orbitron);
    font-weight: 900;
    font-size: 1.4rem;
    color: var(--neon-blue);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.phase-alert-text {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Action Controls Panel */
.controls-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px 20px;
    gap: 15px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.phase-indicator {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.phase-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.phase-name {
    font-family: var(--font-orbitron);
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--neon-blue);
    letter-spacing: 1px;
    text-shadow: 0 0 5px var(--neon-blue-glow);
}

.action-buttons-group {
    display: flex;
    gap: 12px;
}

.selected-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: var(--font-orbitron);
}

/* Sidebar: Admin / Debug Panel */
.sidebar {
    width: 380px;
    background: rgba(10, 13, 28, 0.95);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 69px); /* Subtract header height */
    position: sticky;
    top: 69px;
    z-index: 90;
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    transition: transform var(--transition-speed), width var(--transition-speed);
}

.sidebar.collapsed {
    transform: translateX(100%);
    width: 0;
    overflow: hidden;
    border-left: none;
}

.sidebar-close-btn {
    display: none;
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    padding: 12px;
    cursor: pointer;
    font-family: var(--font-orbitron);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 1px;
    transition: all var(--transition-speed);
}

.tab-btn.active {
    color: var(--neon-blue);
    border-bottom-color: var(--neon-blue);
    background: rgba(255,255,255,0.02);
}

.tab-content {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    gap: 20px;
}

.tab-content.active {
    display: flex;
}

/* Event Log Tab */
.log-container {
    background: #04060d;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 8px;
    padding: 10px;
    flex: 1;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.8rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    line-height: 1.4;
    max-height: 500px;
}

.log-entry {
    border-bottom: 1px solid rgba(255,255,255,0.02);
    padding-bottom: 4px;
    word-break: break-word;
}

.log-entry .timestamp {
    color: #556080;
    margin-right: 8px;
}

.log-info { color: #88c0d0; }
.log-attack { color: #ebcb8b; font-weight: bold; }
.log-damage { color: var(--neon-red); font-weight: bold; }
.log-block { color: #a3be8c; }
.log-heal { color: var(--green); }
.log-ai { color: #b48ead; }
.log-phase { color: #d08770; font-family: var(--font-orbitron); letter-spacing: 0.5px; }

/* Admin Controls Tab */
.admin-group {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.admin-title {
    font-family: var(--font-orbitron);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--neon-blue);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 6px;
}

.admin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.admin-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.admin-input {
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 4px;
    width: 70px;
    text-align: center;
    font-family: var(--font-orbitron);
}

.admin-input:focus {
    border-color: var(--neon-blue);
    outline: none;
}

.admin-select {
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 4px;
    flex: 1;
    font-family: var(--font-outfit);
}

.admin-select:focus {
    border-color: var(--neon-blue);
    outline: none;
}

.deck-list-container {
    background: rgba(0,0,0,0.4);
    border-radius: 6px;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.75rem;
    padding: 5px;
    border: 1px solid rgba(255,255,255,0.05);
}

.deck-card-item {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    display: flex;
    justify-content: space-between;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(4, 5, 13, 0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed);
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal-container {
    background: #0f1426;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px rgba(0,0,0,0.8), 0 0 20px rgba(0, 210, 255, 0.1);
    width: 90%;
    max-width: 950px;
    max-height: 85vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform var(--transition-speed);
}

.modal-overlay.show .modal-container {
    transform: scale(1);
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-family: var(--font-orbitron);
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--neon-blue);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color var(--transition-speed);
}

.modal-close:hover {
    color: var(--neon-red);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.rules-img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
}

/* Card Selection Layout on Hand */
.card-wrapper {
    position: relative;
}

.card-wild-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--gold);
    color: #000;
    font-family: var(--font-orbitron);
    font-size: 0.65rem;
    font-weight: 900;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 5px #000;
    z-index: 5;
}

/* Deck & Discard pile visualizers in play area */
.deck-piles-area {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    grid-column: 2; /* Middle column of battlefield grid */
    flex-direction: column;
    border-left: 1px dashed rgba(255,255,255,0.05);
    border-right: 1px dashed rgba(255,255,255,0.05);
    height: 100%;
    padding: 0 10px;
}

.pile-visual {
    width: 70px;
    height: 100px;
    border-radius: 6px;
    position: relative;
}

.pile-visual.deck {
    background: repeating-linear-gradient(45deg, #0b0d1a, #0b0d1a 5px, #12162b 5px, #12162b 10px);
    border: 1px solid var(--neon-red);
    box-shadow: 0 2px 5px rgba(0,0,0,0.5), 3px 3px 0 rgba(255,0,91,0.2), 6px 6px 0 rgba(255,0,91,0.1);
}

.pile-visual.discard {
    background: rgba(0,0,0,0.3);
    border: 1px dashed var(--text-muted);
}

.pile-count {
    position: absolute;
    bottom: -20px;
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    font-family: var(--font-orbitron);
    color: var(--text-muted);
    font-weight: 700;
}

.pile-label {
    position: absolute;
    top: -20px;
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    font-family: var(--font-orbitron);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Damage Shake Animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s;
}

/* Recoil flash */
@keyframes flash-recoil {
    0% { box-shadow: 0 0 0 rgba(255,106,0,0); }
    50% { box-shadow: 0 0 30px rgba(255,106,0,0.8); border-color: var(--orange); }
    100% { box-shadow: 0 0 0 rgba(255,106,0,0); }
}

.flash-recoil {
    animation: flash-recoil 0.8s;
}

/* Toast System for quick alerts */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(15, 20, 38, 0.95);
    border-left: 4px solid var(--neon-blue);
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 0.85rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.toast-error {
    border-left-color: var(--neon-red);
}

.toast.toast-success {
    border-left-color: var(--green);
}

.toast.toast-warning {
    border-left-color: var(--orange);
}

/* ============================================================
   Rival / opponent card-backs: only the count matters here,
   so keep them compact regardless of screen size.
   ============================================================ */
.card-back {
    width: 46px;
    height: 66px;
    border-radius: 6px;
    border-width: 1px;
}

.card-back::after {
    width: 26px;
    height: 26px;
}

.card-back::before {
    content: '';
}

#opponent-hand-cards {
    min-height: 76px;
    align-items: center;
}

/* ============================================================
   Responsive Layout for Mobile / Narrow Viewports
   ============================================================ */
@media (max-width: 860px) {
    header {
        flex-wrap: wrap;
        row-gap: 8px;
        padding: 10px 12px;
    }

    .logo-img { height: 36px; }
    .logo-text { font-size: 1.05rem; }

    .header-buttons {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 6px;
    }

    .header-buttons .btn {
        padding: 6px 10px;
        font-size: 0.65rem;
    }

    .game-area,
    .game-area.full-width {
        padding: 10px;
        gap: 12px;
        max-width: 100%;
    }

    .player-info {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .hp-container {
        max-width: none;
        margin: 0 10px;
        min-width: 120px;
    }

    .controls-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .action-buttons-group {
        flex-wrap: wrap;
        gap: 8px;
    }

    .action-buttons-group .btn {
        flex: 1 1 auto;
        justify-content: center;
        padding: 8px 10px;
        font-size: 0.7rem;
    }

    .battlefield {
        grid-template-columns: 1fr 70px 1fr;
        padding: 12px;
        min-height: 200px;
    }

    .pile-visual {
        width: 44px;
        height: 62px;
    }

    .pile-label, .pile-count {
        font-size: 0.6rem;
    }

    /* Sidebar becomes a full-height overlay drawer instead of squeezing the game area.
       z-index is kept BELOW the header's (100) so the header - and its Log/PvP
       toggle buttons - always stay on top and clickable even while the drawer is open. */
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        width: min(88vw, 360px);
        height: 100vh;
        z-index: 95;
    }

    .sidebar.collapsed {
        width: min(88vw, 360px);
        overflow: visible;
        transform: translateX(100%);
    }

    /* Leave room so the close button doesn't sit on top of the tab labels */
    .sidebar-tabs {
        padding-right: 44px;
    }

    /* Dedicated close button inside the drawer - the primary way to close it on mobile,
       since the drawer can visually sit over the header's own toggle buttons. */
    .sidebar-close-btn {
        display: flex;
        position: absolute;
        top: 10px;
        right: 10px;
        width: 34px;
        height: 34px;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid var(--border-color);
        border-radius: 50%;
        color: var(--text-main);
        font-size: 1.3rem;
        line-height: 1;
        cursor: pointer;
        z-index: 10;
    }

    .sidebar-close-btn:hover {
        background: rgba(255, 0, 91, 0.15);
        border-color: var(--neon-red);
        color: var(--neon-red);
    }
}

@media (max-width: 560px) {
    .logo-text {
        display: none;
    }

    .card, .card-placeholder {
        width: 74px;
        height: 108px;
    }

    .card-center { font-size: 1.5rem; }
    .card-rank { font-size: 0.95rem; }
    .card-suit-mini { font-size: 0.65rem; }

    .cards-row {
        min-height: 118px;
        gap: 8px;
    }

    .battlefield {
        grid-template-columns: 1fr;
    }

    .deck-piles-area {
        grid-column: 1;
        flex-direction: row;
        border-left: none;
        border-right: none;
        border-top: 1px dashed rgba(255,255,255,0.05);
        border-bottom: 1px dashed rgba(255,255,255,0.05);
        height: auto;
        padding: 10px 0;
    }

    .battle-side.player-side {
        border-right: none;
        border-bottom: 1px dashed rgba(255,255,255,0.05);
        padding-bottom: 10px;
    }

    .battle-side.opponent-side {
        border-left: none;
        padding-top: 10px;
    }

    .avatar {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

/* ============================================================
   Compact mode: shrink everything that isn't the cards
   themselves so the whole board fits without vertical
   scrolling on typical phone viewports (portrait or landscape).
   Triggers on narrow width OR short height.
   ============================================================ */
@media (max-width: 860px), (max-height: 560px) {
    header {
        padding: 6px 10px;
    }

    .logo-img {
        height: 28px;
    }

    .game-area,
    .game-area.full-width {
        gap: 8px;
        padding: 8px;
    }

    .player-panel {
        padding: 8px;
        gap: 6px;
    }

    .avatar {
        width: 26px;
        height: 26px;
        font-size: 0.8rem;
    }

    .player-title {
        font-size: 0.75rem;
    }

    .hp-bar-outer {
        height: 9px;
    }

    .hp-label {
        font-size: 0.7rem;
        width: 44px;
    }

    .selected-count {
        font-size: 0.65rem;
    }

    .cards-row {
        min-height: 92px;
        gap: 6px;
        padding: 2px;
    }

    #opponent-hand-cards {
        min-height: 56px;
    }

    .card, .card-placeholder {
        width: 60px;
        height: 88px;
        padding: 6px;
    }

    .card-rank { font-size: 0.8rem; }
    .card-suit-mini { font-size: 0.55rem; }
    .card-center { font-size: 1.3rem; }

    .battlefield {
        min-height: 0;
        padding: 8px;
        gap: 6px;
    }

    .battle-side {
        gap: 4px;
    }

    .side-label {
        font-size: 0.6rem;
        letter-spacing: 1px;
    }

    .played-cards {
        min-height: 40px;
    }

    /* The idle/status placeholder doesn't need to be card-sized -
       only real played cards (rendered via createCardElement, a
       different element) need the full card dimensions above. */
    .card-placeholder {
        width: 100%;
        height: 30px;
        font-size: 0.65rem;
    }

    .battle-vs {
        font-size: 1rem;
        gap: 2px;
    }

    .battle-action-desc {
        font-size: 0.7rem;
        padding: 2px 8px;
        max-width: 120px;
    }

    .phase-alert {
        padding: 8px 20px;
    }

    .phase-alert-title {
        font-size: 0.95rem;
    }

    .phase-alert-text {
        font-size: 0.7rem;
    }

    .deck-piles-area {
        gap: 8px;
        padding: 2px 0;
    }

    .pile-visual {
        width: 32px;
        height: 46px;
    }

    .pile-label, .pile-count {
        font-size: 0.55rem;
    }

    .controls-panel {
        padding: 8px 10px;
        gap: 6px;
    }

    .phase-label {
        font-size: 0.6rem;
    }

    .phase-name {
        font-size: 0.8rem;
    }

    .selected-combo-info {
        font-size: 0.7rem;
    }

    .action-buttons-group {
        gap: 6px;
    }

    .action-buttons-group .btn {
        padding: 6px 8px;
        font-size: 0.62rem;
        gap: 4px;
    }
}
