/* ============================================================================
   HOLO CARD + MODERN UI LAYER  (โหลดหลัง style.css)
   - การ์ด 3D ประกายฟอยล์ตามระดับความหายาก (data-rarity: N / R / SR / Legend)
   - หน้า Inspect การ์ดใบใหญ่ (แทน detail modal เดิม)
   - ธีมฟอนต์/สีใหม่สำหรับล็อบบี้ Deck Builder และโมดอล
   ============================================================================ */
:root {
  --ui-bg: #0b0d1a;
  --ui-bg-2: #141833;
  --ui-panel: rgba(22, 26, 52, .66);
  --ui-line: rgba(160, 175, 255, .16);
  --ui-fg: #e8eaf7;
  --ui-muted: #9aa1c6;
  --ui-gold: #f3c969;
  --ui-ice: #7fd3ff;
  --rar-n: #8f97b8;
  --rar-r: #4fa7ff;
  --rar-sr: #ff5a6e;
  --rar-legend: #f3c969;
  --font-display: 'Kanit', 'Noto Sans Thai', 'Segoe UI', Tahoma, sans-serif;
  --font-body: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Segoe UI', Tahoma, sans-serif;
  --ease-out: cubic-bezier(.2, .9, .25, 1);
}

/* ---------- ฟอนต์และพื้นหลังทั้งเกม ---------- */
* { font-family: var(--font-body); }
body {
  background: radial-gradient(120% 70% at 50% 0%, #1d2350 0%, var(--ui-bg) 62%) fixed, var(--ui-bg);
  color: var(--ui-fg);
}
h1, h2, h3, .btn, .card-name, .card-power, .card-type,
.leader-name-text, .phase-pill, #turn-indicator, .pile-label, .deck-section-title {
  font-family: var(--font-display);
}

/* ---------- โมดอลและ Deck Builder: กระจกเบลอ ---------- */
/* PERF: ไม่ใช้ backdrop-filter เต็มจอ เพราะการ์ดด้านหลังขยับตลอด ต้องเบลอใหม่ทุกเฟรม */
.modal-overlay { background: rgba(6, 8, 20, .86); }
.modal-box, .deck-builder-box {
  background: linear-gradient(180deg, rgba(30, 35, 70, .92), rgba(16, 19, 40, .94));
  border: 1px solid var(--ui-line); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.06);
}
.deck-section-title { color: var(--ui-gold); letter-spacing: .02em; }
.btn { border-radius: 10px; transition: transform .15s, filter .15s, background .15s; }
.btn:not(:disabled):active { transform: scale(.97); }

/* ---------- กระดานเล่น: เปลี่ยนแค่สี ---------- */
.side-zone, .center-bar, .info-box {
  background-color: rgba(20, 24, 50, .72);
  border-color: var(--ui-line);
}

/* ============================================================================
   HOLO CARD
   ============================================================================ */
.card {
  --rx: 0deg; --ry: 0deg; --px: 0; --py: 0; --hyp: 0; --lift: 0px; --glow: var(--rar-n);
}
.card[data-rarity="R"] { --glow: var(--rar-r); }
.card[data-rarity="SR"] { --glow: var(--rar-sr); }
.card[data-rarity="SSR"], .card[data-rarity="Legend"] {
  --glow: var(--rar-legend);
  border-color: #fde047 !important;
  box-shadow:
    0 6px 16px rgba(0,0,0,.6),
    0 0 0 2px #fde047,
    0 0 22px rgba(250, 204, 21, .88),
    0 0 40px rgba(245, 158, 11, .5) !important;
}
.card[data-rarity]:not([data-rarity="N"]) {
  box-shadow: 0 6px 14px rgba(0,0,0,.5), 0 0 0 1.5px color-mix(in srgb, var(--glow) 75%, transparent),
              0 0 14px color-mix(in srgb, var(--glow) 50%, transparent);
}

/* เลเยอร์ประกาย อยู่ใน .card-art (z-index 0) จึงอยู่ใต้ตัวหนังสือบนการ์ดเสมอ */
.card-art { overflow: hidden; border-radius: inherit; }
.holo-layer { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; overflow: hidden; }
/* PERF: พื้นผิวประกายวาดครั้งเดียว แล้วเลื่อนด้วย transform เท่านั้น */
.holo-layer > i { position: absolute; inset: -50%; display: block; }
.holo-foil {
  --strength: 0;
  mix-blend-mode: color-dodge;
  opacity: calc(var(--strength) * (.35 + .55 * var(--hyp)));
  -webkit-mask-image: linear-gradient(to bottom, #000 0 68%, rgba(0,0,0,.25) 74% 100%);
          mask-image: linear-gradient(to bottom, #000 0 68%, rgba(0,0,0,.25) 74% 100%);
}
.holo-foil > i {
  background: repeating-linear-gradient(115deg, #d9557f 0%, #d9ad4f 6%, #5fd394 12%, #4fadd9 18%, #946bd9 24%, #d9557f 30%);
  transform: translate(calc(var(--px) * -40%), calc(var(--py) * -40%));
}
.card:not(.holo-live) .holo-foil > i { animation: holo-flow 5.5s ease-in-out infinite alternate; }
@keyframes holo-flow { from { transform: translate(-18%, -14%); } to { transform: translate(18%, 14%); } }
.card[data-rarity="R"] .holo-foil { --strength: .45; }
.card[data-rarity="SR"] .holo-foil { --strength: .75; }
.card[data-rarity="SSR"] .holo-foil,
.card[data-rarity="Legend"] .holo-foil { --strength: 1; }
.card[data-rarity="SR"]:not(.holo-live) .holo-foil { opacity: calc(var(--strength) * .52); }
.card[data-rarity="SSR"]:not(.holo-live) .holo-foil,
.card[data-rarity="Legend"]:not(.holo-live) .holo-foil { opacity: .68; }

.holo-sparkle {
  mix-blend-mode: color-dodge;
  opacity: calc(var(--spark, 0) * (.45 + .55 * var(--hyp)));
  -webkit-mask-image: radial-gradient(circle at 50% 42%, #000 0%, rgba(0,0,0,.55) 48%, transparent 82%);
          mask-image: radial-gradient(circle at 50% 42%, #000 0%, rgba(0,0,0,.55) 48%, transparent 82%);
}
.holo-sparkle > i { background-size: 180px 180px; transform: translate(calc(var(--px) * -12%), calc(var(--py) * -12%)); }
.card[data-rarity="SR"] { --spark: .6; }
.card[data-rarity="SSR"], .card[data-rarity="Legend"], .lb-leader[data-rarity="SSR"] { --spark: 1; }
.holo-glare { mix-blend-mode: overlay; opacity: calc(.65 * var(--hyp)); }
.holo-glare > i {
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.55) 0%, rgba(255,255,255,.12) 13%, rgba(0,0,0,.3) 45%);
  transform: translate(calc(var(--px) * 50%), calc(var(--py) * 50%));
}
.card[data-rarity="SSR"] .holo-sheen,
.card[data-rarity="Legend"] .holo-sheen,
.holo-bigcard[data-rarity="SSR"] .holo-sheen,
.holo-bigcard[data-rarity="Legend"] .holo-sheen,
.lb-leader[data-rarity="SSR"] .holo-sheen { mix-blend-mode: screen; }
.card[data-rarity="SSR"] .holo-sheen::before,
.card[data-rarity="Legend"] .holo-sheen::before,
.holo-bigcard[data-rarity="SSR"] .holo-sheen::before,
.holo-bigcard[data-rarity="Legend"] .holo-sheen::before,
.lb-leader[data-rarity="SSR"] .holo-sheen::before {
  content: ""; position: absolute; inset: 0 -150%;
  background: linear-gradient(
    112deg,
    transparent 34%,
    rgba(255, 224, 102, 0.28) 43%,
    rgba(255, 250, 210, 0.85) 50%,
    rgba(255, 215, 64, 0.35) 57%,
    transparent 66%
  );
  animation: holo-sheen 2.8s ease-in-out infinite;
}
@keyframes holo-sheen { from { transform: translateX(42%); } to { transform: translateX(-42%); } }

.holo-stars { -webkit-mask-image: linear-gradient(to bottom, #000 0 62%, transparent 68%); mask-image: linear-gradient(to bottom, #000 0 62%, transparent 68%); }
.holo-tw {
  position: absolute; width: var(--sz, 13%); aspect-ratio: 1; translate: -50% -50%;
  background:
    radial-gradient(circle, #fff 0 6%, rgba(255,255,255,0) 22%),
    linear-gradient(90deg, transparent 47%, rgba(255,255,255,.95) 50%, transparent 53%),
    linear-gradient(0deg, transparent 47%, rgba(255,255,255,.95) 50%, transparent 53%);
  -webkit-mask-image: radial-gradient(circle, #000 0 20%, transparent 70%); mask-image: radial-gradient(circle, #000 0 20%, transparent 70%);
  /* PERF: ห้ามใส่ mix-blend-mode ให้ดาวที่ขยับอยู่บนการ์ด 3D: เบราว์เซอร์จะสร้างพื้นผิวเรนเดอร์ใหม่ทุกเฟรมจน RAM เต็ม การ์ดหาย/ค้าง */
  filter: drop-shadow(0 0 4px var(--tc, #fff));
  opacity: 0; scale: 0;
  animation: holo-twinkle var(--dur, 2.6s) var(--delay, 0s) ease-in-out infinite;
}
@keyframes holo-twinkle {
  0%, 62%, 100% { opacity: 0; scale: 0; rotate: 0deg; }
  74% { opacity: 1; scale: 1; rotate: 45deg; }
  86% { opacity: .2; scale: .4; rotate: 90deg; }
}

/* ปุ่ม ⓘ เปิดหน้าดูการ์ด */
.holo-info-btn {
  position: absolute; top: 40%; right: 4px; z-index: 5;
  width: 22px; height: 22px; border-radius: 50%; padding: 0;
  border: 1px solid rgba(255,255,255,.35); background: rgba(10, 12, 28, .65); color: #fff;
  font: 600 12px/20px var(--font-display); cursor: pointer; opacity: .85;
}
.holo-info-btn:hover, .holo-info-btn:focus-visible { opacity: 1; outline: 2px solid var(--ui-ice); outline-offset: 1px; }

/* การ์ดบนมือ: เอียง 3D ตามเมาส์ (ใช้ --lift แทน translateY เดิม เพื่อไม่ให้ transform ชนกัน) */
#player-hand .card {
  transform: perspective(600px) translateY(var(--lift)) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .45s var(--ease-out), box-shadow .3s;
}
#player-hand .card.holo-live { transition: transform .08s linear, box-shadow .3s; }
#player-hand .card:hover { --lift: -4px; }
#player-hand .card.selected-hand { --lift: -8px; }

/* การ์ดบนสนาม: ไม่มี 3D/ประกายเคลื่อนไหว เหลือแค่ขอบเรืองแสงตามระดับ */
.board-slots .holo-layer, .board-slots .holo-info-btn { display: none; }

/* ---------- แอนิเมชันตามเหตุการณ์ ---------- */
/* จั่วการ์ด: บินเข้ามือพร้อมแสงวาบ */
#player-hand .card.fx-holo-draw { animation: holo-draw .6s var(--ease-out) both; }
@keyframes holo-draw {
  from { opacity: 0; translate: 0 -40px; scale: .7; filter: brightness(2.2); }
  60% { opacity: 1; filter: brightness(1.4); }
  to { translate: 0 0; scale: 1; filter: none; }
}

/* ============================================================================
   INSPECT การ์ดใบใหญ่
   ============================================================================ */
.holo-inspect {
  position: fixed; inset: 0; z-index: 2500; display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  /* ห้ามใส่ backdrop-filter ที่นี่: ด้านหลังมีการ์ดเล่นแอนิเมชันตลอดเวลา ทำให้ต้องเบลอใหม่ทุกเฟรมจนหน้าค้าง */
  background: rgba(6, 8, 20, .9);
  opacity: 0; transition: opacity .3s;
}
/* ระหว่างเปิด Inspect หยุดแอนิเมชันประกายของการ์ดที่อยู่ข้างหลัง */
body.holo-inspecting .card .holo-foil > i, body.holo-inspecting .card .holo-sheen::before, body.holo-inspecting .card .holo-tw { animation-play-state: paused; }
.holo-inspect[hidden] { display: none; }
.holo-inspect.open { opacity: 1; }
.holo-stage { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 340px); gap: clamp(18px, 4vw, 48px); align-items: center; width: 100%; max-width: 820px; }
.holo-big { position: relative; perspective: 1100px; width: 100%; touch-action: none; }
.holo-bigcard {
  --rx: 0deg; --ry: 0deg; --px: 0; --py: 0; --hyp: 0; --glow: var(--rar-n);
  position: relative; aspect-ratio: 750 / 1050; width: 100%; will-change: transform;
  border-radius: 4.2% / 3%; background: #000; cursor: grab;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .5s var(--ease-out), box-shadow .3s;
  box-shadow: 0 14px 30px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.06);
}
.holo-bigcard.holo-live { transition: transform .08s linear, box-shadow .3s; }
.holo-bigcard.dragging { cursor: grabbing; }
.holo-bigcard[data-rarity="R"] { --glow: var(--rar-r); }
.holo-bigcard[data-rarity="SR"] { --glow: var(--rar-sr); --spark: .6; }
.holo-bigcard[data-rarity="SSR"], .holo-bigcard[data-rarity="Legend"] { --glow: var(--rar-legend); --spark: 1; }
.holo-bigcard:not([data-rarity="N"]) {
  box-shadow: 0 14px 30px rgba(0,0,0,.5), 0 0 0 1.5px color-mix(in srgb, var(--glow) 75%, transparent),
              0 0 20px color-mix(in srgb, var(--glow) 55%, transparent);
}
.holo-bigcard[data-rarity="R"] .holo-foil { --strength: .45; }
.holo-bigcard[data-rarity="SR"] .holo-foil { --strength: .75; }
.holo-bigcard[data-rarity="SSR"] .holo-foil, .holo-bigcard[data-rarity="Legend"] .holo-foil { --strength: 1; }
.holo-bigcard[data-rarity="SSR"]:not(.holo-live) .holo-foil, .holo-bigcard[data-rarity="Legend"]:not(.holo-live) .holo-foil { opacity: .68; }
.holo-bigcard:not(.holo-live) .holo-foil > i { animation: holo-flow 5.5s ease-in-out infinite alternate; }
.holo-bigcard .holo-glare { opacity: calc(.15 + .6 * var(--hyp)); }
.holo-bigcard img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; user-select: none; -webkit-user-drag: none; }
#holo-fx { position: absolute; left: -30%; top: -20%; width: 160%; height: 140%; pointer-events: none; z-index: -1; }

.holo-info {
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 16px; padding: 20px;
  display: grid; gap: 14px; text-align: left; color: var(--ui-fg);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
  opacity: 0; transform: translateX(16px); transition: opacity .35s .15s, transform .45s .15s var(--ease-out);
}
.holo-inspect.open .holo-info { opacity: 1; transform: none; }
.holo-info h2 { margin: 0; font: 700 26px/1.15 var(--font-display); color: #fff; text-wrap: balance; }
.holo-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.holo-chip { font: 600 11px/1 var(--font-display); letter-spacing: .08em; padding: 6px 10px; border-radius: 999px; border: 1px solid currentColor; }
.holo-chip.N { color: var(--rar-n); } .holo-chip.R { color: var(--rar-r); } .holo-chip.SR { color: var(--rar-sr); } .holo-chip.SSR, .holo-chip.Legend { color: var(--rar-legend); }
.holo-tag { font: 500 12px var(--font-display); color: var(--ui-muted); padding: 5px 10px; border-radius: 8px; background: rgba(255,255,255,.05); }
.holo-stats { white-space: pre-line; font: 500 14px/1.6 var(--font-body); color: #b9f5c9; }
.holo-desc { white-space: pre-line; line-height: 1.7; font-size: 14px; color: #d5d9f0; border-top: 1px solid var(--ui-line); padding-top: 12px; }
.holo-close {
  position: absolute; top: max(14px, env(safe-area-inset-top, 0px)); right: max(14px, env(safe-area-inset-right, 0px));
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--ui-line); background: var(--ui-panel); color: var(--ui-fg); font-size: 20px; cursor: pointer;
}
.holo-close:focus-visible { outline: 2px solid var(--ui-ice); outline-offset: 2px; }
@media (max-width: 700px) {
  .holo-inspect { overflow-y: auto; place-items: start center; }
  .holo-stage { grid-template-columns: 1fr; justify-items: center; padding-top: 48px; }
  .holo-big { width: min(74vw, 330px); }
  .holo-info { width: 100%; transform: translateY(16px); }
}

/* ---------- ลดการเคลื่อนไหว ---------- */
@media (prefers-reduced-motion: reduce) {
  #player-hand .card, .holo-bigcard { transition: none; transform: none !important; }
  .holo-foil > i, .holo-sheen::before, .holo-tw, .fx-holo-draw { animation: none !important; }
  .holo-tw { display: none; }
  .holo-inspect, .holo-info { transition: none; }
}

/* ใน Deck Builder ปิดเฉพาะการ์ดระดับ N-SR เพื่อความลื่นไหล แต่ให้การ์ด SSR แสดงฟอยล์และประกายทองเต็มที่! */
#main-pool-list .card:not([data-rarity="SSR"]) .holo-foil > i { animation: none; }
#main-pool-list .card:not([data-rarity="SSR"]) .holo-stars,
#main-pool-list .card:not([data-rarity="SSR"]) .holo-sparkle { display: none; }

/* ---------- อุปกรณ์สัมผัส (มือถือ/แท็บเล็ต): ลดงาน GPU ----------
   blur พื้นหลังบนพื้นที่ใหญ่และโฮโลวนบนการ์ดเล็กหลายใบ ทำให้เฟรมตกบนมือถือ
   การ์ดใบใหญ่ (.holo-bigcard) ยังเล่นโฮโลเต็มเหมือนเดิม */
@media (hover: none), (pointer: coarse) {
  .mat-half, .deck-count-badge, #bof-game-arena .player-mat-half .hand-row { backdrop-filter: none; }
  #bof-game-arena .player-mat-half .hand-row { background: rgba(8, 10, 20, .55); }
  .card .holo-foil > i, .card .holo-sheen::before, .card .holo-tw { animation: none !important; }
}
