/* --- แลกเปลี่ยนผู้เล่น --- */
.trade-root,
.trade-invite-root {
    position: fixed;
    inset: 0;
    z-index: 9100;
    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;
}

.trade-root.open,
.trade-invite-root.open {
    pointer-events: auto;
    opacity: 1;
}

.trade-backdrop,
.trade-invite-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%);
}

.trade-sheet {
    position: relative;
    width: min(96vw, 460px);
    max-height: min(92vh, 720px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 10px;
    background: linear-gradient(180deg, #3a2e24 0%, #1e1612 38%, #120e0a 100%);
    box-shadow:
        0 0 0 1px rgba(255, 213, 79, 0.12),
        0 12px 40px rgba(0, 0, 0, 0.55);
}

.trade-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);
}

.trade-title {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: bold;
    color: var(--px-gold);
}

.trade-subtitle,
.trade-status {
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: #a89a8c;
    line-height: 1.35;
}

.trade-status {
    color: #ffe082;
}

.trade-close-btn {
    flex-shrink: 0;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0;
}

.trade-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 10px 6px;
    overflow: auto;
}

.trade-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid rgba(141, 110, 99, 0.35);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.22);
    padding: 6px;
}

.trade-pane-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.trade-pane-badge {
    font-size: 9px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    background: #5d4037;
    color: #fff;
}

.trade-pane-badge--offer {
    background: #2e7d32;
}

.trade-pane-badge--peer {
    background: #1565c0;
}

.trade-pane-title {
    font-size: var(--text-sm);
    font-weight: bold;
    color: #efebe9;
    flex: 1;
}

.trade-pane-gold,
.trade-pane-count {
    font-size: var(--text-xs);
    color: var(--px-gold);
}

.trade-lock-badge {
    font-size: 9px;
    font-weight: bold;
    color: #fff59d;
    background: rgba(245, 127, 23, 0.85);
    padding: 2px 6px;
    border-radius: 4px;
}

.trade-scroll {
    overflow: auto;
    max-height: 22vh;
}

.trade-scroll--offer {
    max-height: 14vh;
}

.trade-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 4px;
}

.trade-slot {
    position: relative;
    aspect-ratio: 1;
    border: 1px solid rgba(141, 110, 99, 0.5);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.35);
    padding: 2px;
    cursor: pointer;
}

.trade-slot img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.trade-slot.empty {
    cursor: default;
    opacity: 0.55;
}

.trade-slot.in-queue {
    outline: 2px solid rgba(255, 213, 79, 0.65);
}

.trade-slot.unsellable,
.trade-slot.locked {
    opacity: 0.4;
    cursor: default;
}

.trade-qty {
    position: absolute;
    right: 2px;
    bottom: 1px;
    font-size: 9px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 0 #000;
}

.trade-gold-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.trade-gold-label {
    font-size: var(--text-xs);
    color: #bcaaa4;
}

.trade-gold-input {
    width: 7em;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid rgba(141, 110, 99, 0.55);
    background: rgba(0, 0, 0, 0.4);
    color: var(--px-gold);
    font-size: var(--text-sm);
}

.trade-gold-unit,
.trade-peer-gold {
    font-size: var(--text-xs);
    color: var(--px-gold);
}

.trade-footer {
    padding: 8px 12px 12px;
    border-top: 2px solid rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.trade-wait {
    margin: 0;
    text-align: center;
    font-size: var(--text-xs);
    color: #ffe082;
}

.trade-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.trade-slot.trade-slot--offer:not(.empty):not(:disabled) {
    cursor: pointer;
}

.trade-slot.trade-slot--offer:not(.empty):not(:disabled):hover {
    outline: 1px solid rgba(255, 213, 79, 0.45);
}

/* invite */
.trade-invite-sheet {
    position: relative;
    width: min(92vw, 340px);
    padding: 16px;
    border-radius: 10px;
    background: linear-gradient(180deg, #3a2e24 0%, #1e1612 100%);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.trade-invite-title {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: bold;
    color: var(--px-gold);
}

.trade-invite-text {
    margin: 10px 0 16px;
    font-size: var(--text-sm);
    color: #efebe9;
    line-height: 1.4;
}

.trade-invite-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
