:root {
    --ui-bg: rgba(94, 73, 56, 0.92);
    --ui-bg-2: rgba(74, 53, 36, 0.95);
    --ui-border: rgba(243, 166, 131, 0.6);
    --accent: #f3a683;
    --accent-2: #ff9ff3;
    --accent-glow: rgba(243, 166, 131, 0.4);
    --gold: #feca57;
    --danger: #ff6b6b;
    --success: #1dd1a1;
    --info: #3498db;
    --shadow-deep: 0 12px 28px rgba(0,0,0,0.55), 0 2px 6px rgba(0,0,0,0.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    overflow: hidden; background: #050505;
    font-family: 'Nunito', sans-serif;
    touch-action: none; user-select: none; -webkit-user-select: none;
}

/* === Pseudo-3D world canvas with perspective tilt === */
#game-container {
    position: relative; width: 100vw; height: 100vh; background: #000;
    perspective: 1200px; perspective-origin: 50% 60%;
}
#game-container::after {
    content: ''; position: absolute; top:0; left:0; right:0; bottom:0;
    box-shadow: inset 0 0 160px rgba(45, 30, 20, 0.85);
    pointer-events: none; z-index: 40;
}
canvas { display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

#shadow-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 15; mix-blend-mode: multiply; opacity: 0.85; }
#lighting-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; mix-blend-mode: multiply; }
#bloom-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 21; transition: opacity 2s ease; mix-blend-mode: screen; opacity: 0; }
#dynamic-light-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 22; mix-blend-mode: screen; }

.ui-layer { position: absolute; z-index: 50; pointer-events: none; }
.interactive { pointer-events: auto; }

.panel {
    background: linear-gradient(180deg, var(--ui-bg) 0%, var(--ui-bg-2) 100%);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 2px solid var(--ui-border);
    border-bottom: 5px solid rgba(243, 166, 131, 0.85);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 12px 20px;
    box-shadow: var(--shadow-deep), 0 0 22px rgba(243,166,131,0.15), inset 0 1px 0 rgba(255,255,255,0.12), inset 0 -2px 4px rgba(0,0,0,0.25);
    color: white;
}

/* Top bar */
#top-bar { top: 15px; left: 15px; right: 15px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;}
.top-left-group { display: flex; flex-direction: column; gap: 10px; pointer-events: auto; }
.top-right-group { display: flex; gap: 10px; flex-direction: row; align-items: center; pointer-events: auto; flex-wrap: wrap; max-width: 300px; justify-content: flex-end;}
/* v4.2: group the 6 secondary menu buttons (journal/hall/wardrobe/upgrades/cooking/craft)
   into one quiet toolbar chunk on desktop instead of 6 independent glowing buttons — same
   functions, less visual noise. #menu-drawer already exists (created by initMobileUI in
   02-systems.js, which moves these 6 buttons into it on every screen size) and the mobile
   media query further down fully re-declares display/position/background for the narrow-
   screen dropdown, so this base styling only affects the wide/desktop appearance. */
#menu-drawer {
    padding: 6px; border-radius: 14px;
    background: rgba(20, 15, 10, 0.55); border: 1px solid rgba(243,166,131,0.35);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
}
#menu-drawer .btn-icon { width: 36px; height: 36px; font-size: 15px; background: rgba(255,255,255,0.04); box-shadow: none; }
#menu-drawer .btn-icon:hover { background: rgba(255,255,255,0.14); transform: scale(1.08); box-shadow: none; }

.stats-group { display: flex; flex-direction: column; gap: 8px; padding: 10px 15px;}
.stat-row { display: flex; align-items: center; gap: 10px; }
.stat-label { font-size: 12px; font-weight: 900; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; }

.energy-track { width: 130px; height: 12px; background: rgba(0,0,0,0.8); border-radius: 6px; overflow: hidden; border: 1px solid rgba(243,166,131,0.3); position: relative; box-shadow: inset 0 2px 5px rgba(0,0,0,1); }
#energy-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #1dd1a1, #00d2d3); border-radius: 6px; transition: width 0.3s; box-shadow: 0 0 10px var(--accent-glow); }

.torch-fuel-track { width: 130px; height: 8px; background: rgba(0,0,0,0.8); border-radius: 4px; overflow: hidden; border: 1px solid rgba(254, 202, 87, 0.4); box-shadow: inset 0 1px 3px rgba(0,0,0,1); margin-top: 2px;}
#torch-fuel-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #e74c3c, #feca57); border-radius: 4px; transition: width 0.2s; }

.time-panel { text-align: center; border-color: var(--gold); border-bottom-color: #e1b12c; padding: 8px 15px;}
#day-txt { font-size: 12px; color: var(--gold); font-weight: 900; letter-spacing: 2px; }
#time-txt { font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 12px; margin-top: 4px; text-shadow: 2px 2px 0 #000; }
#season-txt { font-size: 10px; color: var(--accent); margin-top: 4px; font-weight: 900; }
#outfit-txt { font-size: 10px; color: var(--accent-2); margin-top: 4px; font-weight: 900; letter-spacing: 1px;}

.btn-icon { cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; width: 45px; height: 45px; border-radius: 50%; background: rgba(243, 166, 131, 0.2); border: 2px solid var(--accent); color: white; transition: all 0.2s; box-shadow: 0 0 10px var(--accent-glow), inset 0 2px 4px rgba(255,255,255,0.15);}
.btn-icon:hover { background: var(--accent); color: #000; transform: scale(1.1); }
.btn-icon.gold { background: rgba(254, 202, 87, 0.2); border-color: var(--gold); box-shadow: 0 0 10px rgba(254, 202, 87, 0.4); }
.btn-icon.gold:hover { background: var(--gold); color: #000; }
.btn-icon.active { background: var(--accent); color: #000; box-shadow: 0 0 18px var(--accent-glow), inset 0 2px 4px rgba(0,0,0,0.2); }

/* Inventory */
#inventory-panel { position: absolute; top: 130px; right: 15px; display: none; flex-wrap: wrap; width: 240px; gap: 14px; justify-content: center; padding: 15px; animation: fadeIn 0.2s ease;}
.inv-item { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 48px;}
.inv-item.interactive { cursor: pointer; transition: transform 0.2s; }
.inv-item.interactive:hover { transform: scale(1.1); }
.inv-icon { font-size: 22px; filter: drop-shadow(0 3px 5px rgba(0,0,0,0.6)); }
.inv-count { font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 10px; color: white; text-shadow: 1px 1px 0 #000;}

/* Toolbar */
#bottom-bar {
    bottom: 15px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; padding: 10px; border-radius: 20px;
    width: max-content; max-width: 95vw;
    overflow-x: auto; flex-wrap: nowrap; justify-content: flex-start;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
#bottom-bar::-webkit-scrollbar { display: none; }
.tool-slot {
    flex: 0 0 auto;
    width: 56px; height: 56px; background: linear-gradient(180deg, rgba(20,20,20,0.7), rgba(0,0,0,0.7));
    border: 2px solid rgba(255,255,255,0.1); border-bottom: 3px solid rgba(0,0,0,0.5);
    border-radius: 12px; display: flex; justify-content: center; align-items: center; font-size: 26px;
    position: relative; cursor: pointer; transition: all 0.2s;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.05);
}
.tool-slot.active { background: linear-gradient(180deg, rgba(254, 202, 87, 0.25), rgba(254, 202, 87, 0.1)); border-color: var(--gold); box-shadow: 0 0 25px rgba(254, 202, 87, 0.4), inset 0 0 15px rgba(254, 202, 87, 0.2); transform: translateY(-4px) scale(1.05); }
.tool-slot.locked { filter: grayscale(0.7) brightness(0.6); }
.hotkey { position: absolute; top: -6px; left: -6px; background: var(--ui-bg); border: 1px solid var(--accent); color: white; font-size: 9px; font-weight: 900; width: 18px; height: 18px; display: flex; justify-content: center; align-items: center; border-radius: 5px; box-shadow: 0 2px 6px rgba(0,0,0,0.8); }

/* Dialog & Screens */
.overlay-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle at center, rgba(45,30,20,0.95) 0%, rgba(0,0,0,1) 100%); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 100; }
#main-menu { background: radial-gradient(circle at center, rgba(45,30,20,0.6) 0%, rgba(0,0,0,0.9) 100%); backdrop-filter: blur(3px); }
.title-text { font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 32px; color: var(--gold); text-shadow: 0 10px 20px rgba(0,0,0,1), 0 0 30px var(--gold); text-align: center; line-height: 1.6; margin-bottom: 5px; padding: 0 20px;}
.subtitle { color: var(--accent); font-size: 14px; font-family: 'Press Start 2P', 'Courier New', monospace; letter-spacing: 2px; margin-bottom: 50px; text-shadow: 0 4px 10px rgba(0,0,0,1); text-align: center;}
.btn-primary { background: linear-gradient(180deg, var(--success), #05c46b); color: white; border: none; border-bottom: 6px solid #009432; border-top: 1px solid rgba(255,255,255,0.25); border-radius: 14px; padding: 18px 45px; font-family: 'Nunito', sans-serif; font-size: 22px; font-weight: 900; text-transform: uppercase; letter-spacing: 2px; cursor: pointer; transition: all 0.1s; box-shadow: 0 15px 25px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.3), inset 0 -3px 6px rgba(0,0,0,0.15); text-shadow: 0 2px 0 rgba(0,0,0,0.3);}
.btn-primary:active { transform: translateY(6px); border-bottom-width: 0; box-shadow: 0 5px 10px rgba(0,0,0,0.8); margin-top: 6px; }
.btn-craft { padding: 10px 20px; font-size: 15px; border-radius: 8px; border-bottom-width: 4px; }
.btn-disabled { background: #555 !important; border-bottom-color: #333 !important; color: #888 !important; cursor: not-allowed; }
.btn-outfit { background: linear-gradient(180deg, #9b59b6, #8e44ad); border-bottom-color: #6c3483; }
.btn-outfit:hover { box-shadow: 0 0 20px rgba(155, 89, 182, 0.5); }

.upgrade-row { display:flex; justify-content: space-between; align-items:center; border-bottom: 1px solid var(--accent); padding-bottom:15px; margin-top:5px; gap: 12px; }
.upgrade-row:last-of-type { border-bottom: none; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }

/* Holographic Dialog */
#dialog-box { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%); width: 90%; max-width: 700px; display: none; z-index: 80; background: rgba(30, 20, 15, 0.95); border: 2px solid var(--accent); box-shadow: 0 15px 50px rgba(0,0,0,1), 0 0 30px rgba(243,166,131,0.3); }
.speaker-header { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(243, 166, 131, 0.3); padding-bottom: 10px; margin-bottom: 15px; }
.speaker-avatar { width: 40px; height: 40px; background: rgba(243,166,131,0.2); border: 1px solid var(--accent); border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 20px; }
.speaker-name { font-size: 16px; font-family: 'Press Start 2P', 'Courier New', monospace; color: var(--accent); letter-spacing: 1px; }
.dialog-text { font-size: 18px; line-height: 1.6; color: #fff; text-shadow: 1px 1px 2px #000; }
.dialog-hint { font-size: 12px; color: var(--gold); text-align: right; margin-top: 15px; animation: pulse 1.5s infinite; font-weight: 900;}
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }

.floating-text { position: absolute; font-weight: 900; font-size: 22px; pointer-events: none; z-index: 90; text-shadow: 0 3px 6px rgba(0,0,0,0.9); animation: floatUp 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes floatUp { 0% { opacity: 1; transform: translateY(0) scale(0.8); } 20% { transform: translateY(-10px) scale(1.1); } 100% { opacity: 0; transform: translateY(-50px) scale(1); } }

#mobile-controls { position: absolute; bottom: 110px; right: 20px; display: none; z-index: 60; }
.action-btn { width: 75px; height: 75px; border-radius: 50%; background: rgba(255,255,255,0.15); border: 3px solid rgba(255,255,255,0.5); color: white; font-weight: 900; font-size: 16px; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(8px); box-shadow: 0 10px 20px rgba(0,0,0,0.6); }

/* Outfit card (wardrobe) */
.outfit-card { background: linear-gradient(135deg, rgba(155, 89, 182, 0.18), rgba(52, 152, 219, 0.18)); border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 10px; padding: 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.outfit-card.equipped { border-color: var(--accent-2); box-shadow: 0 0 16px rgba(255, 159, 243, 0.35); }
.outfit-card.locked { opacity: 0.55; }

/* v3.3: Hall card animations */
@keyframes hallPulse {
    0%, 100% { box-shadow: 0 0 14px rgba(254, 202, 87, 0.25); }
    50% { box-shadow: 0 0 22px rgba(254, 202, 87, 0.45); }
}
.hall-card.earned { animation: hallPulse 3s ease-in-out infinite; }

/* Petting heart effect */
.heart-float { position: absolute; pointer-events: none; z-index: 95; font-size: 22px; animation: heartFloat 1.5s ease-out forwards; }
@keyframes heartFloat { 0% { opacity: 1; transform: translate(0, 0) scale(0.5); } 100% { opacity: 0; transform: translate(var(--dx, 0), -50px) scale(1.4); } }

@media(max-width: 800px) {
    #mobile-controls { display: flex; }
    .title-text { font-size: 24px; }
    .tool-slot { width: 48px; height: 48px; font-size: 22px; }
    #inventory-panel { width: 210px; }
}
@media(orientation: landscape) and (max-height: 500px) {
    #mobile-controls { bottom: 20px; }
    #bottom-bar { left: 40%; width: 50vw;}
    #inventory-panel { top: 15px; }
}
