/* 石器翻翻棋：卡牌、棋盘、大厅与卡组编辑（依赖 fun.css 的色板与通用组件）。
   手机防闪屏：不给大量卡牌加常驻 will-change 或 filter；悬停效果只给鼠标设备。 */

/* ================= 卡牌 ================= */
.tcard {
  --cw: 76px;
  --own-a: #fffdf6;
  --own-b: #f3e9d6;
  --edge: #fff;
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: var(--cw);
  aspect-ratio: 5 / 6;
  overflow: hidden;
  background: linear-gradient(160deg, var(--own-a), var(--own-b));
  border: 3px solid var(--edge);
  border-radius: 12px;
  box-shadow: 0 4px 0 rgba(90, 50, 120, .18);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.tcard img {
  width: 72%;
  height: 64%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}
.tcard.own0 { --own-a: #ffe1ec; --own-b: #ffb3cf; }
.tcard.own1 { --own-a: #dff0ff; --own-b: #a9d4ff; }
.tcard.r-R { --edge: #cfe5ff; }
.tcard.r-SR { --edge: #d9c9ff; }
.tcard.r-SSR { --edge: #ffd76a; box-shadow: 0 4px 0 rgba(90, 50, 120, .18), 0 0 10px 1px rgba(255, 197, 58, .75); }
.tn {
  position: absolute;
  z-index: 2;
  min-width: 1.1em;
  color: #fff;
  font-family: var(--font-title);
  font-size: calc(var(--cw) * .2);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  text-shadow: -1px -1px 0 #4a2a5e, 1px -1px 0 #4a2a5e, -1px 1px 0 #4a2a5e, 1px 1px 0 #4a2a5e, 0 2px 0 #4a2a5e;
  pointer-events: none;
}
.tn-t { top: 3%; left: 50%; transform: translateX(-50%); }
.tn-b { bottom: 3%; left: 50%; transform: translateX(-50%); }
.tn-l { top: 50%; left: 4%; transform: translateY(-50%); }
.tn-r { top: 50%; right: 4%; transform: translateY(-50%); }
.tel {
  position: absolute;
  top: 3px;
  left: 3px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: calc(var(--cw) * .22);
  height: calc(var(--cw) * .22);
  min-width: 14px;
  min-height: 14px;
  color: #fff;
  background: #a9a2b3;
  border: 1.5px solid #fff;
  border-radius: 50%;
  font-size: calc(var(--cw) * .12);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}
.tcard.el0 .tel { background: #c9922c; }
.tcard.el1 .tel { background: #3b9cf3; }
.tcard.el2 .tel { background: #ff5a3c; }
.tcard.el3 .tel { background: #37b35a; }
.tadj {
  position: absolute;
  right: 3px;
  bottom: 3px;
  z-index: 2;
  padding: 0 4px;
  color: #fff;
  border-radius: 6px;
  font-size: calc(var(--cw) * .13);
  font-weight: 800;
  pointer-events: none;
}
.tadj.up { background: #22b37a; }
.tadj.down { background: #e2514b; }
.tcard-empty {
  color: #c5b8d2;
  background: repeating-linear-gradient(45deg, #faf6fc, #faf6fc 6px, #f3ecf7 6px, #f3ecf7 12px);
  border: 3px dashed #e3d7ee;
  box-shadow: none;
  font-family: var(--font-title);
  font-size: 26px;
}
.tcard-used { background: #f4eff6; border: 3px dashed #e8dff0; box-shadow: none; opacity: .55; }
.tcard-miss { color: var(--muted); font-size: 22px; }
.tcard.pickable { cursor: pointer; transition: transform .25s var(--jelly), box-shadow .2s ease; }
.tcard.pickable:focus-visible { outline: 3px solid var(--lemon); outline-offset: 2px; }
.tcard.selected { transform: translateY(-10px) scale(1.06); box-shadow: 0 10px 0 rgba(212, 67, 122, .25), 0 0 0 4px #ffc53a; }
.tcard.in-deck::after {
  content: "✓";
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255, 111, 165, .45);
  font-size: 30px;
  font-weight: 800;
}
.tcard.drop { animation: duel-drop .38s var(--jelly); }
.tcard.flipping { animation: duel-flip .42s ease-in-out; }
@keyframes duel-drop { from { transform: translateY(-18px) scale(1.18); opacity: .4; } }
@keyframes duel-flip { 0% { transform: scaleX(1); } 45% { transform: scaleX(.05) scaleY(1.08); } 100% { transform: scaleX(1); } }

/* ================= 大厅 ================= */
.duel-deck-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.duel-deck { display: flex; flex-wrap: wrap; gap: 8px; }
.duel-deck .tcard { --cw: 72px; }
.duel-deck.mini .tcard { --cw: 46px; border-width: 2px; border-radius: 9px; }
.duel-deck-acts { display: flex; flex-wrap: wrap; gap: 10px; }
.duel-tabs { display: flex; flex-wrap: wrap; margin-bottom: 12px; }
.duel-tabs button { flex: 1; min-width: 72px; }

.rule-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.rule-chips.small { justify-content: flex-start; margin: 4px 0; }
.chip { padding: 1px 10px; color: #6a48c9; background: #f1ebff; border-radius: 999px; font-size: 12px; font-weight: 800; }
.chip-elem { color: #b85a12; background: #fff0dc; }
.chip-board { color: #1f8f6f; background: #dcf6ee; }
.chip-same { color: #c23a73; background: #ffe3ef; }
.chip-plus { color: #2a6cbd; background: #e2f0ff; }
.ai-stars i { color: #e2d8ec; font-style: normal; }
.ai-stars i.on { color: #ffb43a; }

.gym-list { display: grid; gap: 10px; }
.gym {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: #fff;
  border: 3px solid #f1e7f6;
  border-radius: 18px;
}
.gym.next { border-color: #ffc5dc; background: linear-gradient(90deg, #fff, #fff4f9); }
.gym.done { border-color: #cdeedd; }
.gym.locked { opacity: .55; }
.gym-img { width: 64px; height: 64px; object-fit: contain; }
.gym-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.gym-title b { font-size: 15px; }
.gym-deck { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.gym .rewards { margin-top: 4px; }

.ladder-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.ladder-stats div { padding: 8px; text-align: center; background: #fff; border-radius: 14px; }
.ladder-stats small { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.ladder-stats b { color: var(--sky); font-size: 18px; }
.ladder-warn { margin: 10px 0 0; padding: 10px 12px; color: #b85a12; background: #fff3e0; border-radius: 12px; font-size: 13px; font-weight: 700; }
.ladder-head { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 8px; }
.ladder-head h3 { margin: 0; font-family: var(--font-title); font-size: 18px; letter-spacing: 1px; }
.opp-list { display: grid; gap: 10px; }
.opp {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: #fff;
  border: 3px solid #e2f0ff;
  border-radius: 18px;
}
.opp-head { display: grid; gap: 2px; min-width: 0; }
.opp-head b { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.opp-rating { color: var(--sky); font-weight: 800; font-size: 13px; }
.opp-head small { color: var(--muted); font-size: 12px; }

.practice-form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 10px; }
.practice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 800; }
.practice-check { display: inline-flex; align-items: center; gap: 4px; font-size: 13.5px; font-weight: 700; cursor: pointer; }
.practice-check input { width: 16px; height: 16px; accent-color: var(--grape); }

/* ================= 对局 ================= */
.duel-match { display: grid; gap: 10px; justify-items: center; }
.match-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; width: 100%; }
.match-side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match-side.me { justify-content: flex-end; text-align: right; }
.match-side img { width: 46px; height: 46px; object-fit: contain; }
.match-side div { display: grid; min-width: 0; }
.match-side b { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.match-side small { color: var(--muted); font-size: 12px; font-weight: 700; }
.match-score { display: flex; align-items: center; gap: 6px; font-family: var(--font-title); font-size: 30px; }
.match-score b:first-child { color: #ff5c98; }
.match-score b:last-child { color: var(--sky); }
.match-score span { color: var(--muted); }
.match-score { flex-direction: row-reverse; }

.hand { display: flex; flex-wrap: nowrap; justify-content: center; gap: clamp(4px, 1.5vw, 10px); width: 100%; padding: 4px 0; }
.hand .tcard { --cw: clamp(54px, 16vw, 80px); }
.hand-opp .tcard { --cw: clamp(46px, 13vw, 64px); }
.board-wrap { position: relative; width: min(100%, 372px); }
.duel-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(5px, 1.6vw, 9px);
  padding: clamp(6px, 2vw, 12px);
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, .5) 0 18px, transparent 19px),
    linear-gradient(160deg, #bfe8a6, #8fd07a);
  border: 4px solid #fff;
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 5 / 6;
  background: rgba(255, 255, 255, .45);
  border: 2px dashed rgba(255, 255, 255, .9);
  border-radius: 14px;
}
.cell .tcard { --cw: 100%; width: 100%; border-radius: 12px; }
.cell .tcard .tn { font-size: clamp(14px, 5vw, 22px); }
.field-mark {
  position: absolute;
  color: rgba(255, 255, 255, .85);
  font-family: var(--font-title);
  font-size: clamp(22px, 8vw, 36px);
  pointer-events: none;
}
.cell.fel0 { background: rgba(201, 146, 44, .35); }
.cell.fel1 { background: rgba(59, 156, 243, .32); }
.cell.fel2 { background: rgba(255, 90, 60, .32); }
.cell.fel3 { background: rgba(55, 179, 90, .32); }
.can-drop .cell.empty { cursor: pointer; border-color: #fff; border-style: solid; box-shadow: inset 0 0 0 3px rgba(255, 197, 58, .8); }
.board-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  padding: 8px 18px;
  color: #fff;
  background: linear-gradient(180deg, #ff8fbc, #ff5c98);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-family: var(--font-title);
  font-size: 22px;
  letter-spacing: 2px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.board-banner.by1 { background: linear-gradient(180deg, #6ab8ff, #3b8fe8); }
.board-banner.show { animation: duel-banner 1.2s var(--jelly) forwards; }
@keyframes duel-banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}
.turn-tip { min-height: 22px; color: var(--grape); font-size: 14px; font-weight: 800; text-align: center; }
.match-acts { display: flex; justify-content: center; }

.duel-result { text-align: center; }
.result-big { font-family: var(--font-title); font-size: 44px; letter-spacing: 4px; }
.result-big.win { color: #ff5c98; }
.result-big.draw { color: var(--grape); }
.result-big.lose { color: #8a96a8; }
.result-score { margin: 4px 0 8px; font-size: 16px; font-weight: 800; }
.result-line { margin: 6px 0; font-weight: 700; }

/* ================= 卡组编辑 ================= */
.deck-editor { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: 12px; background: rgba(58, 47, 69, .45); }
.deck-editor-card {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 10px;
  width: min(100%, 860px);
  max-height: calc(100vh - 24px);
  padding: 16px;
  background: var(--card);
  border: 4px solid #fff;
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
}
.de-head { display: flex; align-items: center; justify-content: space-between; }
.de-head h2 { margin: 0; font-family: var(--font-title); font-size: 22px; letter-spacing: 2px; }
.de-picked { justify-content: center; padding: 8px; background: #fff6fa; border-radius: 16px; }
.de-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.de-filter input {
  flex: 1;
  min-width: 120px;
  height: 36px;
  padding: 0 12px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
}
.de-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 10px 8px;
  min-height: 120px;
  overflow-y: auto;
  padding: 4px 2px 8px;
  overscroll-behavior: contain;
}
.de-item { display: grid; justify-items: center; gap: 2px; }
.de-item .tcard { --cw: 74px; }
.de-name { max-width: 100%; overflow: hidden; color: var(--muted); font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

@media (hover: hover) and (pointer: fine) {
  .tcard.pickable:hover { transform: translateY(-4px); }
  .tcard.selected:hover { transform: translateY(-10px) scale(1.06); }
  .can-drop .cell.empty:hover { background: rgba(255, 255, 255, .75); }
}
@media (max-width: 720px) {
  .gym { grid-template-columns: 48px minmax(0, 1fr); }
  .gym-img { width: 48px; height: 48px; }
  .gym .btn { grid-column: 1 / -1; }
  .opp { grid-template-columns: minmax(0, 1fr) auto; }
  .opp .duel-deck { grid-column: 1 / -1; order: 3; }
  .ladder-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .duel-deck .tcard { --cw: clamp(52px, 16vw, 72px); }
}
@media (max-width: 420px) {
  .match-score { font-size: 24px; }
  .match-side img { width: 36px; height: 36px; }
  .board-banner { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .tcard.drop, .tcard.flipping, .board-banner.show { animation: none; }
}
