/* =====================================================================
   View Transitions (เลียนแบบพฤติกรรมเว็บต้นฉบับ)
   - ทั้งหน้า cross-fade สั้นๆ 0.2s
   - อวาตาร์ "stage-avatar" ย้ายตำแหน่ง/ขนาดข้ามหน้าแบบ morph 0.5s
   - header ไม่ fade (คงที่ระหว่างเปลี่ยนหน้า)
   ===================================================================== */
::view-transition-old(root),
::view-transition-new(root) { animation-duration: .2s; }

.topbar { view-transition-name: topbar; }

::view-transition-group(stage-avatar) {
  animation-duration: .5s;
  animation-timing-function: cubic-bezier(.2, 0, 0, 1);
  z-index: 50;
}
::view-transition-old(stage-avatar),
::view-transition-new(stage-avatar) {
  width: auto; height: 100%; left: 50%; transform: translateX(-50%);
  animation: none;
}
::view-transition-old(stage-avatar) { opacity: 0; }
::view-transition-new(stage-avatar) { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* =====================================================================
   Keyframes
   ===================================================================== */
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes card-enter { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes hero-drop {
  0% { opacity: 0; transform: translateY(-56px); }
  55% { opacity: 1; transform: translateY(0) scale(1.06, .92); }
  78% { transform: scale(.98, 1.03); }
  100% { opacity: 1; transform: none; }
}
@keyframes hero-shadow { 0%, 50% { opacity: 0; transform: translateX(-50%) scale(.3); } 100% { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes hero-pedestal { from { opacity: 0; transform: translateX(-50%) scaleX(.7); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes fill-clip { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
@keyframes bar-fill { from { width: 0; } to { width: var(--w, 0%); } }
@keyframes shimmer { 0% { transform: translateX(-100%); } 40%, 100% { transform: translateX(450%); } }
@keyframes sk-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes grid-drift { to { background-position: 48px 48px, 48px 48px; } }
@keyframes announce-ring { 0%, 18%, 100% { transform: rotate(0); } 3% { transform: rotate(-16deg); } 6% { transform: rotate(14deg); } 9% { transform: rotate(-10deg); } 12% { transform: rotate(8deg); } 15% { transform: rotate(-4deg); } }
@keyframes announce-sheen { 0% { transform: translateX(0); } 35%, 100% { transform: translateX(450%); } }
@keyframes feed-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes stage-swap { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes in-next { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes in-prev { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes tut-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes tut-type { from { max-width: 0; } to { max-width: 100%; } }
@keyframes tut-ripple { from { opacity: .7; transform: scale(.4); } to { opacity: 0; transform: scale(1.8); } }
@keyframes tut-dot { 0%, 60%, 100% { opacity: .5; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes tr-ping { 0% { opacity: .75; transform: scale(1); } 60%, 100% { opacity: 0; transform: scale(2.4); } }
@keyframes cta-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-14deg) scale(1.1); } 50% { transform: rotate(10deg) scale(1.1); } 75% { transform: rotate(-5deg); } }
@keyframes chevron { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 8px); } 15%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -6px); } }

/* ไม่ตั้ง opacity:0 ที่ตัว class — ให้ keyframe แรก (fill: both) ซ่อนไว้ก่อนเริ่มแทน
   ถ้ามีแอนิเมชันอื่นมาแทนที่ (เช่นแสงรุ้งตอนได้ Unique / SSS) การ์ดจะไม่หายไปทั้งใบ */
.rise { animation: rise .5s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms) both; }
.pop { animation: pop .5s cubic-bezier(.2, .7, .2, 1) .1s both; }
.fade-in { animation: fade .35s ease both; }
.card-enter { animation: card-enter .45s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms) both; }
.in-next { animation: in-next .35s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms) both; }
.in-prev { animation: in-prev .35s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms) both; }
.swap { animation: stage-swap .4s cubic-bezier(.2, .7, .2, 1) both; }
.pop-in { animation: tut-pop .35s cubic-bezier(.2, .7, .2, 1) both; }
.tut-pop { animation: tut-pop .4s cubic-bezier(.2, .7, .2, 1) both; }
.tut-type { display: inline-block; overflow: hidden; white-space: nowrap; vertical-align: bottom; animation: tut-type .9s steps(18) both; }

/* พื้นหลังกริดค่อยๆ ไหล */
.bg-grid { animation: grid-drift 6s linear infinite; }

/* =====================================================================
   ทั่วไป
   ===================================================================== */
.txt { color: var(--text); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.grad { background: linear-gradient(90deg, var(--accent-2), #a78bfa); -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 11px; font-weight: 700; font-size: 14px; cursor: pointer;
  transition: transform .15s, box-shadow .15s, background .15s, border-color .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #062420; box-shadow: 0 6px 22px -8px rgba(45, 212, 191, .7); }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: var(--panel); border: 1px solid var(--line-2); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost:hover .cta-ico { animation: cta-wiggle .5s; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line-2); font-size: 14px;
}
.icon-btn:hover { border-color: var(--accent); }
.dot-on { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #4ade80; margin-right: 2px; }
.price { color: var(--accent-2); }
.game-thumb {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 26px; height: 26px; border-radius: 7px; font-size: 14px;
}
.game-thumb.lg { width: 40px; height: 40px; font-size: 20px; border-radius: 10px; }
.page { animation: none; }

/* หน้าแรก: ซ่อนเมนู/ฟุตเตอร์ เหมือนต้นฉบับ */
body[data-page="home"] .nav,
body[data-page="home"] .login-btn,
body[data-page="home"] .footer { display: none; }
body[data-page="home"] .topbar { background: transparent; border-color: transparent; backdrop-filter: none; }

/* segmented progress (ใช้หลายหน้า) */
.seg { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 4px; }
.seg span { height: 7px; border-radius: 3px; background: var(--line-2); position: relative; overflow: hidden; }
.seg span.on { background: #7dd3fc; box-shadow: 0 0 8px rgba(125, 211, 252, .45); animation: fade .3s calc(var(--i) * 40ms + .2s) both; }
.seg span.on:last-of-type::after, .seg span.on:has(+ span:not(.on))::after {
  content: ""; position: absolute; inset: 0; width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent);
  animation: shimmer 2.4s ease-in-out infinite;
}

/* skeleton */
.sk {
  display: block; border-radius: 6px;
  background: linear-gradient(90deg, var(--panel-2) 25%, #1f2a37 50%, var(--panel-2) 75%);
  background-size: 200% 100%; animation: sk-shimmer 1.3s linear infinite;
}

/* =====================================================================
   หน้า /trait
   ===================================================================== */
.trait-page { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.tr-main { position: relative; padding: 0 22px 22px; overflow: visible; }
.tr-banner { display: flex; align-items: center; justify-content: space-between; margin: 0 -22px 18px; padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(45, 212, 191, .18), rgba(167, 139, 250, .18) 60%, rgba(244, 63, 94, .15)); border-radius: var(--radius) var(--radius) 0 0; }
.tr-banner h2 { font-size: 26px; font-weight: 900; letter-spacing: .3px; }
.tr-stage { display: flex; align-items: center; justify-content: center; gap: 28px; margin: 10px 0 18px; }
.tr-slot, .tr-token {
  position: relative; width: 128px; height: 128px; border-radius: 18px; display: grid; place-items: center; text-align: center;
  background: #0d141c; border: 2px solid var(--line-2);
}
.tr-slot-empty { color: var(--muted); font-weight: 800; font-size: 18px; line-height: 1.2; }
.tr-slot.filled { border-color: var(--c); background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c) 40%, transparent), #0d141c 75%); box-shadow: 0 0 26px -6px var(--c); }
.tr-slot.spin .tr-slot-ico { filter: blur(1px); transform: translateY(-2px); }
.tr-slot.land { animation: pop .35s cubic-bezier(.3, 1.6, .5, 1) both; }
.tr-slot-ico { font-size: 58px; transition: transform .08s; }
.tr-slot-ico2 { position: absolute; right: 6px; bottom: 4px; font-size: 30px; filter: drop-shadow(0 2px 4px #000); }
.tr-slot.r-mythic { box-shadow: 0 0 40px -4px var(--c); }
.tr-ping { position: absolute; inset: -2px; border-radius: 18px; border: 2px solid var(--c); animation: tr-ping 1.4s ease-out infinite; }
.tr-arrows { display: flex; gap: 2px; }
.tr-arrows i { width: 18px; height: 34px; background: var(--accent); clip-path: polygon(100% 0, 40% 50%, 100% 100%, 60% 100%, 0 50%, 60% 0); animation: chevron 1.2s ease-in-out infinite; }
.tr-arrows i:nth-child(1) { animation-delay: .45s; } .tr-arrows i:nth-child(2) { animation-delay: .3s; } .tr-arrows i:nth-child(3) { animation-delay: .15s; }
.tr-token { border-color: #a78bfa; background: radial-gradient(circle at 50% 35%, rgba(167, 139, 250, .35), #0d141c 75%); box-shadow: 0 0 26px -8px #a78bfa; }
.tr-token-ico { font-size: 44px; }
.tr-token b { position: absolute; top: 6px; right: 12px; font-size: 26px; font-weight: 900; text-shadow: 0 2px 6px #000; }
.tr-token small { position: absolute; bottom: 8px; font-size: 10px; font-weight: 700; color: var(--muted); }
.tr-result { min-height: 86px; text-align: center; }
.tr-none { font-size: 30px; font-weight: 900; color: var(--muted); padding-top: 10px; }
.tr-name { display: inline-flex; align-items: center; gap: 10px; font-size: 34px; font-weight: 900; color: var(--c); text-shadow: 0 0 22px color-mix(in srgb, var(--c) 50%, transparent); }
.tr-desc { font-size: 13px; color: #fca5a5; font-weight: 700; margin-bottom: 4px; }
.tr-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.tr-btn { padding: 13px; border-radius: 12px; font-size: 17px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .4); transition: transform .12s, filter .12s; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25); }
.tr-btn:hover { filter: brightness(1.1); }
.tr-btn:active { transform: translateY(2px); box-shadow: none; }
.tr-btn:disabled { filter: grayscale(.6); cursor: progress; }
.tr-btn-1 { background: linear-gradient(180deg, #2dd4bf, #0d9488); }
.tr-btn-10 { background: linear-gradient(90deg, #8b5cf6, #ec4899, #f59e0b); }
.tr-btn-until { background: linear-gradient(180deg, #60a5fa, #2563eb); font-size: 14px; padding: 10px 14px; }
.tr-until { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 12px; }
.tr-until select { appearance: none; padding: 10px 12px; border-radius: 10px; background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238494a7'/%3E%3C/svg%3E") no-repeat right 12px center; border: 1px solid var(--line-2); color: var(--text); font: inherit; font-size: 13px; }
.tr-odds { text-align: center; margin-top: 10px; }
.tr-toast { position: absolute; left: 50%; top: 52%; padding: 8px 16px; border-radius: 10px; background: #7f1d1d; color: #fecaca; font-weight: 800; opacity: 0; pointer-events: none; transform: translateX(-50%); }
.tr-toast.show { animation: toast 1.1s ease both; }

.tr-side { padding: 16px; display: grid; gap: 12px; }
.tr-side-head { display: flex; justify-content: space-between; align-items: center; }
.tr-side-head h3 { font-size: 18px; font-weight: 900; }
.tr-total { font-size: 14px; color: var(--muted); }
.tr-total b { font-size: 34px; font-weight: 900; color: var(--text); margin-right: 4px; }
.tr-rbar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line-2); }
.tr-rbar i { display: block; background: var(--c); transition: width .4s; }
.tr-rcounts { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.tr-rcounts b { display: block; font-size: 15px; }
.tr-rcounts span { font-size: 11px; font-weight: 700; }
.tr-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 11px; background: var(--panel-2); border: 1px solid var(--line); }
.tr-switch button { padding: 7px; border-radius: 8px; font-weight: 800; font-size: 13px; color: var(--muted); }
.tr-switch button.active { background: var(--accent); color: #062420; }
.tr-colhead { text-align: right; }
.tr-col { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.tr-cell { aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center; align-content: center; background: var(--panel-2); border: 1px solid var(--line); position: relative; }
.tr-cell span { font-size: 18px; filter: grayscale(1) brightness(.5); }
.tr-cell small { font-size: 9px; color: var(--muted); line-height: 1; }
.tr-cell.got { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--panel-2)); animation: pop .3s both; }
.tr-cell.got span { filter: none; }
.tr-cell.got small { color: var(--text); font-weight: 700; }
.tr-log { max-height: 260px; overflow-y: auto; display: grid; gap: 4px; font-size: 12px; }
.tr-log-row { display: flex; gap: 8px; padding: 5px 8px; border-radius: 7px; background: var(--panel-2); }
.tr-latest { border-top: 1px solid var(--line); padding-top: 10px; }
.tr-latest-row { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.tr-chip { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; font-size: 14px; border: 1px solid var(--c); background: color-mix(in srgb, var(--c) 18%, var(--panel-2)); }
.tr-chip:first-child { animation: pop .3s both; }
.tr-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; cursor: pointer; }
.tr-toggle input { display: none; }
.tr-toggle i { width: 36px; height: 20px; border-radius: 10px; background: var(--line-2); position: relative; transition: background .2s; flex-shrink: 0; }
.tr-toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.tr-toggle input:checked + i { background: var(--accent); }
.tr-toggle input:checked + i::after { transform: translateX(16px); }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); animation: fade .2s both; }
.modal[hidden] { display: none; }
.modal-card { width: min(420px, 100%); padding: 20px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line-2); }
.modal-card h3 { font-size: 18px; margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chances { width: min(520px, 100%); max-height: 80vh; display: flex; flex-direction: column; }
.chance-list { overflow-y: auto; display: grid; gap: 6px; margin-top: 12px; padding-right: 4px; }
.chance { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); background: linear-gradient(90deg, color-mix(in srgb, var(--c) 18%, transparent), transparent); }
.chance-ico { font-size: 22px; text-align: center; }
.chance b { color: var(--c); }
.chance small { display: block; font-size: 11px; color: var(--muted); }
.chance-p { font-weight: 900; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1100px) {
  .job-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 960px) {
  .landing { grid-template-columns: 1fr; gap: 28px; min-height: 0; }
  .ov-grid, .trait-page, .sp-grid { grid-template-columns: 1fr; }
  .sp-steps { grid-template-columns: repeat(3, 1fr); }
  .sp-cta { grid-column: 1 / -1; }
  .footer-inner { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  /* เมนูล่างจอสำหรับมือถือ */
  .nav { display: flex !important; position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 20; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); background: rgba(17, 24, 33, .95); backdrop-filter: blur(10px); }
  .nav-item { flex-direction: column; gap: 1px; padding: 6px 14px; font-size: 11px; white-space: nowrap; border-radius: 16px; }
  .nav-item .ico { font-size: 16px; }
  .topbar { backdrop-filter: none; background: rgba(10, 14, 20, .97); } /* backdrop-filter ทำให้ position:fixed ของลูกเพี้ยน */
  body { padding-bottom: 64px; }
  body[data-page="home"] { padding-bottom: 0; }
}
@media (max-width: 640px) {
  .landing { padding: 12px 14px 30px; }
  .landing-stats { grid-template-columns: repeat(2, 1fr); row-gap: 16px; }
  .landing-stats div:nth-child(3) { border-left: 0; padding-left: 0; }
  .show-card { height: 400px; min-height: 0; }
  .show-figure .stage { font-size: 15px; }
  .featured { grid-template-columns: 1fr; }
  .featured-stage .stage { font-size: 14px; }
  .featured-info { padding: 0 18px 18px; }
  .job-grid { grid-template-columns: repeat(2, 1fr); }
  .tr-stage { gap: 12px; }
  .tr-slot, .tr-token { width: 96px; height: 96px; }
  .tr-slot-ico { font-size: 42px; }
  .tr-arrows i { width: 10px; height: 22px; }
  .tr-until { grid-template-columns: 1fr; }
  .tr-name { font-size: 26px; }
  .sp-steps { grid-template-columns: repeat(2, 1fr); }
  .dc { grid-template-columns: 1fr; height: 430px; }
  .dc-side { display: none; }
  .footer-inner { grid-template-columns: 1fr; }
}
