:root {
    --primary: #00d4ff;
    --secondary: #7b2cbf;
    --accent: #ff6b6b;
    --bg-dark: #0a0a1a;
    --bg-card: rgba(20, 20, 40, 0.8);
    --text: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    --success: #00ff88;
    --error: #ff4757;
    --warning: #ffa502;
    --border-radius: 12px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --glow: 0 0 20px rgba(0, 212, 255, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans SC', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.screen {
    display: none;
    min-height: 100vh;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.glass-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow);
}

.logo-container {
    text-align: center;
    margin-bottom: 2rem;
}

.game-logo {
    font-family: 'Orbitron', sans-serif;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.logo-tetris {
    font-size: 3rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-battle {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.logo-subtitle {
    color: var(--text-muted);
    font-size: 1.2rem;
    margin-top: 0.5rem;
}

.menu-card {
    width: 100%;
    max-width: 400px;
}

.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.input-group input {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #0099cc);
    color: var(--bg-dark);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), #ff8787);
    color: white;
}

.btn-accent:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.5);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-icon-only {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    opacity: 0.7;
    transition: opacity 0.3s;
}

.btn-icon-only:hover {
    opacity: 1;
}

.btn-icon {
    font-size: 1.2rem;
}

.hidden {
    display: none !important;
}

.join-form {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.controls-info {
    max-width: 400px;
    margin-top: 2rem;
    text-align: center;
}

.controls-info h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
}

.control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.key {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-family: 'Orbitron', monospace;
    font-size: 0.85rem;
}

.room-header {
    text-align: center;
    margin-bottom: 2rem;
}

.room-header h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.room-code-display {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.room-code-display span {
    font-family: 'Orbitron', monospace;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: 0.1em;
}

.players-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.player-slot {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    min-width: 180px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s;
}

.player-slot.empty {
    opacity: 0.5;
}

.player-slot.ready {
    border-color: var(--success);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.player-avatar {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.player-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.player-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.player-slot.ready .status-dot {
    background: var(--success);
}

.vs-divider {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.room-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

#game-screen {
    padding: 1rem;
}

.game-container {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 2rem;
    width: 100%;
    max-width: 900px;
}

.opponents-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.opponents-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.opponent-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.opponent-header {
    text-align: center;
    margin-bottom: 0.5rem;
}

.opponent-name {
    font-weight: 600;
    color: var(--accent);
}

.opponent-canvas-wrapper {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
}

.opponent-canvas-wrapper canvas {
    display: block;
    background: #0a0a1a;
}

.opponent-stats-mini {
    display: flex;
    justify-content: space-around;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.main-game-section {
    display: flex;
    gap: 1.5rem;
}

.game-board-wrapper {
    position: relative;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow), 0 0 30px rgba(0, 212, 255, 0.2);
}

#game-canvas {
    display: block;
    background: #0a0a1a;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.game-overlay.active {
    display: flex;
}

.attack-indicator {
    position: absolute;
    bottom: 0;
    left: -10px;
    width: 8px;
    height: 0;
    background: linear-gradient(to top, var(--error), transparent);
    border-radius: 4px;
    transition: height 0.3s;
}

.attack-indicator.active {
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.next-piece-container,
.item-container,
.stats-container {
    text-align: center;
}

.next-piece-container h4,
.item-container h4 {
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

#next-canvas {
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

.current-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.3s;
}

.current-item.item-active {
    background: rgba(0, 212, 255, 0.2);
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.3);
}

.item-icon {
    font-size: 1.5rem;
}

.item-name {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.stat-value {
    font-family: 'Orbitron', monospace;
    font-size: 1.1rem;
    font-weight: 700;
}

.glow-text {
    color: var(--primary);
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.combo-display {
    display: none;
    text-align: center;
}

.combo-display.active {
    display: block;
    animation: comboIn 0.3s ease-out;
}

@keyframes comboIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.combo-label {
    display: block;
    color: var(--accent);
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
}

.combo-value {
    font-family: 'Orbitron', monospace;
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 15px rgba(255, 107, 107, 0.5);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.modal-content {
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    text-align: center;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.result-message {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

.result-message.win {
    color: var(--success);
}

.result-message.lose {
    color: var(--error);
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.result-stat {
    text-align: center;
}

.result-stat .stat-label {
    display: block;
    margin-bottom: 0.3rem;
}

.result-stat .stat-value {
    font-size: 1.5rem;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.lobby-content {
    max-width: 600px;
}

.lobby-table-container,
.leaderboard-table-container {
    overflow-x: auto;
    margin-bottom: 1rem;
}

#lobby-table,
#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

#lobby-table th,
#lobby-table td,
#leaderboard-table th,
#leaderboard-table td {
    padding: 0.8rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#lobby-table th,
#leaderboard-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
}

.status-waiting {
    color: var(--success);
}

.status-playing {
    color: var(--warning);
}

#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    background: var(--bg-card);
    border-left: 4px solid var(--primary);
    animation: slideIn 0.3s ease-out;
    max-width: 300px;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--error);
}

.toast.warning {
    border-color: var(--warning);
}

.toast.hiding {
    animation: slideOut 0.3s ease-out forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@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 ease-in-out;
}

@media (max-width: 768px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }

    .opponents-section {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .main-game-section {
        flex-direction: column;
        align-items: center;
    }

    .game-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .players-container {
        flex-direction: column;
    }

    .vs-divider {
        transform: rotate(90deg);
    }
}
/* Mobile Controls */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    width: 100%;
    padding: 0 20px;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 100;
    pointer-events: none; /* Allow clicks to pass through container */
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    pointer-events: auto; /* Re-enable clicks for buttons */
    user-select: none;
    touch-action: manipulation;
    transition: all 0.1s;
}

.control-btn:active {
    background: rgba(0, 212, 255, 0.4);
    transform: scale(0.95);
}

.d-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    align-items: center;
}

.btn-left { grid-column: 1; }
.btn-down { grid-column: 2; }
.btn-right { grid-column: 3; }

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.btn-drop {
    width: 70px;
    height: 70px;
    border-color: var(--accent);
    background: rgba(255, 107, 107, 0.2);
}

.btn-item {
    width: 50px;
    height: 50px;
    font-size: 1rem;
    border-color: var(--primary);
    background: rgba(0, 212, 255, 0.2);
}

@media (max-width: 768px) {
    .mobile-controls {
        display: flex;
    }

    /* Adjust game container to make room for controls */
    #game-screen {
        padding-bottom: 180px;
    }
    
    .game-container {
        gap: 1rem;
    }
    
    .game-board-wrapper {
        margin-bottom: 1rem;
    }
}
