/* --------------------------------------------------------------
   Woman Cube Stacker v6.0 – CSS (with below-canvas mobile layout)
   -------------------------------------------------------------- */
.lms-wrap, .lms-wrap * { box-sizing: border-box; }
.lms-wrap {
    margin: 0; padding: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    font-family: 'Courier New', Courier, monospace;
    color: #fff; overflow: hidden;
    touch-action: none;
    overscroll-behavior: contain;
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}
.lms-wrap h1 { margin: 12px 0 4px; color: #ff9f1c; text-shadow: 2px 2px 0 #c44511; letter-spacing: 2px; font-size: 20px; text-align: center; }
.lms-wrap #info { margin: 0 0 8px; font-size: 12px; text-align: center; color: #a8e6cf; padding: 0 8px; }
.lms-wrap .ver { color:#ff9f1c; font-weight:bold; }
.lms-wrap canvas {
    background: #a8e6cf; border: 4px solid #16213e;
    box-shadow: 0 0 30px rgba(255,159,28,0.4);
    border-radius: 8px; display:block; cursor: crosshair;
    width: min(800px, calc(100vw - 16px));
    height: auto;
    aspect-ratio: 4 / 3;
    touch-action: none;
    flex-shrink: 0;
}

/* === NAME MODAL === */
.lms-wrap #nameModal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
.lms-wrap #nameModal.show { display: flex; }
.lms-wrap #nameModalBox {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 4px solid #ff9f1c;
    border-radius: 12px;
    padding: 24px 28px;
    text-align: center;
    box-shadow: 0 0 40px rgba(255,159,28,0.5);
    max-width: 92vw;
    width: 360px;
}
.lms-wrap #nameModalTitle {
    margin: 0 0 10px;
    font-size: 26px;
    text-shadow: 2px 2px 0 #c44511;
}
.lms-wrap #nameModalScore { color: #a8e6cf; margin: 0 0 16px; font-size: 13px; }
.lms-wrap #nameModalBox p { color: #fff; margin: 0 0 12px; font-size: 13px; }
.lms-wrap #nameInput {
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    padding: 8px 12px;
    border: 3px solid #ff9f1c;
    border-radius: 6px;
    background: #16213e;
    color: #fff;
    text-align: center;
    width: 90%;
    margin-bottom: 12px;
    outline: none;
}
.lms-wrap #nameInput:focus { border-color: #ffd54f; box-shadow: 0 0 10px rgba(255,159,28,0.5); }
.lms-wrap #nameSubmit, .lms-wrap #nameSkip {
    font-family: 'Courier New', Courier, monospace;
    font-size: 15px;
    font-weight: bold;
    padding: 10px 22px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin: 5px;
    transition: transform 0.1s;
}
.lms-wrap #nameSubmit { background: #ff9f1c; color: #1a1a2e; }
.lms-wrap #nameSkip { background: transparent; color: #a8e6cf; border: 2px solid #a8e6cf; font-size: 13px; font-weight: normal; }
.lms-wrap #nameSubmit:hover, .lms-wrap #nameSkip:hover { transform: scale(1.05); }

/* === TOUCH CONTROLS - DESKTOP / OVERLAY MODE === */
.lms-wrap #touchControls {
    position: fixed;
    bottom: 12px;
    left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 16px;
    z-index: 100;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.lms-wrap.has-touch #touchControls { display: flex !important; }
.lms-wrap.no-touch #touchControls { display: none; }
.lms-wrap #dpad {
    position: relative;
    width: 168px;
    height: 168px;
    pointer-events: auto;
}
.lms-wrap .dpad-btn {
    position: absolute;
    width: 56px; height: 56px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: 2px solid rgba(255, 159, 28, 0.85);
    border-radius: 10px;
    font-size: 26px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    display: flex; align-items: center; justify-content: center;
    padding: 0; margin: 0;
    transition: background 0.08s, transform 0.08s;
}
.lms-wrap .dpad-btn:active, .lms-wrap .dpad-btn.pressed {
    background: rgba(255, 159, 28, 0.75);
    border-color: #ffd54f;
    transform: scale(0.94);
}
.lms-wrap .dpad-btn[data-dir="up"]    { top: 0;     left: 56px; }
.lms-wrap .dpad-btn[data-dir="down"]  { top: 112px; left: 56px; }
.lms-wrap .dpad-btn[data-dir="left"]  { top: 56px;  left: 0;    }
.lms-wrap .dpad-btn[data-dir="right"] { top: 56px;  left: 112px; }
.lms-wrap #attackBtn {
    pointer-events: auto;
    width: 86px; height: 86px;
    border-radius: 50%;
    background: rgba(229, 57, 53, 0.8);
    color: #fff;
    border: 3px solid #fff;
    font-size: 34px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    padding: 0; margin: 0 6px 24px 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    transition: transform 0.08s, background 0.08s, opacity 0.15s;
}
.lms-wrap #attackBtn:active, .lms-wrap #attackBtn.pressed {
    background: rgba(229, 57, 53, 1);
    transform: scale(0.92);
}
.lms-wrap #attackBtn.cooldown {
    opacity: 0.45; transform: scale(0.88); pointer-events: none;
}
.lms-wrap #attackBtn .atk-label {
    display: block; font-size: 10px; margin-top: 2px; letter-spacing: 1px;
}

/* === MOBILE LAYOUT - CONTROLS BELOW GAME === */
@media (max-width: 768px) {
    /* === CHANGED: wrapper only as tall as its content, no forced 100vh === */
    .lms-wrap {
        min-height: auto;
        height: auto;
        justify-content: flex-start;   /* stack from top, no forced vertical centering */
        align-items: center;           /* keep horizontal centering for canvas/controls */
        padding: 6px 0 0 0;            /* small top breathing room, NO bottom padding */
        overflow: visible;             /* don't clip shadows or borders */
    }

    .lms-wrap h1 { font-size: 18px; margin: 4px 0 2px; }
    .lms-wrap #info { font-size: 11px; margin: 0 0 6px; }

    /* === CHANGED: reduced shadow so the canvas glow doesn't get clipped === */
    .lms-wrap canvas {
        width: calc(100vw - 24px);
        border-width: 3px;
        box-shadow: 0 0 12px rgba(255,159,28,0.3);
    }

    /* === CHANGED: controls inset from edges with breathing room, reduced shadow === */
    .lms-wrap #touchControls {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        width: calc(100vw - 24px);
        max-width: 800px;
        margin: 10px 0 0 0;            /* only top margin, no bottom */
        padding: 10px 14px;
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        background: linear-gradient(180deg, rgba(20,20,46,0.85) 0%, rgba(22,33,62,0.95) 100%);
        border: 3px solid #16213e;
        border-radius: 8px;
        box-shadow: 0 0 12px rgba(255,159,28,0.25);  /* smaller, won't get clipped */
        box-sizing: border-box;
        flex-shrink: 0;
    }

    /* Scale down the D-pad so it fits comfortably in a row */
    .lms-wrap #dpad {
        width: 140px;
        height: 140px;
    }
    .lms-wrap .dpad-btn {
        width: 46px; height: 46px;
        font-size: 22px;
        border-radius: 8px;
    }
    .lms-wrap .dpad-btn[data-dir="up"]    { top: 0;    left: 47px; }
    .lms-wrap .dpad-btn[data-dir="down"]  { top: 94px; left: 47px; }
    .lms-wrap .dpad-btn[data-dir="left"]  { top: 47px; left: 0;    }
    .lms-wrap .dpad-btn[data-dir="right"] { top: 47px; left: 94px; }

    /* Attack button — right side of the row, no bottom margin */
    .lms-wrap #attackBtn {
        width: 72px; height: 72px;
        font-size: 28px;
        margin: 0;
    }
    .lms-wrap #attackBtn .atk-label { font-size: 9px; }
}

/* === SMALL PHONES === */
@media (max-width: 480px) {
    .lms-wrap #touchControls {
        padding: 8px 12px;
    }
    .lms-wrap #dpad {
        width: 120px;
        height: 120px;
    }
    .lms-wrap .dpad-btn {
        width: 40px; height: 40px;
        font-size: 18px;
        border-radius: 6px;
    }
    .lms-wrap .dpad-btn[data-dir="up"]    { top: 0;    left: 40px; }
    .lms-wrap .dpad-btn[data-dir="down"]  { top: 80px; left: 40px; }
    .lms-wrap .dpad-btn[data-dir="left"]  { top: 40px; left: 0;    }
    .lms-wrap .dpad-btn[data-dir="right"] { top: 40px; left: 80px; }

    .lms-wrap #attackBtn {
        width: 64px; height: 64px;
        font-size: 24px;
    }
    .lms-wrap #attackBtn .atk-label { font-size: 8px; }
}

/* === SHORT LANDSCAPE — KEEP CONTROLS AS OVERLAY === */
@media (max-height: 500px) and (orientation: landscape) {
    .lms-wrap {
        min-height: 100dvh;     /* back to full viewport in landscape */
        justify-content: center;
    }
    .lms-wrap #touchControls {
        position: fixed !important;
        bottom: 8px !important;
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        margin-top: 0;
        background: none;
        border: none;
        box-shadow: none;
        padding: 0 12px;
    }
    .lms-wrap #dpad {
        width: 132px; height: 132px;
    }
    .lms-wrap .dpad-btn {
        width: 44px; height: 44px;
        font-size: 20px;
    }
    .lms-wrap .dpad-btn[data-dir="up"]    { top: 0;    left: 44px; }
    .lms-wrap .dpad-btn[data-dir="down"]  { top: 88px; left: 44px; }
    .lms-wrap .dpad-btn[data-dir="left"]  { top: 44px; left: 0;    }
    .lms-wrap .dpad-btn[data-dir="right"] { top: 44px; left: 88px; }
    .lms-wrap #attackBtn {
        width: 64px; height: 64px;
        font-size: 24px;
        margin: 0 4px 8px 0;
    }
    .lms-wrap #attackBtn .atk-label { font-size: 8px; }
}
/* === RESTART BUTTON (mobile only) === */
.lms-wrap #restartBtn {
    pointer-events: auto;
    display: none;  /* hidden on desktop by default */
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255, 159, 28, 0.85);
    color: #1a1a2e;
    border: 3px solid #fff;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    padding: 0;
    margin: 0 4px 0 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    transition: transform 0.08s, background 0.08s, opacity 0.15s;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.lms-wrap #restartBtn:active,
.lms-wrap #restartBtn.pressed {
    background: rgba(255, 159, 28, 1);
    transform: scale(0.92);
}
.lms-wrap #restartBtn .restart-icon {
    font-size: 26px;
    display: block;
    line-height: 1;
}
.lms-wrap #restartBtn .restart-label {
    font-size: 8px;
    letter-spacing: 1px;
    margin-top: 1px;
    display: block;
    line-height: 1;
}

/* === RESTART BUTTON (mobile only) === */
.lms-wrap #restartBtn {
    pointer-events: auto;
    display: none;  /* hidden on desktop by default */
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255, 159, 28, 0.85);
    color: #1a1a2e;
    border: 3px solid #fff;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    padding: 0;
    margin: 0 4px 0 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    transition: transform 0.08s, background 0.08s, opacity 0.15s;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.lms-wrap #restartBtn:active,
.lms-wrap #restartBtn.pressed {
    background: rgba(255, 159, 28, 1);
    transform: scale(0.92);
}
.lms-wrap #restartBtn .restart-icon {
    font-size: 26px;
    display: block;
    line-height: 1;
}
.lms-wrap #restartBtn .restart-label {
    font-size: 8px;
    letter-spacing: 1px;
    margin-top: 1px;
    display: block;
    line-height: 1;
}

/* Show restart button only on game-over states */
.lms-wrap.state-win #restartBtn,
.lms-wrap.state-gameover #restartBtn,
.lms-wrap.state-ceremony #restartBtn {
    display: flex;
    animation: pulseRestart 1.4s ease-in-out infinite;
}

/* Subtle pulse animation so the player notices it */
@keyframes pulseRestart {
    0%, 100% { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 0 0 rgba(255, 159, 28, 0.7); }
    50%      { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 0 12px rgba(255, 159, 28, 0); }
}
