/* --- ฮอตบาร์ในเกม (ขั้นบันได + โจมตี 2×2 ช่อง) ---
              [5][6]
              [7][8]
   [Z][X]
   [9][0]
   [1][2][โจมตี]
   [3][4]
   Z/X = นั่ง/ขี่ · 9/0 = จิปาถะ  */
.skill-corner {
    display: flex;
    align-items: flex-end;
    margin-bottom: 2px;
    pointer-events: auto;
}

.skill-fixed-quick {
    position: relative;
    width: clamp(34px, 9vw, 40px);
    height: clamp(34px, 9vw, 40px);
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(165deg, #4a6a7e 0%, #2c3e50 55%, #1a2830 100%);
    border-color: #64b5f6;
    box-shadow:
        inset 0 1px 0 rgba(144, 202, 249, 0.35),
        0 2px 0 rgba(8, 6, 4, 0.5),
        0 0 10px rgba(100, 181, 246, 0.2);
    touch-action: manipulation;
    box-sizing: border-box;
    flex-shrink: 0;
}

.skill-fixed-quick .skill-slot-img {
    width: 72%;
    height: 72%;
}

.skill-fixed-quick .ui-hotkey {
    position: absolute;
    left: 3px;
    top: 1px;
    font-size: 0.65rem;
    z-index: 1;
}

.skill-fixed-quick .skill-slot-cd {
    border-radius: inherit;
}

.skill-fixed-quick.skill-mount-active {
    background: linear-gradient(180deg, #6d4c41, #4e342e);
    border-color: #8d6e63;
    box-shadow: 0 0 10px rgba(141, 110, 99, 0.45);
}

.skill-fixed-quick.skill-sit-active {
    background: linear-gradient(180deg, #558b2f, #33691e);
    border-color: #aed581;
    box-shadow: 0 0 10px rgba(174, 213, 129, 0.4);
}

.skill-fixed-quick.on-cooldown {
    filter: saturate(0.55);
}

.skill-fixed-quick.is-disabled {
    opacity: 0.45;
    filter: grayscale(0.35);
}

.skill-hotbar-layout {
    --skill-gap: 5px;
    --skill-cell: var(--skill-cell-size, clamp(40px, 10.5vw, 48px));
    display: grid;
    grid-template-columns: repeat(4, var(--skill-cell));
    grid-template-rows: repeat(4, var(--skill-cell));
    gap: var(--skill-gap);
    align-items: center;
}

.skill-hotbar-layout #btn-attack {
    grid-column: 3 / span 2;
    grid-row: 3 / span 2;
    width: calc(2 * var(--skill-cell) + var(--skill-gap));
    height: calc(2 * var(--skill-cell) + var(--skill-gap));
    min-width: unset;
    min-height: unset;
    justify-self: center;
    align-self: center;
    margin-bottom: 0;
    box-sizing: border-box;
}

.skill-slot-wrap {
    position: relative;
    width: clamp(40px, 10.5vw, 48px);
    height: clamp(40px, 10.5vw, 48px);
    min-width: var(--touch-min);
    min-height: var(--touch-min);
}

.skill-slot-wrap .skill-slot {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

/* กองวงกลมเหนือช่อง 1–2: Z/X บน · จิปาถะ 9/0 ล่าง */
.skill-quick-stack {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 4px);
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.potion-quick {
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    z-index: 2;
    width: clamp(34px, 9vw, 40px);
    height: clamp(34px, 9vw, 40px);
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 16, 12, 0.9);
    touch-action: manipulation;
    box-sizing: border-box;
    flex-shrink: 0;
}

.potion-quick.empty {
    opacity: 0.4;
}

.potion-quick.filled {
    opacity: 1;
}

.potion-quick-hp.filled {
    border-color: #c62828;
    box-shadow: 0 0 8px rgba(198, 40, 40, 0.35);
}

.potion-quick-mp.filled {
    border-color: #1565c0;
    box-shadow: 0 0 8px rgba(21, 101, 192, 0.35);
}

.potion-quick-img {
    width: 72%;
    height: 72%;
    object-fit: contain;
    image-rendering: pixelated;
    pointer-events: none;
}

.potion-quick-qty {
    position: absolute;
    left: 2px;
    bottom: 2px;
    padding: 0 2px;
    min-width: 12px;
    font-size: 8px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    color: #fff8e8;
    background: #000;
    background-color: #000;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 3px;
    pointer-events: none;
    text-shadow: none;
    z-index: 3;
    box-sizing: border-box;
}

.potion-quick-cd {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fffde7;
    font-size: 12px;
    font-weight: 700;
    text-shadow: 0 1px 2px #000;
    pointer-events: none;
    border-radius: inherit;
    z-index: 4;
}

.potion-quick.on-cooldown {
    filter: saturate(0.55);
}

.skill-slot-cd {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fffde7;
    font-size: 12px;
    font-weight: 700;
    text-shadow: 0 1px 2px #000;
    pointer-events: none;
    border-radius: inherit;
    z-index: 4;
}

.skill-slot.on-cooldown {
    filter: saturate(0.55);
}

.potion-quick .ui-hotkey {
    position: absolute;
    right: 2px;
    bottom: 1px;
    font-size: 0.65rem;
    z-index: 1;
}

.skill-slot {
    position: relative;
    width: clamp(40px, 10.5vw, 48px);
    height: clamp(40px, 10.5vw, 48px);
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(145deg, rgba(42, 34, 26, 0.95) 0%, rgba(14, 10, 8, 0.92) 100%);
    box-shadow:
        inset 0 1px 0 rgba(141, 110, 99, 0.25),
        0 2px 0 rgba(8, 6, 4, 0.5);
    touch-action: manipulation;
}

.skill-slot.empty {
    opacity: 0.35;
    pointer-events: none;
}

.skill-slot.filled {
    background: linear-gradient(165deg, #4a6a7e 0%, #2c3e50 55%, #1a2830 100%);
    border-color: #64b5f6;
    box-shadow:
        inset 0 1px 0 rgba(144, 202, 249, 0.35),
        0 2px 0 rgba(8, 6, 4, 0.5),
        0 0 10px rgba(100, 181, 246, 0.2);
}

.skill-slot.skill-mount-active {
    background: linear-gradient(180deg, #6d4c41, #4e342e);
    border-color: #8d6e63;
    box-shadow: 0 0 10px rgba(141, 110, 99, 0.45);
}

.skill-slot.skill-sit-active {
    background: linear-gradient(180deg, #558b2f, #33691e);
    border-color: #aed581;
    box-shadow: 0 0 10px rgba(174, 213, 129, 0.4);
}

.skill-slot-img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    image-rendering: pixelated;
    pointer-events: none;
}

.skill-slot .ui-hotkey {
    position: absolute;
    left: 3px;
    bottom: 2px;
    z-index: 1;
}

#btn-attack {
    flex-shrink: 0;
}

#btn-attack.is-disabled {
    opacity: 0.45;
    filter: grayscale(0.6);
    pointer-events: none;
    box-shadow: none;
}

.potion-quick.is-disabled,
.skill-slot.is-disabled {
    opacity: 0.45;
    filter: grayscale(0.55);
    pointer-events: none;
}

/* --- เมนูสกิล (เต็มความกว้างแบบกระเป๋า สูงตามเนื้อหา) --- */
#skill-menu-root {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 55;
    --skill-top-clearance: calc(var(--safe-top) + clamp(92px, 15vh, 118px));
    --skill-lib-cell: 46px;
    --skill-lib-gap: 5px;
    --skill-grid-max-cols: 9;
}

#skill-menu-root.open {
    pointer-events: auto;
}

/* โปร่งใส — ไม่มืดทับเกม (ยังแตะพื้นที่ว่างเพื่อปิดได้) */
[data-skill-menu-backdrop] {
    position: fixed;
    inset: 0;
    background: transparent;
    opacity: 0;
    pointer-events: none;
}

#skill-menu-root.open [data-skill-menu-backdrop] {
    opacity: 1;
    pointer-events: auto;
}

[data-skill-menu-sheet] {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    width: 100%;
    min-width: 100%;
    max-width: none;
    height: auto;
    max-height: calc(100% - var(--skill-top-clearance) - var(--safe-bottom));
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 10px max(10px, env(safe-area-inset-right, 0px)) calc(10px + var(--safe-bottom))
        max(10px, env(safe-area-inset-left, 0px));
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.28s ease-out;
    border-radius: 10px 10px 0 0;
    pointer-events: auto;
    background: linear-gradient(180deg, #2a2118 0%, #1a1410 100%);
    box-sizing: border-box;
}

#skill-menu-root.open [data-skill-menu-sheet] {
    transform: translateY(0);
}

[data-skill-menu-sheet] .inv-header-row {
    margin-bottom: 6px;
}

.skill-menu-hint {
    margin: 0 0 6px;
    font-size: var(--text-xs);
    color: #9a8f82;
    text-align: center;
    line-height: 1.3;
    flex-shrink: 0;
}

.skill-menu-section-title {
    margin: 0 0 6px;
    font-size: var(--text-sm);
    font-weight: bold;
    color: var(--px-gold);
    flex-shrink: 0;
}

.skill-menu-hotbar-block {
    flex-shrink: 0;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 2px solid #4a3728;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.skill-menu-hotbar-block .skill-menu-section-title {
    text-align: center;
    width: 100%;
}

[data-skill-menu-bar] {
    display: flex;
    justify-content: center;
    width: 100%;
}

.skill-menu-hotbar-layout {
    --skill-gap: 6px;
    --skill-cell: 46px;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
}

.skill-menu-hotbar-layout .skill-menu-bar-slot {
    width: var(--skill-cell);
    height: var(--skill-cell);
    min-width: var(--skill-cell);
    min-height: var(--skill-cell);
}

/*
 * จอกว้าง (คอม) — ช่องใช้งานในเมนูสกิลเรียงแถวเดียว 8 ช่อง
 * display:flex ทำให้ grid-column/row (inline) ของขั้นบันไดไม่มีผล
 */
html.layout-wide .skill-menu-hotbar-layout {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: var(--skill-gap);
    width: 100%;
}

html.layout-wide .skill-menu-hotbar-layout .skill-menu-bar-slot {
    flex: 1 1 0;
    width: auto;
    height: auto;
    aspect-ratio: 1 / 1;
    min-width: 0;
    min-height: 0;
    max-width: var(--skill-cell);
    box-sizing: border-box;
}

/* ไม่มีปุ่มโจมตีบนคอม — ไม่ต้องโชว์วงโจมตีในเมนู */
html.layout-wide .skill-menu-hotbar-layout .skill-menu-bar-attack {
    display: none;
}

.skill-menu-hotbar-layout .skill-menu-bar-attack {
    width: calc(2 * var(--skill-cell) + var(--skill-gap));
    height: calc(2 * var(--skill-cell) + var(--skill-gap));
    justify-self: center;
    align-self: center;
    border: 2px dashed #4a3728;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #6d6358;
    text-align: center;
    line-height: 1.2;
}

.skill-menu-bar-slot {
    position: relative;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
}

.skill-menu-bar-slot.filled {
    background: linear-gradient(180deg, #3d5a6e, #2c3e50);
}

.skill-menu-bar-slot.is-pending {
    border-color: var(--px-gold);
    box-shadow: 0 0 10px rgba(201, 162, 39, 0.45);
}

.skill-menu-bar-slot.empty {
    opacity: 0.85;
}

.skill-menu-slot-num {
    position: absolute;
    right: 3px;
    bottom: 2px;
    font-size: 8px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.55);
    pointer-events: none;
}

.skill-slot-plus {
    font-size: var(--text-lg);
    color: #6d6358;
}

.skill-library-block {
    flex: 1;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.skill-library-scroll {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2px 4px 6px;
    box-sizing: border-box;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.skill-library-scroll::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.skill-menu-library-grid {
    --skill-grid-width: calc(
        var(--skill-grid-max-cols) * var(--skill-lib-cell) +
            (var(--skill-grid-max-cols) - 1) * var(--skill-lib-gap)
    );
    display: grid;
    width: min(100%, var(--skill-grid-width));
    margin-inline: auto;
    grid-template-columns: repeat(auto-fill, var(--skill-lib-cell));
    grid-auto-rows: var(--skill-lib-cell);
    gap: var(--skill-lib-gap);
    justify-content: center;
    align-content: start;
    box-sizing: border-box;
}

.skill-lib-slot {
    position: relative;
    width: var(--skill-lib-cell);
    height: var(--skill-lib-cell);
    justify-self: center;
    padding: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a221c;
    min-height: 0;
    box-sizing: border-box;
}

.skill-lib-slot .skill-slot-img {
    width: 88%;
    height: 88%;
}

.skill-lib-slot-empty {
    opacity: 0.4;
    pointer-events: none;
}

.skill-lib-slot:not(.skill-lib-slot-empty) {
    background: linear-gradient(180deg, #3d4a3a, #2a3228);
    border-color: #5d6e5d;
    cursor: grab;
    touch-action: manipulation;
}

.skill-lib-slot.is-equipped {
    border-color: #2ecc71;
    box-shadow:
        inset 0 0 0 1px rgba(46, 204, 113, 0.35),
        0 0 8px rgba(46, 204, 113, 0.45);
    background: linear-gradient(180deg, #3a5244, #2a3d32);
}

.skill-lib-slot.is-equipped::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 7px;
    height: 7px;
    border-radius: 1px;
    background: #2ecc71;
    box-shadow: 0 0 4px rgba(46, 204, 113, 0.8);
    pointer-events: none;
    z-index: 1;
}

.skill-lib-equipped-badge {
    position: absolute;
    right: 2px;
    bottom: 2px;
    min-width: 12px;
    height: 12px;
    padding: 0 2px;
    font-size: 8px;
    font-weight: bold;
    line-height: 12px;
    text-align: center;
    color: #1a1410;
    background: #2ecc71;
    border-radius: 3px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
    pointer-events: none;
    z-index: 1;
}

.skill-menu-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 16px;
    text-align: center;
    color: #8a7f72;
    font-size: var(--text-sm);
}

/* --- สวมใส่ / รายละเอียด (ในเมนูสกิล) --- */
.skill-action-root {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* เหนือเมนูสกิล (30) และดูข้อมูลผู้เล่น (9150) */
.skill-detail-root,
#skill-detail-root {
    position: fixed;
    inset: 0;
    z-index: 9200;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.skill-action-root:not([hidden]),
.skill-detail-root:not([hidden]) {
    pointer-events: auto;
}

.skill-action-backdrop,
.skill-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.skill-action-menu {
    position: relative;
    z-index: 1;
    width: min(280px, 92vw);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: linear-gradient(180deg, #2e241c 0%, #1a1410 100%);
}

.skill-action-name {
    margin: 0 0 4px;
    font-size: var(--text-md);
    font-weight: bold;
    color: var(--px-gold);
    text-align: center;
    line-height: 1.3;
}

.skill-action-menu .pixel-btn {
    width: 100%;
    min-height: var(--touch-min);
}

.skill-action-menu .pixel-btn:disabled {
    opacity: 0.4;
}

.skill-detail-panel {
    position: relative;
    z-index: 1;
    width: min(320px, 94vw);
    max-height: min(70vh, 420px);
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: linear-gradient(180deg, #2e241c 0%, #1a1410 100%);
}

.skill-detail-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.skill-detail-icon {
    flex-shrink: 0;
    image-rendering: pixelated;
    border: 2px solid #4a3728;
    background: #1a1410;
}

.skill-detail-title {
    margin: 0;
    font-size: var(--text-md);
    font-weight: bold;
    color: var(--px-gold);
}

.skill-detail-rows {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.skill-detail-row {
    display: grid;
    grid-template-columns: minmax(72px, 1fr) minmax(0, 1.5fr);
    gap: 6px;
    font-size: var(--text-sm);
    padding: 5px 6px;
    background: rgba(0, 0, 0, 0.28);
}

.skill-detail-row dt {
    margin: 0;
    color: #9a8f82;
    font-weight: normal;
}

.skill-detail-row dd {
    margin: 0;
    color: #fff;
    font-weight: bold;
    text-align: right;
}

.skill-detail-close {
    width: 100%;
    min-height: var(--touch-min);
}

@media (min-width: 480px) {
    #skill-menu-root {
        --skill-lib-cell: 52px;
    }

    [data-skill-menu-sheet] {
        padding-left: max(14px, env(safe-area-inset-left, 0px));
        padding-right: max(14px, env(safe-area-inset-right, 0px));
    }
}

@media (max-height: 680px) {
    #skill-menu-root {
        --skill-top-clearance: calc(var(--safe-top) + 86px);
    }

    [data-skill-menu-sheet] {
        padding: 8px 8px calc(8px + var(--safe-bottom));
    }
}
