#controls-layer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--controls-h) + var(--safe-bottom));
    padding-bottom: calc(var(--safe-bottom) + 16px);
    padding-left: 10px;
    padding-right: 10px;
    padding-top: 6px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 7;
}

/*
 * จอกว้าง (คอม) — ฮอตบาร์แถวเดียวในคอลัมน์กลาง (ไม่มีปุ่มโจมตี)
 * ลำดับ: 1 2 3 4 5 6 7 8 9 0 Z X
 */
html.layout-wide #controls-layer {
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    min-height: 0;
    padding: 8px 8px calc(10px + var(--safe-bottom));
    justify-content: center;
    align-items: flex-end;
}

html.layout-wide #controls-layer .action-cluster {
    width: 100%;
    justify-content: stretch;
    margin-bottom: 0;
}

html.layout-wide .skill-corner--wide {
    width: 100%;
    margin-bottom: 0;
}

html.layout-wide .skill-hotbar-layout--wide {
    --skill-gap: 4px;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: auto;
    gap: var(--skill-gap);
    align-items: start;
    justify-content: stretch;
    width: 100%;
    box-sizing: border-box;
}

html.layout-wide .skill-hotbar-layout--wide .skill-slot,
html.layout-wide .skill-hotbar-layout--wide .potion-quick,
html.layout-wide .skill-hotbar-layout--wide .skill-fixed-quick {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    flex: none;
    box-sizing: border-box;
    border-radius: 8px;
    padding: 0;
    /* ช่องว่างต้องกินพื้นที่เท่าช่องที่มีสกิล */
    overflow: hidden;
}

html.layout-wide .skill-hotbar-layout--wide .skill-slot.empty,
html.layout-wide .skill-hotbar-layout--wide .potion-quick.empty {
    /* คงขนาดกล่อง — แค่จาง ไม่ยุบ/ย่อ */
    opacity: 0.45;
    pointer-events: none;
}

html.layout-wide .skill-hotbar-layout--wide .potion-quick,
html.layout-wide .skill-hotbar-layout--wide .skill-fixed-quick {
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
}

html.layout-wide .skill-hotbar-layout--wide #btn-attack,
html.layout-wide #btn-attack {
    display: none !important;
}

/* มือถือบนเลย์เอาต์คอม — ปุ่มโจมตีลอยมุมล่างขวา โปร่งใส ไม่ยุบฮอตบาร์ */
html.layout-wide.touch-play #controls-layer {
    overflow: visible;
}

html.layout-wide.touch-play #btn-attack.btn-attack--touch-float,
html.layout-wide.touch-play #controls-layer > #btn-attack.btn-attack--touch-float {
    display: flex !important;
    position: absolute;
    right: calc(-1 * var(--game-col-w) + 12px);
    bottom: calc(12px + var(--safe-bottom));
    left: auto;
    top: auto;
    z-index: 9;
    width: clamp(64px, 9vw, 76px);
    height: clamp(64px, 9vw, 76px);
    margin: 0;
    opacity: 0.78;
    pointer-events: auto;
}

html.layout-wide.touch-play #btn-attack.btn-attack--touch-float.pressed {
    opacity: 0.95;
}

/* พื้นที่รับสัมผัสซ้าย — จอยลอยโผล่ตรงจุดแตะ (เมาส์ไม่ใช้ — ปล่อยคลิกผ่านไป canvas) */
#joystick-pad {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(58%, calc(100% - var(--skill-hotbar-w) - 20px));
    z-index: 2;
    touch-action: none;
    pointer-events: auto;
}

/* จอกว้าง + สัมผัส — ยื่น pad ครอบคอลัมน์ซ้ายถึงครึ่งคอลัมน์กลาง */
html.layout-wide.touch-play #joystick-pad {
    left: calc(-1 * var(--game-col-w));
    width: calc(var(--game-col-w) + 48%);
    bottom: calc(56px + var(--safe-bottom));
}

/* เมาส์/แทร็กแพด — ไม่รับอีเวนต์ ให้คลิกบ้าน/โลกถึง canvas */
@media (hover: hover) and (pointer: fine) {
    #joystick-pad {
        pointer-events: none;
    }
}

#joystick-zone.joystick-floating {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--joystick-size);
    height: var(--joystick-size);
    margin: 0;
    flex-shrink: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, rgba(60, 48, 36, 0.55) 0%, rgba(0, 0, 0, 0.45) 70%);
    border: 2px solid rgba(141, 110, 99, 0.45);
    box-shadow:
        inset 0 0 20px rgba(0, 0, 0, 0.35),
        0 4px 12px rgba(0, 0, 0, 0.25);
    touch-action: none;
    pointer-events: none;
    z-index: 8;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, -50%);
    transition: opacity 0.08s ease-out;
}

#joystick-zone.joystick-floating.is-visible {
    opacity: 0.72;
    visibility: visible;
}

html.touch-play #joystick-zone.joystick-floating.is-visible {
    opacity: 0.68;
}

html.touch-play #joystick-zone.joystick-floating.active.is-visible {
    opacity: 0.85;
}

.joystick-keys {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

/* ลูกศรสี่ทิศแบบกากบาท (ไอโซ) — ภายในวงกลมเล็ก (knob) */
.joystick-dirs {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.joystick-dir {
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
    opacity: 0.75;
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.55));
}

.joystick-dir-ne {
    top: 14%;
    left: 68%;
    border-width: 0 4px 7px 4px;
    border-color: transparent transparent rgba(255, 236, 179, 0.95) transparent;
    transform: translate(-50%, 0) rotate(45deg);
}

.joystick-dir-nw {
    top: 14%;
    left: 32%;
    border-width: 0 4px 7px 4px;
    border-color: transparent transparent rgba(255, 236, 179, 0.95) transparent;
    transform: translate(-50%, 0) rotate(-45deg);
}

.joystick-dir-sw {
    top: auto;
    bottom: 14%;
    left: 32%;
    border-width: 0 4px 7px 4px;
    border-color: transparent transparent rgba(255, 236, 179, 0.95) transparent;
    transform: translate(-50%, 0) rotate(-135deg);
}

.joystick-dir-se {
    top: auto;
    bottom: 14%;
    left: 68%;
    border-width: 0 4px 7px 4px;
    border-color: transparent transparent rgba(255, 236, 179, 0.95) transparent;
    transform: translate(-50%, 0) rotate(135deg);
}

#joystick-zone.active .joystick-dir {
    opacity: 0.95;
}

.joystick-key {
    position: absolute;
    font-size: clamp(12px, 3.2vw, 14px);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.5);
    text-shadow: 1px 1px 0 #000;
    line-height: 1;
}

.joystick-key-w {
    top: 14%;
    left: 72%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, 0);
}

.joystick-key-a {
    top: 14%;
    left: 28%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, 0);
}

.joystick-key-s {
    top: auto;
    bottom: 14%;
    left: 28%;
    right: auto;
    transform: translate(-50%, 0);
}

.joystick-key-d {
    top: auto;
    bottom: 14%;
    left: 72%;
    right: auto;
    transform: translate(-50%, 0);
}

#joystick-zone.active {
    border-color: rgba(255, 213, 79, 0.5);
    background: radial-gradient(circle at 35% 30%, rgba(80, 64, 48, 0.6) 0%, rgba(0, 0, 0, 0.5) 70%);
    box-shadow:
        inset 0 0 24px rgba(255, 213, 79, 0.08),
        0 0 16px rgba(255, 213, 79, 0.12);
}

#joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 1;
    width: clamp(48px, 14vw, 56px);
    height: clamp(48px, 14vw, 56px);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.28) 0%, rgba(180, 160, 140, 0.2) 100%);
    border: 2px solid rgba(255, 236, 179, 0.55);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 3px 8px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    overflow: hidden;
}

.action-cluster {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    margin-bottom: 2px;
    flex-shrink: 0;
    pointer-events: auto;
}

#btn-attack {
    width: clamp(68px, 19vw, 80px);
    height: clamp(68px, 19vw, 80px);
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    margin-bottom: 0;
    border-radius: 50%;
    font-size: var(--text-md);
    background: radial-gradient(circle at 35% 28%, #ff8a80 0%, #e53935 45%, #b71c1c 100%);
    border: 3px solid #8b0000;
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.25),
        0 4px 0 #4a1210,
        0 0 14px rgba(229, 57, 53, 0.35);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px;
    line-height: 1.15;
}

.btn-attack-label {
    font-size: var(--text-sm);
}

/* อุปกรณ์ไม่มีแป้นพิมพ์ — ซ่อนป้ายคีย์ลัด */
html.no-keyboard-hints .ui-hotkey,
html.no-keyboard-hints .game-menu-kbd,
html.no-keyboard-hints .joystick-keys,
html.no-keyboard-hints .game-menu-footer-hint {
    display: none !important;
}

html.no-keyboard-hints .game-menu-subtitle {
    visibility: hidden;
    height: 0;
    margin: 0;
    overflow: hidden;
}

/* ป้ายคีย์ลัด — ใช้ร่วมกับจอย / โจมตี / เมนู / สกิล */
.ui-hotkey {
    font-size: 9px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
}

.ui-hotkey--inline {
    display: inline-block;
    margin-left: 4px;
    vertical-align: middle;
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.65);
}

#btn-attack.pressed {
    box-shadow: 0 1px 0 #4a1210;
}

.btn-icon.menu {
    background: linear-gradient(180deg, #5d6d7e, #34495e);
    font-size: clamp(20px, 5.5vw, 24px);
}

.btn-icon {
    width: clamp(48px, 13vw, 56px);
    height: clamp(48px, 13vw, 56px);
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    border-radius: 10px;
    font-size: clamp(18px, 5vw, 22px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
