:root {
    --bg-color: #0f0c29;
    --bg-gradient: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    --primary: #f0f;
    --primary-hover: #d0d;
    --secondary: #0ff;
    --secondary-hover: #0cc;
    --accent: #ffea00;
    --danger: #ff4757;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text: #fff;
    --text-muted: #aaa;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Prompt', sans-serif;
}

body {
    background: var(--bg-gradient);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    position: relative;
    padding: 20px;
}

/* Screens */
.screen {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    height: 100%;
}
.screen.active {
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
}

/* Glassmorphism */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.glow-text {
    text-shadow: 0 0 10px var(--primary), 0 0 20px var(--primary);
    margin-bottom: 10px;
}
.text-accent {
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent);
}
.text-danger {
    color: var(--danger);
    text-shadow: 0 0 10px var(--danger);
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 20px;
    text-align: center;
}

/* Inputs & Buttons */
input {
    width: 100%;
    padding: 12px 20px;
    margin: 10px 0;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: rgba(0,0,0,0.2);
    color: white;
    font-size: 16px;
    outline: none;
    transition: border 0.3s;
}
input:focus {
    border-color: var(--primary);
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    color: white;
}
.btn.primary {
    background: var(--primary);
    box-shadow: 0 0 15px var(--primary);
}
.btn.primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 25px var(--primary);
    transform: translateY(-2px);
}
.btn.secondary {
    background: transparent;
    border: 2px solid var(--secondary);
    color: var(--secondary);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.2);
}
.btn.secondary:hover {
    background: var(--secondary);
    color: #000;
    box-shadow: 0 0 20px var(--secondary);
    transform: translateY(-2px);
}
.btn:disabled, .btn[disabled] {
    background: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    box-shadow: none !important;
    cursor: not-allowed !important;
    transform: none !important;
}
.btn-pulse {
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 15px var(--primary); }
    50% { transform: scale(1.05); box-shadow: 0 0 25px var(--primary); }
    100% { transform: scale(1); box-shadow: 0 0 15px var(--primary); }
}

/* Login */
.login-box {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

/* Lobby */
.lobby-container {
    width: 100%;
    max-width: 600px;
    text-align: center;
}
.qr-container {
    background: white;
    padding: 15px;
    border-radius: 15px;
    display: inline-block;
    margin-bottom: 20px;
}
.qr-container img {
    width: 200px;
    height: 200px;
}
.qr-container p {
    color: #333;
    font-weight: bold;
    margin-top: 10px;
}
.qr-container input {
    color: #333;
    border: 1px solid #ccc;
    background: #eee;
    text-align: center;
}

.player-list ul {
    list-style: none;
    padding: 0;
    margin: 15px 0;
    max-height: 200px;
    overflow-y: auto;
}
.player-list li {
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.badge {
    background: var(--accent);
    color: #000;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
}

/* Game Layout */
.game-container {
    display: grid;
    grid-template-columns: 250px 1fr 250px;
    gap: 20px;
    height: 100%;
    width: 100%;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
}

.players-panel, .log-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.players-panel ul, .log-panel ul {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    margin-top: 10px;
}
.players-panel li, .log-panel li {
    padding: 8px 0;
    border-bottom: 1px solid var(--glass-border);
    font-size: 14px;
}
.log-panel li {
    color: var(--text-muted);
}

.main-board {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

.board-header {
    text-align: center;
    margin-bottom: 20px;
}
.penalty-hint {
    font-size: 18px;
    color: var(--accent);
}

.admin-controls {
    margin-top: 30px;
    width: 100%;
}

.pyramid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: -20px; /* Overlap slightly */
}

.pyramid-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: -30px; /* Vertical overlap */
    position: relative;
}

.card {
    width: 60px;
    height: 90px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    color: black;
    position: relative;
    user-select: none;
    transition: transform 0.3s;
}
.card.red {
    color: #ff4757;
}
.card.black {
    color: #2f3542;
}
.card.facedown {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: transparent;
    border: 2px solid #fff;
    background-image: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.1) 10px, rgba(255,255,255,0.1) 20px);
}
.card.highlight {
    box-shadow: 0 0 20px var(--accent);
    transform: translateY(-10px);
}

.card.past-row {
    opacity: 0.3;
    filter: grayscale(100%);
    box-shadow: none;
}
.card.unplayable {
    opacity: 0.5;
    filter: grayscale(100%);
    pointer-events: none;
}

/* Card Flip Animations */
.card-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.card-back-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border: 2px solid #fff;
    background-image: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.1) 10px, rgba(255,255,255,0.1) 20px);
    border-radius: 8px;
    z-index: 10;
    display: none;
}

.card.facedown .card-back-overlay {
    display: block;
}

.card.animate-flip .card-back-overlay {
    display: block;
    animation: flipOut 0.4s forwards;
    animation-delay: var(--delay, 0s);
}

.card.animate-flip .card-content {
    opacity: 0;
    animation: flipInContent 0.4s forwards;
    animation-delay: var(--delay, 0s);
}

@keyframes flipOut {
    0% { transform: scaleX(1); opacity: 1; }
    49% { transform: scaleX(0); opacity: 1; }
    50% { opacity: 0; }
    100% { transform: scaleX(0); opacity: 0; }
}

@keyframes flipInContent {
    0% { transform: scaleX(0); opacity: 0; }
    49% { opacity: 0; }
    50% { transform: scaleX(0); opacity: 1; }
    100% { transform: scaleX(1); opacity: 1; }
}

.player-hand-container {
    width: 100%;
    margin-top: 40px;
}
.hand-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.hand {
    display: flex;
    justify-content: center;
    gap: 15px;
}
.hand .card {
    width: 80px;
    height: 120px;
    font-size: 32px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.hand .card:not(.unplayable):hover {
    transform: translateY(-15px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal.active {
    display: flex;
    animation: fadeIn 0.3s;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.target-grid, .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-top: 20px;
}
.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.stat-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 15px;
    text-align: left;
}
.stat-card h4 {
    color: var(--accent);
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 5px;
}
.stat-card ul {
    list-style: none;
    font-size: 14px;
}
.stat-card ul li {
    padding: 3px 0;
}

.target-btn {
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}
.target-btn:hover {
    background: var(--primary);
}
.icon-skull {
    font-size: 60px;
    animation: shake 0.5s infinite;
}
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

/* Realistic Card Styling */
.card-content {
    width: 100%;
    height: 100%;
    position: relative;
    background: white;
    border-radius: 6px;
    display: block; /* Overwrite flex */
}

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

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

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

.corner .rank {
    font-size: 0.8em;
    font-weight: bold;
}

.corner .suit-small {
    font-size: 0.6em;
}

.center-suit {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5em;
}

/* Deck Viewer */
.deck-viewer-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 10px 15px;
    cursor: pointer;
    font-size: 18px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 15px;
    transition: transform 0.2s;
}
.deck-viewer-btn:hover {
    transform: scale(1.05);
}
.deck-content {
    background-color: #1a1625;
    border-radius: 15px;
    padding: 20px;
    max-width: 400px;
    width: 95%;
    color: white;
    margin: auto;
}
.deck-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.deck-title {
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}
.deck-count-badge {
    background-color: #ff3366;
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 16px;
}
.deck-divider {
    height: 1px;
    background-color: rgba(255,255,255,0.2);
    margin: 15px 0;
}
.suit-row {
    display: flex;
    margin-bottom: 15px;
    align-items: flex-start;
}
.suit-icon-large {
    font-size: 32px;
    width: 40px;
    display: flex;
    justify-content: center;
    margin-right: 15px;
    margin-top: 5px;
}
.ranks-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.rank-box {
    width: 36px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    border: 1.5px solid;
    transition: all 0.2s;
}
.rank-box.dimmed {
    opacity: 0.15;
}

/* Colors based on suit */
.suit-row.red .suit-icon-large {
    color: #ff3366;
}
.suit-row.red .rank-box {
    color: #ff3366;
    border-color: #ff3366;
    background-color: rgba(255, 51, 102, 0.05);
}
.suit-row.black .suit-icon-large {
    color: #d1d1d1;
}
.suit-row.black .rank-box {
    color: #d1d1d1;
    border-color: #d1d1d1;
    background-color: rgba(209, 209, 209, 0.05);
}

/* Toast */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: white;
    padding: 15px 30px;
    border-radius: 30px;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    transition: bottom 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 2000;
}
.toast.show {
    bottom: 30px;
}

/* Responsive */
@media (max-width: 900px) {
    .game-container {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        gap: 15px;
    }
    .main-board {
        order: 1;
    }
    .left-sidebar {
        order: 2;
    }
    .right-sidebar {
        order: 3;
    }
    #app {
        height: auto;
        min-height: 100vh;
    }
    .pyramid-row {
        margin-bottom: -20px;
    }
    .card {
        width: 50px;
        height: 75px;
        font-size: 18px;
    }
    .hand .card {
        width: 65px;
        height: 95px;
        font-size: 26px;
    }
    .card .suit-icon {
        font-size: 14px;
    }
}
