:root {
    --primary-red: #ff4444;
    --primary-green: #00ff88;
    --primary-purple: #9d50bb;
    --accent-gold: #ffcc00;
    --bg-dark: #0a0a0c;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --neon-glow: 0 0 15px rgba(255, 68, 68, 0.5);
    --font-main: 'Inter', sans-serif;
    --font-display: 'Orbitron', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
}

/* Lazy Loader */
#game-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.8s;
}

.loader-content {
    text-align: center;
}

.loader-animation {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 0 auto 40px;
}

.loader-suar {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    z-index: 2;
    filter: drop-shadow(0 0 15px rgba(157, 80, 187, 0.4));
}

.loader-chaser {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    margin-top: -25px;
    margin-left: -25px;
}

.c1 { animation: spin-1 3s linear infinite; }
.c2 { animation: spin-2 3s linear infinite; }
.c3 { animation: spin-3 3s linear infinite; }
.c4 { animation: spin-4 3s linear infinite; }
.c5 { animation: spin-5 3s linear infinite; }
.c6 { animation: spin-6 3s linear infinite; }
.c7 { animation: spin-7 3s linear infinite; }
.c8 { animation: spin-8 3s linear infinite; }

@keyframes spin-1 { 0% { transform: rotate(0deg) translateX(90px) rotate(0deg); } 100% { transform: rotate(360deg) translateX(90px) rotate(-360deg); } }
@keyframes spin-2 { 0% { transform: rotate(45deg) translateX(90px) rotate(-45deg); } 100% { transform: rotate(405deg) translateX(90px) rotate(-405deg); } }
@keyframes spin-3 { 0% { transform: rotate(90deg) translateX(90px) rotate(-90deg); } 100% { transform: rotate(450deg) translateX(90px) rotate(-450deg); } }
@keyframes spin-4 { 0% { transform: rotate(135deg) translateX(90px) rotate(-135deg); } 100% { transform: rotate(495deg) translateX(90px) rotate(-495deg); } }
@keyframes spin-5 { 0% { transform: rotate(180deg) translateX(90px) rotate(-180deg); } 100% { transform: rotate(540deg) translateX(90px) rotate(-540deg); } }
@keyframes spin-6 { 0% { transform: rotate(225deg) translateX(90px) rotate(-225deg); } 100% { transform: rotate(585deg) translateX(90px) rotate(-585deg); } }
@keyframes spin-7 { 0% { transform: rotate(270deg) translateX(90px) rotate(-270deg); } 100% { transform: rotate(630deg) translateX(90px) rotate(-630deg); } }
@keyframes spin-8 { 0% { transform: rotate(315deg) translateX(90px) rotate(-315deg); } 100% { transform: rotate(675deg) translateX(90px) rotate(-675deg); } }

.loader-text {
    font-family: var(--font-display);
    color: var(--primary-red);
    font-size: 1.2rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    animation: text-flicker 2s infinite;
}

@keyframes text-flicker {
    0%, 100% { opacity: 1; text-shadow: 0 0 10px var(--primary-red); }
    50% { opacity: 0.5; text-shadow: none; }
}

/* Animated Background */
.animated-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(circle at 50% 50%, #1a1a2e 0%, #0a0a0c 100%);
}

.animated-bg::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background-image: url('https://www.transparenttextures.com/patterns/stardust.png');
    opacity: 0.2;
    animation: rotate 100s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.container {
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: 20px;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    justify-content: center;
}

/* Typography */
.game-logo {
    max-width: 100%;
    height: auto;
    max-height: 100px;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.2));
    animation: logo-entrance 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes logo-entrance {
    from { transform: translateY(-20px) scale(0.8); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.glitch-line {
    height: 2px;
    width: 60%;
    margin: 0 auto 20px;
    background: linear-gradient(90deg, transparent, var(--primary-red), transparent);
    position: relative;
    overflow: hidden;
}

.glitch-line::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, #fff, transparent);
    animation: sweep 3s infinite;
}

@keyframes sweep {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

/* Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    margin-bottom: 20px;
}

/* Inputs */
.input-wrapper {
    position: relative;
    margin-bottom: 20px;
}

#join-id {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 15px;
    color: #fff;
    font-family: var(--font-display);
    text-align: center;
    font-size: 1.1rem;
    letter-spacing: 2px;
    transition: all 0.3s ease;
}

#join-id:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.2);
}

/* Buttons */
.btn-group {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.primary-btn, .secondary-btn, .action-btn {
    font-family: var(--font-display);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
}

.primary-btn {
    flex: 1;
    padding: 15px;
    font-size: 0.9rem;
}

.primary-btn.host { background: linear-gradient(135deg, #0088ff, #0044aa); }
.primary-btn.join { background: linear-gradient(135deg, #00cc00, #007700); }

.secondary-btn.solo {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, var(--primary-purple), #5b247a);
    color: white;
}

.primary-btn:hover, .secondary-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.2);
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
}

.primary-btn:active, .secondary-btn:active {
    transform: translateY(0);
}

/* HUD */
.hud-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px !important;
    min-height: 70px;
}

.hud-value {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.lobby-status-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 5px;
}

.status-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.status-divider {
    width: 1px;
    height: 25px;
    background: var(--glass-border);
}

.status-mini-label {
    font-size: 0.55rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.status-mini-value {
    font-family: var(--font-display);
    font-size: 1rem;
    white-space: nowrap;
}

.status-mini-value.accent {
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.3);
}

/* Board */
.board-container {
    background: rgba(0,0,0,0.2);
    border-radius: 25px;
    padding: 15px;
    margin: 20px 0;
    border: 1px solid var(--glass-border);
}

.board {
    display: grid;
    gap: 12px;
    margin: 0 auto;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
}

.grid-3x3 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.grid-4x4 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }

.cell {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.cell:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.02);
    border-color: rgba(255, 255, 255, 0.3);
}

.cell::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.cell:hover::after { opacity: 1; }

.player-icon {
    width: 75%;
    height: 75%;
    object-fit: contain;
    animation: appear 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes appear {
    from { transform: scale(0) rotate(-15deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

.status-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.pulse-active {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.2); }
    70% { box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.your-turn {
    font-size: 0.7rem;
    color: var(--accent-gold);
    margin-left: 5px;
    animation: blink 1s infinite;
}

@keyframes blink {
    50% { opacity: 0.3; }
}

/* Bottom Controls */
.controls-bottom {
    margin-top: 20px;
}

.action-btn {
    width: 100%;
    padding: 18px;
    margin-bottom: 15px;
    color: white;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.action-btn.start { background: linear-gradient(135deg, #ff8800, #ff4400); box-shadow: 0 4px 15px rgba(255, 136, 0, 0.3); }
.action-btn.reset { background: linear-gradient(135deg, var(--primary-red), #cc0000); }

.back-link {
    display: inline-block;
    color: #666;
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 1px;
    transition: color 0.3s;
    margin-top: 10px;
}

.back-link:hover { color: #aaa; }

/* Responsive */
@media (max-width: 480px) {
    .container { 
        padding: 10px; 
        justify-content: flex-start;
        padding-top: 20px;
    }
    .game-logo { max-height: 80px; }
    .glitch-line { margin-bottom: 15px; }
    .glass-panel { padding: 15px; margin-bottom: 10px; }
    .hud-top { 
        grid-template-columns: 1fr 1fr; 
        gap: 10px; 
        margin-bottom: 10px;
    }
    .hud-item { padding: 8px !important; min-height: 60px; }
    .status-mini-label { font-size: 0.5rem; }
    .status-mini-value { font-size: 0.85rem; }
    .btn-group { flex-direction: row; gap: 10px; }
    .primary-btn, .secondary-btn { padding: 12px; font-size: 0.8rem; }
    .board-container { padding: 8px; margin: 10px 0; }
    .board { gap: 6px; }
    .action-btn { padding: 12px; font-size: 0.9rem; margin-bottom: 10px; }
    .back-link { margin-top: 5px; font-size: 0.7rem; }
}

/* Specific Player Highlights */
.cell.kanglu { border-bottom: 3px solid var(--primary-red); }
.cell.lahori { border-bottom: 3px solid var(--primary-green); }
.cell.suar { border-bottom: 3px solid var(--primary-purple); }
