.item-action-root,
.item-detail-root {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.item-action-root:not([hidden]),
.item-detail-root:not([hidden]) {
    pointer-events: auto;
}

.item-action-backdrop,
.item-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.item-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%);
    border: 2px solid #5a4636;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.item-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;
}

.item-action-menu .pixel-btn {
    width: 100%;
    min-height: var(--touch-min);
}

.pixel-btn.danger {
    background: linear-gradient(180deg, #6b2e28 0%, #4a1c18 100%);
    border-color: #8b3a32;
    color: #ffd5d0;
}

.item-detail-panel {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    /* กว้างพออ่านสบาย — หดอัตโนมัติถ้าพื้นที่แม่แคบกว่า กันล้นจอ */
    width: 360px;
    max-width: calc(100% - 24px);
    max-height: min(520px, calc(100% - 24px));
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(165deg, #352a22 0%, #1a1410 55%, #120e0c 100%);
    border: 2px solid #6b5344;
    box-shadow:
        0 0 0 1px rgba(255, 215, 120, 0.12) inset,
        0 10px 28px rgba(0, 0, 0, 0.5);
}

.item-detail-panel.item-detail-panel--fit-width {
    width: 360px;
    min-width: 0;
    max-width: calc(100% - 24px);
}

.item-detail-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    width: 36px;
    height: 36px;
    min-height: 0;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #6b5344;
    border-radius: 4px;
    background: linear-gradient(180deg, #3d3028 0%, #241c16 100%);
    color: #e8dcc8;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 2px 0 #1a1410;
}

.item-detail-close:hover {
    background: linear-gradient(180deg, #4a3a30 0%, #2e241c 100%);
    color: #fff8e8;
}

.item-detail-close:active {
    transform: translateY(1px);
    box-shadow: none;
}

.item-detail-close-icon {
    font-size: 22px;
    font-weight: bold;
    line-height: 1;
    margin-top: -2px;
}

.item-detail-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 48px 10px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 215, 120, 0.15);
    background: linear-gradient(180deg, rgba(90, 70, 50, 0.35) 0%, transparent 100%);
}

.item-detail-icon {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    image-rendering: pixelated;
    border: 2px solid #8b7355;
    background: #0f0c0a;
    box-shadow: 0 2px 0 #3d2f24;
}

.item-detail-title {
    margin: 0;
    flex: 1;
    font-size: var(--text-md);
    font-weight: bold;
    color: var(--px-gold);
    line-height: 1.35;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

.item-detail-body {
    padding: 10px 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.item-detail-rows {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.item-detail-row {
    display: grid;
    grid-template-columns: minmax(96px, 1.15fr) minmax(0, 1.5fr);
    gap: 8px;
    align-items: baseline;
    font-size: var(--text-sm);
    padding: 7px 8px;
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.32);
    border-left: 3px solid rgba(139, 115, 85, 0.55);
}

.item-detail-row:nth-child(odd) {
    background: rgba(0, 0, 0, 0.22);
}

.item-detail-row--wide {
    grid-template-columns: 1fr;
    gap: 4px;
}

.item-detail-row--wide dd.item-detail-val--block {
    text-align: left;
}

.item-detail-row--ability {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
}

.item-detail-row--ability dt,
.item-detail-row--ability dd {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.item-detail-row--ability dd {
    text-align: left;
}

.item-detail-row--ability dt.item-detail-dt--muted {
    color: transparent;
    user-select: none;
}

.item-detail-row dt {
    margin: 0;
    color: #a89888;
    font-weight: normal;
    line-height: 1.35;
}

.item-detail-row dd {
    margin: 0;
    color: #f0ebe4;
    font-weight: bold;
    text-align: right;
    line-height: 1.35;
    word-break: break-word;
}

.item-detail-row dd.item-detail-val--muted {
    color: #7a7268;
    font-weight: normal;
}

.item-detail-row dd.item-detail-val--bonus {
    color: #7fd47f;
}

.item-detail-row dd .item-detail-val--bonus {
    color: #7fd47f;
    font-weight: bold;
}

.item-detail-row dd .item-detail-val--penalty {
    color: #ef5350;
    font-weight: bold;
}

.item-detail-row dd.item-detail-val--block {
    text-align: left;
    font-weight: normal;
    color: #d8cfc4;
    line-height: 1.5;
}

.item-detail-flavor {
    margin: 0;
    padding: 10px 10px 10px 12px;
    font-size: var(--text-xs);
    line-height: 1.55;
    color: #c4b8a8;
    font-style: italic;
    border-top: 1px dashed rgba(139, 115, 85, 0.45);
    background: rgba(0, 0, 0, 0.2);
}

.item-detail-flavor::before {
    content: '“';
    color: #8b7355;
    margin-right: 2px;
}

.item-detail-flavor::after {
    content: '”';
    color: #8b7355;
    margin-left: 2px;
}
