/* Global Reset & Base Styling */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #070b19;
    color: #f3f4f6;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Three.js Canvas Container */
#canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Center Crosshair */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    transform: translate(-50%, -50%);
    z-index: 5;
    pointer-events: none;
}

#crosshair::before, #crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.85);
    mix-blend-mode: difference; /* Inverts color over light backgrounds */
}

#crosshair::before {
    top: 7px;
    left: 0;
    width: 16px;
    height: 2px;
}

#crosshair::after {
    top: 0;
    left: 7px;
    width: 2px;
    height: 16px;
}

/* Common Overlay Styles (Main Menu, Pause Menu) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    background: radial-gradient(circle, rgba(15, 23, 42, 0.4) 0%, rgba(7, 11, 25, 0.8) 100%);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Glassmorphic Panels */
.glass-panel {
    background: rgba(13, 18, 30, 0.65);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    max-width: 680px;
    width: 90%;
    text-align: center;
    transform: translateY(0);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.overlay:not(.hidden) .glass-panel {
    transform: translateY(0);
}

/* Main Menu Title (Logo) */
.logo-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #10b981 0%, #3b82f6 50%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    text-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    letter-spacing: -2px;
    animation: titleGlow 4s infinite alternate ease-in-out;
}

.subtitle-text {
    font-size: 1.1rem;
    color: #9ca3af;
    margin-bottom: 40px;
    font-weight: 300;
    letter-spacing: 0.5px;
}

/* Menu Layout Sections */
.menu-sections {
    display: flex;
    gap: 30px;
    text-align: left;
    margin-bottom: 30px;
}

.menu-controls-box {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.menu-controls-box h3 {
    font-size: 1.1rem;
    color: #e5e7eb;
    margin-bottom: 8px;
    font-weight: 600;
}

.menu-actions {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
}

/* Input Form Controls */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 0.85rem;
    color: #9ca3af;
    font-weight: 500;
}

.styled-select {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f3f4f6;
    padding: 12px;
    border-radius: 10px;
    outline: none;
    font-size: 0.95rem;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.2s, background-color 0.2s;
}

.styled-select:hover, .styled-select:focus {
    border-color: #3b82f6;
    background-color: #25354f;
}

/* Button System */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 14px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
    filter: brightness(1.1);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: #f3f4f6;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.4);
    filter: brightness(1.1);
}

.btn-danger-outline {
    background: transparent;
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: #ef4444;
}

.btn-disabled {
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    color: #4b5563 !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    transform: none !important;
    filter: none !important;
}

.btn-lg {
    padding: 16px 28px;
    font-size: 1rem;
    font-weight: 700;
}

/* Dividers */
.divider {
    border: 0;
    height: 1px;
    background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
    margin: 25px 0;
}

/* Instructions Subpanel */
.instructions-panel {
    text-align: left;
}

.instructions-panel h3 {
    font-size: 1.05rem;
    color: #e5e7eb;
    margin-bottom: 12px;
    font-weight: 600;
}

.instruction-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    font-size: 0.85rem;
    color: #9ca3af;
}

.instruction-grid div {
    background: rgba(255, 255, 255, 0.02);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.instruction-grid strong {
    color: #3b82f6;
}

/* Pause Panel Customizations */
.pause-panel {
    max-width: 420px;
}

.pause-panel h2 {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1.8rem;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    color: #fff;
}

.pause-panel p {
    color: #9ca3af;
    font-size: 0.95rem;
    margin-bottom: 30px;
}

.pause-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* In-game HUD Layout */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px;
    transition: opacity 0.2s ease;
}

/* Debug panel on top-left */
#debug-info {
    align-self: flex-start;
    background: rgba(13, 18, 30, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 12px 18px;
    font-family: monospace;
    font-size: 0.8rem;
    color: #10b981;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#debug-info div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

#debug-info span {
    color: #fff;
    font-weight: bold;
}

/* Inventory Hotbar Overlay */
#hotbar-container {
    align-self: center;
    background: rgba(13, 18, 30, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 6px;
    display: flex;
    gap: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    pointer-events: auto; /* Allow clicking slots */
}

.hotbar-slot {
    width: 54px;
    height: 54px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.hotbar-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.hotbar-slot.active {
    background: rgba(59, 130, 246, 0.2);
    border: 2px solid #3b82f6;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
    transform: scale(1.08);
}

.slot-key {
    position: absolute;
    bottom: 2px;
    right: 5px;
    font-size: 0.65rem;
    color: #6b7280;
    font-family: monospace;
    font-weight: bold;
}

.hotbar-slot.active .slot-key {
    color: #3b82f6;
}

/* Flat Voxel Pixel Previews inside HUD Hotbar */
.block-preview {
    width: 32px;
    height: 32px;
    border-radius: 4px;
}

.block-preview.dirt {
    background: linear-gradient(135deg, #866043 0%, #5c3e26 100%);
    border: 1px solid #452e1b;
}

.block-preview.grass {
    background: linear-gradient(to bottom, #5b8731 30%, #866043 30%);
    border: 1px solid #3e5e21;
}

.block-preview.stone {
    background: linear-gradient(135deg, #949494 0%, #5e5e5e 100%);
    border: 1px solid #4a4a4a;
}

.block-preview.wood {
    background: linear-gradient(135deg, #b08253 0%, #785532 100%);
    border: 1px solid #583e24;
}

.block-preview.brick {
    background: linear-gradient(135deg, #a84a32 0%, #7a3120 100%);
    border: 1px solid #572115;
}

.block-preview.glass {
    background: rgba(238, 245, 252, 0.25);
    border: 1px solid rgba(238, 245, 252, 0.7);
    box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.5);
}

.block-preview.leaves {
    background: linear-gradient(135deg, #4c8c24 0%, #2c5314 100%);
    border: 1px solid #1c360c;
}

.block-preview.water {
    background: linear-gradient(135deg, rgba(102, 204, 255, 0.6) 0%, rgba(51, 102, 204, 0.8) 100%);
    border: 1px solid #204080;
}

/* Animations */
@keyframes titleGlow {
    0% {
        filter: drop-shadow(0 4px 10px rgba(59, 130, 246, 0.2));
    }
    100% {
        filter: drop-shadow(0 8px 25px rgba(16, 185, 129, 0.5));
    }
}

/* Responsive Scaling details */
@media (max-width: 600px) {
    .logo-text {
        font-size: 2rem;
    }
    .menu-sections {
        flex-direction: column;
        gap: 16px;
    }
    .instruction-grid {
        grid-template-columns: 1fr;
    }
    .glass-panel {
        padding: 24px;
    }
}

/* Crafting & Inventory System Styles */
.crafting-panel {
    max-width: 800px;
    width: 90%;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.crafting-workspace {
    display: flex;
    gap: 24px;
    margin: 20px 0;
    text-align: left;
}

.inv-section, .recipe-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevents flex items from breaking layout */
}

.inv-section h3, .recipe-section h3 {
    font-size: 1.1rem;
    color: #e5e7eb;
    margin-bottom: 12px;
    font-weight: 600;
}

.inv-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    overflow-y: auto;
    padding: 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    height: 320px;
}

/* Item Slot Styling */
.item-slot {
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.item-slot:hover:not(.empty) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.item-slot.active {
    background: rgba(16, 185, 129, 0.15);
    border-color: #10b981;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
}

.item-slot.empty {
    opacity: 0.25;
    cursor: default;
}

.slot-count {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 0.75rem;
    color: #f3f4f6;
    font-family: monospace;
    font-weight: 800;
    text-shadow: 1px 1px 2px #000;
}

/* Recipe List and Cards */
.recipe-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    height: 145px;
    background: rgba(0, 0, 0, 0.15);
    padding: 6px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.recipe-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.recipe-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.recipe-card.selected {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid #10b981;
    box-shadow: inset 0 0 8px rgba(16, 185, 129, 0.2);
}

.recipe-card.disabled {
    opacity: 0.4;
}

.recipe-card .recipe-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #f3f4f6;
}

.recipe-card .recipe-table-badge {
    font-size: 0.65rem;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    letter-spacing: 0.3px;
}

/* Recipe Detail Card */
.recipe-detail {
    background: rgba(13, 18, 30, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 12px;
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 160px;
}

.recipe-detail h4 {
    margin: 0;
    font-size: 0.9rem;
    color: #fff;
    font-weight: bold;
}

.recipe-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 1;
}

.recipe-visual {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.visual-label {
    font-size: 0.75rem;
    color: #9ca3af;
}

.detail-ingredients-list {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.ingredient-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: monospace;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.ingredient-badge.met {
    color: #10b981;
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.15);
}

.ingredient-badge.unmet {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.15);
}

.recipe-arrow {
    font-size: 1.5rem;
    color: #6b7280;
}

.recipe-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 80px;
}

.output-name {
    font-size: 0.7rem;
    color: #9ca3af;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* Count overlays for HUD Hotbar */
.hotbar-slot .slot-count {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.7rem;
    color: #fff;
    font-family: monospace;
    font-weight: bold;
    text-shadow: 1px 1px 2px #000;
}

/* Custom previews for new blocks */
.block-preview.logTop {
    background: linear-gradient(135deg, #dfb782 0%, #b68953 100%);
    border: 1px solid #8c6437;
}

.block-preview.logSide {
    background: linear-gradient(135deg, #734e29 0%, #5c3e21 100%);
    border: 1px solid #412b17;
}

.block-preview.woodPlanks {
    background: linear-gradient(135deg, #b08253 0%, #785532 100%);
    border: 1px solid #583e24;
}

.block-preview.craftingTop {
    background: linear-gradient(135deg, #b08253 0%, #5c3e21 100%);
    border: 1px dashed #ffb938;
}

.block-preview.craftingSide {
    background: linear-gradient(135deg, #b08253 0%, #5c3e21 100%);
    border: 1px solid #785532;
}

.block-preview.stick {
    background: linear-gradient(135deg, #c79c6d 0%, #866043 100%);
    border: 1px solid #5c3e26;
    clip-path: polygon(0 85%, 85% 0, 100% 15%, 15% 100%);
}

@media (max-width: 768px) {
    .crafting-workspace {
        flex-direction: column;
        gap: 16px;
    }
    .inv-grid {
        height: 180px;
    }
    .recipe-detail {
        height: auto;
    }
    .recipe-layout {
        flex-direction: column;
        gap: 8px;
    }
    .recipe-arrow {
        transform: rotate(90deg);
        margin: 4px 0;
    }
}

/* Previews de bloques interactivos y de fundición */
.block-preview.chestTop    { background: linear-gradient(135deg, #a9763a 0%, #6e4a1f 100%); border: 1px solid #54381a; }
.block-preview.door        { background: linear-gradient(135deg, #9c6b32 0%, #6e4a1f 100%); border: 1px solid #3a2710; }
.block-preview.bedTop      { background: linear-gradient(135deg, #d14a47 0%, #b5322f 100%); border: 1px solid #8f2421; }
.block-preview.lever       { background: linear-gradient(135deg, #9a9a9a 0%, #5e5e5e 100%); border: 1px solid #3a2710; }
.block-preview.furnaceTop  { background: linear-gradient(135deg, #6f6f6f 0%, #2a2a2a 100%); border: 1px solid #565656; }
.block-preview.coal        { background: linear-gradient(135deg, #454545 0%, #0d0d0d 100%); border: 1px solid #000; }
.block-preview.smoothStone { background: linear-gradient(135deg, #a6a6a6 0%, #8c8c8c 100%); border: 1px solid #777; }
.block-preview.ironOre     { background: linear-gradient(135deg, #7a7a7a 0%, #5e5e5e 100%); border: 1px solid #b3835a; }
.block-preview.ironIngot   { background: linear-gradient(135deg, #ececec 0%, #b0b0b0 100%); border: 1px solid #9a9a9a; }
.block-preview.conveyorTop    { background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%); border: 1px solid #e7c44a; }
.block-preview.extractor      { background: linear-gradient(135deg, #6a6a6a 0%, #4a4a4a 100%); border: 1px solid #e7c44a; }
.block-preview.autosmelterTop { background: linear-gradient(135deg, #6f6f6f 0%, #ff8a3c 100%); border: 1px solid #565656; }
.block-preview.containerTop   { background: linear-gradient(135deg, #9c6b32 0%, #6e4a1f 100%); border: 1px solid #9a9a9a; }
.block-preview.filterTop      { background: linear-gradient(135deg, #454b55 0%, #2f343c 100%); border: 1px solid #5bd16a; }
.block-preview.elevatorTop    { background: linear-gradient(135deg, #5a606b 0%, #22262c 100%); border: 1px solid #5bd16a; }
.block-preview.assemblerTop   { background: linear-gradient(135deg, #4a5160 0%, #343a45 100%); border: 1px solid #5a9bd8; }
.block-preview.meat           { background: linear-gradient(135deg, #e0958f 0%, #9c2f29 100%); border: 1px solid #7a221c; }

/* Barra de vida del jugador */
#health-bar {
    position: absolute;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    height: 14px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(0, 0, 0, 0.6);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
#health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #e8413a, #ff7a6e);
    transition: width 0.2s ease;
}
.block-preview.wool           { background: linear-gradient(135deg, #ffffff 0%, #d0d0d0 100%); border: 1px solid #b0b0b0; }
.block-preview.feather        { background: linear-gradient(135deg, #f4f4f4 0%, #c0c0c0 100%); border: 1px solid #a0a0a0; }
.block-preview.watermillTop   { background: linear-gradient(135deg, #9c6b32 0%, #6e4a1f 100%); border: 1px solid #5a9bd8; }
.block-preview.dike           { background: linear-gradient(135deg, #7a7a7a 0%, #5e5e5e 100%); border: 1px solid #6e4a1f; }
.block-preview.sluiceClosed   { background: linear-gradient(135deg, #8a929c 0%, #5a606b 100%); border: 1px solid #3a3f47; }

/* Horno: línea de combustible y barra de progreso */
.furnace-fuel-line {
    color: #ffd27a;
    font-size: 0.95rem;
    margin: 4px 0 14px;
    text-align: center;
}
.furnace-fuel-hint {
    display: block;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    margin-top: 2px;
}
.furnace-progress-wrap {
    height: 14px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 7px;
    overflow: hidden;
    margin: 14px 0;
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.furnace-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ff8a3c, #ffd27a);
    border-radius: 7px;
    transition: width 0.1s linear;
}
