/* ========================================
   OpenClaw Mines - OSRS-Style with Movement
   ======================================== */

:root {
    /* OSRS Colors */
    --bg-dark: #0e0c0b;
    --bg-panel: #3d3426;
    --bg-panel-dark: #2d2418;
    --bg-panel-light: #4d4436;
    --border-light: #5d4a32;
    --border-dark: #1d1408;
    --border-gold: #8b7355;
    
    /* Text colors */
    --text-yellow: #ffff00;
    --text-white: #ffffff;
    --text-cyan: #00ffff;
    --text-green: #00ff00;
    --text-orange: #ff9900;
    --text-red: #ff0000;
    --text-purple: #9945ff;
    --text-mithril: #4a90d9;
    
    /* Ore glow colors */
    --glow-gold: rgba(255, 215, 0, 0.4);
    --glow-mithril: rgba(74, 144, 217, 0.4);
    --glow-runite: rgba(0, 255, 255, 0.4);
    --glow-adamantite: rgba(40, 100, 40, 0.4);
    --glow-iron: rgba(139, 90, 43, 0.4);
    
    /* Layout */
    --header-height: 50px;
    --chat-height: 160px;
    --inventory-width: 200px;
    
    /* Game world */
    --world-width: 800px;
    --world-height: 450px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: var(--bg-dark);
    color: var(--text-white);
    min-height: 100vh;
    overflow: hidden;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: none;
}

/* ========================================
   Game Container
   ======================================== */

#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: #000;
}

/* ========================================
   Header
   ======================================== */

#header {
    height: var(--header-height);
    background: linear-gradient(180deg, #5d4c36 0%, #3d3426 50%, #2d2418 100%);
    border-bottom: 4px solid #1a1208;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-icon {
    width: 28px;
    height: 28px;
    image-rendering: pixelated;
}

#header h1 {
    font-size: 12px;
    color: var(--text-yellow);
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
    letter-spacing: 1px;
}

#stats {
    font-size: 9px;
    color: var(--text-green);
    text-shadow: 1px 1px 0 #000;
}

/* ========================================
   Main Game Area
   ======================================== */

#game-area {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* ========================================
   Mine Scene - Top-Down View
   ======================================== */

#mine-scene {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #1a0f08;
}

#game-world {
    position: relative;
    width: var(--world-width);
    height: var(--world-height);
    margin: 0 auto;
    cursor: crosshair;
    overflow: hidden;
    background: 
        url('assets/sprites/background/dwarven_mine.png') center center / cover no-repeat,
        linear-gradient(180deg, #2c2010 0%, #1a0f08 60%, #0d0705 100%);
}

/* Floor tiles */
#floor-layer {
    position: absolute;
    inset: 0;
    background: 
        repeating-linear-gradient(
            0deg,
            transparent 0px,
            transparent 31px,
            rgba(0,0,0,0.2) 31px,
            rgba(0,0,0,0.2) 32px
        ),
        repeating-linear-gradient(
            90deg,
            transparent 0px,
            transparent 31px,
            rgba(0,0,0,0.2) 31px,
            rgba(0,0,0,0.2) 32px
        );
    pointer-events: none;
    opacity: 0.3;
}

/* Decoration layer */
#decoration-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.cave-wall {
    position: absolute;
    background: linear-gradient(180deg, #3d2a1a 0%, #2a1a0a 100%);
}

.cave-wall.top {
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: 
        linear-gradient(180deg, #1a0f08 0%, #2c1a10 70%, transparent 100%),
        repeating-linear-gradient(90deg, #3a2515 0px, #3a2515 40px, #2a1a10 40px, #2a1a10 80px);
}

.cave-wall.left {
    top: 0;
    left: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(90deg, #1a0f08 0%, transparent 100%);
}

.cave-wall.right {
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(270deg, #1a0f08 0%, transparent 100%);
}

/* Mine cart decoration */
.mine-cart {
    position: absolute;
    width: 40px;
    height: 30px;
    background: #5a4a3a;
    border: 2px solid #3a2a1a;
    border-radius: 4px 4px 0 0;
}

.mine-cart::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 5px;
    width: 30px;
    height: 8px;
    background: repeating-linear-gradient(90deg, #888 0px, #888 4px, transparent 4px, transparent 8px);
}

/* Torch decoration */
.torch {
    position: absolute;
    width: 12px;
    height: 24px;
    background: linear-gradient(180deg, #8b4513 0%, #5a2a0a 100%);
    border-radius: 2px;
}

.torch::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    background: radial-gradient(ellipse, #ff6600 0%, #ff3300 40%, transparent 70%);
    animation: torch-flicker 0.5s ease-in-out infinite alternate;
}

@keyframes torch-flicker {
    0% { opacity: 0.8; transform: translateX(-50%) scale(1); }
    100% { opacity: 1; transform: translateX(-50%) scale(1.1); }
}

/* ========================================
   Rocks - Positioned in World
   ======================================== */

#rocks {
    position: absolute;
    inset: 0;
    z-index: 10;
}

.rock {
    position: absolute;
    width: 80px;
    height: 70px;
    cursor: pointer;
    transition: transform 0.1s;
    /* Position set via inline style */
}

.rock:hover {
    transform: scale(1.08);
}

.rock:active {
    transform: scale(0.95);
}

.rock-sprite,
.rock-depleted {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 60px;
    object-fit: contain;
    image-rendering: pixelated;
    filter: drop-shadow(2px 4px 4px rgba(0,0,0,0.6));
}

.rock-depleted {
    display: none;
    filter: grayscale(100%) brightness(0.4) drop-shadow(2px 4px 4px rgba(0,0,0,0.6));
}

.rock.depleted .rock-sprite { display: none; }
.rock.depleted .rock-depleted { display: block; }
.rock.depleted { cursor: not-allowed; }
.rock.depleted:hover { transform: none; }

.rock-label {
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
    white-space: nowrap;
    z-index: 20;
}

.rock-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90px;
    height: 70px;
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    animation: rock-pulse 2s ease-in-out infinite;
}

.rock:hover .rock-glow { opacity: 1; }

.rock-glow.gold { background: radial-gradient(ellipse, var(--glow-gold) 0%, transparent 70%); }
.rock-glow.mithril { background: radial-gradient(ellipse, var(--glow-mithril) 0%, transparent 70%); }
.rock-glow.runite { background: radial-gradient(ellipse, var(--glow-runite) 0%, transparent 70%); }
.rock-glow.adamantite { background: radial-gradient(ellipse, var(--glow-adamantite) 0%, transparent 70%); }
.rock-glow.iron { background: radial-gradient(ellipse, var(--glow-iron) 0%, transparent 70%); }

@keyframes rock-pulse {
    0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.7; transform: translate(-50%, -50%) scale(1.1); }
}

.rock.mining {
    animation: rock-shake 0.12s steps(2) infinite;
}

.rock.mining .rock-glow {
    opacity: 1 !important;
    animation: mining-glow 0.3s ease-in-out infinite;
}

@keyframes rock-shake {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-3px); }
}

@keyframes mining-glow {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ========================================
   Player Character - OSRS Style
   ======================================== */

#players {
    position: absolute;
    inset: 0;
    z-index: 15;
    pointer-events: none;
}

.player {
    position: absolute;
    transform: translate(-50%, -100%); /* Anchor at feet */
    z-index: 15;
    pointer-events: none;
    /* Smooth movement transition */
    transition: left 0.1s linear, top 0.1s linear;
}

.player.local {
    z-index: 20; /* Local player on top */
    transition: none; /* Immediate updates for local player */
}

.player-name {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
    white-space: nowrap;
    z-index: 25;
}

.player-sprite {
    position: relative;
    width: 32px;
    height: 48px;
}

.player-shadow {
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 8px;
    background: radial-gradient(ellipse, rgba(0,0,0,0.5) 0%, transparent 70%);
    border-radius: 50%;
}

.player-body {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 40px;
}

/* Head */
.player-head {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    background: #ffd699; /* Skin tone */
    border-radius: 50% 50% 40% 40%;
    box-shadow: inset -2px 0 0 rgba(0,0,0,0.2);
}

/* Hair */
.player-head::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 8px;
    background: #654321;
    border-radius: 50% 50% 0 0;
}

/* Eyes */
.player-head::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 2px;
    width: 10px;
    height: 3px;
    background: linear-gradient(90deg, 
        #000 0%, #000 20%, 
        transparent 20%, transparent 40%,
        #000 40%, #000 60%,
        transparent 60%, transparent 100%
    );
}

/* Torso */
.player-torso {
    position: absolute;
    top: 13px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 14px;
    background: #2d8b4a; /* Green tunic */
    border-radius: 2px;
    box-shadow: inset -3px 0 0 rgba(0,0,0,0.2);
}

/* Arms (on torso) */
.player-torso::before {
    content: '';
    position: absolute;
    top: 2px;
    left: -6px;
    width: 6px;
    height: 10px;
    background: #2d8b4a;
    border-radius: 2px;
    box-shadow: inset -1px 0 0 rgba(0,0,0,0.2);
}

.player-torso::after {
    content: '';
    position: absolute;
    top: 2px;
    right: -6px;
    width: 6px;
    height: 10px;
    background: #2d8b4a;
    border-radius: 2px;
    box-shadow: inset 1px 0 0 rgba(255,255,255,0.1);
}

/* Legs */
.player-legs {
    position: absolute;
    top: 26px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    background: linear-gradient(90deg, #5a4632 48%, transparent 48%, transparent 52%, #5a4632 52%);
}

/* Pickaxe */
.player-pickaxe {
    position: absolute;
    top: 12px;
    right: -14px;
    width: 20px;
    height: 20px;
    background: 
        linear-gradient(135deg, transparent 40%, #4a90d9 40%, #4a90d9 60%, transparent 60%),
        linear-gradient(45deg, #8b5a2b 0%, #8b5a2b 100%);
    background-size: 12px 12px, 4px 18px;
    background-position: top right, bottom center;
    background-repeat: no-repeat;
    transform-origin: bottom left;
}

/* Remote player - different color */
.player.remote .player-torso,
.player.remote .player-torso::before,
.player.remote .player-torso::after {
    background: #8b2d2d; /* Red tunic */
}

/* ========================================
   Walking Animation
   ======================================== */

.player.walking .player-legs {
    animation: walk-legs 0.3s steps(2) infinite;
}

.player.walking .player-body {
    animation: walk-bob 0.3s ease-in-out infinite;
}

@keyframes walk-legs {
    0% { 
        background: linear-gradient(90deg, #5a4632 45%, transparent 45%, transparent 55%, #5a4632 55%);
    }
    50% { 
        background: linear-gradient(90deg, #5a4632 40%, transparent 40%, transparent 60%, #5a4632 60%);
    }
}

@keyframes walk-bob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-2px); }
}

/* ========================================
   Direction Facing
   ======================================== */

/* Default: facing down */
.player[data-direction="down"] .player-body {
    /* Default state */
}

/* Facing up */
.player[data-direction="up"] .player-head::after {
    display: none; /* Hide eyes when facing away */
}

.player[data-direction="up"] .player-head::before {
    height: 10px; /* More hair visible */
}

.player[data-direction="up"] .player-body {
    transform: translateX(-50%);
}

/* Facing left */
.player[data-direction="left"] {
    transform: translate(-50%, -100%) scaleX(-1);
}

.player[data-direction="left"] .player-name {
    transform: translateX(-50%) scaleX(-1); /* Keep name readable */
}

/* Facing right - default horizontal */
.player[data-direction="right"] .player-body {
    transform: translateX(-50%);
}

/* ========================================
   Mining Animation
   ======================================== */

.player.mining .player-pickaxe {
    animation: mining-swing 0.4s ease-in-out infinite;
}

.player.mining .player-body {
    animation: mining-body 0.4s ease-in-out infinite;
}

@keyframes mining-swing {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-60deg); }
}

@keyframes mining-body {
    0%, 100% { transform: translateX(-50%) rotate(0deg); }
    50% { transform: translateX(-50%) rotate(-5deg); }
}

/* ========================================
   Click Indicator (Yellow X)
   ======================================== */

#click-indicator {
    position: absolute;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
}

#click-indicator.hidden {
    opacity: 0;
}

#click-indicator.show {
    opacity: 1;
    animation: click-fade 0.5s ease-out forwards;
}

.click-x {
    position: absolute;
    width: 100%;
    height: 100%;
}

.click-x::before,
.click-x::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 3px;
    background: var(--text-yellow);
    box-shadow: 0 0 4px rgba(255, 255, 0, 0.8);
}

.click-x::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.click-x::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

@keyframes click-fade {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}

/* ========================================
   Mining Progress Bar
   ======================================== */

#mining-progress {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    text-align: center;
}

#mining-progress.hidden { display: none; }

.progress-bar {
    width: 200px;
    height: 20px;
    background: var(--bg-panel-dark);
    border: 3px solid var(--border-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(180deg, #4CAF50 0%, #2E7D32 100%);
    transition: width 0.1s linear;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.3);
}

.progress-text {
    display: block;
    font-size: 8px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000;
    margin-top: 4px;
}

/* ========================================
   Particles
   ======================================== */

#particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 50;
}

.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    animation: particle-fly 1s ease-out forwards;
    image-rendering: pixelated;
}

.particle.ore-particle {
    width: 16px;
    height: 16px;
    border-radius: 0;
}

@keyframes particle-fly {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0.3) rotate(360deg);
    }
}

.particle.gold { background: #ffd700; box-shadow: 0 0 4px #ffd700; }
.particle.mithril { background: #4a90d9; box-shadow: 0 0 4px #4a90d9; }
.particle.runite { background: #00ffff; box-shadow: 0 0 4px #00ffff; }
.particle.adamantite { background: #2d5a2d; box-shadow: 0 0 4px #2d5a2d; }
.particle.iron { background: #8b5a2b; box-shadow: 0 0 4px #8b5a2b; }

/* ========================================
   Inventory Panel
   ======================================== */

#inventory {
    width: var(--inventory-width);
    background: linear-gradient(180deg, #4a3d2a 0%, #3d3020 50%, #2d2418 100%);
    border-left: 4px solid #1a1208;
    box-shadow: inset 2px 0 0 rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
}

.inventory-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
    border-bottom: 3px solid #1a1208;
}

.inv-header-icon {
    width: 24px;
    height: 24px;
    image-rendering: pixelated;
}

#inventory h2 {
    font-size: 9px;
    color: var(--text-orange);
    text-shadow: 1px 1px 0 #000;
}

#inventory-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 8px;
    flex: 1;
}

.inv-slot {
    background: rgba(0,0,0,0.5);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 70px;
    transition: all 0.15s;
}

.inv-slot:not(.empty):hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--border-gold);
}

.inv-slot.gained {
    animation: slot-flash 0.4s ease-out;
}

@keyframes slot-flash {
    0% { background: rgba(255,255,0,0.5); border-color: #ffff00; }
    100% { background: rgba(0,0,0,0.5); border-color: var(--border-dark); }
}

.ore-icon {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    margin-bottom: 4px;
}

.inv-count {
    font-size: 10px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000;
}

.inv-label {
    font-size: 6px;
    color: var(--text-white);
    opacity: 0.7;
    margin-top: 2px;
}

.inv-slot.empty {
    background: rgba(0,0,0,0.3);
    border-color: rgba(29,20,8,0.5);
}

#total-mined {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: rgba(0,0,0,0.3);
    border-top: 2px solid var(--border-dark);
    font-size: 8px;
    color: var(--text-green);
}

.coins-icon {
    width: 20px;
    height: 20px;
    image-rendering: pixelated;
}

#total-count {
    color: var(--text-yellow);
    font-size: 10px;
}

#skill-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: linear-gradient(180deg, #3d3020 0%, #2d2418 100%);
    border-top: 2px solid var(--border-light);
}

.skill-icon {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
}

.skill-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.skill-name {
    font-size: 8px;
    color: var(--text-orange);
    text-shadow: 1px 1px 0 #000;
}

.skill-level {
    font-size: 8px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000;
}

/* ========================================
   Chat Box
   ======================================== */

#chat-container {
    height: var(--chat-height);
    background: linear-gradient(180deg, #3d3426 0%, #2d2418 100%);
    border-top: 4px solid #1a1208;
    display: flex;
    flex-direction: column;
}

#chat-tabs {
    display: flex;
    gap: 1px;
    background: #1a1208;
    overflow-x: auto;
}

.chat-tab {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 8px 10px;
    background: linear-gradient(180deg, #4d3c26 0%, #3d2c16 100%);
    border: none;
    border-right: 1px solid #1a1208;
    color: var(--text-white);
    cursor: pointer;
    transition: all 0.1s;
    white-space: nowrap;
}

.chat-tab:hover {
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
}

.chat-tab.active {
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
    color: var(--text-yellow);
    box-shadow: inset 0 -2px 0 var(--text-yellow);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-size: 9px;
    line-height: 1.8;
    background: rgba(0,0,0,0.2);
}

.chat-message {
    margin-bottom: 2px;
    word-wrap: break-word;
}

.chat-message.system { color: var(--text-cyan); }
.chat-message.game { color: var(--text-orange); }
.chat-message .sender { color: var(--text-yellow); }
.chat-message .text { color: var(--text-white); }

#chat-input-container {
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    background: #1a1208;
}

#player-name {
    width: 80px;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 8px 6px;
    background: #0a0a0a;
    border: 2px solid var(--border-dark);
    color: var(--text-cyan);
    outline: none;
}

#player-name::placeholder { color: #444; }

#chat-input {
    flex: 1;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 8px 6px;
    background: #0a0a0a;
    border: 2px solid var(--border-dark);
    color: var(--text-white);
    outline: none;
}

#chat-input:focus { border-color: var(--border-light); }
#chat-input:disabled { background: #050505; border-color: #222; color: #444; }
#chat-input::placeholder { color: #444; }

#send-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 8px 12px;
    background: linear-gradient(180deg, #4d3c26 0%, #3d2c16 100%);
    border: 2px solid var(--border-dark);
    color: var(--text-white);
    cursor: pointer;
    transition: all 0.1s;
}

#send-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
    color: var(--text-yellow);
}

#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ========================================
   Connection Overlay
   ======================================== */

#connection-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

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

.overlay-content { text-align: center; }

.loading-pickaxe {
    width: 64px;
    height: 64px;
    margin: 0 auto;
    animation: loading-swing 0.6s ease-in-out infinite alternate;
}

.loading-pickaxe img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

@keyframes loading-swing {
    0% { transform: rotate(-20deg) scale(1); }
    100% { transform: rotate(20deg) scale(1.1); }
}

.overlay-content p {
    margin-top: 20px;
    font-size: 10px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000;
}

/* ========================================
   Mobile Controls
   ======================================== */

#mobile-controls {
    display: none;
    position: fixed;
    bottom: calc(var(--chat-height) + 10px);
    right: 10px;
    gap: 8px;
    z-index: 100;
}

#mobile-controls button {
    width: 48px;
    height: 48px;
    font-size: 20px;
    background: linear-gradient(180deg, #4d3c26 0%, #3d2c16 100%);
    border: 3px solid var(--border-dark);
    border-radius: 4px;
    cursor: pointer;
}

/* ========================================
   Mining Stats Panel (Top Right)
   ======================================== */

#mining-stats-panel {
    position: fixed;
    top: 60px;
    right: 16px;
    width: 180px;
    background: linear-gradient(180deg, #4a3d2a 0%, #3d3020 50%, #2d2418 100%);
    border: 3px solid #1a1208;
    border-radius: 4px;
    box-shadow: 
        inset 0 1px 0 rgba(255,255,255,0.1),
        0 4px 12px rgba(0,0,0,0.5);
    z-index: 100;
    font-family: 'Press Start 2P', monospace;
}

.stats-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
    border-bottom: 2px solid #1a1208;
    border-radius: 2px 2px 0 0;
}

.stats-icon {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

.stats-header > span {
    font-size: 7px;
    color: var(--text-orange);
    text-shadow: 1px 1px 0 #000;
    flex: 1;
}

.mining-status {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #666;
    box-shadow: 0 0 4px rgba(102, 102, 102, 0.5);
}

.status-dot.active {
    background: var(--text-green);
    box-shadow: 0 0 6px rgba(0, 255, 0, 0.6);
    animation: status-pulse 1.5s ease-in-out infinite;
}

.status-dot.paused {
    background: var(--text-yellow);
    box-shadow: 0 0 6px rgba(255, 255, 0, 0.5);
}

.status-dot.stopped {
    background: var(--text-red);
    box-shadow: 0 0 4px rgba(255, 0, 0, 0.5);
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.status-text {
    font-size: 5px;
    color: var(--text-green);
    text-shadow: 1px 1px 0 #000;
}

.status-text.paused { color: var(--text-yellow); }
.status-text.stopped { color: var(--text-red); }

.stats-body {
    padding: 8px 10px;
}

.stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(26, 18, 8, 0.5);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row.primary {
    padding: 6px 0;
    margin-bottom: 4px;
}

.stat-row.primary .stat-value {
    font-size: 11px;
    color: var(--text-cyan);
}

.stat-label {
    font-size: 6px;
    color: rgba(255, 255, 255, 0.7);
    text-shadow: 1px 1px 0 #000;
}

.stat-value {
    font-size: 8px;
    color: var(--text-yellow);
    text-shadow: 1px 1px 0 #000;
}

.stat-value.usd {
    color: var(--text-green);
}

.stat-unit {
    font-size: 6px;
    color: rgba(255, 255, 255, 0.5);
    margin-left: 2px;
}

.stat-row.lifetime {
    background: rgba(0, 0, 0, 0.2);
    margin: 4px -10px;
    padding: 6px 10px;
}

.stat-row.lifetime .stat-value {
    color: var(--text-orange);
}

/* CPU Usage Bar */
.stat-row.cpu-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding-top: 6px;
}

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

.cpu-bar {
    flex: 1;
    height: 10px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    overflow: hidden;
}

.cpu-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(180deg, var(--text-green) 0%, #006600 100%);
    transition: width 0.3s ease, background 0.3s ease;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.3);
}

.cpu-fill.medium {
    background: linear-gradient(180deg, var(--text-yellow) 0%, #666600 100%);
}

.cpu-fill.high {
    background: linear-gradient(180deg, var(--text-orange) 0%, #663300 100%);
}

.cpu-fill.critical {
    background: linear-gradient(180deg, var(--text-red) 0%, #660000 100%);
    animation: cpu-critical 0.5s ease-in-out infinite;
}

@keyframes cpu-critical {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.cpu-percent {
    font-size: 7px;
    color: var(--text-white);
    text-shadow: 1px 1px 0 #000;
    min-width: 24px;
    text-align: right;
}

/* Temperature Warning */
.stat-row.temp-row {
    background: rgba(255, 0, 0, 0.15);
    margin: 4px -10px 0;
    padding: 6px 10px;
    animation: temp-flash 1s ease-in-out infinite;
}

@keyframes temp-flash {
    0%, 100% { background: rgba(255, 0, 0, 0.15); }
    50% { background: rgba(255, 0, 0, 0.3); }
}

.temp-icon {
    font-size: 10px;
}

.temp-text {
    font-size: 6px;
    color: var(--text-red);
    text-shadow: 1px 1px 0 #000;
    flex: 1;
    margin-left: 4px;
}

.temp-value {
    font-size: 8px;
    color: var(--text-red);
    text-shadow: 1px 1px 0 #000;
}

/* Mining Controls */
.stats-controls {
    display: flex;
    gap: 4px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 2px solid var(--border-dark);
}

.osrs-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 8px 10px;
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 50%, #3d2c16 100%);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    color: var(--text-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.1s;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}

.osrs-btn:hover {
    background: linear-gradient(180deg, #6d5c46 0%, #5d4c36 50%, #4d3c26 100%);
    border-color: var(--border-gold);
}

.osrs-btn:active {
    background: linear-gradient(180deg, #3d2c16 0%, #4d3c26 50%, #5d4c36 100%);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.osrs-btn.mining-active {
    background: linear-gradient(180deg, #2d5a2d 0%, #1d4a1d 50%, #0d3a0d 100%);
    border-color: #1a3a1a;
}

.osrs-btn.mining-active:hover {
    background: linear-gradient(180deg, #3d6a3d 0%, #2d5a2d 50%, #1d4a1d 100%);
    border-color: #2a4a2a;
}

.osrs-btn.mining-paused {
    background: linear-gradient(180deg, #5a5a2d 0%, #4a4a1d 50%, #3a3a0d 100%);
    border-color: #3a3a1a;
}

#mining-toggle-btn {
    flex: 1;
}

.btn-icon {
    font-size: 10px;
}

.btn-text {
    text-shadow: 1px 1px 0 #000;
}

/* Settings Panel */
.settings-panel {
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 2px solid var(--border-dark);
}

.settings-panel.hidden {
    display: none;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.setting-label {
    font-size: 6px;
    color: var(--text-white);
    text-shadow: 1px 1px 0 #000;
}

.thread-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.thread-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    width: 20px;
    height: 20px;
    background: linear-gradient(180deg, #5d4c36 0%, #3d2c16 100%);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    color: var(--text-yellow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thread-btn:hover {
    background: linear-gradient(180deg, #6d5c46 0%, #4d3c26 100%);
    border-color: var(--border-gold);
}

.thread-btn:active {
    background: linear-gradient(180deg, #3d2c16 0%, #5d4c36 100%);
}

.thread-count {
    font-size: 10px;
    color: var(--text-cyan);
    text-shadow: 1px 1px 0 #000;
    min-width: 16px;
    text-align: center;
}

/* Custom Checkbox */
.setting-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.setting-checkbox input {
    display: none;
}

.checkmark {
    width: 14px;
    height: 14px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    position: relative;
}

.setting-checkbox:hover .checkmark {
    border-color: var(--border-gold);
}

.setting-checkbox input:checked + .checkmark {
    background: linear-gradient(180deg, var(--text-green) 0%, #006600 100%);
    border-color: #004400;
}

.setting-checkbox input:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 8px;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
}

.setting-info {
    padding-top: 6px;
    border-top: 1px solid rgba(26, 18, 8, 0.5);
    margin-top: 4px;
}

#settings-info-text {
    font-size: 5px;
    color: rgba(255, 255, 255, 0.5);
    text-shadow: 1px 1px 0 #000;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 900px) {
    :root {
        --inventory-width: 160px;
        --world-width: 600px;
    }
    
    .rock { width: 65px; height: 58px; }
    .rock-sprite, .rock-depleted { width: 55px; height: 48px; }
}

@media (max-width: 768px) {
    :root {
        --chat-height: 140px;
        --inventory-width: 140px;
        --world-width: 100%;
    }

    #game-world {
        width: 100%;
        height: 350px;
    }

    .rock { width: 55px; height: 48px; }
    .rock-sprite, .rock-depleted { width: 45px; height: 40px; }
    .rock-label { font-size: 6px; }

    #inventory {
        position: fixed;
        right: 0;
        top: var(--header-height);
        bottom: var(--chat-height);
        transform: translateX(100%);
        transition: transform 0.3s;
        z-index: 50;
    }

    #inventory.visible { transform: translateX(0); }

    #mobile-controls { display: flex; }
    
    /* Mining stats panel mobile */
    #mining-stats-panel {
        position: fixed;
        top: auto;
        bottom: calc(var(--chat-height) + 60px);
        right: 8px;
        width: 160px;
        font-size: 90%;
    }
    
    .stats-header > span {
        font-size: 6px;
    }
    
    .stat-row.primary .stat-value {
        font-size: 9px;
    }
    
    .stat-label {
        font-size: 5px;
    }
    
    .stat-value {
        font-size: 7px;
    }
    
    .osrs-btn {
        padding: 6px 8px;
        font-size: 6px;
    }
    
    .btn-icon {
        font-size: 8px;
    }
}

/* ========================================
   Virtual Joystick
   ======================================== */

.virtual-joystick {
    position: fixed;
    bottom: calc(var(--chat-height) + 30px);
    left: 30px;
    width: 120px;
    height: 120px;
    z-index: 100;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.virtual-joystick.hidden {
    display: none;
}

.joystick-base {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(61, 52, 38, 0.9) 0%, rgba(29, 20, 8, 0.9) 100%);
    border: 4px solid var(--border-light);
    border-radius: 50%;
    box-shadow: 
        inset 0 4px 8px rgba(0, 0, 0, 0.4),
        0 4px 12px rgba(0, 0, 0, 0.6);
}

.joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    margin-left: -25px;
    margin-top: -25px;
    background: linear-gradient(180deg, #6d5c46 0%, #4d3c26 100%);
    border: 3px solid var(--border-gold);
    border-radius: 50%;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.2),
        0 4px 8px rgba(0, 0, 0, 0.5);
    transition: transform 0.05s ease-out;
}

.virtual-joystick.active .joystick-knob {
    background: linear-gradient(180deg, #8d7c66 0%, #6d5c46 100%);
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.4);
}

.virtual-joystick.active .joystick-base {
    border-color: var(--text-yellow);
}

/* ========================================
   Mobile-Specific Styles
   ======================================== */

.is-mobile {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: pan-x pan-y;
}

.is-mobile #game-world {
    cursor: pointer;
    touch-action: none;
}

.is-mobile .rock {
    /* Larger tap targets on mobile */
    min-width: 70px;
    min-height: 60px;
}

.is-mobile .rock:active {
    transform: scale(0.92);
}

.is-mobile .player-name {
    font-size: 10px;
}

/* Prevent text selection on touch */
.is-mobile * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text input selection */
.is-mobile input[type="text"] {
    -webkit-user-select: text;
    user-select: text;
}

/* Mobile Controls Enhanced */
#mobile-controls {
    flex-wrap: wrap;
    max-width: 120px;
    justify-content: flex-end;
}

#mobile-controls button {
    border-radius: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s, background 0.1s;
}

#mobile-controls button:active,
#mobile-controls button.active {
    transform: scale(0.95);
    background: linear-gradient(180deg, #6d5c46 0%, #5d4c36 100%);
    border-color: var(--text-yellow);
}

#mobile-run-btn.active {
    background: linear-gradient(180deg, #4a6d4a 0%, #3a5d3a 100%);
    border-color: var(--text-green);
}

/* ========================================
   Responsive - Mobile (Enhanced)
   ======================================== */

@media (max-width: 768px) {
    :root {
        --chat-height: 120px;
        --header-height: 44px;
    }

    body {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    #game-container {
        height: 100%;
        height: 100dvh; /* Dynamic viewport height for mobile */
    }

    #header h1 {
        font-size: 10px;
    }

    #stats {
        font-size: 8px;
    }

    #game-world {
        height: calc(100dvh - var(--header-height) - var(--chat-height));
        min-height: 280px;
        transform-origin: center center;
    }

    /* Touch-friendly rock sizing */
    .rock { 
        width: 70px; 
        height: 60px;
        /* Larger touch target */
        padding: 10px;
        margin: -10px;
    }
    .rock-sprite, .rock-depleted { 
        width: 55px; 
        height: 48px; 
    }
    .rock-label { 
        font-size: 8px;
        padding: 2px 6px;
        background: rgba(0, 0, 0, 0.6);
        border-radius: 4px;
    }

    /* Inventory sidebar */
    #inventory {
        width: 160px;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    }

    /* Show mobile controls */
    #mobile-controls { 
        display: flex;
        bottom: calc(var(--chat-height) + 20px);
    }

    /* Collapsible chat */
    #chat-container {
        transition: height 0.3s ease-out;
    }

    #chat-container.collapsed {
        height: 40px;
    }

    #chat-container.collapsed #chat-messages,
    #chat-container.collapsed #chat-input-container {
        display: none;
    }

    #chat-tabs {
        -webkit-overflow-scrolling: touch;
    }

    .chat-tab {
        font-size: 8px;
        padding: 10px 12px;
        min-width: max-content;
    }

    #chat-input-container {
        padding: 8px;
        gap: 4px;
    }

    #player-name {
        width: 70px;
        font-size: 8px;
        padding: 10px 8px;
    }

    #chat-input {
        font-size: 8px;
        padding: 10px 8px;
    }

    #send-btn {
        font-size: 8px;
        padding: 10px 14px;
    }

    /* Mining progress - mobile positioning */
    #mining-progress {
        top: 60px;
    }

    .progress-bar {
        width: 160px;
        height: 24px;
    }

    .progress-text {
        font-size: 9px;
    }

    /* Virtual joystick positioning */
    .virtual-joystick {
        bottom: calc(var(--chat-height) + 20px);
        left: 20px;
        width: 100px;
        height: 100px;
    }

    .joystick-knob {
        width: 44px;
        height: 44px;
        margin-left: -22px;
        margin-top: -22px;
    }
    
    /* Hide mining stats panel on mobile */
    #mining-stats-panel {
        display: none;
    }
}

/* ========================================
   Responsive - Small Mobile (iPhone SE, etc)
   ======================================== */

@media (max-width: 375px) {
    :root {
        --chat-height: 100px;
        --header-height: 40px;
    }

    #header h1 {
        font-size: 8px;
    }

    .header-icon {
        width: 20px;
        height: 20px;
    }

    .rock { 
        width: 60px; 
        height: 50px;
    }
    .rock-sprite, .rock-depleted { 
        width: 45px; 
        height: 38px; 
    }
    .rock-label { 
        font-size: 7px;
    }

    .virtual-joystick {
        width: 90px;
        height: 90px;
        bottom: calc(var(--chat-height) + 15px);
        left: 15px;
    }

    .joystick-knob {
        width: 40px;
        height: 40px;
        margin-left: -20px;
        margin-top: -20px;
    }

    #mobile-controls {
        bottom: calc(var(--chat-height) + 15px);
        right: 8px;
    }

    #mobile-controls button {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }

    #inventory {
        width: 140px;
    }

    .inv-slot {
        min-height: 60px;
        padding: 4px;
    }

    .ore-icon {
        width: 28px;
        height: 28px;
    }

    .inv-count {
        font-size: 9px;
    }
}

/* ========================================
   Landscape Mobile
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --chat-height: 80px;
        --header-height: 36px;
    }

    #game-world {
        height: calc(100dvh - var(--header-height) - var(--chat-height));
    }

    .virtual-joystick {
        bottom: calc(var(--chat-height) + 10px);
        left: 15px;
        width: 80px;
        height: 80px;
    }

    .joystick-knob {
        width: 36px;
        height: 36px;
        margin-left: -18px;
        margin-top: -18px;
    }

    #mobile-controls {
        bottom: calc(var(--chat-height) + 10px);
        flex-direction: column;
    }

    #mobile-controls button {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    #chat-container.collapsed {
        height: 30px;
    }

    .chat-tab {
        padding: 6px 8px;
        font-size: 7px;
    }
}

/* ========================================
   iOS Safari Specific Fixes
   ======================================== */

@supports (-webkit-touch-callout: none) {
    /* iOS specific styles */
    body {
        /* Prevent bounce scrolling */
        position: fixed;
        overflow: hidden;
    }

    #game-container {
        /* Use safe area insets for notch/home indicator */
        padding-bottom: env(safe-area-inset-bottom);
    }

    .virtual-joystick {
        bottom: calc(var(--chat-height) + 20px + env(safe-area-inset-bottom));
    }

    #mobile-controls {
        bottom: calc(var(--chat-height) + 20px + env(safe-area-inset-bottom));
    }

    #chat-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ========================================
   Android Chrome Specific
   ======================================== */

@media screen and (display-mode: standalone) {
    /* PWA mode adjustments */
    #game-container {
        padding-top: env(safe-area-inset-top);
    }
}

/* ========================================
   Touch Feedback (no hover on touch devices)
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Touch device - no hover states */
    .rock:hover {
        transform: none;
    }
    
    .rock:hover .rock-glow {
        opacity: 0;
    }

    /* Active states instead */
    .rock:active {
        transform: scale(0.95);
    }

    .rock:active .rock-glow {
        opacity: 1;
    }

    .inv-slot:hover {
        background: rgba(0, 0, 0, 0.5);
        border-color: var(--border-dark);
    }

    .inv-slot:active {
        background: rgba(255, 255, 255, 0.1);
        border-color: var(--border-gold);
    }
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: #1a1208; }
::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #5d4c36 0%, #3d2c16 100%);
    border: 1px solid #1a1208;
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #6d5c46 0%, #4d3c26 100%);
}

/* ========================================
   Utility Classes
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   LOADING SCREEN
   ======================================== */

#loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, #1a0f08 0%, #0d0705 50%, #000 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

#loading-screen.fade-out {
    animation: fade-out 0.5s ease-out forwards;
}

@keyframes fade-out {
    to { opacity: 0; pointer-events: none; }
}

.loading-content {
    text-align: center;
    max-width: 400px;
    padding: 20px;
}

.loading-logo {
    margin-bottom: 40px;
}

.logo-pickaxe {
    font-size: 64px;
    animation: pickaxe-swing 1s ease-in-out infinite;
    display: inline-block;
}

@keyframes pickaxe-swing {
    0%, 100% { transform: rotate(-15deg); }
    50% { transform: rotate(15deg); }
}

.loading-logo h1 {
    font-size: 20px;
    color: var(--text-yellow);
    text-shadow: 2px 2px 0 #000, 0 0 20px rgba(255, 255, 0, 0.3);
    margin: 16px 0 8px;
    letter-spacing: 2px;
}

.loading-logo .tagline {
    font-size: 10px;
    color: var(--text-orange);
    text-shadow: 1px 1px 0 #000;
    opacity: 0.8;
}

.loading-animation {
    margin: 30px 0;
}

.loading-bar {
    width: 300px;
    height: 24px;
    background: var(--bg-panel-dark);
    border: 4px solid var(--border-light);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto 12px;
}

.loading-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, 
        #ffd700 0%, 
        #ffaa00 25%, 
        #ffd700 50%, 
        #ffaa00 75%, 
        #ffd700 100%
    );
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s linear infinite;
    transition: width 0.3s ease-out;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        0 0 10px rgba(255, 215, 0, 0.5);
}

@keyframes loading-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.loading-text {
    font-size: 9px;
    color: var(--text-white);
    text-shadow: 1px 1px 0 #000;
}

.loading-tips {
    margin: 30px 0;
    min-height: 40px;
}

.loading-tips p {
    font-size: 8px;
    color: var(--text-cyan);
    text-shadow: 1px 1px 0 #000;
    transition: opacity 0.3s;
}

#start-game {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    padding: 16px 32px;
    background: linear-gradient(180deg, #5d8a3d 0%, #3d6a2d 50%, #2d5a1d 100%);
    border: 4px solid #1d4a0d;
    border-radius: 4px;
    color: var(--text-white);
    cursor: pointer;
    text-shadow: 2px 2px 0 #000;
    box-shadow: 
        inset 0 2px 0 rgba(255, 255, 255, 0.2),
        0 4px 0 #1d3a0d,
        0 6px 12px rgba(0, 0, 0, 0.5);
    transition: all 0.1s;
    animation: pulse-glow 2s ease-in-out infinite;
}

#start-game:hover {
    background: linear-gradient(180deg, #6d9a4d 0%, #4d7a3d 50%, #3d6a2d 100%);
    transform: translateY(-2px);
    box-shadow: 
        inset 0 2px 0 rgba(255, 255, 255, 0.3),
        0 6px 0 #1d3a0d,
        0 8px 16px rgba(0, 0, 0, 0.6);
}

#start-game:active {
    transform: translateY(2px);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.3),
        0 2px 0 #1d3a0d,
        0 3px 8px rgba(0, 0, 0, 0.4);
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 4px 0 #1d3a0d, 0 6px 12px rgba(0, 0, 0, 0.5), 0 0 20px rgba(93, 138, 61, 0.3); }
    50% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 4px 0 #1d3a0d, 0 6px 12px rgba(0, 0, 0, 0.5), 0 0 40px rgba(93, 138, 61, 0.6); }
}

.loading-version {
    position: absolute;
    bottom: 16px;
    right: 16px;
    font-size: 8px;
    color: rgba(255, 255, 255, 0.3);
}

/* ========================================
   HEADER ENHANCEMENTS
   ======================================== */

#header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    font-size: 18px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    transition: transform 0.1s;
    filter: drop-shadow(1px 1px 0 #000);
}

.icon-btn:hover {
    transform: scale(1.2);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ========================================
   SETTINGS MODAL
   ======================================== */

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
}

.modal-content {
    position: relative;
    background: linear-gradient(180deg, #4a3d2a 0%, #3d3020 50%, #2d2418 100%);
    border: 4px solid #1a1208;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
    border-bottom: 3px solid #1a1208;
}

.modal-header h2 {
    font-size: 12px;
    color: var(--text-yellow);
    text-shadow: 2px 2px 0 #000;
}

.modal-close {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    background: none;
    border: none;
    color: var(--text-white);
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.7;
    transition: opacity 0.1s;
}

.modal-close:hover {
    opacity: 1;
    color: var(--text-red);
}

.modal-body {
    padding: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 2px solid var(--border-dark);
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.settings-tab {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    color: var(--text-white);
    cursor: pointer;
    transition: all 0.1s;
}

.settings-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-light);
}

.settings-tab.active {
    background: var(--bg-panel);
    border-color: var(--text-yellow);
    color: var(--text-yellow);
}

/* Settings Content */
.settings-content {
    padding: 8px 0;
}

.settings-content.hidden {
    display: none;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 9px;
    color: var(--text-white);
    text-shadow: 1px 1px 0 #000;
    cursor: pointer;
    padding: 8px 0;
}

.setting-label input[type="checkbox"] {
    display: none;
}

.setting-label .toggle {
    width: 40px;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--border-dark);
    border-radius: 10px;
    position: relative;
    transition: all 0.2s;
}

.setting-label .toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: #666;
    border-radius: 50%;
    transition: all 0.2s;
}

.setting-label input:checked + .toggle {
    background: rgba(0, 180, 0, 0.3);
    border-color: #00aa00;
}

.setting-label input:checked + .toggle::after {
    left: 22px;
    background: var(--text-green);
    box-shadow: 0 0 6px rgba(0, 255, 0, 0.5);
}

.setting-slider {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.setting-slider input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--border-dark);
    border-radius: 4px;
    outline: none;
}

.setting-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: linear-gradient(180deg, #6d5c46 0%, #4d3c26 100%);
    border: 2px solid var(--border-gold);
    border-radius: 50%;
    cursor: pointer;
}

.setting-slider input[type="range"]::-webkit-slider-thumb:hover {
    background: linear-gradient(180deg, #8d7c66 0%, #6d5c46 100%);
}

.slider-value {
    font-size: 8px;
    color: var(--text-cyan);
    min-width: 30px;
    text-align: right;
}

.setting-buttons {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.quality-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    color: var(--text-white);
    cursor: pointer;
    transition: all 0.1s;
}

.quality-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.quality-btn.active {
    background: linear-gradient(180deg, #5d8a3d 0%, #3d6a2d 100%);
    border-color: #2d5a1d;
    color: var(--text-white);
}

/* Buttons */
.btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 10px 16px;
    border: 2px solid var(--border-dark);
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.1s;
    text-shadow: 1px 1px 0 #000;
}

.btn-primary {
    background: linear-gradient(180deg, #5d8a3d 0%, #3d6a2d 100%);
    color: var(--text-white);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #6d9a4d 0%, #4d7a3d 100%);
}

.btn-secondary {
    background: linear-gradient(180deg, #5d4c36 0%, #3d2c16 100%);
    color: var(--text-white);
}

.btn-secondary:hover {
    background: linear-gradient(180deg, #6d5c46 0%, #4d3c26 100%);
}

/* ========================================
   TUTORIAL OVERLAY
   ======================================== */

.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 8000;
    pointer-events: none;
}

.tutorial-overlay.fade-out {
    animation: fade-out 0.3s ease-out forwards;
}

.tutorial-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    pointer-events: auto;
}

.tutorial-overlay.with-highlight .tutorial-backdrop {
    background: rgba(0, 0, 0, 0.85);
}

.tutorial-highlight {
    position: absolute;
    border: 3px solid var(--text-yellow);
    border-radius: 8px;
    box-shadow: 
        0 0 0 4000px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(255, 255, 0, 0.5),
        inset 0 0 20px rgba(255, 255, 0, 0.2);
    animation: highlight-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
    display: none;
}

@keyframes highlight-pulse {
    0%, 100% { box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 255, 0, 0.5), inset 0 0 20px rgba(255, 255, 0, 0.2); }
    50% { box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.8), 0 0 30px rgba(255, 255, 0, 0.8), inset 0 0 30px rgba(255, 255, 0, 0.3); }
}

.tutorial-tooltip {
    position: fixed;
    background: linear-gradient(180deg, #4a3d2a 0%, #3d3020 50%, #2d2418 100%);
    border: 4px solid var(--border-gold);
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
    max-width: 320px;
    z-index: 8001;
    pointer-events: auto;
    animation: tooltip-appear 0.3s ease-out;
}

.tutorial-tooltip.fade-out {
    animation: fade-out 0.3s ease-out forwards;
}

@keyframes tooltip-appear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tutorial-tooltip.center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.tutorial-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(180deg, #5d4c36 0%, #4d3c26 100%);
    border-bottom: 3px solid #1a1208;
}

.tutorial-icon {
    font-size: 20px;
}

.tutorial-title {
    flex: 1;
    font-size: 10px;
    color: var(--text-yellow);
    text-shadow: 2px 2px 0 #000;
}

.tutorial-step {
    font-size: 8px;
    color: var(--text-white);
    opacity: 0.6;
}

.tutorial-text {
    padding: 16px;
    font-size: 9px;
    color: var(--text-white);
    text-shadow: 1px 1px 0 #000;
    line-height: 1.8;
    white-space: pre-line;
}

.tutorial-actions {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 2px solid var(--border-dark);
}

.tutorial-skip {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: var(--text-white);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.1s;
}

.tutorial-skip:hover {
    opacity: 1;
    color: var(--text-red);
}

.tutorial-next {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 10px 16px;
    background: linear-gradient(180deg, #5d8a3d 0%, #3d6a2d 100%);
    border: 2px solid #2d5a1d;
    border-radius: 2px;
    color: var(--text-white);
    cursor: pointer;
    text-shadow: 1px 1px 0 #000;
    transition: all 0.1s;
}

.tutorial-next:hover:not(:disabled) {
    background: linear-gradient(180deg, #6d9a4d 0%, #4d7a3d 100%);
}

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

/* ========================================
   FPS COUNTER
   ======================================== */

#fps-counter {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 8px;
    color: var(--text-green);
    text-shadow: 1px 1px 0 #000;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 2px;
    z-index: 100;
}

#fps-counter.hidden {
    display: none;
}

/* ========================================
   LEVEL UP PARTICLES
   ======================================== */

.particle.level-up-particle {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
}

.particle.mining-particle {
    width: 6px;
    height: 6px;
    animation: particle-fly 0.4s ease-out forwards;
}

/* ========================================
   GRAPHICS QUALITY SETTINGS
   ======================================== */

/* Low quality - disable effects */
html[data-quality="low"] .torch::before,
html[data-quality="low"] .rock-glow,
html[data-quality="low"] #particles {
    display: none !important;
}

html[data-quality="low"] .player {
    transition: none !important;
}

/* Medium quality - reduce effects */
html[data-quality="medium"] .torch::before {
    animation: none;
}

html[data-quality="medium"] .rock-glow {
    animation: none;
}

/* No particles mode */
html.no-particles #particles {
    display: none !important;
}

/* No animations mode */
html.no-animations * {
    animation: none !important;
    transition: none !important;
}

/* High contrast mode */
html.high-contrast {
    filter: contrast(1.3);
}

html.high-contrast .rock-label,
html.high-contrast .player-name {
    background: rgba(0, 0, 0, 0.8);
    padding: 2px 6px;
    border-radius: 2px;
}

/* Large text mode */
html.large-text {
    font-size: 112.5%;
}

html.large-text .chat-message,
html.large-text .rock-label,
html.large-text .inv-label {
    font-size: 1.1em;
}

/* ========================================
   HIDDEN UTILITY
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   SCROLLBAR (Update for modals)
   ======================================== */

.modal-content::-webkit-scrollbar { width: 10px; }
.modal-content::-webkit-scrollbar-track { background: #1a1208; }
.modal-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #5d4c36 0%, #3d2c16 100%);
    border: 1px solid #1a1208;
    border-radius: 2px;
}
