/* styles-magical.css */
/* Google Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Poppins:wght@300;400;500;600&display=swap');

:root {
    --primary-dark: #0a0329;
    --primary-purple: #5e31a8;
    --primary-blue: #3161a8;
    --accent-gold: #e0c45c;
    --text-light: #f8f6ff;
    --gradient-purple: linear-gradient(135deg, #5e31a8, #3b1d68);
    --gradient-blue: linear-gradient(135deg, #2c4fa3, #183061);
    --gradient-gold: linear-gradient(135deg, #e0c45c, #a89331);
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Poppins', sans-serif;
    background-color: var(--primary-dark); /* Magical dark background */
    overscroll-behavior: none; /* Prevent pull-to-refresh */
    color: var(--text-light); /* Default text color */
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxkZWZzPjxwYXR0ZXJuIGlkPSJzdGFycyIgd2lkdGg9IjEwMCIgaGVpZ2h0PSIxMDAiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiPjxjaXJjbGUgY3g9IjUiIGN5PSI1IiByPSIwLjUiIGZpbGw9IiNmZmZmZmYiIG9wYWNpdHk9IjAuMyIvPjxjaXJjbGUgY3g9IjI1IiBjeT0iMTUiIHI9IjAuMyIgZmlsbD0iI2ZmZmZmZiIgb3BhY2l0eT0iMC4yIi8+PGNpcmNsZSBjeD0iNDAiIGN5PSI0MCIgcj0iMC40IiBmaWxsPSIjZmZmZmZmIiBvcGFjaXR5PSIwLjMiLz48Y2lyY2xlIGN4PSI2NSIgY3k9IjI1IiByPSIwLjIiIGZpbGw9IiNmZmZmZmYiIG9wYWNpdHk9IjAuMiIvPjxjaXJjbGUgY3g9Ijg1IiBjeT0iNTAiIHI9IjAuMyIgZmlsbD0iI2ZmZmZmZiIgb3BhY2l0eT0iMC4zIi8+PGNpcmNsZSBjeD0iMzUiIGN5PSI3NSIgcj0iMC40IiBmaWxsPSIjZmZmZmZmIiBvcGFjaXR5PSIwLjIiLz48Y2lyY2xlIGN4PSI2NSIgY3k9Ijg1IiByPSIwLjIiIGZpbGw9IiNmZmZmZmYiIG9wYWNpdHk9IjAuMiIvPjwvcGF0dGVybj48L2RlZnM+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNzdGFycykiLz48L3N2Zz4=');
    width: 100%;
    height: 100%;
    position: fixed;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
    font-family: 'Cinzel', serif;
    font-weight: 700;
}

canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}

#loading {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--primary-dark);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    color: var(--text-light); z-index: 1000;
    cursor: pointer; /* Indicate clickable */
    transition: opacity 0.5s ease-out; /* Fade out */
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxkZWZzPjxwYXR0ZXJuIGlkPSJzdGFycyIgd2lkdGg9IjEwMCIgaGVpZ2h0PSIxMDAiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiPjxjaXJjbGUgY3g9IjUiIGN5PSI1IiByPSIwLjUiIGZpbGw9IiNmZmZmZmYiIG9wYWNpdHk9IjAuMyIvPjxjaXJjbGUgY3g9IjI1IiBjeT0iMTUiIHI9IjAuMyIgZmlsbD0iI2ZmZmZmZiIgb3BhY2l0eT0iMC4yIi8+PGNpcmNsZSBjeD0iNDAiIGN5PSI0MCIgcj0iMC40IiBmaWxsPSIjZmZmZmZmIiBvcGFjaXR5PSIwLjMiLz48Y2lyY2xlIGN4PSI2NSIgY3k9IjI1IiByPSIwLjIiIGZpbGw9IiNmZmZmZmYiIG9wYWNpdHk9IjAuMiIvPjxjaXJjbGUgY3g9Ijg1IiBjeT0iNTAiIHI9IjAuMyIgZmlsbD0iI2ZmZmZmZiIgb3BhY2l0eT0iMC4zIi8+PGNpcmNsZSBjeD0iMzUiIGN5PSI3NSIgcj0iMC40IiBmaWxsPSIjZmZmZmZmIiBvcGFjaXR5PSIwLjIiLz48Y2lyY2xlIGN4PSI2NSIgY3k9Ijg1IiByPSIwLjIiIGZpbGw9IiNmZmZmZmYiIG9wYWNpdHk9IjAuMiIvPjwvcGF0dGVybj48L2RlZnM+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNzdGFycykiLz48L3N2Zz4=');
}

#loading h1 { 
    margin-bottom: 20px; 
    font-family: 'Cinzel', serif;
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(224, 196, 92, 0.5);
}

#progress-container { 
    width: 50%; 
    height: 20px; 
    background-color: rgba(94, 49, 168, 0.3); 
    border-radius: 10px; 
    overflow: hidden;
    border: 1px solid rgba(224, 196, 92, 0.3);
}

#progress-bar { 
    height: 100%; 
    width: 0%; 
    background: var(--gradient-purple);
    transition: width 0.3s; 
}

#loading-text { 
    margin-top: 15px;
    font-family: 'Poppins', sans-serif;
}

#crosshair {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 20px; height: 20px; pointer-events: none; z-index: 90;
}

#crosshair::before, #crosshair::after { 
    content: ""; 
    position: absolute; 
    background-color: var(--accent-gold);
}

#crosshair::before { width: 2px; height: 20px; left: 9px; top: 0; }
#crosshair::after { width: 20px; height: 2px; left: 0; top: 9px; }

#debug-info {
    position: fixed; /* Use fixed for consistency */
    top: 10px; left: 10px; 
    color: var(--text-light); 
    background-color: rgba(10, 3, 41, 0.8);
    padding: 10px; 
    font-family: 'Poppins', monospace; 
    font-size: 12px; 
    border-radius: 5px; 
    display: none; 
    z-index: 150; /* High z-index */
    max-height: 150px; /* Prevent it taking too much space */
    overflow-y: auto; /* Allow scrolling if needed */
    scrollbar-width: thin;
    scrollbar-color: rgba(94, 49, 168, 0.5) rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(94, 49, 168, 0.3);
}

#debug-info::-webkit-scrollbar { width: 6px; }
#debug-info::-webkit-scrollbar-thumb { 
    background-color: rgba(94, 49, 168, 0.5); 
    border-radius: 3px; 
}

/* General Panel Styles */
.game-panel {
    position: fixed; /* Use fixed positioning */
    color: var(--text-light);
    background-color: rgba(10, 3, 41, 0.85); /* Magical dark background */
    border: 1px solid rgba(94, 49, 168, 0.3); /* Purple border */
    border-radius: 8px;
    padding: 15px;
    font-family: 'Poppins', sans-serif; /* Magical font */
    z-index: 100;
    display: none; /* Hidden by default */
    box-shadow: 0 0 20px rgba(94, 49, 168, 0.25); /* Magical glow */
    backdrop-filter: blur(4px); /* Slightly less blur */
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Enable scrolling */
    overflow-x: hidden; /* Prevent horizontal scroll */
    scrollbar-width: thin; /* For Firefox */
    scrollbar-color: rgba(94, 49, 168, 0.5) rgba(0, 0, 0, 0.3); /* Custom scrollbar */
}

/* Webkit Scrollbar */
.game-panel::-webkit-scrollbar { width: 8px; }
.game-panel::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.3); border-radius: 4px; }
.game-panel::-webkit-scrollbar-thumb { 
    background-color: rgba(94, 49, 168, 0.5); 
    border-radius: 4px; 
    border: 1px solid rgba(0, 0, 0, 0.5); 
}

.game-panel h3, .game-panel h4 {
    margin-top: 0;
    color: var(--accent-gold);
    text-align: center;
    border-bottom: 1px solid rgba(224, 196, 92, 0.4);
    padding-bottom: 8px;
    margin-bottom: 15px;
    font-weight: 600;
    font-family: 'Cinzel', serif;
}

.panel-close-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(94, 49, 168, 0.6);
    color: var(--text-light);
    border: 1px solid rgba(224, 196, 92, 0.3);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    line-height: 22px;
    text-align: center;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.panel-close-button:hover {
    background: rgba(94, 49, 168, 0.8);
}

/* --- Specific Panel Styles --- */

/* Instructions Overlay (replaces blocker) */
#ui-instructions {
    position: fixed; /* Use fixed for overlays */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-light);
    background-color: rgba(10, 3, 41, 0.8);
    padding: 25px;
    border-radius: 10px;
    font-family: 'Poppins', sans-serif;
    z-index: 101; /* Above canvas, below panels */
    display: none; /* Managed by UI.js */
    border: 1px solid rgba(94, 49, 168, 0.3);
    box-shadow: 0 0 15px rgba(94, 49, 168, 0.3);
    backdrop-filter: blur(5px);
    max-width: 90%;
    width: 600px; /* Fixed width on larger screens */
    max-height: 90vh; /* Prevent overflow */
    overflow-y: auto; /* Add scrolling if needed */
}

#ui-instructions h3 { 
    color: var(--accent-gold); 
    margin-bottom: 15px; 
    font-family: 'Cinzel', serif;
}

#ui-instructions p { 
    margin: 8px 0; 
    line-height: 1.4; 
    font-family: 'Poppins', sans-serif;
}

#ui-instructions strong { 
    color: var(--accent-gold); 
}

/* Message Box */
#ui-message-box {
    position: fixed;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 3, 41, 0.8);
    color: var(--text-light);
    padding: 20px;
    border-radius: 8px;
    max-width: 80%;
    z-index: 1000;
    transition: opacity 1s ease;
    border: 1px solid rgba(94, 49, 168, 0.3);
    box-shadow: 0 0 15px rgba(94, 49, 168, 0.3);
}

.tutorial-message {
    text-align: center;
}

.tutorial-message h4 {
    color: var(--accent-gold);
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.4em;
    font-family: 'Cinzel', serif;
}

.tutorial-message p {
    margin-bottom: 0;
    line-height: 1.5;
    font-size: 1.1em;
    font-family: 'Poppins', sans-serif;
}

/* Styling for hint messages */
.tutorial-message.hint {
    border-left: 4px solid var(--accent-gold); /* Gold border for hints */
    padding-left: 10px;
    text-align: left;
}

.tutorial-message.hint h4 {
    color: var(--accent-gold); /* Gold title for hints */
    font-size: 1.2em;
}

.tutorial-message.hint p {
    font-style: italic;
    font-size: 1em;
}

/* Help Panel */
#ui-help-panel {
    top: 20px;
    right: 20px;
    width: 350px;
    max-width: 90%;
}

#ui-help-panel p { 
    font-size: 0.9em; 
    margin-bottom: 10px; 
    font-family: 'Poppins', sans-serif;
}

#ui-help-panel strong { 
    color: var(--accent-gold); 
}

#ui-help-panel h4 { 
    margin-top: 15px; 
    text-align: left; 
    border: none; 
    padding: 0; 
    font-size: 1.1em;
    font-family: 'Cinzel', serif;
}

/* Crystal List Panel */
#ui-crystal-list {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 450px;
    max-width: 90%;
}

/* Crystal List Panel Content */
#crystal-list-content ul { list-style: none; padding: 0; margin: 0; }
#crystal-list-content li {
    background-color: rgba(94, 49, 168, 0.08);
    border: 1px solid rgba(224, 196, 92, 0.2);
    border-radius: 5px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 0.9em;
    font-family: 'Poppins', sans-serif;
}
#crystal-list-content li div { margin-bottom: 5px; }
#crystal-list-content button {
    background: var(--gradient-purple);
    border: 1px solid var(--accent-gold);
    color: var(--text-light);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s ease;
    font-size: 0.9em;
    font-family: 'Poppins', sans-serif;
}
#crystal-list-content button:hover { 
    background: var(--gradient-blue);
    box-shadow: 0 0 8px rgba(94, 49, 168, 0.6);
}

/* Inventory Panel */
#inventory-panel {
    bottom: 20px;
    left: 20px;
    transform: none;
    width: 280px;
    max-width: 40%;
}
#inventory-list { 
    list-style: none; 
    padding: 0; 
    margin: 0; 
    font-family: 'Poppins', sans-serif;
}
#inventory-list li {
    display: flex; 
    justify-content: space-between;
    padding: 5px 0; 
    font-size: 14px;
    border-bottom: 1px dashed rgba(224, 196, 92, 0.1);
}
#inventory-list li:last-child { border-bottom: none; }
#inventory-list li span:first-child { 
    font-weight: bold; 
    color: var(--accent-gold); 
    margin-right: 10px;
}
#inventory-list li span:last-child { 
    font-weight: normal; 
    color: var(--text-light);
}

/* Building Panel */
#build-panel {
    top: 20px;
    left: 20px;
    transform: none;
    width: 280px;
    max-width: 40%;
}
#build-list button {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    background: rgba(94, 49, 168, 0.2);
    border: 1px solid rgba(224, 196, 92, 0.3);
    color: var(--text-light);
    cursor: pointer;
    text-align: left;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s ease;
    position: relative;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}
#build-list button:hover { 
    background: rgba(94, 49, 168, 0.3);
    border-color: var(--accent-gold);
}
#build-list button:disabled {
    background-color: rgba(100, 100, 100, 0.1);
    color: #777;
    border-color: rgba(100, 100, 100, 0.4);
    cursor: not-allowed;
    opacity: 0.6;
}
#build-list button:disabled:hover { background-color: rgba(100, 100, 100, 0.1); }
.cost { 
    font-size: 0.85em; 
    color: #bbb; 
    margin-left: 5px; 
    display: block; 
    margin-top: 3px; 
    font-family: 'Poppins', sans-serif;
}
.cost .resource-met { color: #aaffaa; }
.cost .resource-unmet { color: #ffaaaa; }

/* Placement Hint */
#placement-hint {
    font-size: 0.9em;
    color: var(--accent-gold);
    margin-top: 15px;
    padding: 10px;
    background-color: rgba(94, 49, 168, 0.05);
    border: 1px dashed rgba(224, 196, 92, 0.3);
    border-radius: 4px;
    display: none;
    font-family: 'Poppins', sans-serif;
}
#placing-building-name { 
    font-weight: bold;
    font-family: 'Cinzel', serif;
}

/* Tech Tree Panel */
#tech-tree-panel {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 850px;
}
.tech-tier {
    background: rgba(94, 49, 168, 0.05);
    border: 1px solid rgba(224, 196, 92, 0.1);
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 15px;
    transition: all 0.3s ease;
    position: relative;
}
.tech-tier.locked {
    opacity: 0.7;
    border-left: 5px solid #ff4444;
    padding-left: 15px;
}
.tech-tier.unlocked {
    border-left: 5px solid #00ffaa;
    padding-left: 15px;
    opacity: 1.0;
}
.tech-tier h4 {
    margin: 0 0 10px 0;
    color: var(--accent-gold);
    text-align: left;
    border: none;
    padding: 0;
    font-size: 1.2em;
    font-family: 'Cinzel', serif;
}
.tech-tier p { 
    margin: 5px 0; 
    font-size: 0.9em; 
    color: var(--text-light); 
    font-family: 'Poppins', sans-serif;
}
.tech-tier strong { 
    color: var(--accent-gold); 
    font-weight: 600; 
}
.tech-tier div { 
    margin-top: 8px; 
    font-size: 0.85em; 
    color: var(--text-light);
    font-family: 'Poppins', sans-serif;
}

.tech-requirements { margin-top: 10px !important; }
.tech-requirements strong { 
    display: block; 
    margin-bottom: 5px; 
    color: var(--accent-gold); 
}
.tech-requirements ul { list-style: none; padding: 0; margin: 0; }
.tech-requirements li { 
    margin-bottom: 4px; 
    padding-left: 18px; 
    position: relative; 
    font-size: 0.95em;
    font-family: 'Poppins', sans-serif;
}
.tech-requirements li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ff4444;
    border: 1px solid rgba(224, 196, 92, 0.2);
}
.requirement-met::before { background-color: #00ff00 !important; }
.requirement-not-met::before { background-color: #ff4444 !important; }
.requirement-met { color: #aaffaa; }
.requirement-not-met { color: #ffaaaa; }

/* Mobile Controls Container */
#mobile-controls-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    /* Let content determine height + padding, remove fixed height */
    /* height: 220px; REMOVED */
    pointer-events: none;
    z-index: 95;
    display: none; /* Controlled by JS */
    touch-action: none; /* Prevent browser gestures within the container */
    box-sizing: border-box; /* Include padding in width/height calculations */

    /* --- SAFE AREA PADDING --- */
    /* Add padding to the bottom to avoid overlap with iOS home indicator / Android nav bar */
    /* env() provides the safe area inset values. Fallback provides minimal padding. */
    padding-bottom: calc(15px + env(safe-area-inset-bottom)); /* Base padding + safe area */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Make direct children interactive */
#mobile-controls-container > * {
    pointer-events: auto;
}

/* Mobile Joystick Container */
#joystick-container {
    position: absolute;
    /* Adjust positioning relative to the padded container */
    bottom: calc(20px + env(safe-area-inset-bottom)); /* Use calc() with safe area */
    left: calc(20px + env(safe-area-inset-left));   /* Use calc() with safe area */
    width: 160px; /* Slightly smaller default */
    height: 160px;
    z-index: 100; /* Lower than buttons */
    opacity: 0.7; /* Adjusted opacity */
    border-radius: 50%;
    background-color: rgba(10, 3, 41, 0.2); /* Less obtrusive background */
    border: 2px dashed rgba(224, 196, 92, 0.2); /* Softer border */
    touch-action: none; /* Prevent browser gestures */
    box-sizing: border-box;
}

/* Styling NippleJS via its classes */
.nipple {
    touch-action: none !important; /* Ensure nipplejs respects touch action */
    position: relative !important; /* Ensure positioning context */
}
.nipple .front {
    background-color: rgba(224, 196, 92, 0.7) !important;
    box-shadow: 0 0 10px rgba(224, 196, 92, 0.5);
    width: 60px !important; /* Adjust nipple size */
    height: 60px !important;
    margin-left: -30px !important; /* Center based on new size */
    margin-top: -30px !important;
    opacity: 1.0 !important; /* Fully opaque */
}
.nipple .back {
    background-color: rgba(94, 49, 168, 0.4) !important; /* Slightly lighter purple */
    border: 1px solid rgba(224, 196, 92, 0.3);
    width: 100% !important; /* Ensure back fills container */
    height: 100% !important;
    opacity: 1.0 !important; /* Fully opaque */
}

/* Mobile Buttons */
.mobile-button {
    position: absolute;
    border-radius: 50%;
    border: 2px solid var(--accent-gold);
    background-color: rgba(10, 3, 41, 0.6); /* Darker background for contrast */
    color: var(--text-light);
    font-size: 14px; /* Base size */
    font-weight: bold;
    z-index: 110; /* Above joystick base */
    touch-action: none; /* Prevent browser gestures */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.85; /* Slightly more opaque */
    transition: background-color 0.1s ease, transform 0.1s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    box-shadow: 0 0 6px rgba(224, 196, 92, 0.2);
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
    user-select: none; /* Prevent text selection */
    overflow: hidden; /* Ensure icon doesn't overflow */
}
.mobile-button:active {
    background-color: rgba(94, 49, 168, 0.7);
    transform: scale(0.95); /* Keep active feedback */
    box-shadow: 0 0 12px rgba(224, 196, 92, 0.5); /* Stronger glow */
}
/* Size icons relative to button */
.mobile-button img {
    width: 65% !important;  /* Make icons slightly smaller within button */
    height: 65% !important;
    filter: drop-shadow(0 0 2px rgba(224, 196, 92, 0.4));
    pointer-events: none; /* Critical: prevents img intercepting touch */
    display: block; /* Ensure image behaves predictably */
}

/* --- Specific Button Positions/Sizes - Using calc() with safe area --- */
/* Portrait Mode Defaults (adjust numbers as needed for your layout) */
#mobile-button-jump {
    right: calc(25px + env(safe-area-inset-right));
    bottom: calc(125px + env(safe-area-inset-bottom));
    width: 80px; height: 80px;
}
#mobile-button-action {
    right: calc(120px + env(safe-area-inset-right)); /* Further from edge */
    bottom: calc(40px + env(safe-area-inset-bottom));
    width: 90px; height: 90px; /* Primary action button larger */
}
#mobile-button-inventory {
    right: calc(25px + env(safe-area-inset-right));
    bottom: calc(35px + env(safe-area-inset-bottom));
    width: 70px; height: 70px;
}
#mobile-button-build {
    right: calc(120px + env(safe-area-inset-right));
    bottom: calc(140px + env(safe-area-inset-bottom)); /* Position relative to action/jump */
    width: 70px; height: 70px;
}

#mobile-button-tech-tree {
    /* Position Tech Tree low, near Inventory */
    right: calc(25px + env(safe-area-inset-right));
    bottom: calc(35px + env(safe-area-inset-bottom)); /* Lowest right */
    width: 70px; height: 70px;
}


/* --- Media queries for orientation and screen size --- */

/* Landscape layout */
@media (orientation: landscape) {
    #mobile-controls-container {
        /* No fixed height needed, rely on content + padding */
        /* height: 180px; REMOVED */
        padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Less bottom padding needed */
    }
    #joystick-container {
        bottom: calc(15px + env(safe-area-inset-bottom));
        left: calc(15px + env(safe-area-inset-left));
        width: 130px; height: 130px;
    }
    .nipple .front { width: 50px !important; height: 50px !important; margin-left: -25px !important; margin-top: -25px !important; }

    /* Adjust landscape button positions (example layout) */
     #mobile-button-jump {
         right: calc(20px + env(safe-area-inset-right));
         bottom: calc(80px + env(safe-area-inset-bottom));
         width: 65px; height: 65px;
     }
     #mobile-button-action {
         right: calc(100px + env(safe-area-inset-right));
         bottom: calc(15px + env(safe-area-inset-bottom));
         width: 75px; height: 75px;
     }
     #mobile-button-inventory {
         right: calc(20px + env(safe-area-inset-right));
         bottom: calc(15px + env(safe-area-inset-bottom));
         width: 55px; height: 55px;
     }
     #mobile-button-build {
         right: calc(100px + env(safe-area-inset-right));
         bottom: calc(80px + env(safe-area-inset-bottom));
         width: 55px; height: 55px;
     }
     #mobile-button-tech-tree {
        /* Place near build button */
        right: calc(170px + env(safe-area-inset-right)); /* Furthest right */
        bottom: calc(80px + env(safe-area-inset-bottom)); /* Mid */
        width: 55px; height: 55px;
    }
}

/* Adjustments for small screens (phones) - applies to both portrait and landscape */
@media (max-width: 767px) { /* Use 767px to avoid overlap with tablets */
    #crosshair { display: none; }
    #debug-info { font-size: 10px; top: 5px; left: 5px; padding: 5px;}

    /* Adjust panel positions considering controls container padding */
    /* Use calc() to push panels above the estimated control area height + safe area */
    #inventory-panel {
        width: 45%; left: calc(10px + env(safe-area-inset-left));
        /* Estimate control area height ~180px + safe area */
        bottom: calc(180px + env(safe-area-inset-bottom));
        max-height: 35vh; /* Limit height more */
    }
    #build-panel {
        width: 45%; left: auto; right: calc(10px + env(safe-area-inset-right));
        top: 10px; /* Keep near top */
        max-height: 35vh;
    }
    #ui-message-box {
        /* Position above controls */
        bottom: calc(190px + env(safe-area-inset-bottom));
        width: 85%; /* Slightly wider */
        font-size: 0.9em; padding: 8px 15px;
    }
    #tech-tree-panel, #ui-help-panel, #ui-crystal-list {
        max-height: 55vh; /* Reduce max height */
        width: 90%;
    }
    #ui-instructions {
        width: 90%; max-height: 65vh; font-size: 0.9em; padding: 15px;
    }

    /* Further adjustments for portrait on small screens */
    @media (orientation: portrait) {
        #joystick-container {
            width: 150px; height: 150px;
            bottom: calc(15px + env(safe-area-inset-bottom));
            left: calc(15px + env(safe-area-inset-left));
        }
        .nipple .front { width: 55px !important; height: 55px !important; margin-left: -27.5px !important; margin-top: -27.5px !important; }

         #mobile-button-jump { width: 75px; height: 75px; right: calc(20px + env(safe-area-inset-right)); bottom: calc(115px + env(safe-area-inset-bottom));}
         #mobile-button-action { width: 85px; height: 85px; right: calc(110px + env(safe-area-inset-right)); bottom: calc(30px + env(safe-area-inset-bottom)); }
         #mobile-button-inventory { width: 65px; height: 65px; right: calc(20px + env(safe-area-inset-right)); bottom: calc(25px + env(safe-area-inset-bottom)); }
         #mobile-button-build { width: 65px; height: 65px; right: calc(110px + env(safe-area-inset-right)); bottom: calc(120px + env(safe-area-inset-bottom)); }
         #mobile-button-tech-tree { width: 65px; height: 65px; right: calc(20px + env(safe-area-inset-right)); bottom: calc(25px + env(safe-area-inset-bottom)); } /* Adjusted bottom */

        }
}

/* Fix for very low height screens (landscape primarily) */
@media (max-height: 450px) and (orientation: landscape) {
    #mobile-controls-container { padding-bottom: calc(5px + env(safe-area-inset-bottom)); } /* Minimal padding */

    #joystick-container {
        width: 110px; height: 110px;
        bottom: calc(10px + env(safe-area-inset-bottom));
        left: calc(10px + env(safe-area-inset-left));
    }
    .nipple .front { width: 45px !important; height: 45px !important; margin-left: -22.5px !important; margin-top: -22.5px !important; }

    /* Smaller buttons, tightly packed */
    #mobile-button-jump { width: 55px; height: 55px; right: calc(15px + env(safe-area-inset-right)); bottom: calc(65px + env(safe-area-inset-bottom)); }
    #mobile-button-action { width: 65px; height: 65px; right: calc(80px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); }
    #mobile-button-inventory { width: 45px; height: 45px; right: calc(15px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); }
    #mobile-button-build { width: 45px; height: 45px; right: calc(80px + env(safe-area-inset-right)); bottom: calc(65px + env(safe-area-inset-bottom)); }
    #mobile-button-tech-tree { width: 45px; height: 45px; right: calc(135px + env(safe-area-inset-right)); bottom: calc(65px + env(safe-area-inset-bottom)); }

    /* Move panels up even more aggressively */
     #inventory-panel, #build-panel { bottom: calc(130px + env(safe-area-inset-bottom)); max-height: 30vh;}
     #ui-message-box { bottom: calc(140px + env(safe-area-inset-bottom)); }
}

/* Star Map Popup Styles */
#starmap-popup {
    z-index: 1001;
    text-align: center;
    background: var(--primary-dark);
    border: 2px solid var(--accent-gold);
    box-shadow: 0 0 20px rgba(224, 196, 92, 0.5);
}

#starmap-preview {
    background-size: cover;
    background-position: center;
    border-radius: 5px;
    border: 1px solid var(--accent-gold);
}

#starmap-popup .popup-button {
    padding: 10px 20px;
    font-size: 1em;
    background: var(--gradient-purple);
    border: 1px solid var(--accent-gold);
    color: var(--text-light);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Poppins', sans-serif;
}

#starmap-popup .popup-button:hover {
    background: var(--gradient-blue);
    box-shadow: 0 0 8px rgba(94, 49, 168, 0.6);
}
#starmap-popup .popup-button:disabled {
    background-color: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.4);
    color: #888;
    cursor: not-allowed;
}

/* Stats.js panels styling */
#stats-container > div {
    transform-origin: top right;
    transform: scale(1.3);
    margin-bottom: 5px;
    box-shadow: 0 0 5px rgba(10, 3, 41, 0.5);
    border: 1px solid rgba(224, 196, 92, 0.2);
}

#stats-container {
    position: fixed !important;
    top: 15px !important;
    right: 15px !important;
    left: auto !important;
    z-index: 150 !important;
    cursor: pointer !important;
    opacity: 0.9;
}

/* Buttons and interactive elements */
.game-button {
    background: var(--gradient-purple);
    color: var(--text-light);
    border: 1px solid var(--accent-gold);
    border-radius: 4px;
    padding: 8px 16px;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 0 8px rgba(94, 49, 168, 0.4);
}

.game-button:hover {
    background: var(--gradient-blue);
    box-shadow: 0 0 12px rgba(94, 49, 168, 0.6);
}

.game-button:active {
    transform: scale(0.98);
}

/* Tech tree and crafting styles */
.tech-tier {
    background: rgba(94, 49, 168, 0.1);
    border: 1px solid rgba(224, 196, 92, 0.2);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 15px;
}

.tech-tier h4 {
    color: var(--accent-gold);
    font-family: 'Cinzel', serif;
    margin-top: 0;
}

/* Resource display */
.resource-display {
    background: rgba(10, 3, 41, 0.6);
    border: 1px solid var(--accent-gold);
    border-radius: 4px;
    padding: 5px 10px;
    display: inline-block;
    margin: 5px;
    font-family: 'Poppins', sans-serif;
}

.resource-icon {
    color: var(--accent-gold);
    margin-right: 5px;
}

/* Starmap and celestial elements */
#starmap-popup {
    background: var(--primary-dark);
    border: 2px solid var(--accent-gold);
    box-shadow: 0 0 20px rgba(224, 196, 92, 0.5);
}

.celestial-body {
    border: 1px solid var(--accent-gold);
    background: var(--gradient-purple);
    color: var(--text-light);
    padding: 10px;
    margin: 10px 0;
    border-radius: 6px;
    font-family: 'Poppins', sans-serif;
}

.celestial-body h4 {
    color: var(--accent-gold);
    font-family: 'Cinzel', serif;
    margin-top: 0;
}

/* Media queries - keep these at the end */
@media (max-width: 768px) {
    #loading h1 {
        font-size: 1.5em;
    }
    
    #progress-container {
        width: 80%;
    }
    
    .game-panel {
        max-width: 95%;
    }
}

/* Mobile UI Buttons Container */
#ui-buttons-container {
    display: flex;
    flex-direction: row;
    gap: 10px;
    padding: 5px;
    background-color: rgba(10, 3, 41, 0.6);
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(94, 49, 168, 0.4);
    border: 1px solid rgba(224, 196, 92, 0.3);
    z-index: 2000;
}

/* Style for buttons in the UI container */
#inventory-button, #build-button, #tech-tree-button, #crystal-button {
    background: var(--gradient-purple);
    border: 2px solid var(--accent-gold);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 0 8px rgba(224, 196, 92, 0.3);
}

#inventory-button:active, #build-button:active, #tech-tree-button:active, #crystal-button:active {
    transform: scale(0.9);
    background: rgba(94, 49, 168, 0.9);
    box-shadow: 0 0 12px rgba(224, 196, 92, 0.5);
}

/* Special glow effect for crystal button */
#crystal-button {
    background: var(--gradient-gold);
    box-shadow: 0 0 10px rgba(224, 196, 92, 0.5);
}

#crystal-button:active {
    background: rgba(224, 196, 92, 0.8);
    box-shadow: 0 0 15px rgba(224, 196, 92, 0.7);
}

/* Media query adjustments for UI buttons container */
@media (max-width: 767px) {
    #ui-buttons-container {
        top: calc(10px + env(safe-area-inset-top)) !important;
        right: calc(10px + env(safe-area-inset-right)) !important;
        gap: 8px;
        padding: 4px;
    }
    
    #inventory-button, #build-button, #tech-tree-button, #crystal-button {
        width: 45px !important;
        height: 45px !important;
    }
}
