body, html {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* UI Layer: This must strictly follow the 16:9 bounds of the Phaser Canvas */
#ui-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    aspect-ratio: 16/9;
    max-width: 100vw;
    max-height: 100vh;
    pointer-events: none;
    z-index: 2;
    overflow: hidden;
}

#ui-layer * {
    pointer-events: auto;
}

/* Main Title Menu */
#title-menu-panel {
    position: absolute;
    top: 65%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    gap: 1.5vw;
    padding: 3vw;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    border-radius: 2vw;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
    width: 25vw;
}

.menu-btn {
    padding: 1vw 2vw;
    font-size: 1.2vw;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 0.8vw;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.1vw;
}

.menu-btn.start:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: #ffd700;
    color: #ffd700;
    box-shadow: 0 0 1.5vw rgba(255, 215, 0, 0.4);
    transform: translateY(-0.3vw);
}

.menu-btn.encyclopedia:hover {
    background: rgba(0, 255, 255, 0.2);
    border-color: #00ffff;
    color: #00ffff;
    box-shadow: 0 0 1.5vw rgba(0, 255, 255, 0.4);
    transform: translateY(-0.3vw);
}

.menu-btn.settings:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-0.3vw);
}

/* Resource Display (Top-Right) */
.resource-panel {
    position: absolute;
    top: 2%;
    right: 2%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border: 0.1vw solid rgba(255, 215, 0, 0.3);
    border-radius: 1vw;
    padding: 1vw 2vw;
    color: #ffd700;
    font-size: 1.5vw;
    font-weight: bold;
    box-shadow: 0 0.5vw 1.5vw rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 0.8vw;
    transition: transform 0.2s ease, text-shadow 0.2s ease;
}

.resource-panel.pop {
    transform: scale(1.1);
    text-shadow: 0 0 1vw #ffffff, 0 0 0.3vw #ffd700;
}

.resource-icon {
    width: 1.5vw;
    height: 1.5vw;
    background: #ffd700;
    border-radius: 50%;
    box-shadow: 0 0 0.8vw #ffd700;
}

/* UI Card Panel (Bottom-Left) */
#ui-card-panel {
    position: absolute;
    bottom: 3%;
    left: 3%;
    display: flex;
    gap: 1.2vw;
    padding: 1.5vw;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-radius: 1.5vw;
    border: 0.1vw solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 1vw 3vw rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.ui-card {
    width: 9vw;
    height: 12vw;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 1vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: white;
    text-align: center;
    padding: 0.8vw;
    user-select: none;
    border: 0.2vw solid transparent;
}

.ui-card .icon {
    font-size: 2.5vw;
    margin-bottom: 1vw;
}

.ui-card .label {
    font-weight: 600;
    font-size: 0.9vw;
    letter-spacing: 0.05vw;
}

.card-summon { border-color: rgba(255, 215, 0, 0.3); }
.card-summon:hover {
    transform: translateY(-1vw);
    border-color: #ffd700;
    box-shadow: 0 0 1.5vw rgba(255, 215, 0, 0.4);
    background: rgba(255, 215, 0, 0.1);
}

.card-encyclopedia { border-color: rgba(0, 255, 255, 0.3); }
.card-encyclopedia:hover {
    transform: translateY(-1vw);
    border-color: #00ffff;
    box-shadow: 0 0 1.5vw rgba(0, 255, 255, 0.4);
    background: rgba(0, 255, 255, 0.1);
}

.card-tbd {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: rgba(128, 128, 128, 0.3);
}

.card-clicked { transform: scale(0.9) !important; }

/* Game Over Panel */
#game-over-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(40, 0, 0, 0.7);
    backdrop-filter: blur(15px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: #ff4444;
    text-align: center;
}

#game-over-panel h1 {
    font-size: 6vw;
    margin-bottom: 2vw;
    text-shadow: 0 0 1.5vw #ff0000, 0 0 3vw #ffd700;
    letter-spacing: 0.4vw;
}

#restart-btn {
    padding: 1vw 3vw;
    font-size: 1.5vw;
    background: transparent;
    border: 0.2vw solid #ffd700;
    color: #ffd700;
    border-radius: 4vw;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-weight: bold;
    box-shadow: 0 0 1vw rgba(255, 215, 0, 0.3);
}

#restart-btn:hover {
    background: #ffd700;
    color: #000;
    box-shadow: 0 0 2.5vw rgba(255, 215, 0, 0.6);
    transform: scale(1.1);
}

/* Encyclopedia Modal */
#encyclopedia-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    height: 80vh;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 1.5vw;
    display: none;
    flex-direction: row; /* Split into two panes */
    padding: 2vw;
    z-index: 200;
    color: white;
    gap: 2vw;
}

#encyclopedia-modal h2 {
    position: absolute;
    top: -4vw;
    left: 0;
    width: 100%;
    text-align: center;
    color: #ffd700;
    font-size: 3vw;
    font-family: 'Arial Black', sans-serif;
    text-shadow: 0 0 1vw rgba(255, 215, 0, 0.5);
}

/* Left Pane: Grid */
.encyclopedia-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.entity-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.2vw;
    overflow-y: auto;
    padding: 1vw;
    height: 100%;
}

.entity-slot {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 1vw;
    aspect-ratio: 1/1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.entity-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.entity-slot.locked img {
    filter: brightness(0) grayscale(100%);
}

.entity-slot.locked::after {
    content: '?';
    position: absolute;
    font-size: 2vw;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.3);
}

/* Tier-based Borders */
.entity-slot.tier-Common { border-color: #888; }
.entity-slot.tier-Rare { border-color: #00ffff; box-shadow: 0 0 0.5vw rgba(0, 255, 255, 0.3); }
.entity-slot.tier-Epic { border-color: #ffd700; box-shadow: 0 0 0.8vw rgba(255, 215, 0, 0.4); }

/* Right Pane: Details */
.encyclopedia-right {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 1.5vw;
    padding: 2vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#detail-view-anim {
    width: 12vw;
    height: 12vw;
    image-rendering: pixelated;
    margin-bottom: 1.5vw;
}

#detail-name { font-size: 2.5vw; color: #ffd700; margin-bottom: 0.5vw; font-family: 'Arial Black'; }
#detail-tier { font-size: 1.2vw; margin-bottom: 1.5vw; text-transform: uppercase; letter-spacing: 0.2vw; }
#detail-stats { font-size: 1vw; color: #aaa; margin-bottom: 1.5vw; line-height: 1.6; }
#detail-lore { font-size: 1.1vw; font-style: italic; line-height: 1.4; color: #eee; }

.close-btn {
    position: absolute;
    top: 1.5vw;
    right: 1.5vw;
    cursor: pointer;
    font-size: 2vw;
    color: #ff4444;
    z-index: 210;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake { animation: shake 0.2s ease-in-out 0s 2; }

canvas {
    image-rendering: pixelated;
    display: block;
}
