/* ===== WebCraft Styles ===== */
:root {
    --primary: #4ade80;
    --primary-dark: #22c55e;
    --secondary: #8b5cf6;
    --danger: #ef4444;
    --bg-dark: #0f0f0f;
    --bg-card: rgba(30, 30, 30, 0.95);
    --glass: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text: #ffffff;
    --text-muted: #a1a1aa;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    overflow: hidden;
    cursor: default;
}

/* Exit Button */
.webcraft-exit-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    /* Important for SVG fill */
    text-decoration: none;
    transition: all 0.3s ease;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.webcraft-exit-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

/* ===== Mode Tabs ===== */
.mode-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 1rem;
    background: var(--glass);
    border-radius: 12px;
    padding: 4px;
}

.mode-tab {
    flex: 1;
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: auto !important;
    position: relative;
    z-index: 1001;
}


.mode-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.mode-tab.active {
    background: var(--primary);
    color: #000;
}

/* ===== Room Code Display ===== */
#room-code-display {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
}

#room-code-display strong {
    color: var(--primary);
    font-family: monospace;
    letter-spacing: 1px;
}

#copy-room-code {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

#copy-room-code:hover {
    background: var(--primary);
}

/* ===== Death Screen ===== */
#death-screen {
    position: fixed;
    inset: 0;
    background: rgba(139, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
}

.death-content {
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.death-content h2 {
    font-size: 4rem;
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.5);
    margin-bottom: 1rem;
}

.death-content p {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}



/* ===== Loading Screen ===== */
#loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

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

.loading-content h1 {
    font-size: 4rem;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.loading-bar {
    width: 300px;
    height: 8px;
    background: var(--glass);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto 1rem;
}

.loading-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
    animation: loading 2s ease-in-out infinite;
}

@keyframes loading {
    0% {
        width: 0%;
    }

    50% {
        width: 70%;
    }

    100% {
        width: 100%;
    }
}

#loading-text {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* ===== Menu Screen ===== */
#menu-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    /* align-items: center; justify-content: center;  <-- Removed to let margin: auto handle it safely */
    overflow-y: auto;
    z-index: 900;
    padding: 20px;
}

.menu-content {
    /* Using margin: auto in a flex container centers the item, whilst being scroll-safe */
    margin: auto;
    text-align: center;
    max-width: 500px;
    width: 100%;
}

.menu-content h1 {
    font-size: 4rem;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.menu-box {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.menu-box input {
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    background: var(--glass);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text);
    margin-bottom: 1rem;
    transition: all 0.3s ease;
}

.menu-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(74, 222, 128, 0.3);
}

.menu-btn {
    width: 100%;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 0.5rem;
}

.menu-btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #000;
}

.menu-btn.primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(74, 222, 128, 0.4);
}

.menu-btn.danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: white;
}

.menu-btn.danger:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.4);
}

.menu-btn.secondary {
    background: var(--glass);
    border: 2px solid var(--glass-border);
    color: var(--text);
}

.menu-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--primary);
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--glass-border);
}

.divider::before {
    margin-right: .5em;
}

.divider::after {
    margin-left: .5em;
}

.server-status {
    margin-top: 1rem;
    color: var(--text-muted);
}

.server-status span {
    color: var(--primary);
    font-weight: 600;
}

.controls-info {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.5rem;
    text-align: left;
}

.controls-info h3 {
    margin-bottom: 1rem;
    color: var(--primary);
}

.controls-info ul {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.controls-info li {
    font-size: 0.9rem;
    color: var(--text-muted);
}

kbd {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    margin-right: 2px;
}

/* ===== Game Canvas ===== */
#game-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}


/* ===== HUD ===== */
#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
}

#hud>* {
    pointer-events: auto;
}

/* Crosshair */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: white;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

/* Status Bars */
#status-bars {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 8px 16px;
}

.status-icon {
    font-size: 1.2rem;
}

.bar-container {
    width: 100px;
    height: 12px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    overflow: hidden;
}

.bar {
    height: 100%;
    border-radius: 6px;
    transition: width 0.3s ease;
}

.bar.health {
    background: linear-gradient(90deg, #ef4444, #f87171);
    width: 100%;
}

.bar.hunger {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    width: 100%;
}

/* Hotbar */
#hotbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    padding: 8px;
    z-index: 200;
    /* Ensure visibility */
    opacity: 1 !important;
}

/* Scope Overlay */
#scope-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    display: none;
    background: radial-gradient(circle at center, transparent 0%, transparent 25%, black 26%);
}

#scope-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 60px;
    background: red;
}

#scope-crosshair::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 2px;
    background: red;
}

.hotbar-slot {
    width: 50px;
    height: 50px;
    background: var(--glass);
    border: 2px solid transparent;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.hotbar-slot:hover {
    background: rgba(255, 255, 255, 0.15);
}

.hotbar-slot.selected {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.5);
}

/* Block Icons */
.block-icon {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    image-rendering: pixelated;
}

.block-icon.grass {
    background: linear-gradient(180deg, #4ade80 30%, #854d0e 30%);
}

.block-icon.dirt {
    background: #854d0e;
}

.block-icon.stone {
    background: #71717a;
}

.block-icon.wood {
    background: linear-gradient(90deg, #78350f 0%, #92400e 50%, #78350f 100%);
}

.block-icon.leaves {
    background: #22c55e;
    opacity: 0.9;
}

.block-icon.sand {
    background: #fcd34d;
}

.block-icon.cobblestone {
    background: repeating-conic-gradient(#52525b 0% 25%, #71717a 0% 50%) 50% / 12px 12px;
}

.block-icon.planks {
    background: repeating-linear-gradient(90deg, #92400e 0px, #a16207 6px, #92400e 12px);
}

.block-icon.brick {
    background: repeating-linear-gradient(0deg,
            #b91c1c 0px, #b91c1c 8px,
            #1f1f1f 8px, #1f1f1f 10px);
}

.block-icon.sword {
    background: linear-gradient(45deg, transparent 40%, #cbd5e1 40%, #cbd5e1 60%, transparent 60%),
        linear-gradient(-45deg, transparent 45%, #94a3b8 45%, #94a3b8 55%, transparent 55%);
    background-color: #475569;
    border: 2px solid #94a3b8;
}

.block-icon.bow {
    background:
        radial-gradient(circle at 30% 50%, transparent 6px, #8b4513 7px, #8b4513 8px, transparent 9px),
        linear-gradient(90deg, transparent 48%, #fff 48%, #fff 52%, transparent 52%);
    background-color: #a0522d;
    border: 2px solid #5d4037;
}

.block-icon.rocket {
    background: linear-gradient(180deg, #ef4444 0%, #ef4444 30%, #333 30%, #333 100%);
    border: 2px solid #991b1b;
}

/* Player List */
#player-list {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 16px;
    min-width: 150px;
}

#player-list h4 {
    font-size: 0.9rem;
    color: var(--primary);
    margin-bottom: 8px;
}

#players {
    list-style: none;
    font-size: 0.85rem;
}

#players li {
    padding: 4px 0;
    color: var(--text-muted);
}

/* Coordinates */
#coordinates {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#coordinates span {
    color: var(--text-muted);
}

/* Chat */
#chat {
    position: absolute;
    bottom: 100px;
    left: 20px;
    width: 350px;
}

#chat-messages {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 8px;
}

#chat-messages .message {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    padding: 6px 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 0.9rem;
    /* Animation removed to prevent conflicts, or just kept simple */
    animation: none;
    opacity: 1;
    transition: opacity 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#chat-input {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text);
    font-size: 0.9rem;
}

#chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Pause Menu */
#pause-menu {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.pause-content {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    text-align: center;
    min-width: 300px;
}

.pause-content h2 {
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.pause-content .menu-btn {
    margin-bottom: 1rem;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--glass);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--glass-border);
}

/* Loading Progress Bar */
#loading-progress-container {
    width: 300px;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #fff;
    margin-top: 15px;
    border-radius: 10px;
    overflow: hidden;
    display: none;
}

#loading-progress-bar {
    width: 0%;
    height: 100%;
    background: #4ade80;
    transition: width 0.1s linear;
}

/* Shop Screen */
#shop-screen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
}

.shop-content {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    text-align: center;
    max-width: 800px;
    width: 90%;
    color: var(--text);
}

.shop-content h2 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.shop-money {
    font-size: 1.5rem;
    color: gold;
    margin-bottom: 2rem;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.shop-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.shop-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.shop-item:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.1);
}

.shop-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.shop-info h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text);
}

.shop-info p {
    margin: 0.2rem 0 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.shop-item .menu-btn {
    font-size: 1rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0;
}

/* ===== Mobile Controls ===== */
#mobile-controls {
    display: none;
    /* Hidden by default, shown via JS if touch detected */
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 500;
}

#joystick-zone {
    position: absolute;
    bottom: 50px;
    left: 50px;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    pointer-events: auto;
    touch-action: none;
}

#joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    pointer-events: none;
}

#mobile-actions {
    position: absolute;
    bottom: 50px;
    right: 50px;
    display: flex;
    gap: 20px;
    pointer-events: auto;
}

.mobile-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    backdrop-filter: blur(5px);
    touch-action: none;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.mobile-btn:active {
    background: rgba(74, 222, 128, 0.5);
}

@media (pointer: coarse) {
    #mobile-controls {
        display: block;
    }

    /* Move hotbar up slightly */
    #hotbar {
        bottom: 140px;
    }

    #status-bars {
        bottom: 200px;
    }
}

.shop-item .menu-btn.special {
    background: linear-gradient(135deg, #fbbf24, #d97706);
    color: black;
}