* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Nunito', sans-serif;
    overflow: hidden;
    background: #1a1a2e;
    touch-action: none;
}

#canvas {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 200;
}

#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

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

/* HUD Top Left */
#hud-topleft {
    position: absolute;
    top: 20px;
    left: 20px;
    background: #F4E8C8;
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#player-card {
    display: flex;
    align-items: center;
    gap: 10px;
}

#player-sprite {
    width: 32px;
    height: 32px;
    background: linear-gradient(180deg, #3498DB 30%, #F4D03F 30%, #F4D03F 70%, #27AE60 70%);
    border-radius: 4px;
}

#player-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#player-level {
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    color: #2c3e50;
}

.xp-bar {
    width: 60px;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    overflow: hidden;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, #9B59B6, #8E44AD);
    width: 0%;
    transition: width 0.3s ease;
}

#bars {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bar-container {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bar-icon {
    font-size: 12px;
}

.bar {
    width: 100px;
    height: 10px;
    background: #ddd;
    border-radius: 5px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

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

.energy-bar .bar-fill {
    background: linear-gradient(90deg, #F39C12, #E67E22);
    width: 100%;
}

/* HUD Top Right */
#hud-topright {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

.item-counter {
    background: white;
    padding: 8px 14px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

/* D-Pad */
#dpad-container {
    position: absolute;
    bottom: 30px;
    left: 30px;
}

#dpad {
    width: 140px;
    height: 140px;
    position: relative;
    background: rgba(100,100,100,0.3);
    border-radius: 50%;
}

.dpad-btn {
    position: absolute;
    width: 46px;
    height: 46px;
    background: #444;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, transform 0.1s;
}

.dpad-btn:active {
    background: #666;
    transform: scale(0.95);
}

#dpad-up { top: 5px; left: 50%; transform: translateX(-50%); }
#dpad-down { bottom: 5px; left: 50%; transform: translateX(-50%); }
#dpad-left { left: 5px; top: 50%; transform: translateY(-50%); }
#dpad-right { right: 5px; top: 50%; transform: translateY(-50%); }

.dpad-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    background: #333;
    border-radius: 50%;
}

/* Action Buttons */
#action-buttons {
    position: absolute;
    bottom: 30px;
    right: 30px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.action-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

.action-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.action-btn.pulse {
    animation: btnPulse 1s infinite;
}

@keyframes btnPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
    50% { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
}

.catch-btn { background: #E74C3C; }
.interact-btn { background: #27AE60; }
.craft-btn { background: #F39C12; }
.inventory-btn { background: #3498DB; }

/* Achievement Toast */
#achievement-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.achievement-toast {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    padding: 12px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toastIn 0.5s ease, toastOut 0.5s ease 3.5s forwards;
    box-shadow: 0 4px 20px rgba(255,215,0,0.4);
}

@keyframes toastIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(-50px); opacity: 0; }
}

.achievement-toast .achievement-icon {
    font-size: 32px;
}

.achievement-toast .achievement-info {
    display: flex;
    flex-direction: column;
}

.achievement-toast .achievement-name {
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    color: #2c3e50;
}

.achievement-toast .achievement-desc {
    font-size: 12px;
    color: #5d4e37;
}

/* Title Screen */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #90C290 0%, #5BA3D0 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.5s;
}

#title-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

#title-content {
    text-align: center;
    color: white;
}

#title-content h1 {
    font-family: 'Fredoka One', cursive;
    font-size: 48px;
    text-shadow: 3px 3px 0 #2c3e50;
    margin-bottom: 0;
}

#title-content h2 {
    font-family: 'Nunito', sans-serif;
    font-size: 20px;
    font-weight: 400;
    opacity: 0.9;
    margin-bottom: 20px;
}

#title-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
}

.title-stat {
    background: rgba(255,255,255,0.2);
    padding: 8px 16px;
    border-radius: 20px;
    font-family: 'Fredoka One', cursive;
}

#start-btn, #continue-btn {
    background: #F4D03F;
    color: #2c3e50;
    border: none;
    padding: 16px 40px;
    font-family: 'Fredoka One', cursive;
    font-size: 20px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    transition: transform 0.2s;
    animation: pulse 2s infinite;
    margin: 5px;
}

#continue-btn {
    background: #27AE60;
    color: white;
}

#start-btn:hover, #continue-btn:hover {
    transform: scale(1.05);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#title-controls {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
    opacity: 0.8;
}

/* Modal */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#modal-overlay.hidden {
    display: none;
}

#modal-content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 90%;
    max-height: 80%;
    overflow-y: auto;
}

.minigame-container {
    text-align: center;
    min-width: 280px;
}

.minigame-container h2 {
    font-family: 'Fredoka One', cursive;
    color: #2c3e50;
    margin-bottom: 15px;
}

.monster-preview {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    margin: 15px auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.monster-preview.big {
    width: 80px;
    height: 80px;
}

.monster-preview.shiny {
    animation: shinyGlow 1s infinite alternate;
}

@keyframes shinyGlow {
    from { box-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700; }
    to { box-shadow: 0 0 20px #FFD700, 0 0 40px #FFD700; }
}

.badges {
    font-size: 14px;
    color: #FFD700;
    font-weight: bold;
    margin-bottom: 10px;
}

.xp-gain {
    color: #9B59B6;
    font-family: 'Fredoka One', cursive;
    font-size: 18px;
}

.arrow-sequence {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.arrow-item {
    width: 50px;
    height: 50px;
    background: #ecf0f1;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.2s;
}

.arrow-item.correct {
    background: #27AE60;
    color: white;
}

.arrow-item.correct.perfect {
    background: #FFD700;
    color: #2c3e50;
    animation: perfectPop 0.3s ease;
}

@keyframes perfectPop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.arrow-item.wrong {
    background: #E74C3C;
    color: white;
}

.timer-bar {
    width: 100%;
    height: 8px;
    background: #ecf0f1;
    border-radius: 4px;
    overflow: hidden;
    margin: 15px 0;
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, #E74C3C, #F39C12);
    transition: width 0.05s linear;
}

.minigame-hint {
    color: #7f8c8d;
    font-size: 14px;
}

.trivia-category {
    display: inline-block;
    background: #3498DB;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    margin-bottom: 10px;
}

.trivia-question {
    font-size: 18px;
    color: #2c3e50;
    margin: 20px 0;
    line-height: 1.4;
}

.trivia-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.trivia-btn {
    padding: 14px 20px;
    background: #ecf0f1;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.trivia-btn:hover {
    background: #bdc3c7;
}

.trivia-btn.correct {
    background: #27AE60;
    color: white;
}

.trivia-btn.wrong {
    background: #E74C3C;
    color: white;
}

.minigame-result {
    text-align: center;
}

.minigame-result h2 {
    font-size: 32px;
}

.continue-btn {
    margin-top: 20px;
    padding: 12px 30px;
    background: #3498DB;
    color: white;
    border: none;
    border-radius: 25px;
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    cursor: pointer;
}

/* Craft & Inventory Menus */
.craft-menu, .inventory-menu {
    min-width: 320px;
}

.craft-menu h2, .inventory-menu h2, .inventory-menu h3 {
    font-family: 'Fredoka One', cursive;
    color: #2c3e50;
    margin-bottom: 15px;
}

.inventory-display {
    display: flex;
    justify-content: space-around;
    padding: 10px;
    background: #ecf0f1;
    border-radius: 10px;
    margin-bottom: 15px;
}

.recipe-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.recipe {
    padding: 12px;
    background: #ecf0f1;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.recipe:hover:not(.disabled) {
    background: #27AE60;
    color: white;
}

.recipe.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.recipe-name {
    font-weight: bold;
}

.recipe-cost {
    font-size: 12px;
    color: #7f8c8d;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.inv-item {
    padding: 12px;
    background: #ecf0f1;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.monster-collection {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
}

.empty-msg {
    color: #95a5a6;
    text-align: center;
    padding: 20px;
}

.monster-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #ecf0f1;
    border-radius: 10px;
}

.monster-card.shiny-card {
    background: linear-gradient(135deg, #FFF8DC, #FFE4B5);
    border: 2px solid #FFD700;
}

.monster-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.monster-details {
    flex: 1;
}

.monster-name {
    font-weight: bold;
    font-size: 14px;
}

.happiness-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
}

.happiness-bar span {
    font-size: 12px;
}

.happiness-fill {
    height: 6px;
    background: linear-gradient(90deg, #E74C3C, #FF69B4);
    border-radius: 3px;
    width: 50px;
}

.feed-btn {
    background: #F39C12;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.achievement-slot {
    padding: 10px;
    background: #ecf0f1;
    border-radius: 10px;
    text-align: center;
    opacity: 0.5;
}

.achievement-slot.unlocked {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    opacity: 1;
}

.achievement-slot .achievement-icon {
    font-size: 24px;
    display: block;
}

.achievement-slot .achievement-name {
    font-size: 11px;
    display: block;
    margin-top: 4px;
}

.close-btn {
    width: 100%;
    padding: 12px;
    background: #95a5a6;
    color: white;
    border: none;
    border-radius: 10px;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
}

/* Game Message */
.game-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 15px 30px;
    border-radius: 10px;
    font-family: 'Fredoka One', cursive;
    font-size: 18px;
    z-index: 60;
    animation: fadeInOut 2s ease;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Footer */
#game-footer {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
}

#game-footer a {
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    font-size: 12px;
}

#game-footer a:hover {
    color: white;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    #hud-topleft {
        top: 10px;
        left: 10px;
        padding: 8px 12px;
    }
    
    #player-level {
        font-size: 14px;
    }
    
    .bar {
        width: 70px;
    }
    
    #hud-topright {
        top: 10px;
        right: 10px;
    }
    
    .item-counter {
        padding: 6px 10px;
        font-size: 14px;
    }
    
    #dpad-container {
        bottom: 20px;
        left: 20px;
    }
    
    #dpad {
        width: 120px;
        height: 120px;
    }
    
    .dpad-btn {
        width: 40px;
        height: 40px;
    }
    
    #action-buttons {
        bottom: 20px;
        right: 20px;
        gap: 8px;
    }
    
    .action-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    #title-content h1 {
        font-size: 32px;
    }
    
    #title-content h2 {
        font-size: 16px;
    }
    
    #modal-content {
        padding: 20px;
    }
    
    .craft-menu, .inventory-menu {
        min-width: 280px;
    }
}

/* Desktop: Hide D-pad */
@media (min-width: 1024px) and (hover: hover) {
    #dpad-container {
        opacity: 0.3;
    }
}