/* ---- Base ---- */
* { box-sizing: border-box; }
body {
    background-color: #121212;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

/* ---- Canvas ---- */
#canvas-wrapper {
    line-height: 0;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
}
canvas {
    image-rendering: pixelated;
    border: 1px solid #1a3a1a;
    cursor: crosshair;
    width: 100%;
    height: auto;
    display: block;
}

/* ---- Shared ---- */
.stat-btn {
    transition: all 0.1s;
    cursor: pointer;
}
.stat-btn:hover {
    background-color: #2d5a2d;
    color: #fff;
}
.stat-btn:active {
    transform: scale(0.95);
}

/* ---- Login ---- */
#login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
}
#login-box {
    background-color: #1a1a2e;
    border: 1px solid #2a4a2a;
    border-radius: 8px;
    padding: 32px 40px;
    text-align: center;
    min-width: 300px;
    max-width: 90vw;
}
#login-box input {
    background-color: #0d0d1a;
    border: 1px solid #2a4a2a;
    color: #aaddaa;
    padding: 8px 12px;
    border-radius: 4px;
    width: 100%;
    margin-bottom: 12px;
    font-family: monospace;
    font-size: 16px; /* prevent iOS zoom */
}
#login-box button {
    background-color: #2d5a2d;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-family: monospace;
    margin: 4px;
    font-size: 14px;
}
#login-box button:hover { background-color: #3a7a3a; }
#login-error { color: #ff4444; font-family: monospace; font-size: 0.9em; min-height: 1.5em; margin-top: 8px; }

/* ---- Game Layout ---- */
#game-ui {
    width: 100%;
    max-width: 1300px;
    margin: 0 auto;
    padding: 8px;
}
#game-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    justify-content: center;
}
#canvas-area {
    flex-shrink: 0;
}

/* ---- Panel ---- */
#panel {
    flex-shrink: 0;
    width: 250px;
    position: relative;
    transition: transform 0.3s ease;
}
#panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a4a2a;
}
#panel-header h2 { margin: 0; }
#panel-close {
    background: none;
    border: none;
    color: #ff4444;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
}

/* ---- Keyboard help (desktop only) ---- */
#keyboard-help { display: block; }

/* ---- D-pad (mobile, hidden by default) ---- */
#dpad-container, #mobile-mode-bar, #mobile-utils {
    display: none;
}

#dpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    width: min(200px, 45vw);
    height: min(200px, 45vw);
    margin: 12px auto;
}
.dpad-btn {
    background: #1a1a2e;
    border: 1px solid #2a4a2a;
    color: #aaddaa;
    font-size: min(28px, 8vw);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.dpad-btn:active {
    background: #2d5a2d;
    color: #fff;
    transform: scale(0.92);
}
.dpad-btn.dpad-center {
    background: #2d2d3e;
    font-size: 16px;
}

/* ---- Mode toggle bar ---- */
#mobile-mode-bar {
    display: none;
    justify-content: center;
    gap: 4px;
    margin: 6px 0;
    flex-wrap: wrap;
}
.mode-btn {
    background: #1a1a2e;
    border: 1px solid #2a4a2a;
    color: #aaddaa;
    font-family: monospace;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
}
.mode-btn.active {
    background: #2d5a2d;
    color: #fff;
    border-color: #44cc44;
}
.mode-btn:active {
    transform: scale(0.95);
}

/* ---- Utility buttons ---- */
#mobile-utils {
    display: none;
    justify-content: center;
    gap: 4px;
    margin: 6px 0;
    flex-wrap: wrap;
}
.util-btn {
    background: #1a1a2e;
    border: 1px solid #2a4a2a;
    color: #aaddaa;
    font-family: monospace;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
}
.util-btn:active {
    background: #2d5a2d;
    color: #fff;
}

/* ---- Inventory items (clickable on mobile) ---- */
#inventory li {
    cursor: default;
    padding: 4px 6px;
    border-radius: 4px;
    margin: 1px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    transition: background 0.1s;
}
#inventory li:hover {
    background: rgba(45, 90, 45, 0.3);
}
.inv-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.inv-actions button {
    background: #1a1a2e;
    border: 1px solid #2a4a2a;
    color: #aaddaa;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-family: monospace;
}
.inv-actions button:active {
    background: #2d5a2d;
    color: #fff;
}
.inv-use { color: #44cc44 !important; }
.inv-destroy { color: #ff4444 !important; }
.inv-repair { color: #ffaa00 !important; }

/* ---- Panel overlay (mobile backdrop) ---- */
#panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
}

/* ============ MOBILE (< 768px) ============ */
@media (max-width: 767px) {
    body {
        min-height: 100dvh;
        display: flex;
        align-items: flex-start;
    }

    #game-layout {
        flex-direction: column;
        gap: 0;
    }
    #canvas-area {
        width: 100%;
        max-width: 100vw;
    }
    #floor-label {
        text-align: center;
        margin-top: 2px;
    }
    #message {
        text-align: center;
        font-size: 12px;
        padding: 0 4px;
    }

    /* Mobile controls visible */
    #dpad-container { display: block; }
    #mobile-mode-bar { display: flex; }
    #mobile-utils { display: flex; }

    /* Panel becomes a bottom drawer */
    #panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70dvh;
        overflow-y: auto;
        z-index: 200;
        border-radius: 12px 12px 0 0;
        transform: translateY(85%);
        transition: transform 0.3s ease;
        padding: 12px 16px;
    }
    #panel.open {
        transform: translateY(0);
    }
    #panel-close {
        display: block;
    }
    #panel-overlay {
        display: block;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    #panel-overlay.show {
        opacity: 1;
        pointer-events: auto;
    }

    /* Hide keyboard help on mobile */
    #keyboard-help { display: none; }

    /* Compact panel content */
    #panel .space-y-2 > * { margin-bottom: 4px; }
}
