/* ==========================================================================
   Omni-Cast Matrix // Snow317.io - Enterprise Stylesheet v2.0
   Architecture: CSS Variables, GPU Animation, Fluid Responsive Grid
   ========================================================================== */

:root {
    /* Color Palette */
    --bg-top: #3a5a8a;
    --bg-bottom: #6b8aaa;
    --text-primary: #00FFFF;
    --text-secondary: #FFFFFF;
    --text-warning: #FFFF00;
    --text-danger: #FF0000;
    --text-critical: #FF4500;
    --text-success: #00FF00;
    --text-surge: #FF00FF;
    
    /* UI Elements */
    --ui-bg-dark: rgba(0, 0, 0, 0.5);
    --ui-bg-light: rgba(255, 255, 255, 0.1);
    --btn-bg: #2c3e50;
    --btn-disabled: #555555;
    
    /* Z-Index Hierarchy */
    --z-background: 0;
    --z-base: 1;
    --z-content: 5;
    --z-buttons: 10;
    --z-hud-low: 90;
    --z-hud-high: 100;
    --z-modal: 1000;
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: linear-gradient(var(--bg-top), var(--bg-bottom));
    background-attachment: fixed;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
    overflow-x: hidden;
    text-shadow: 0 0 3px #000000, 0 0 5px #000000;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Background Animations (GPU Accelerated)
   ========================================================================== */
.snowflakes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: var(--z-background);
}

.snowflake {
    position: absolute;
    top: 0;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    animation: fall linear infinite;
    pointer-events: none;
    will-change: transform; /* Hint to browser for GPU rendering */
    transform: translateZ(0); /* Force hardware acceleration */
}

@keyframes fall {
    0% { transform: translate3d(0, -10vh, 0); opacity: 1; }
    100% { transform: translate3d(0, 110vh, 0); opacity: 0.5; }
}

@keyframes glow {
    0% { text-shadow: 0 0 3px #000000, 0 0 5px #000000; }
    50% { text-shadow: 0 0 10px currentColor, 0 0 15px currentColor; }
    100% { text-shadow: 0 0 3px #000000, 0 0 5px #000000; }
}

/* ==========================================================================
   Main Layout Structure
   ========================================================================== */
#snow317-ui {
    position: relative;
    padding: 20px;
    z-index: var(--z-base);
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

/* ==========================================================================
   HUD & Fixed Displays
   ========================================================================== */
#player-display {
    position: fixed;
    top: 10px;
    left: 15px;
    font-size: clamp(1.2em, 3vw, 2.4em); /* Fluid typography */
    color: #CC0000;
    z-index: var(--z-hud-high);
    text-align: left;
    margin: 0;
    pointer-events: none; /* Prevent blocking clicks */
}

#player-hp-display {
    font-size: 0.5em; /* Scales relative to clamp above */
    margin-top: 5px;
}

#wave-cycle-display {
    position: fixed;
    top: 10px;
    right: 15px;
    font-size: clamp(0.8em, 2vw, 1em);
    color: var(--text-primary);
    z-index: var(--z-hud-low);
    text-align: right;
    pointer-events: none;
}

#wave-cycle-display p {
    margin: 5px 0;
}

#stats-display {
    position: absolute;
    top: 60px;
    right: 15px;
    font-size: clamp(0.8em, 2vw, 1.2em);
    color: var(--text-primary);
    z-index: var(--z-buttons);
    text-align: right;
    pointer-events: none;
}

#stats-display p {
    margin: 5px 0;
}

#reset-display {
    margin-top: auto;
    padding-top: 20px;
    z-index: var(--z-buttons);
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
button {
    background: var(--btn-bg);
    color: var(--text-primary);
    border: 2px solid var(--text-secondary);
    padding: 10px 20px;
    margin: 5px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    font-family: 'Press Start 2P', monospace;
    font-size: 1em;
    z-index: var(--z-buttons);
    border-radius: 4px;
    text-transform: uppercase;
}

button[data-affordable="true"]:hover {
    background: linear-gradient(45deg, var(--text-primary), var(--text-surge), var(--text-warning));
    color: #101010;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
}

button:disabled, .disabled-button {
    background: var(--btn-disabled);
    cursor: not-allowed;
    box-shadow: none;
    color: #999;
    border-color: #777;
    transform: none;
}

#attack-button {
    background: var(--text-primary);
    color: #FFFFFF;
    font-size: clamp(1.5em, 4vw, 2em);
    padding: 20px 40px;
    border: 3px solid var(--text-secondary);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.6);
}

#attack-button:hover {
    background: #00CCCC;
    box-shadow: 0 0 30px rgba(0, 255, 255, 1);
    transform: scale(1.05);
}

#auto-attack-button {
    background: var(--btn-disabled);
    color: #101010;
    font-size: 0.8em;
    padding: 12px 20px;
}

#auto-attack-button.active {
    background: var(--text-primary);
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.8);
}

#auto-attack-button:hover:not(.active) {
    background: #666;
}

#auto-attack-button.active:hover {
    background: #00CCCC;
}

#heal-button {
    background: var(--text-success);
    color: #000000;
    font-size: 0.8em;
    padding: 12px 20px;
    border: 2px solid var(--text-secondary);
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

#heal-button:hover {
    background: #00CC00;
}

/* Dynamic Tab Grid */
.main-stats + div {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin: 20px 0;
    width: 100%;
}

button[id^="tab-"] {
    margin: 0;
    width: 100%;
    padding: 12px 10px;
    font-size: 0.8em;
}

/* ==========================================================================
   Combat & Main Interface
   ========================================================================== */
.main-stats {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 80px; /* Buffer for HUD */
    width: 100%;
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: 15px;
}

.monster-info {
    font-size: clamp(1.5em, 5vw, 2.5em);
    margin: 15px 0;
    word-break: break-word;
}

#monster-hp, #monster-max-hp {
    font-size: clamp(1.8em, 4vw, 2.5em);
    animation: glow 2s ease-in-out infinite;
}

.gold-coins {
    font-size: clamp(1.2em, 3vw, 1.8em);
    margin: 10px 0;
    word-break: break-all;
}

.coins-icon {
    width: 38px;
    height: 38px;
    vertical-align: middle;
    margin-right: 5px;
}

/* Text Formatting Classes */
.hp-low { color: var(--text-critical); font-weight: bold; }
.error { color: var(--text-danger); font-weight: bold; }
.death { color: var(--text-critical); font-weight: bold; }
.success { color: var(--text-success); font-weight: bold; }
.crit { color: var(--text-warning); font-weight: bold; }
.low-hp-warning { color: var(--text-warning); font-weight: bold; }
.danger-hp-warning { color: #FFA500; font-weight: bold; }
.critical-hp-warning { color: var(--text-danger); font-weight: bold; }
.coin-surge {
    color: var(--text-surge);
    font-weight: bold;
    text-shadow: 0 0 5px rgba(255, 0, 255, 0.8);
}

#player-username, #npcdrops-link { color: var(--text-warning); }
#snow317coins-label { color: #FFD700; text-shadow: 0 0 5px #FFFF00, 0 0 10px #FFA500; }
#snow317coins { color: var(--text-success); }
#wave-count { color: var(--text-surge); }
#cycle-count { color: #FFA500; }

#monster-name {
    text-shadow: 0 0 3px #000000, 0 0 5px #000000;
    animation: glow 2s ease-in-out infinite;
}

#npcdrops-link {
    text-decoration: underline;
    cursor: pointer;
    z-index: 15;
    font-size: 0.5em;
    display: inline-block;
    margin-left: 10px;
    vertical-align: middle;
}

#npcdrops-link:hover { color: var(--text-surge); }

/* ==========================================================================
   Content Panels & Logs
   ========================================================================== */
.tab-content {
    display: none;
    margin: 10px 0;
    background: var(--ui-bg-light);
    padding: 20px;
    border: 2px solid var(--text-primary);
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
    z-index: var(--z-content);
    border-radius: 8px;
    width: 100%;
}

.tab-content.active { display: block; }

#combat-log {
    height: 300px;
    overflow-y: auto;
    background: var(--ui-bg-dark);
    padding: 15px;
    border: 2px solid var(--text-primary);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    font-size: 0.9em;
    line-height: 1.5;
    border-radius: 4px;
    text-align: left;
    scrollbar-width: thin;
    scrollbar-color: var(--text-primary) var(--btn-bg);
}

#combat-log p {
    margin: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

#combat-log::-webkit-scrollbar { width: 8px; }
#combat-log::-webkit-scrollbar-track { background: var(--btn-bg); }
#combat-log::-webkit-scrollbar-thumb { background: var(--text-primary); border-radius: 4px; }

/* ==========================================================================
   Inventory Grids (Weapons, Armor, Pets)
   ========================================================================== */
#armor-list, #weapon-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 50vh;
    min-height: 300px;
    overflow-y: auto;
    width: 100%;
    padding: 15px;
    background: var(--ui-bg-dark);
    border: 2px solid var(--text-primary);
    box-shadow: inset 0 0 15px rgba(0,0,0,0.9);
    border-radius: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-primary) var(--btn-bg);
}

#armor-list::-webkit-scrollbar, #weapon-list::-webkit-scrollbar { width: 8px; }
#armor-list::-webkit-scrollbar-track, #weapon-list::-webkit-scrollbar-track { background: var(--btn-bg); }
#armor-list::-webkit-scrollbar-thumb, #weapon-list::-webkit-scrollbar-thumb { background: var(--text-primary); border-radius: 4px; }

.armor-item, .weapon-item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 15px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.6), rgba(0, 255, 255, 0.15), rgba(0, 0, 0, 0.6));
    border: 1px solid rgba(0, 255, 255, 0.3);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    transition: transform 0.2s ease, filter 0.3s;
    animation: shine 4s infinite linear;
    background-size: 200% auto;
}

.armor-item span, .weapon-item span {
    flex: 1;
    text-align: left;
    padding: 0 10px;
    font-size: 0.9em;
    color: var(--text-secondary);
    line-height: 1.4;
}

.armor-item button, .weapon-item button {
    min-width: 140px;
    margin: 0;
}

/* Pets - Horizontal Snap Grid */
#pet-list {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 15px;
    gap: 15px;
    background: var(--ui-bg-dark);
    border: 2px solid var(--text-primary);
    border-radius: 8px;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: var(--text-primary) var(--btn-bg);
}

#pet-list::-webkit-scrollbar { height: 8px; }
#pet-list::-webkit-scrollbar-track { background: var(--btn-bg); }
#pet-list::-webkit-scrollbar-thumb { background: var(--text-primary); border-radius: 4px; }

.pet-item {
    flex: 0 0 auto;
    width: 220px;
    min-height: 250px;
    padding: 15px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.6), rgba(0, 255, 255, 0.1));
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    scroll-snap-align: center;
    animation: shine 4s infinite linear;
    background-size: 200% auto;
}

.pet-item span {
    font-size: 0.9em;
    color: var(--text-secondary);
    line-height: 1.5;
}

.pet-item button {
    width: 100%;
}

.tier-header {
    color: var(--text-warning);
    font-size: 1.2em;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    text-shadow: 0 0 5px #000000;
    align-self: center;
}

/* Inventory Item States */
.not-affordable {
    filter: grayscale(100%) opacity(0.7);
}

.not-affordable:hover {
    filter: grayscale(100%) opacity(1);
    transform: scale(1.02);
}

.affordable:hover {
    transform: scale(1.02);
    border-color: var(--text-primary);
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
}

/* Visual FX Properties */
.glow {
    box-shadow: inset 0 0 20px rgba(255, 215, 0, 0.4), 0 0 15px rgba(0, 255, 255, 0.5);
}

.sparkle {
    position: relative;
    overflow: hidden;
}

.sparkle::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 20px;
    height: 200%;
    background: rgba(255, 255, 255, 0.4);
    transform: rotate(45deg);
    animation: sparkle 2.5s infinite linear;
    pointer-events: none;
}

@keyframes sparkle {
    0% { left: -50%; }
    100% { left: 150%; }
}

@keyframes shine {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

/* ==========================================================================
   Modals & Popups
   ========================================================================== */
.popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(10, 15, 25, 0.95);
    border: 4px solid var(--text-primary);
    padding: 25px;
    width: 90vw;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--text-primary);
    z-index: var(--z-modal);
    box-shadow: 0 0 30px rgba(0, 0, 0, 1), 0 0 20px rgba(0, 255, 255, 0.4);
    border-radius: 8px;
    text-align: left;
}

.popup.active { display: block; }

.popup h2 {
    color: var(--text-warning);
    margin-top: 0;
    text-align: center;
    border-bottom: 2px solid var(--ui-bg-light);
    padding-bottom: 10px;
}

.popup p { margin: 12px 0; line-height: 1.4; }

.popup-close {
    position: absolute;
    top: 15px;
    right: 15px;
    color: var(--text-danger);
    cursor: pointer;
    font-size: 1.5em;
    font-weight: bold;
    transition: color 0.2s;
}

.popup-close:hover { color: var(--text-surge); }

/* ==========================================================================
   Guides & Leaderboard
   ========================================================================== */
.guide-content, .leaderboard-container {
    border: 2px solid var(--text-danger);
    padding: 20px;
    background-color: var(--ui-bg-dark);
    color: var(--text-secondary);
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8), 0 0 10px rgba(255, 0, 0, 0.3);
    margin: 0 auto;
    width: 100%;
    border-radius: 6px;
    text-align: left;
}

.leaderboard-container {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    gap: 20px;
}

.leaderboard-column { flex: 1; }
.leaderboard-column h3 {
    color: var(--text-primary);
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 10px;
}
.leaderboard-column p { margin: 8px 0; font-size: 0.9em; }

.guide-section { margin-bottom: 25px; }
.guide-section h2 { color: var(--text-primary); font-size: 1.1em; }
.guide-section ul { list-style-type: none; padding-left: 10px; }
.guide-section li { margin-bottom: 12px; border-left: 2px solid var(--text-primary); padding-left: 10px;}

/* ==========================================================================
   Responsive Viewport Execution (Mobile Scale)
   ========================================================================== */
@media screen and (max-width: 850px) {
    /* Compress HUD for tablets/large phones */
    #player-display { top: 5px; left: 5px; font-size: 1.2em; max-width: 50%; word-break: break-all; }
    #wave-cycle-display { top: 5px; right: 5px; background: var(--ui-bg-dark); padding: 5px; border-radius: 4px; }
    #stats-display { top: 40px; right: 5px; background: var(--ui-bg-dark); padding: 5px; border-radius: 4px; font-size: 0.7em;}
    
    .leaderboard-container { flex-direction: column; }
    .leaderboard-column { margin-bottom: 20px; }
}

@media screen and (max-width: 600px) {
    /* Strict Mobile Viewport Enforcements */
    #snow317-ui { padding: 10px; padding-top: 70px; }
    
    .button-group { flex-direction: column; gap: 10px; }
    
    button { 
        width: 100%; 
        min-height: 48px; /* Force minimum touch target size */
        margin: 0;
    }
    
    #attack-button {
        padding: 25px;
        font-size: 1.8em;
        border-radius: 8px;
    }
    
    /* Convert Inventory Rows to Stacks */
    .armor-item, .weapon-item {
        flex-direction: column;
        text-align: center;
        gap: 12px;
        padding: 20px 10px;
    }
    
    .armor-item span, .weapon-item span {
        text-align: center;
        width: 100%;
        padding: 0;
    }
    
    .armor-item button, .weapon-item button {
        width: 100%;
    }
    
    /* Adjust Pet Grid */
    .pet-item { width: 180px; }
    .tier-header { writing-mode: horizontal-tb; transform: none; margin-bottom: 10px; width: 100%; text-align: left;}
    #pet-list { flex-direction: column; scroll-snap-type: none; height: 50vh; overflow-y: auto; overflow-x: hidden;}
    .pet-item { width: 100%; min-height: unset; flex-direction: row; flex-wrap: wrap; text-align: left; gap: 10px;}
    .pet-item span { flex: 1; min-width: 150px;}
    .pet-item button { width: 100%;}
    
    .popup { padding: 15px; }
}

@media screen and (max-width: 400px) {
    /* Ultra-narrow devices (e.g. iPhone SE) */
    .main-stats + div { grid-template-columns: repeat(2, 1fr); }
    #attack-button { font-size: 1.5em; }
    #player-display { font-size: 1em; }
}