/* ============================================================================
   CHOICE UI (BOF v0.5) — หน้าต่างเลือกของเกม (#custom-choice-modal)
   ยืนยัน (ใช้การ์ด / ยอมแพ้ / สกิล) · ชนะ · แพ้   ใช้คู่กับ choice-ui.js
   ============================================================================ */

/* ---------- โหมดยืนยัน ---------- */
#custom-choice-modal.um-choice .modal-box { max-width: 560px !important; padding: 26px 26px 22px !important; overflow: visible !important; }
.um-choice-icon {
  --ring: 243, 201, 105;
  width: 84px; height: 84px; margin: -66px auto 10px; border-radius: 50%; position: relative;
  display: grid; place-items: center; font-size: 42px; line-height: 1;
  background: radial-gradient(circle at 50% 35%, rgba(var(--ring), .28), rgba(14, 16, 36, .96) 70%);
  border: 2px solid rgba(var(--ring), .85);
  box-shadow: 0 0 0 6px rgba(var(--ring), .12), 0 0 34px rgba(var(--ring), .45), 0 10px 24px rgba(0, 0, 0, .5);
}
.um-choice-icon .um-ico-glyph { display: inline-block; }
.um-choice-icon::after { /* วงแสงหายใจ (opacity ล้วน) */
  content: ""; position: absolute; inset: -10px; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 2px rgba(var(--ring), .55), 0 0 28px rgba(var(--ring), .5);
  animation: um-ring 2.4s ease-in-out infinite;
}
@keyframes um-ring { 0%, 100% { opacity: .15; } 50% { opacity: .9; } }
.um-choice.um-tone-danger .um-choice-icon { --ring: 248, 113, 113; }
.um-choice.um-tone-arcane .um-choice-icon { --ring: 167, 139, 250; }

#custom-choice-modal.um-choice #choice-modal-title {
  background: linear-gradient(100deg, #fff 20%, #f3c969 60%, #fff 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent !important; -webkit-text-fill-color: transparent;
  font-family: var(--font-display); font-size: 24px; line-height: 1.3;
}
#custom-choice-modal.um-choice.um-tone-danger #choice-modal-title { background-image: linear-gradient(100deg, #fff 15%, #fca5a5 60%, #fff 95%); }
#custom-choice-modal.um-choice #choice-modal-desc { color: #c9cde6 !important; font-size: 15px; }
.um-subtitle { display: block; margin-top: 4px; font: 500 13px var(--font-body); color: #9aa1c6; letter-spacing: .02em; }

/* แถวการ์ด: รูปซ้าย ความสามารถขวา */
.um-card-row { display: flex; gap: 16px; align-items: stretch; text-align: left; margin: 4px 0 18px; }
.um-card-row img {
  width: 116px; aspect-ratio: 750 / 1050; object-fit: cover; border-radius: 10px; flex: none;
  border: 1px solid rgba(243, 201, 105, .6); box-shadow: 0 10px 24px rgba(0, 0, 0, .55), 0 0 18px rgba(243, 201, 105, .25);
}
.um-ability {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 14px; white-space: pre-line; line-height: 1.65; font-size: 14px; color: #e8eaf7;
  background: rgba(255, 255, 255, .04); border: 1px solid rgba(160, 175, 255, .16);
}
.um-ability-label { display: block; margin-bottom: 6px; font: 600 12px var(--font-display); letter-spacing: .08em; color: #f3c969; }
.um-stat { display: inline-block; margin: 0 0 8px; padding: 3px 10px; border-radius: 999px; font: 600 12px var(--font-display); color: #1a1405; background: linear-gradient(135deg, #f7d77f, #e0a83c); }

/* ปุ่มตามธีม (แปลงจากสีที่ game.js ส่งมา) */
#choice-modal-buttons .btn { padding: 12px 16px !important; font-size: 15px; letter-spacing: .01em; }
#choice-modal-buttons .btn.um-btn-primary:not(:disabled) { background: linear-gradient(135deg, #f7d77f, #e0a83c) !important; color: #1a1405 !important; box-shadow: 0 8px 22px rgba(243, 201, 105, .28), inset 0 1px 0 rgba(255, 255, 255, .5) !important; }
#choice-modal-buttons .btn.um-btn-danger:not(:disabled) { background: linear-gradient(135deg, #b91c1c, #7f1d1d) !important; color: #fff !important; border: 1px solid rgba(248, 113, 113, .8) !important; box-shadow: 0 0 20px rgba(239, 68, 68, .35) !important; }
#choice-modal-buttons .btn.um-btn-ghost { background: rgba(255, 255, 255, .06) !important; color: #d7dbef !important; border: 1px solid rgba(160, 175, 255, .2) !important; }
#choice-modal-buttons .btn.um-btn-ice:not(:disabled) { background: rgba(127, 211, 255, .12) !important; color: #dff4ff !important; border: 1px solid rgba(127, 211, 255, .6) !important; }
#choice-modal-buttons .btn.um-btn-arcane:not(:disabled) { background: linear-gradient(135deg, #7c5cf0, #4c2fb8) !important; color: #fff !important; border: 1px solid rgba(167, 139, 250, .7) !important; }
#choice-modal-buttons .btn.um-btn-amber:not(:disabled) { background: linear-gradient(135deg, #f59e0b, #b45309) !important; color: #fff !important; }

/* ---------- ตารางเลือกการ์ดด้วยรูปภาพ (ตอนค้นหา / เก็บจากนรก / ชุบ / ไฮบริด) ---------- */
#custom-choice-modal.um-choice.um-has-card-grid .modal-box {
  max-width: 780px !important;
  max-height: 90vh !important;
}
.um-card-pick-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin: 6px 0 16px;
  padding: 12px 10px;
  max-height: 56vh;
  overflow-y: auto;
  border-radius: 14px;
  background: rgba(10, 12, 24, .55);
  border: 1px solid rgba(160, 175, 255, .15);
}
.um-card-pick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: 132px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid rgba(243, 201, 105, .28);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.um-card-pick-item:hover:not(.is-disabled) {
  transform: translateY(-6px) scale(1.03);
  border-color: rgba(243, 201, 105, .95);
  background: rgba(243, 201, 105, .1);
  box-shadow: 0 12px 26px rgba(0, 0, 0, .6), 0 0 20px rgba(243, 201, 105, .38);
}
.um-card-pick-item:active:not(.is-disabled) {
  transform: translateY(-2px) scale(.98);
}
.um-card-pick-item.is-disabled {
  opacity: .42;
  filter: grayscale(.7);
  cursor: not-allowed;
}
/* การ์ดที่แสดงให้ดูอย่างเดียว (ไม่ใช่ตัวเลือก) */
.um-card-pick-item.is-preview { cursor: default; }
.um-card-pick-item.is-preview:hover { transform: none; box-shadow: none; background: rgba(255, 255, 255, .03); }
.um-card-pick-item .card {
  width: 118px;
  height: 162px;
  margin: 0;
  pointer-events: auto;
}
.um-pick-zone-badge {
  display: none !important;
}
.um-pick-caption {
  display: block;
  width: 100%;
  padding: 4px 6px;
  border-radius: 8px;
  font: 600 11.5px/1.3 var(--font-body, sans-serif);
  color: #1a1405;
  background: linear-gradient(135deg, #f7d77f, #e0a83c);
  text-align: center;
  box-shadow: 0 3px 10px rgba(243, 201, 105, .25);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- โหมดชนะ / แพ้ (เต็มจอ) ---------- */
#custom-choice-modal.um-end { background: radial-gradient(ellipse at 50% 45%, rgba(36, 28, 8, .96), rgba(4, 5, 12, .985) 70%) !important; }
#custom-choice-modal.um-end.um-defeat { background: radial-gradient(ellipse at 50% 45%, rgba(36, 6, 10, .96), rgba(3, 3, 8, .985) 72%) !important; }
#custom-choice-modal.um-end .modal-box {
  background: none !important; border: 0 !important; box-shadow: none !important; max-width: 720px !important; overflow: visible !important; position: relative;
}
#custom-choice-modal.um-end .um-choice-icon { width: 110px; height: 110px; margin: 0 auto 6px; font-size: 56px; }
.um-defeat .um-choice-icon { --ring: 248, 113, 113; }
.um-end-word { display: block; font: 800 clamp(56px, 10vw, 112px)/1 var(--font-display); letter-spacing: .14em; margin: 4px 0 6px; padding-left: .14em; }
/* ไล่สีที่ตัวอักษรแต่ละตัว (ถ้าไล่ที่กล่องแม่ Chromium จะไม่วาดตัวลูกที่เป็น inline-block) */
.um-end-char {
  background: linear-gradient(180deg, #fff6d8 0%, #f3c969 45%, #b9822d 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
/* เงาเรืองแสงใต้ป้าย: ชั้นแยกที่ไม่ขยับ (ไม่ใช้ filter บนตัวอักษรที่กำลังเคลื่อนไหว) */
.um-end-glow { position: absolute; left: 50%; width: 70%; height: 90px; margin-left: -35%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(ellipse, rgba(243, 201, 105, .28), rgba(243, 201, 105, 0) 70%); }
.um-defeat .um-end-glow { background: radial-gradient(ellipse, rgba(239, 68, 68, .26), rgba(239, 68, 68, 0) 70%); }
.um-defeat .um-end-char { background-image: linear-gradient(180deg, #fecaca 0%, #ef4444 50%, #7f1d1d 100%); }
.um-end-char { display: inline-block; }
#custom-choice-modal.um-end #choice-modal-title {
  color: #fff !important; -webkit-text-fill-color: #fff; background: none; font: 600 22px var(--font-display);
}
#custom-choice-modal.um-end #choice-modal-desc { color: #c9cde6 !important; }
#custom-choice-modal.um-end #choice-modal-buttons { flex-direction: row !important; justify-content: center; gap: 14px !important; margin-top: 8px; }
#custom-choice-modal.um-end #choice-modal-buttons .btn { min-width: 220px; }
.um-burst {
  position: absolute; left: 50%; top: 32%; width: 520px; height: 520px; margin: -260px 0 0 -260px; border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, rgba(255, 240, 200, .75) 0%, rgba(243, 201, 105, .3) 30%, rgba(243, 201, 105, 0) 65%);
}
.um-spark {
  position: absolute; left: 50%; top: 32%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, #fff 0 25%, rgba(255, 214, 120, .9) 45%, rgba(255, 200, 90, 0) 70%);
}
.um-vignette {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 45%, rgba(140, 10, 20, .55) 100%);
}

/* PERF: ประกาย/วงแสงแยกเลเยอร์ ไม่ให้พื้นหลังไล่สีเต็มจอถูกวาดใหม่ทุกเฟรม */
.um-burst, .um-spark, .um-vignette { will-change: transform, opacity; }

@media (max-width: 640px) {
  .um-card-row { flex-direction: column; align-items: center; }
  #custom-choice-modal.um-end #choice-modal-buttons { flex-direction: column !important; }
  #custom-choice-modal.um-end #choice-modal-buttons .btn { min-width: 0; }

  #custom-choice-modal .modal-box {
    width: calc(100vw - 20px) !important;
    max-width: 480px;
    max-height: 88dvh;
    padding: 16px 14px;
    border-radius: 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #choice-modal-title {
    font-size: 18px;
  }

  #choice-modal-desc {
    font-size: 13px;
    margin: 8px 0 14px 0;
    line-height: 1.4;
  }

  #choice-modal-buttons {
    gap: 8px;
  }

  #choice-modal-buttons .btn {
    font-size: 13px;
    padding: 10px 14px;
    min-height: 42px;
    touch-action: manipulation;
  }
}
@media (prefers-reduced-motion: reduce) { .um-choice-icon::after { animation: none; } }
/* ป้ายใต้การ์ดที่เปิดให้ดูอย่างเดียว (ไม่ใช่ตัวเลือก) */
.um-pick-caption.is-peek { background: rgba(255, 255, 255, .08); color: #cbd5e1; box-shadow: none; }
/* รูปการ์ดที่ตัวชี้เป้าโหมดฝึกเลือก: เรืองทองแทนกรอบปุ่ม */
.um-card-pick-item.bof-guided-highlight { overflow: visible !important; border-color: #ffe39a !important; animation-name: bofGuidePulseFlat !important; }

/* ---------- ปุ่มดูสนาม (Peek Field) และโหมดดูสนาม ---------- */
.btn-peek-field {
  position: absolute;
  top: 14px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #38bdf8;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  z-index: 20;
}
.btn-peek-field:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
  color: #fff;
  transform: translateY(-1px);
}
.modal-overlay.is-peeking-field {
  background: transparent !important;
  backdrop-filter: none !important;
  pointer-events: none !important;
}
.modal-overlay.is-peeking-field .modal-box {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition: opacity 0.15s ease, transform 0.15s ease !important;
}
.um-card-pick-item.is-selected {
  border-color: #38bdf8 !important;
  background: rgba(56, 189, 248, 0.22) !important;
  box-shadow: 0 0 22px rgba(56, 189, 248, 0.65), 0 8px 24px rgba(0, 0, 0, 0.7) !important;
  transform: translateY(-4px) scale(1.04);
}
.um-card-pick-item.is-selected .um-pick-caption {
  background: #0284c7 !important;
  color: #fff !important;
  font-weight: bold;
}
.bof-peek-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: rgba(15, 23, 42, 0.94);
  border: 2px solid #38bdf8;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 0 20px rgba(56, 189, 248, 0.35);
  border-radius: 9999px;
  color: #f8fafc;
  z-index: 999999;
  font-family: var(--font-display, 'Kanit', sans-serif);
  animation: bofPeekSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto !important;
}
@keyframes bofPeekSlideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.bof-peek-bar .peek-status-text {
  font-size: 14px;
  font-weight: 500;
  color: #cbd5e1;
}
.bof-peek-bar .peek-return-btn {
  padding: 6px 14px;
  background: #0284c7;
  border: none;
  border-radius: 20px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.bof-peek-bar .peek-return-btn:hover {
  background: #0369a1;
}
@media (max-width: 768px) {
  .btn-peek-field {
    top: 10px;
    right: 12px;
    padding: 5px 10px;
    font-size: 12px;
  }
  .bof-peek-bar {
    bottom: 16px;
    padding: 8px 14px;
    gap: 8px;
    width: min(92%, 360px);
    justify-content: space-between;
  }
  .bof-peek-bar .peek-status-text {
    font-size: 12.5px;
  }
  .bof-peek-bar .peek-return-btn {
    padding: 5px 10px;
    font-size: 12px;
  }
}
