@media (max-width:480px){.game-header{padding:5px 8px}.home-btn{width:40px;height:40px;font-size:1.2rem;top:10px;left:10px}}
*{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{width:100%;height:100%;overflow:hidden;font-family:'Zen Maru Gothic',sans-serif;user-select:none;touch-action:manipulation}
body{background:linear-gradient(180deg,#ECEFF1 0%,#CFD8DC 100%)}
.home-btn{position:fixed;top:12px;left:12px;width:48px;height:48px;background:#fff;border-radius:50%;display:flex;justify-content:center;align-items:center;font-size:1.4rem;text-decoration:none;box-shadow:0 4px 12px rgba(0,0,0,.15);z-index:9999;border:3px solid #607D8B}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    padding: 0;
}

/* Sidebar (Left) */
.side-panel {
    width: 280px;
    background: rgba(255, 255, 255, 0.4);
    border-right: 2px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    padding: 15px;
    gap: 15px;
    flex-shrink: 0;
    overflow-y: auto;
}

.game-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.title-badge {
    background: #fff;
    padding: 8px 14px;
    border-radius: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    box-shadow: 0 3px 0 #B0BEC5;
}

.level-pill {
    background: #fff;
    padding: 6px 14px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 2px 0 #B0BEC5;
}

.stat-pill {
    background: #fff;
    padding: 10px 16px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 3px 0 #B0BEC5;
    text-align: center;
}

.stat-pill.budget-zero {
    background: #FFCDD2;
    color: #C62828;
    box-shadow: 0 3px 0 #E57373;
}

.side-actions {
    margin-top: 5px;
}

.side-btn {
    width: 100%;
    font-family: inherit;
    font-weight: 700;
    padding: 12px;
    border-radius: 16px;
    border: none;
    background: #546E7A;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #37474F;
    transition: all 0.15s;
}

.side-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.side-hint {
    font-size: 0.75rem;
    color: #455A64;
    line-height: 1.5;
    background: rgba(255, 255, 255, 0.6);
    padding: 10px;
    border-radius: 12px;
    margin-top: auto;
}

/* Grid Area (Right) */
.grid-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.02);
    min-width: 0;
}

.grid-wrap {
    padding: 20px;
}

.gear-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 8px;
    width: min(75vmin, 450px);
    height: min(75vmin, 450px);
    background: #78909C;
    border: 8px solid #546E7A;
    border-radius: 24px;
    padding: 12px;
    box-shadow: inset 0 4px 12px rgba(0,0,0,0.2), 0 10px 30px rgba(0,0,0,0.15);
}

.cell {
    border-radius: 12px;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background .15s;
}

.cell.empty.placeable {
    cursor: pointer;
    background: rgba(255,255,255,.35);
}

.cell.empty.placeable:active {
    background: rgba(255,255,255,.6);
    transform: scale(.95);
}

.cell.user-gear {
    cursor: pointer;
}

.gear-svg {
    width: 90%;
    height: 90%;
    display: block;
}

.gear-svg.spin {
    animation: spin 2s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.overlay.hidden { display: none !important; }

.overlay-card {
    background: #fff;
    border-radius: 30px;
    padding: 30px;
    width: min(90%, 320px);
    text-align: center;
    box-shadow: 0 15px 40px rgba(0,0,0,.2);
}

.overlay-title { font-size: 1.6rem; font-weight: 900; color: #37474F; margin-bottom: 20px; }

.overlay-btn {
    width: 100%;
    font-family: inherit;
    font-weight: 700;
    padding: 15px;
    border-radius: 20px;
    border: none;
    background: #607D8B;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 5px 0 #37474F;
    font-size: 1.1rem;
}

@media screen and (max-height: 500px) {
    #game-container {
        margin-left: 0 !important;
        width: 100% !important;
        flex-direction: row !important;
    }
    .side-panel {
        width: 180px;
        padding: 8px;
        gap: 6px;
        background: rgba(255, 255, 255, 0.7);
    }
    .game-header { gap: 4px; }
    .title-badge { font-size: 0.7rem; padding: 4px 8px; }
    .level-pill { font-size: 0.65rem; padding: 3px 8px; }
    .stat-pill { font-size: 0.8rem; padding: 6px; }
    .side-btn { font-size: 0.8rem; padding: 8px; border-radius: 12px; }
    .side-hint { display: none; }

    .grid-panel {
        flex: 1;
        padding: 5px;
        display: flex;
        justify-content: flex-end; /* Align to the right */
        align-items: center;
    }
    .grid-wrap {
        padding: 5px 20px 5px 5px;
    }
    .gear-grid {
        width: min(90vh, 320px) !important;
        height: min(90vh, 320px) !important;
        padding: 8px !important;
        border-width: 6px !important;
        gap: 5px !important;
    }
}
