/* CSS Reset and Font Setup */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

:root {
    --bg-primary: #0a0d14;
    --bg-secondary: #121824;
    --bg-panel: rgba(20, 30, 48, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 229, 255, 0.2);
    
    --color-text: #e2e8f0;
    --color-muted: #94a3b8;
    --color-accent: #00e5ff;
    --color-gold: #ffd700;
    --color-danger: #ff5252;
    --color-success: #00e676;
    
    /* Block Colors */
    --color-sky: linear-gradient(180deg, #1e3c72 0%, #2a5298 100%);
    --color-grass: #4caf50;
    --color-grass-top: #81c784;
    --color-dirt: #5c4033;
    --color-clay: #a1887f;
    --color-stone: #546e7a;
    --color-stone-hard: #37474f;
    --color-stone-hardest: #212121;
    --color-quicksand: #e0d0b0;
    --color-coal: #212121;
    --color-iron: #d7ccc8;
    --color-gold-ore: #ffd54f;
    --color-diamond: #4dd0e1;
    
    /* Viewport Size */
    --cell-size: min(44px, 6.2vw);
}

body {
    background-color: var(--bg-primary);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 10px;
}

#game-container {
    width: 100%;
    max-width: 1100px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 
                0 0 40px rgba(0, 229, 255, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* HEADER */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 24px;
    background: rgba(18, 24, 36, 0.9);
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: 1.1rem;
    background: linear-gradient(90deg, #00e5ff, #00e676);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
}

#depth-counter {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.75rem;
    color: var(--color-muted);
}

/* MAIN LAYOUT */
#main-layout {
    display: flex;
    flex-wrap: wrap;
    flex-grow: 1;
    background: #0d121c;
}

/* SCREEN & VIEWPORT */
#screen-wrapper {
    flex: 1 1 500px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    position: relative;
    background: #07090e;
    overflow: hidden;
}

#game-viewport {
    display: grid;
    grid-template-columns: repeat(15, var(--cell-size));
    grid-template-rows: repeat(13, var(--cell-size));
    gap: 1px;
    background-color: rgba(0, 0, 0, 0.85);
    border: 3px solid #1a2236;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
    position: relative;
}

#effect-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    transition: background-color 0.15s ease-out;
}

/* HUD PANEL */
#hud-panel {
    width: 320px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: 80vh;
}

.hud-group {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hud-group h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-accent);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 6px;
    margin-bottom: 4px;
}

/* Status Rows */
.stat-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-muted);
    font-weight: 600;
}

#gold-amount {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--color-gold);
}

.gold-coin {
    animation: pulse 1.5s infinite alternate;
}

/* Progress Bars */
.progress-bar-container {
    height: 18px;
    background: #090c10;
    border-radius: 9px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.progress-bar {
    height: 100%;
    width: 100%;
    transition: width 0.3s ease;
}

#hp-bar {
    background: linear-gradient(90deg, #ff1744, #ff5252);
}

#bag-bar {
    background: linear-gradient(90deg, #2979ff, #00e5ff);
}

.progress-bar-container span {
    position: absolute;
    width: 100%;
    text-align: center;
    font-size: 0.65rem;
    font-weight: 800;
    line-height: 16px;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
}

/* Tool Grid Selection */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tool-slot {
    background: rgba(13, 18, 28, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
    transition: all 0.2s ease;
}

.tool-slot:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.02);
}

.tool-slot.active {
    border-color: var(--color-accent);
    background: rgba(0, 229, 255, 0.15);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.15);
}

.slot-num {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.6rem;
    color: var(--color-muted);
    font-weight: 800;
}

.tool-icon {
    font-size: 1.4rem;
}

.tool-name {
    font-size: 0.75rem;
    font-weight: 600;
}

.tool-level, .tool-count {
    font-size: 0.6rem;
    color: var(--color-muted);
}

.tool-slot.active .tool-level, 
.tool-slot.active .tool-count {
    color: #fff;
}

/* Inventory List */
#inventory-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
}

.inv-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(13, 18, 28, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.03);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
}

.inv-item.empty {
    color: var(--color-muted);
    justify-content: center;
    font-style: italic;
}

/* Mobile Controls */
#mobile-controls {
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    width: 150px;
    height: 150px;
}

.btn-ctrl {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--color-text);
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.btn-ctrl:active, .btn-ctrl:hover {
    background: var(--color-accent);
    color: #000;
    box-shadow: 0 0 10px var(--color-accent);
}

#btn-center {
    font-size: 0.7rem;
    font-weight: 800;
}

/* BLOCKS DESIGN */
.block {
    width: 100%;
    height: 100%;
    position: relative;
    box-sizing: border-box;
    transition: background-color 0.2s ease, opacity 0.3s ease;
}

.block.sky {
    background: var(--color-sky);
}

.block.shop-door {
    background: #4e342e;
    border: 2px dashed var(--color-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
}

.block.shop-door::after {
    content: "🏬";
    font-size: 1rem;
}

.block.grass {
    background: var(--color-dirt);
    border-top: 5px solid var(--color-grass);
}

.block.dirt {
    background: var(--color-dirt);
    box-shadow: inset 1px 1px 2px rgba(0,0,0,0.3);
}

.block.clay {
    background: var(--color-clay);
    box-shadow: inset 1px 1px 2px rgba(0,0,0,0.3);
}

.block.stone {
    background: var(--color-stone);
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-shadow: inset 2px 2px 0 rgba(255,255,255,0.08);
}

.block.stone-hard {
    background: var(--color-stone-hard);
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: inset 2px 2px 0 rgba(255,255,255,0.05);
}

.block.stone-hardest {
    background: var(--color-stone-hardest);
    border: 1px solid #000;
}

.block.quicksand {
    background: var(--color-quicksand);
    animation: sand-wave 3s infinite ease-in-out;
}

/* Ores */
.block.coal::after,
.block.iron::after,
.block.gold-ore::after,
.block.diamond::after {
    content: "";
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    border-radius: 3px;
    transform: rotate(45deg);
}

.block.coal {
    background: #37474f;
}
.block.coal::after {
    background: var(--color-coal);
    box-shadow: 0 0 4px #000;
}

.block.iron {
    background: #4e5d6c;
}
.block.iron::after {
    background: #d84315;
    box-shadow: 0 0 4px #d84315;
}

.block.gold-ore {
    background: #4e4d35;
}
.block.gold-ore::after {
    background: var(--color-gold-ore);
    box-shadow: 0 0 6px var(--color-gold-ore);
    animation: pulse 1s infinite alternate;
}

.block.diamond {
    background: #274d5a;
}
.block.diamond::after {
    background: var(--color-diamond);
    box-shadow: 0 0 10px var(--color-diamond);
    animation: pulse 0.7s infinite alternate;
}

/* Block Hit Cracks Overlay */
.block .cracks {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-size: cover;
    opacity: 0.7;
}

.block .cracks.crack-1 {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"><path d="M10,0 L15,12 L5,20 L22,25 L30,40" stroke="rgba(0,0,0,0.5)" stroke-width="2" fill="none"/></svg>');
}
.block .cracks.crack-2 {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"><path d="M10,0 L15,12 L5,20 L22,25 L30,40 M0,20 L15,15 L25,30 M22,25 L35,10" stroke="rgba(0,0,0,0.6)" stroke-width="2" fill="none"/></svg>');
}
.block .cracks.crack-3 {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"><path d="M10,0 L15,12 L5,20 L22,25 L30,40 M0,20 L15,15 L25,30 M22,25 L35,10 M3,3 L10,8 M38,38 L30,32 M35,2 L25,12" stroke="rgba(0,0,0,0.8)" stroke-width="2" fill="none"/></svg>');
}

/* Light / Shadow Fog System */
.block::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 2;
}

.block.lit::before {
    opacity: 0;
}

.block.dim::before {
    opacity: 0.6;
}

/* ENTITIES */
.player-avatar {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.explorer-body {
    font-size: 1.3rem;
    position: relative;
    z-index: 2;
    animation: bounce 0.6s infinite alternate;
}

.tool-in-hand {
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 0.95rem;
    z-index: 3;
    transform-origin: bottom left;
    transition: transform 0.1s ease-out;
}

.tool-in-hand.swinging {
    animation: tool-strike 0.16s ease-in-out;
}

@keyframes tool-strike {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-45deg); }
    100% { transform: rotate(0deg); }
}

/* Helmet beam */
.player-avatar::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 130px;
    height: 130px;
    background: radial-gradient(circle, rgba(0, 229, 255, 0.18) 0%, rgba(0, 229, 255, 0) 70%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: -1;
}

.zombie-avatar {
    width: 86%;
    height: 86%;
    background: #2e7d32;
    border-radius: 20%;
    position: absolute;
    top: 7%;
    left: 7%;
    border: 2px solid #81c784;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: zombie-wobble 1s infinite alternate;
}

.zombie-avatar::before {
    content: "🧟";
    font-size: 1rem;
}

.zombie-avatar.stunned {
    filter: grayscale(0.8);
    animation: rotate 1s infinite linear;
}

/* Bomb Entity placement */
.bomb-entity {
    width: 80%;
    height: 80%;
    background: #ff1744;
    border-radius: 50%;
    position: absolute;
    top: 10%;
    left: 10%;
    border: 2px dashed #000;
    box-shadow: 0 0 10px #ff1744;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    animation: bomb-flash 0.5s infinite alternate;
}

.bomb-entity.sonic {
    background: #2979ff;
    box-shadow: 0 0 10px #2979ff;
}

/* FOOTER */
footer {
    padding: 10px 20px;
    background: rgba(10, 13, 20, 0.95);
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.7rem;
    color: var(--color-muted);
}

footer strong {
    color: var(--color-accent);
}

/* MODAL / SHOP SYSTEM */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.modal-content.glass {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.6), 
                0 0 40px rgba(0, 229, 255, 0.1);
}

.modal-content {
    width: 90%;
    max-width: 650px;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--color-gold);
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
}

.close-btn {
    background: none;
    border: none;
    color: var(--color-muted);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--color-danger);
}

.shop-welcome {
    padding: 14px 24px;
    font-size: 0.8rem;
    color: var(--color-muted);
    background: rgba(0, 0, 0, 0.2);
}

.shop-sections {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 16px;
    padding: 20px;
}

@media (max-width: 600px) {
    .shop-sections {
        grid-template-columns: 1fr;
    }
}

.shop-box {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shop-box h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--color-accent);
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 6px;
}

#shop-sell-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
    min-height: 120px;
    max-height: 200px;
    overflow-y: auto;
}

.shop-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.03);
    padding: 8px 10px;
    border-radius: 8px;
}

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

.shop-item-title {
    font-size: 0.8rem;
    font-weight: 600;
}

.shop-item-desc {
    font-size: 0.65rem;
    color: var(--color-muted);
}

.btn-buy {
    background: var(--bg-primary);
    border: 1px solid var(--color-gold);
    color: var(--color-gold);
    font-size: 0.75rem;
    font-weight: 800;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-buy:hover {
    background: var(--color-gold);
    color: #000;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.btn-buy.disabled {
    opacity: 0.4;
    border-color: var(--color-muted);
    color: var(--color-muted);
    cursor: not-allowed;
}

.btn-buy.disabled:hover {
    background: none;
    color: var(--color-muted);
    box-shadow: none;
}

.btn-action {
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.btn-action.green {
    background: var(--color-success);
    color: #000;
}

.btn-action.green:hover {
    box-shadow: 0 0 12px var(--color-success);
}

.btn-action.red {
    background: var(--color-danger);
    color: #fff;
}

.btn-action.red:hover {
    box-shadow: 0 0 12px var(--color-danger);
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: flex-end;
}

/* AUDIO CONTROL FLOAT */
#audio-control {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 30px;
    font-size: 0.75rem;
    cursor: pointer;
    z-index: 200;
    backdrop-filter: blur(10px);
    transition: all 0.2s;
}

#audio-control:hover {
    border-color: var(--color-accent);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.15);
}

/* ANIMATIONS */
@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.08); opacity: 1; }
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-3px); }
}

@keyframes zombie-wobble {
    0% { transform: rotate(-5deg); }
    100% { transform: rotate(5deg); }
}

@keyframes bomb-flash {
    0% { background: #d50000; }
    100% { background: #ff5252; transform: scale(1.08); }
}

@keyframes sand-wave {
    0%, 100% { background-color: var(--color-quicksand); }
    50% { background-color: #d7ccc8; }
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Shaking Effect for Exploding */
.shake {
    animation: screen-shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes screen-shake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(3px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Flash effect */
.damage-flash {
    animation: flash-red 0.15s ease-out;
}

@keyframes flash-red {
    0% { background-color: rgba(255, 0, 0, 0.4); }
    100% { background-color: rgba(255, 0, 0, 0); }
}

.sonic-flash {
    animation: flash-cyan 0.3s ease-out;
}

@keyframes flash-cyan {
    0% { background-color: rgba(0, 229, 255, 0.3); }
    100% { background-color: rgba(0, 229, 255, 0); }
}
