/* ---- Player trading ------------------------------------------------------------------------- */

.trade-panel,
.trade-invite,
.trade-waiting,
.trade-done {
  --r-common: #9fb3d1;
  --r-rare: #3ee0ff;
  --r-epic: #b77bff;
  --r-legendary: #ffd23f;
  --r-mythical: #ff5ea8;
  font-family: var(--font-body);
  color: var(--text);
}

/* incoming request */
.trade-invite {
  position: fixed;
  top: 92px;
  left: 50%;
  z-index: 70;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: min(460px, calc(100vw - 32px));
  padding: 12px 14px 16px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  box-shadow: var(--hard), 0 0 0 3px rgba(255, 210, 63, .35), 0 12px 40px rgba(0, 0, 0, .45);
  transform: translateX(-50%);
}
.trade-invite.show { animation: tradeDrop .42s cubic-bezier(.2, 1.4, .4, 1); }
.trade-invite[hidden] { display: none; }
.ti-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffe680, var(--yellow));
  color: var(--ink);
  box-shadow: var(--hard-sm);
  animation: tradeWiggle 1.4s ease-in-out infinite;
}
.ti-icon svg { width: 30px; height: 30px; }
.ti-copy { display: grid; min-width: 0; line-height: 1.15; }
.ti-copy b { overflow: hidden; font-family: var(--font-display); font-weight: 400; font-size: 1.2rem; text-overflow: ellipsis; white-space: nowrap; }
.ti-copy span { color: var(--muted); font-weight: 800; font-size: .8rem; }
.ti-actions { display: flex; gap: 8px; }
.ti-actions button,
.trade-waiting button {
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  font-family: var(--font-display);
  font-size: .95rem;
  cursor: pointer;
  box-shadow: var(--hard-sm);
}
.ti-actions button:active,
.trade-waiting button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.ti-no { background: var(--ink-2); color: var(--text); }
.ti-yes { background: var(--green); color: var(--ink); }
.ti-timer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: var(--yellow);
  transform-origin: left;
  animation: tradeTimer var(--ms, 20000ms) linear forwards;
}

/* outgoing request */
.trade-waiting {
  position: fixed;
  top: 92px;
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--hard-sm);
  font-weight: 800;
  font-size: .9rem;
  transform: translateX(-50%);
  animation: tradeDrop .35s ease-out;
}
.trade-waiting[hidden] { display: none; }
.trade-waiting em { color: var(--yellow); font-style: normal; }
.trade-waiting button { padding: 4px 10px; background: var(--ink-2); color: var(--text); font-size: .82rem; }
.tw-spin {
  width: 16px;
  height: 16px;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: tradeSpin .8s linear infinite;
}

/* the trading table */
.trade-panel {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 60;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(960px, calc(100vw - 24px));
  max-height: min(64vh, 640px);
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 26px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 210, 63, .12), transparent 60%),
    linear-gradient(180deg, var(--panel-hi), var(--panel) 40%, var(--panel-lo));
  box-shadow: var(--hard), 0 18px 60px rgba(0, 0, 0, .5);
  transform: translateX(-50%);
}
.trade-panel[hidden] { display: none; }
.trade-panel.show { animation: tradeRise .45s cubic-bezier(.2, 1.25, .4, 1); }

.tp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 8px 16px;
}
.tp-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tp-title b { display: block; font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; letter-spacing: .01em; }
.tp-title small { color: var(--muted); font-weight: 800; font-size: .76rem; }
.tp-swap {
  display: grid;
  flex: none;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 3px solid var(--ink);
  border-radius: 13px;
  background: linear-gradient(180deg, #ffe680, var(--yellow));
  color: var(--ink);
  box-shadow: var(--hard-sm);
}
.tp-swap svg { width: 28px; height: 28px; }
.tp-x {
  flex: none;
  width: 36px;
  height: 36px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  background: var(--ink-2);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.tp-table {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  padding: 0 14px;
}
.tp-side {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: rgba(20, 6, 22, .45);
  transition: box-shadow .2s, background .2s;
}
.tp-side.mine { --side: var(--green); }
.tp-side.theirs { --side: var(--cyan); }
.tp-side.is-locked {
  background: rgba(61, 220, 114, .12);
  box-shadow: 0 0 0 3px var(--green), 0 0 26px rgba(61, 220, 114, .35);
}
.tp-side.bump { animation: tradeBump .4s ease-out; }
.tp-who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tp-who b { overflow: hidden; font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; text-overflow: ellipsis; white-space: nowrap; color: var(--side); }
.tp-lv { flex: none; padding: 1px 7px; border: 2px solid var(--ink); border-radius: 8px; background: var(--ink-2); font-weight: 900; font-size: .7rem; }
.tp-flag {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  color: var(--muted);
  font-weight: 900;
  font-size: .72rem;
}
.tp-flag.on { color: var(--green); }
.tp-flag svg { width: 14px; height: 14px; }

.tp-slots {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}
.tp-slot {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 2px dashed rgba(255, 255, 255, .14);
  border-radius: 12px;
  background: rgba(255, 255, 255, .03);
  font-style: normal;
}
.tp-slot.filled {
  border: 3px solid var(--rarity);
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--rarity) 35%, transparent), rgba(0, 0, 0, .25));
  box-shadow: 0 0 12px color-mix(in srgb, var(--rarity) 40%, transparent);
  color: var(--text);
  cursor: pointer;
}
.tp-slot.filled.new { animation: tradePop .28s cubic-bezier(.2, 1.6, .4, 1); }
.tp-slot.filled[tabindex="-1"] { cursor: default; }
.tp-slot.flash { animation: tradeFlash .7s ease-out; }
.tp-slot span,
.tp-item span {
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 2px;
  overflow: hidden;
  font-weight: 900;
  font-size: .56rem;
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink);
}
.tp-slot em,
.tp-item em {
  position: absolute;
  top: 2px;
  right: 3px;
  padding: 0 4px;
  border-radius: 6px;
  background: var(--ink);
  font-style: normal;
  font-weight: 900;
  font-size: .62rem;
}
.tp-thumb { width: 82%; height: 82%; }

.tp-money { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tp-money label,
.tp-money > span {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 4px 6px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: rgba(0, 0, 0, .3);
}
.tp-money input {
  width: 100%;
  min-width: 0;
  padding: 3px 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1rem;
  outline: none;
}
.tp-money input:focus { color: var(--yellow); }
.tp-money button {
  flex: none;
  padding: 2px 6px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--ink-2);
  color: var(--muted);
  font-weight: 900;
  font-size: .66rem;
  cursor: pointer;
}
.tp-money input:disabled,
.tp-money button:disabled { opacity: .55; cursor: not-allowed; }
.tp-money.read b { font-family: var(--font-display); font-weight: 400; font-size: 1rem; }

.tp-mid { display: grid; place-items: center; text-align: center; }
.tp-arrows,
.tp-count { display: grid; justify-items: center; gap: 6px; }
.tp-arrows i,
.tp-count i {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: linear-gradient(180deg, #ffe680, var(--yellow));
  color: var(--ink);
  box-shadow: var(--hard-sm);
  animation: tradeSway 2.4s ease-in-out infinite;
}
.tp-arrows svg,
.tp-count svg { width: 34px; height: 34px; }
.tp-arrows small,
.tp-count small { color: var(--muted); font-weight: 900; font-size: .7rem; line-height: 1.15; }
.tp-count b {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: conic-gradient(var(--green) 0 100%, transparent 0);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2rem;
  box-shadow: 0 0 0 4px rgba(61, 220, 114, .3), 0 0 28px rgba(61, 220, 114, .6);
  animation: tradeBeat 1s ease-in-out infinite;
}
.tp-count.go i { animation: tradeSpin .6s linear infinite; }

.tp-locker {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  min-height: 0;
  margin: 10px 14px 0;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: rgba(20, 6, 22, .35);
}
.tp-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tp-tabs button {
  padding: 4px 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--ink-2);
  color: var(--muted);
  font-weight: 900;
  font-size: .76rem;
  cursor: pointer;
}
.tp-tabs button.on { background: var(--yellow); color: var(--ink); }
.tp-hint { margin-left: auto; color: var(--muted); font-weight: 800; font-size: .7rem; }
.tp-inv {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 6px;
  min-height: 92px;
  max-height: 190px;
  overflow-y: auto;
  padding: 2px;
}
.tp-item {
  --rarity: var(--r-common);
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 13px;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--rarity) 28%, transparent), rgba(0, 0, 0, .22));
  box-shadow: inset 0 -4px 0 color-mix(in srgb, var(--rarity) 60%, var(--ink));
  color: var(--text);
  cursor: pointer;
  transition: transform .12s;
}
.tp-item:hover:not(:disabled) { transform: translateY(-3px); box-shadow: inset 0 -4px 0 var(--rarity), 0 0 14px color-mix(in srgb, var(--rarity) 50%, transparent); }
.tp-item.used { opacity: .35; filter: grayscale(.6); cursor: not-allowed; }
.tp-eq {
  position: absolute;
  top: 2px;
  left: 3px;
  padding: 0 4px;
  border-radius: 6px;
  background: var(--green);
  color: var(--ink);
  font-style: normal;
  font-weight: 900;
  font-size: .56rem;
}
.tp-empty { margin: auto; padding: 18px; color: var(--muted); font-weight: 800; font-size: .85rem; text-align: center; }

.trade-panel .rarity-common, .trade-done .rarity-common { --rarity: var(--r-common); }
.trade-panel .rarity-rare, .trade-done .rarity-rare { --rarity: var(--r-rare); }
.trade-panel .rarity-epic, .trade-done .rarity-epic { --rarity: var(--r-epic); }
.trade-panel .rarity-legendary, .trade-done .rarity-legendary { --rarity: var(--r-legendary); }
.trade-panel .rarity-mythical, .trade-done .rarity-mythical { --rarity: var(--r-mythical); }

.tp-foot { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px 14px; }
.tp-foot button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--hard-sm);
}
.tp-foot button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.tp-cancel { background: var(--ink-2); color: var(--text); }
.tp-lock { min-width: 170px; justify-content: center; background: linear-gradient(180deg, #6ff59a, var(--green)); color: var(--ink); }
.tp-lock svg { width: 20px; height: 20px; }
.tp-lock.unlock { background: linear-gradient(180deg, #ffe680, var(--yellow)); }
.tp-lock.nudge { animation: tradeNudge 1.2s ease-in-out infinite; }
.tp-lock:disabled { opacity: .6; cursor: wait; }

/* item flying from your Locker onto the table */
.tp-fly {
  position: fixed;
  z-index: 95;
  margin: 0;
  pointer-events: none;
  transition: transform .38s cubic-bezier(.3, .9, .3, 1), opacity .38s;
}

/* the swap: both offers slide across the table */
.trade-panel.swapping [data-slots] { transition: transform .55s cubic-bezier(.6, 0, .3, 1), opacity .55s; transform: translateX(var(--dx)) scale(.9); opacity: .2; }
.trade-panel.swapping .tp-mid i { animation: tradeSpin .5s linear infinite; }

/* trade complete */
.trade-done {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 4, 14, .55);
}
.trade-done[hidden] { display: none; }
.td-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(520px, 100%);
  padding: 30px 22px 22px;
  border: 3px solid var(--ink);
  border-radius: 28px;
  background:
    radial-gradient(100% 70% at 50% 0%, rgba(255, 210, 63, .28), transparent 65%),
    linear-gradient(180deg, var(--panel-hi), var(--panel));
  box-shadow: var(--hard), 0 0 0 4px rgba(255, 210, 63, .4), 0 24px 80px rgba(0, 0, 0, .6);
  text-align: center;
}
.trade-done.show .td-card { animation: tradeDone .6s cubic-bezier(.2, 1.5, .35, 1); }
.td-burst {
  position: absolute;
  top: -40px;
  left: 50%;
  width: 260px;
  height: 260px;
  margin-left: -130px;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 210, 63, .35) 0 12deg, transparent 12deg 30deg);
  -webkit-mask: radial-gradient(circle, #000 20%, transparent 70%);
  mask: radial-gradient(circle, #000 20%, transparent 70%);
  animation: tradeSpin 9s linear infinite;
  pointer-events: none;
}
.td-badge {
  position: relative;
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-top: -6px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: linear-gradient(180deg, #7dffaa, var(--green));
  color: var(--ink);
  box-shadow: var(--hard);
}
.trade-done.show .td-badge { animation: tradeStamp .7s .15s cubic-bezier(.2, 1.8, .4, 1) both; }
.td-badge svg { width: 52px; height: 52px; }
.td-card h2 { position: relative; margin: 6px 0 0; font-family: var(--font-display); font-weight: 400; font-size: 2.1rem; letter-spacing: .02em; color: var(--yellow); text-shadow: 0 3px 0 var(--ink); }
.td-card > p { position: relative; margin: 0; color: var(--muted); font-weight: 800; }
.td-cols { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 10px; }
.td-cols section { padding: 10px; border: 3px solid var(--ink); border-radius: 16px; background: rgba(0, 0, 0, .25); }
.td-cols .got { box-shadow: 0 0 0 2px var(--green); }
.td-cols h3 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 400; font-size: 1rem; }
.td-cols .got h3 { color: var(--green); }
.td-cols .gave h3 { color: var(--muted); }
.td-cols ul { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.td-cols li {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 3px 6px;
  border-left: 4px solid var(--rarity, var(--yellow));
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  font-weight: 800;
  font-size: .82rem;
  text-align: left;
}
.td-cols li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-cols li .tp-thumb { flex: none; width: 34px; height: 34px; }
.td-cols li.none { border-color: transparent; color: var(--muted); }
.td-ok {
  position: relative;
  margin-top: 12px;
  padding: 10px 34px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffe680, var(--yellow));
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--hard-sm);
}

/* player card row */
.hub-dd-row.trade-row i { color: var(--yellow); }
.hub-dd-row.trade-row small { margin-left: auto; color: var(--muted); font-weight: 900; font-size: .68rem; }

@keyframes tradeDrop { from { opacity: 0; transform: translate(-50%, -24px) scale(.9); } }
@keyframes tradeRise { from { opacity: 0; transform: translate(-50%, 40px) scale(.96); } }
@keyframes tradeTimer { to { transform: scaleX(0); } }
@keyframes tradeSpin { to { transform: rotate(360deg); } }
@keyframes tradeWiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes tradeSway { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(-1); } }
@keyframes tradePop { from { transform: scale(.5); opacity: 0; } }
@keyframes tradeFlash { 0% { box-shadow: 0 0 0 4px #fff, 0 0 30px var(--rarity); } 100% { box-shadow: 0 0 12px color-mix(in srgb, var(--rarity) 40%, transparent); } }
@keyframes tradeBump { 30% { transform: scale(1.02); } }
@keyframes tradeBeat { 50% { transform: scale(1.1); } }
@keyframes tradeNudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); box-shadow: var(--hard-sm), 0 0 18px rgba(61, 220, 114, .7); } }
@keyframes tradeDone { from { opacity: 0; transform: scale(.6) rotate(-4deg); } }
@keyframes tradeStamp { from { opacity: 0; transform: scale(2.4) rotate(-20deg); } }

.reduced-motion .trade-panel,
.reduced-motion .trade-panel *,
.reduced-motion .trade-invite,
.reduced-motion .trade-invite *,
.reduced-motion .trade-done * { animation: none !important; transition: none !important; }

@media (max-width: 720px) {
  .trade-panel { bottom: 0; width: 100vw; max-height: 72vh; border-radius: 22px 22px 0 0; }
  .tp-table { grid-template-columns: minmax(0, 1fr) 54px minmax(0, 1fr); padding: 0 8px; gap: 4px; }
  .tp-side { padding: 7px; }
  .tp-slots { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tp-slot:nth-child(n + 9) { display: none; }
  .tp-slot.filled:nth-child(n + 9) { display: grid; }
  .tp-money { grid-template-columns: 1fr; }
  .tp-arrows i, .tp-count i { width: 40px; height: 40px; }
  .tp-count b { width: 46px; height: 46px; font-size: 1.5rem; }
  .tp-title small, .tp-hint { display: none; }
  .tp-locker { margin: 8px 8px 0; }
  .tp-inv { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); max-height: 130px; }
  .tp-foot { padding: 10px 8px 12px; }
  .tp-lock { min-width: 0; flex: 1; }
  .td-cols { grid-template-columns: 1fr; }
}
