.npc-enhance-root {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.npc-enhance-root.open {
    pointer-events: auto;
    opacity: 1;
}

.npc-enhance-backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 40%, rgba(20, 28, 36, 0.72) 0%, rgba(0, 0, 0, 0.78) 70%);
}

.npc-enhance-sheet {
    position: relative;
    width: min(96vw, 440px);
    max-height: min(88vh, 640px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 10px;
    background: linear-gradient(180deg, #2e2438 0%, #1a1420 38%, #100c14 100%);
    box-shadow:
        0 0 0 1px rgba(186, 104, 200, 0.15),
        0 12px 40px rgba(0, 0, 0, 0.55);
}

.npc-enhance-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px 10px;
    border-bottom: 2px solid rgba(0, 0, 0, 0.35);
}

.npc-enhance-title {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: bold;
    color: var(--px-gold);
}

.npc-enhance-gold,
.npc-enhance-ore {
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: #b0a8b8;
}

.npc-enhance-close-btn {
    flex-shrink: 0;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
}

.npc-enhance-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 12px;
}

.npc-enhance-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.npc-enhance-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 6px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    cursor: pointer;
    color: #e8e0ec;
    font-family: inherit;
    font-size: var(--text-xs);
}

.npc-enhance-item.selected {
    border-color: rgba(255, 213, 79, 0.65);
    background: rgba(74, 52, 36, 0.35);
}

.npc-enhance-item-name {
    text-align: center;
    line-height: 1.25;
    word-break: break-word;
}

.npc-enhance-item-where {
    display: block;
    margin-top: 2px;
    color: #c9b896;
    font-size: 0.85em;
    opacity: 0.9;
}

.npc-enhance-item-lvl {
    color: var(--px-gold);
    font-weight: bold;
}

.npc-enhance-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 16px 8px;
    text-align: center;
    color: #a89a8c;
    font-size: var(--text-sm);
    line-height: 1.4;
}

.npc-enhance-foot {
    flex-shrink: 0;
    padding: 10px 14px 14px;
    border-top: 2px solid rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.npc-enhance-info {
    margin: 0;
    font-size: var(--text-sm);
    color: #e0d8e8;
}

.npc-enhance-dur {
    margin: 0;
    font-size: var(--text-xs);
    color: #b0a8b8;
    font-variant-numeric: tabular-nums;
}

.npc-enhance-dur.is-low {
    color: #ffab91;
}

.npc-enhance-cost {
    margin: 0;
    font-size: var(--text-xs);
    color: #c5b8d0;
}

.npc-enhance-rate {
    margin: 0;
    font-size: var(--text-xs);
    color: #9a8fa8;
    line-height: 1.35;
}

.npc-enhance-warn {
    margin: 0;
    padding: 8px 10px;
    border: 1px solid rgba(239, 83, 80, 0.55);
    border-radius: 6px;
    background: rgba(183, 28, 28, 0.22);
    color: #ffcdd2;
    font-size: var(--text-xs);
    font-weight: bold;
    line-height: 1.35;
}

.npc-enhance-warn[hidden] {
    display: none !important;
}

.npc-enhance-cluster {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 2px 0 0;
    padding: 8px 10px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.28);
    color: #e0d8e8;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.npc-enhance-cluster:hover:not(:disabled):not(.is-disabled) {
    border-color: rgba(129, 212, 250, 0.45);
    background: rgba(2, 119, 189, 0.14);
}

.npc-enhance-cluster.is-on {
    border-color: rgba(79, 195, 247, 0.75);
    background: linear-gradient(135deg, rgba(2, 119, 189, 0.28), rgba(74, 52, 36, 0.22));
    box-shadow: inset 0 0 0 1px rgba(179, 229, 252, 0.12);
}

.npc-enhance-cluster.is-disabled,
.npc-enhance-cluster:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.npc-enhance-cluster-icon-wrap {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(129, 212, 250, 0.25);
}

.npc-enhance-cluster.is-on .npc-enhance-cluster-icon-wrap {
    border-color: rgba(129, 212, 250, 0.7);
    box-shadow: 0 0 10px rgba(79, 195, 247, 0.35);
}

.npc-enhance-cluster-icon {
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.npc-enhance-cluster-qty {
    position: absolute;
    right: -4px;
    bottom: -4px;
    min-width: 1.4em;
    padding: 1px 4px;
    border-radius: 4px;
    background: #141018;
    border: 1px solid rgba(255, 213, 79, 0.45);
    color: var(--px-gold, #ffd54f);
    font-size: 10px;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    text-align: center;
}

.npc-enhance-cluster-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.npc-enhance-cluster-name {
    font-size: var(--text-sm);
    font-weight: bold;
    color: #e8f5fc;
    line-height: 1.25;
}

.npc-enhance-cluster-hint {
    font-size: var(--text-xs);
    color: #9ab8c8;
    line-height: 1.3;
}

.npc-enhance-cluster.is-on .npc-enhance-cluster-hint {
    color: #b3e5fc;
}

.npc-enhance-cluster-mark {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.35);
    color: transparent;
    font-size: 11px;
    line-height: 1;
}

.npc-enhance-cluster.is-on .npc-enhance-cluster-mark {
    border-color: rgba(255, 213, 79, 0.7);
    background: rgba(255, 213, 79, 0.18);
    color: var(--px-gold, #ffd54f);
    text-shadow: 0 0 6px rgba(255, 213, 79, 0.55);
}

/* --- สุ่มความสามารถรองใหม่: เลย์เอาต์แยกโซน --- */
.npc-reroll-sheet {
    width: min(96vw, 460px);
    max-height: min(92vh, 720px);
}

.npc-reroll-section-label {
    margin: 0 0 6px;
    padding: 0 2px;
    font-size: var(--text-xs);
    color: #b0a8b8;
    line-height: 1.35;
}

.npc-reroll-section-label--lock {
    color: #ffe082;
    font-weight: bold;
}

.npc-reroll-section-label--lock strong {
    color: var(--px-gold, #ffd54f);
}

.npc-reroll-equip {
    flex-shrink: 0;
    min-width: 0;
    width: 100%;
    padding: 8px 10px 8px;
    border-bottom: 2px solid rgba(0, 0, 0, 0.35);
    background: rgba(0, 0, 0, 0.18);
}

.npc-reroll-equip-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
    min-width: 0;
    width: 100%;
}

.npc-reroll-equip-nav {
    flex: 0 0 auto;
    align-self: center;
    min-width: 36px;
    min-height: 44px;
    padding: 0 4px;
    font-size: 22px;
    line-height: 1;
}

.npc-reroll-equip-nav:disabled {
    opacity: 0.35;
    cursor: default;
}

.npc-reroll-equip-list {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    padding: 2px 2px 10px;
}

.npc-reroll-equip-list .npc-enhance-item {
    flex: 0 0 92px;
    width: 92px;
    max-width: 92px;
    padding: 6px 4px;
}

.npc-reroll-equip-list .npc-enhance-item img {
    width: 36px;
    height: 36px;
}

.npc-reroll-equip-list .npc-enhance-item-name {
    max-width: 100%;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.npc-reroll-equip-list .npc-enhance-empty {
    flex: 1 0 auto;
    min-width: 100%;
    padding: 10px 6px;
    text-align: center;
}

.npc-reroll-main {
    flex: 1 1 auto;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    padding: 10px 12px 4px;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(2, 119, 189, 0.1) 0%, transparent 28%);
}

.npc-reroll-rolls {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.npc-reroll-rolls:empty::before {
    content: 'เลือกอุปกรณ์ด้านบน แล้วกดแถวด้านล่างเพื่อล็อก';
    display: block;
    margin: 12px 4px;
    padding: 14px 12px;
    border: 1px dashed rgba(129, 212, 250, 0.35);
    border-radius: 8px;
    color: #9ab8c8;
    font-size: var(--text-xs);
    text-align: center;
    line-height: 1.4;
}

.npc-reroll-rolls-head {
    display: none;
}

.npc-reroll-roll {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 10px;
    border: 2px solid rgba(129, 212, 250, 0.28);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.32);
    color: #e0d8e8;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.npc-reroll-roll:hover:not(:disabled) {
    border-color: rgba(129, 212, 250, 0.65);
    background: rgba(2, 119, 189, 0.16);
}

.npc-reroll-roll.is-locked {
    border-color: rgba(255, 213, 79, 0.8);
    background: rgba(74, 52, 36, 0.42);
    box-shadow: inset 0 0 0 1px rgba(255, 213, 79, 0.2);
}

.npc-reroll-roll:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.npc-reroll-roll-mark {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.35);
    font-size: 13px;
    line-height: 1;
}

.npc-reroll-roll.is-locked .npc-reroll-roll-mark {
    border-color: rgba(255, 213, 79, 0.7);
    background: rgba(255, 213, 79, 0.18);
}

.npc-reroll-roll-text {
    flex: 1;
    min-width: 0;
    font-size: var(--text-xs);
    line-height: 1.35;
    word-break: break-word;
}

.npc-reroll-roll-state {
    flex-shrink: 0;
    min-width: 3.5em;
    padding: 3px 6px;
    border-radius: 4px;
    background: rgba(2, 119, 189, 0.25);
    color: #b3e5fc;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
}

.npc-reroll-roll.is-locked .npc-reroll-roll-state {
    background: rgba(255, 213, 79, 0.22);
    color: var(--px-gold, #ffd54f);
}

.npc-reroll-foot {
    flex-shrink: 0;
}

.npc-enhance-confirm {
    width: 100%;
    min-height: var(--touch-min);
    margin-top: 4px;
}

.npc-enhance-confirm:disabled {
    opacity: 0.45;
}

/* --- รอตีบวก (10 วิ) --- */
.npc-enhance-busy {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 6, 12, 0.72);
    pointer-events: auto;
}

.npc-enhance-busy[hidden] {
    display: none !important;
}

.npc-enhance-busy-panel {
    width: min(88%, 280px);
    padding: 20px 18px 18px;
    text-align: center;
    background: linear-gradient(180deg, #3a2e48 0%, #1a1424 100%);
}

.npc-enhance-busy-label {
    margin: 0 0 8px;
    font-size: var(--text-sm);
    color: #d1c4e9;
    font-weight: bold;
}

.npc-enhance-busy-sec {
    margin: 0 0 14px;
    font-size: clamp(32px, 10vw, 44px);
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: #ce93d8;
    text-shadow: 0 0 12px rgba(206, 147, 216, 0.65);
    line-height: 1;
}

.npc-enhance-busy-bar {
    height: 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.45);
    overflow: hidden;
    border: 1px solid rgba(186, 104, 200, 0.45);
}

.npc-enhance-busy-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #7b1fa2, #ce93d8);
    transition: width 0.95s linear;
    border-radius: 3px;
}

.npc-enhance-root.is-enhancing .npc-enhance-close-btn,
.npc-enhance-root.is-augmenting .npc-enhance-close-btn {
    opacity: 0.4;
    pointer-events: none;
}
