*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0b0e14;
    color: white;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
}

img {
    display: none;
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #000;
}

#main_screen {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    touch-action: none;
}

/* ---- Mobile touch controls (phones/tablets only) ---- */
#mobile-controls {
    display: none !important;
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.touch-cluster {
    position: absolute;
    pointer-events: auto;
    display: flex;
    gap: 8px;
    align-items: center;
    touch-action: none;
}

.touch-dpad {
    bottom: 14px;
    left: 12px;
    display: grid;
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
    gap: 6px;
}

.touch-dpad .btn-up    { grid-column: 2; grid-row: 1; }
.touch-dpad .btn-left  { grid-column: 1; grid-row: 2; }
.touch-dpad .btn-right { grid-column: 3; grid-row: 2; }
.touch-dpad .btn-down  { grid-column: 2; grid-row: 3; }

.touch-actions {
    bottom: 22px;
    right: 14px;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.touch-menu {
    top: 12px;
    right: 12px;
}

.touch-btn {
    width: 52px;
    height: 52px;
    border: 2px solid rgba(249, 115, 22, 0.85);
    border-radius: 14px;
    background: rgba(20, 12, 8, 0.72);
    color: #ffedd5;
    font-size: 1.15rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    font-family: system-ui, -apple-system, sans-serif;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

.touch-btn.jump {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border-color: rgba(251, 191, 36, 0.85);
    color: #fbbf24;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
}

.touch-btn.attack {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border-color: rgba(248, 113, 113, 0.9);
    color: #fecaca;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
}

.touch-btn.ok {
    width: auto;
    min-width: 72px;
    height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    border-color: rgba(74, 222, 128, 0.85);
    color: #bbf7d0;
}

.touch-btn:active,
.touch-btn.active {
    background: rgba(249, 115, 22, 0.4);
    transform: scale(0.94);
}

.touch-btn.jump:active,
.touch-btn.jump.active {
    background: rgba(251, 191, 36, 0.35);
}

.touch-btn.attack:active,
.touch-btn.attack.active {
    background: rgba(248, 113, 113, 0.35);
}

@media (hover: none) and (pointer: coarse) {
    #mobile-controls { display: block !important; }
}

@media (max-height: 480px) and (hover: none) and (pointer: coarse) {
    .touch-dpad {
        grid-template-columns: 40px 40px 40px;
        grid-template-rows: 40px 40px 40px;
        gap: 4px;
        bottom: 8px;
        left: 8px;
    }
    .touch-btn { width: 40px; height: 40px; font-size: 1rem; border-radius: 10px; }
    .touch-btn.jump { width: 58px; height: 58px; font-size: 0.7rem; }
    .touch-btn.attack { width: 52px; height: 52px; font-size: 0.65rem; }
    .touch-actions { bottom: 12px; right: 10px; gap: 8px; }
    .touch-menu { top: 8px; right: 8px; }
}
