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

body {
    overflow: hidden;
    background: #1a1a2e;
    font-family: 'Fredoka', sans-serif;
    color: #fff;
    user-select: none;
}

#scene-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
}

#scene-container canvas {
    display: block;
}

/* HUD */
#hud {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

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

#hud-top-left {
    position: absolute;
    top: 16px; left: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#hp-bar-container, #xp-bar-container {
    position: relative;
    width: 220px;
    height: 26px;
    background: rgba(0,0,0,0.6);
    border-radius: 13px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.15);
}

#hp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #e74c3c, #ff6b6b);
    border-radius: 13px;
    transition: width 0.3s ease;
    width: 100%;
}

#xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #8e44ad, #bb6bd9);
    border-radius: 13px;
    transition: width 0.3s ease;
    width: 0%;
}

#hp-bar-container span, #xp-bar-container span {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    font-family: 'JetBrains Mono', monospace;
}

#hud-top-right {
    position: absolute;
    top: 16px; right: 16px;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

#coin-display {
    background: rgba(0,0,0,0.6);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 18px;
    font-weight: 700;
    border: 2px solid rgba(255,215,0,0.4);
    font-family: 'JetBrains Mono', monospace;
}

#zone-name {
    font-size: 16px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.5s;
    text-shadow: 0 2px 8px rgba(0,0,0,0.8);
    color: #ffeaa7;
}

#zone-name.visible {
    opacity: 1;
}

#hud-bottom-center {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

#hotbar {
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.5);
    padding: 6px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.1);
}

.hotbar-slot {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.08);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    position: relative;
    border: 2px solid transparent;
}

.hotbar-slot.equipped {
    border-color: #ffd700;
    background: rgba(255,215,0,0.15);
}

.hotbar-slot .key-label {
    position: absolute;
    top: 2px; left: 4px;
    font-size: 9px;
    opacity: 0.5;
    font-family: 'JetBrains Mono', monospace;
}

/* Boss Bar */
#boss-bar-container {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 400px;
    max-width: 90vw;
    text-align: center;
}

#boss-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #ff6b6b;
    text-shadow: 0 0 10px rgba(231,76,60,0.5);
}

#boss-bar-outer {
    height: 18px;
    background: rgba(0,0,0,0.7);
    border-radius: 9px;
    overflow: hidden;
    border: 2px solid rgba(231,76,60,0.5);
}

#boss-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #c0392b, #e74c3c, #ff6b6b);
    border-radius: 9px;
    transition: width 0.3s;
    width: 100%;
}

/* Damage Numbers */
#damage-numbers {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 15;
}

.damage-number {
    position: absolute;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 24px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    animation: floatUp 1s ease-out forwards;
    pointer-events: none;
}

.damage-number.player-dmg { color: #ff6b6b; }
.damage-number.enemy-dmg { color: #ffd700; }
.damage-number.heal { color: #2ecc71; }
.damage-number.xp { color: #bb6bd9; font-size: 18px; }

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1.2); }
    100% { opacity: 0; transform: translateY(-80px) scale(0.7); }
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 20;
    pointer-events: none;
}

.toast {
    background: rgba(0,0,0,0.85);
    padding: 10px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    animation: toastIn 0.3s ease, toastOut 0.5s 2.5s ease forwards;
    border: 1px solid rgba(255,255,255,0.15);
    text-align: center;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(20px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* Interact Prompt */
#interact-prompt {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 12;
    border: 1px solid rgba(255,255,255,0.2);
}

#interact-prompt kbd {
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
}

/* Menu Overlays */
.menu-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;
    backdrop-filter: blur(4px);
}

.menu-panel {
    background: linear-gradient(135deg, #1e2a3a, #16213e);
    border-radius: 16px;
    padding: 24px;
    max-width: 500px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.menu-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.close-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

.close-btn:hover {
    background: rgba(255,100,100,0.3);
}

/* Inventory Grid */
#inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.inv-slot {
    aspect-ratio: 1;
    background: rgba(255,255,255,0.06);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    position: relative;
}

.inv-slot:hover {
    background: rgba(255,255,255,0.12);
}

.inv-slot.selected {
    border-color: #3498db;
    background: rgba(52,152,219,0.15);
}

.inv-slot.equipped-slot {
    border-color: #ffd700;
    box-shadow: 0 0 10px rgba(255,215,0,0.3);
}

#item-detail {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: 10px;
    min-height: 80px;
}

#item-detail h3 {
    font-size: 16px;
    margin-bottom: 4px;
}

#item-detail p {
    font-size: 13px;
    opacity: 0.7;
    margin-bottom: 8px;
}

#item-detail button {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    border: none;
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 14px;
}

#item-detail button:hover {
    filter: brightness(1.1);
}

/* Shop Items */
.shop-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    margin-bottom: 8px;
    gap: 12px;
}

.shop-item .item-icon {
    font-size: 32px;
    width: 48px;
    text-align: center;
}

.shop-item .item-info {
    flex: 1;
}

.shop-item .item-info h4 {
    font-size: 15px;
}

.shop-item .item-info p {
    font-size: 12px;
    opacity: 0.6;
}

.shop-item .buy-btn {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

.shop-item .buy-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shop-item .buy-btn.owned {
    background: #27ae60;
}

/* Quest List */
.quest-item {
    padding: 14px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    margin-bottom: 8px;
    border-left: 4px solid #555;
}

.quest-item.active {
    border-left-color: #f39c12;
}

.quest-item.completed {
    border-left-color: #2ecc71;
    opacity: 0.7;
}

.quest-item.locked {
    opacity: 0.4;
}

.quest-item h4 {
    font-size: 15px;
    margin-bottom: 4px;
}

.quest-item p {
    font-size: 12px;
    opacity: 0.7;
}

.quest-progress {
    margin-top: 6px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

.quest-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #f39c12, #e67e22);
    border-radius: 3px;
    transition: width 0.3s;
}

.quest-rewards {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
}

/* Settings */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.setting-row label {
    font-size: 14px;
    font-weight: 500;
}

.setting-row input[type="range"] {
    width: 160px;
    accent-color: #3498db;
}

.setting-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.setting-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.color-row label {
    width: 50px;
    font-size: 13px;
}

.color-options {
    display: flex;
    gap: 6px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.selected {
    border-color: #fff;
    box-shadow: 0 0 8px rgba(255,255,255,0.5);
}

.controls-ref {
    font-size: 12px;
    line-height: 2;
    opacity: 0.7;
}

.controls-ref span {
    background: rgba(255,255,255,0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 11px;
}

.setting-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.setting-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}

#save-btn { background: linear-gradient(135deg, #3498db, #2980b9); }
#new-game-btn { background: linear-gradient(135deg, #e74c3c, #c0392b); }

/* Gate Locked */
#gate-locked {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
}

.gate-msg {
    background: rgba(0,0,0,0.9);
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    border: 2px solid rgba(231,76,60,0.5);
    animation: pulse 1.5s ease infinite;
}

/* Death Screen */
#death-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(139,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
}

.death-msg {
    text-align: center;
}

.death-msg h2 {
    font-size: 48px;
    margin-bottom: 12px;
}

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

/* Mobile Controls */
#mobile-controls {
    display: none;
    position: fixed;
    bottom: 0; left: 0;
    width: 100%; height: 200px;
    pointer-events: none;
    z-index: 11;
}

#joystick-area {
    position: absolute;
    bottom: 30px;
    left: 30px;
    pointer-events: auto;
}

#joystick-base {
    width: 120px;
    height: 120px;
    background: rgba(255,255,255,0.12);
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
}

#joystick-thumb {
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,0.35);
    border-radius: 50%;
    transition: transform 0.05s;
}

#mobile-buttons {
    position: absolute;
    bottom: 30px;
    right: 20px;
    display: flex;
    gap: 12px;
    pointer-events: auto;
}

.mobile-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.3);
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
}

.mobile-btn:active {
    background: rgba(255,255,255,0.3);
}

/* Footer */
#game-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 11px;
    padding: 4px;
    background: rgba(0,0,0,0.4);
    z-index: 5;
    opacity: 0.6;
}

#game-footer a {
    color: #74b9ff;
    text-decoration: none;
}

#game-footer a:hover {
    text-decoration: underline;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

/* Mobile */
@media (max-width: 768px) {
    #mobile-controls { display: block; }
    #hud-bottom-center { bottom: 210px; }
    #hp-bar-container, #xp-bar-container { width: 160px; height: 22px; }
    #hp-bar-container span, #xp-bar-container span { font-size: 9px; }
    #coin-display { font-size: 14px; padding: 4px 12px; }
    .menu-panel { padding: 16px; max-height: 90vh; }
    #toast-container { bottom: 230px; }
    #interact-prompt { bottom: 230px; }
}

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