/* Shieldfall · CSS ใช้จัดตำแหน่งชิ้นภาพเจนเท่านั้น (กรอบ ปุ่ม หลอด มาจาก UI Kit ของค่าย + ภาพเจนของเกม) */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a1a10; color: #4a2e1f; font-family: 'Mitr', system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
img { -webkit-user-drag: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.out { color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 2px #4a2e1f; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px; background: url(img/bg-farm.webp) center / cover; z-index: 10; overflow: auto; }
.screen.dim { background: rgba(30, 18, 10, 0.6); z-index: 12; }
.logo { width: min(340px, 60vw, 36vh); }
.card { position: relative; width: min(440px, 100%); padding: 22px 26px; border: 26px solid transparent; border-image: url(img/kit-window.webp) 60 fill / 26px stretch; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 24px); }
.card.wide { width: min(720px, 100%); }
.head { font-weight: 600; font-size: 20px; text-align: center; }
.lbl { font-weight: 600; font-size: 14px; }
#name { font: inherit; font-size: 17px; padding: 8px 12px; border: 0; border-radius: 12px; background: rgba(255, 255, 255, 0.85); color: #4a2e1f; }
.btn { font-weight: 600; font-size: 17px; color: #4a2e1f; min-height: 50px; padding: 0 22px; border: 0; background: url(img/kit-btn-primary.webp) center / 100% 100% no-repeat; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; text-align: center; }
.btn:active { background-image: url(img/kit-btn-primary-pressed.webp); }
.btn.sub { background-image: url(img/kit-btn-secondary.webp); font-size: 14px; min-height: 44px; }
.btn.sub:active { background-image: url(img/kit-btn-secondary-pressed.webp); }
.btn.accent { background-image: url(img/kit-btn-accent.webp); }
.btn.small { min-height: 38px; font-size: 14px; padding: 0 14px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn img { height: 22px; }
.note { font-size: 11px; margin: 0; opacity: 0.75; text-align: center; }
.x { position: absolute; right: -14px; top: -14px; width: 44px; height: 44px; border: 0; background: none; padding: 0; cursor: pointer; z-index: 2; }
.x img { width: 100%; }
#pbody { overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
#mbody { text-align: center; white-space: pre-line; display: flex; flex-direction: column; align-items: center; gap: 6px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button { pointer-events: auto; cursor: pointer; }
#me { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 8px; display: flex; align-items: center; gap: 6px; }
.portrait { width: 64px; height: 64px; background: url(img/kit-portrait-ring.webp) center / contain no-repeat; display: grid; place-items: center; position: relative; }
.portrait img { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; object-position: 50% 8%; }
.lvl { position: absolute; left: 40px; top: 42px; width: 36px; height: 24px; background: url(img/kit-level-badge.webp) center / 100% 100% no-repeat; display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.bars { display: flex; flex-direction: column; gap: 3px; width: 170px; }
.name { font-size: 13px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 2px #4a2e1f; }
.bar { position: relative; height: 18px; background: url(img/kit-bar-frame.webp) center / 100% 100% no-repeat; padding: 4px 7px; }
.bar.thin { height: 12px; padding: 3px 6px; }
.bar.wide { width: min(420px, 60vw); height: 22px; }
.fill { height: 100%; background-size: 100% 100%; border-radius: 6px; transition: width 0.15s; }
.fill.hp { background-image: url(img/kit-fill-hp.webp); }
.fill.xp { background-image: url(img/kit-fill-exp.webp); }
.bar span { position: absolute; inset: 0; font-size: 10px; line-height: 18px; text-align: center; color: #fff; text-shadow: 0 1px 1px #4a2e1f; }
#info { position: absolute; left: max(12px, env(safe-area-inset-left)); top: 76px; font-size: 12px; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 2px #4a2e1f; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; max-width: 260px; }
#info span { display: inline-flex; align-items: center; gap: 2px; }
#info img { width: 18px; }

.pill { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 240px; height: 50px; border: 0; background: url(img/pill-shield.webp) center / 100% 100% no-repeat; display: flex; align-items: center; justify-content: center; padding: 0 0 0 44px; font-size: 21px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px #1c4a5a, 0 0 3px #1c4a5a; }
.pill.kills { background-image: url(img/pill-kills.webp); text-shadow: 0 1px 2px #5a1c1c, 0 0 3px #5a1c1c; }
.pill.clock { background-image: url(img/pill-clock.webp); top: 60px; width: 180px; height: 40px; font-size: 15px; padding-left: 36px; text-shadow: 0 1px 2px #2a1a10; }
.pill.sated::after { content: ''; position: absolute; right: -22px; top: -10px; width: 40px; height: 34px; background: url(img/crown.webp) center / contain no-repeat; }
#bossbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); }
#minimap { position: absolute; right: max(10px, env(safe-area-inset-right)); top: 8px; width: 104px; height: 104px; }
#menu { position: absolute; right: max(118px, calc(env(safe-area-inset-right) + 118px)); top: 6px; display: flex; gap: 2px; }
#menu button { width: 50px; border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; }
#menu img { width: 36px; height: 36px; object-fit: contain; }
#menu b { font-size: 10px; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 2px #4a2e1f; margin-top: -2px; }
#menu button.on img { filter: drop-shadow(0 0 6px #ffd34a); }
#partybox { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 120px; display: flex; flex-direction: column; gap: 4px; }
#partybox .pm { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #fff; text-shadow: 0 1px 2px #4a2e1f; }
#partybox img { width: 26px; height: 26px; object-fit: cover; object-position: 50% 8%; border-radius: 50%; background: rgba(255, 240, 210, 0.85); }
#partybox .bar { width: 80px; height: 12px; padding: 3px 5px; }
#feed { position: absolute; right: max(10px, env(safe-area-inset-right)); top: 118px; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12px; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 2px #4a2e1f; }
#toast { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); min-width: 260px; max-width: 92vw; padding: 14px 34px; background: url(img/kit-header.webp) center / 100% 100% no-repeat; text-align: center; font-weight: 600; font-size: 16px; white-space: nowrap; }
#invite { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); padding: 14px 24px; background: url(img/kit-header.webp) center / 100% 100% no-repeat; display: flex; align-items: center; gap: 8px; font-weight: 600; pointer-events: auto; white-space: nowrap; }
.btn.event { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background-image: url(img/kit-btn-accent.webp); }

#buttons { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3, 70px); grid-template-rows: repeat(2, 70px); gap: 6px; }
.rb { width: 70px; height: 70px; border: 0; padding: 0; background: none; position: relative; }
.rb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.rb.sk .ic { inset: 12%; width: 76%; height: 76%; border-radius: 50%; }
.rb b { position: absolute; left: 0; right: 0; bottom: -2px; font-size: 13px; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 3px #4a2e1f; }
.rb i { position: absolute; inset: 0; display: grid; place-items: center; font-style: normal; font-size: 22px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px #000; }
.rb.cd .ic { opacity: 0.35; filter: grayscale(1); }
.rb.auto.on img { filter: drop-shadow(0 0 8px #ffd34a) brightness(1.15); }
#b-exit { grid-column: 1; grid-row: 1; }
#b-auto { grid-column: 3; grid-row: 1; }
#b-dash { grid-column: 1; grid-row: 2; }
#b-s2 { grid-column: 2; grid-row: 2; }
#b-s1 { grid-column: 3; grid-row: 2; }
#b-s2.none { visibility: hidden; }
#net { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: 8px; font-size: 10px; color: #fff; opacity: 0.7; text-shadow: 0 1px 1px #000; }
#devbar { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: 26px; display: flex; gap: 4px; pointer-events: auto; }
#devbar button { font-size: 10px; padding: 2px 6px; border-radius: 6px; border: 0; background: rgba(255, 255, 255, 0.7); }

#splash { position: fixed; inset: 0; width: 100vw; height: 100vh; object-fit: cover; z-index: 8; pointer-events: none; animation: splash 1.8s ease forwards; }
@keyframes splash { 0% { opacity: 0; transform: scale(1.08); } 12% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }

/* แผง: กาชา / อาชีพ / คลัง / ตี้ / ยืดโล่ */
.row { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.altar { width: min(320px, 70%); align-self: center; }
.rates { font-size: 12px; text-align: center; opacity: 0.85; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ccard { position: relative; aspect-ratio: 0.82; border: 0; padding: 0; background: center / 100% 100% no-repeat; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.ccard[data-r="1"] { background-image: url(img/card-1.webp); } .ccard[data-r="2"] { background-image: url(img/card-2.webp); }
.ccard[data-r="3"] { background-image: url(img/card-3.webp); } .ccard[data-r="4"] { background-image: url(img/card-4.webp); }
.ccard[data-r="0"] { background-image: url(img/card-1.webp); }
.ccard img.who { position: absolute; left: 14%; right: 14%; top: 9%; height: 62%; width: 72%; object-fit: contain; }
.ccard .nm { position: relative; font-size: 12px; font-weight: 600; margin-bottom: 7%; }
.ccard .lives { position: absolute; top: 4%; right: 6%; font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 2px #4a2e1f; }
.ccard .stars { position: absolute; top: 4%; left: 8%; display: flex; }
.ccard .stars img { width: 13px; }
.ccard.off { filter: grayscale(1); opacity: 0.45; }
.ccard.cur { filter: drop-shadow(0 0 8px #ffd34a); }
.slots { display: flex; gap: 8px; justify-content: center; }
.slotb { width: 72px; height: 72px; border: 0; padding: 8px; background: url(img/kit-slot-equip.webp) center / 100% 100% no-repeat; position: relative; }
.slotb img { width: 100%; height: 100%; object-fit: contain; }
.slotb small { position: absolute; left: 0; right: 0; bottom: -16px; font-size: 10px; }
.items { display: grid; grid-template-columns: repeat(auto-fill, 58px); gap: 6px; justify-content: center; }
.itb { width: 58px; height: 58px; border: 0; padding: 7px; background: url(img/kit-slot.webp) center / 100% 100% no-repeat; position: relative; }
.itb.sel { background-image: url(img/kit-slot-selected.webp); }
.itb img { width: 100%; height: 100%; object-fit: contain; }
.itb[data-r="1"]::after, .itb[data-r="2"]::after { content: ''; position: absolute; right: 2px; top: 2px; width: 14px; height: 14px; background: url(img/star.webp) center / contain no-repeat; }
.itb[data-r="2"] { filter: drop-shadow(0 0 4px #b46cff); }
.detail { font-size: 13px; text-align: center; min-height: 20px; }
.ext { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ext > div { border: 18px solid transparent; border-image: url(img/kit-panel.webp) 40 fill / 18px stretch; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 13px; }
.ext img { width: 56px; }

/* เปิดกาชา */
#cards { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 760px; }
.rc { position: relative; width: min(120px, 17vw, 15vh); aspect-ratio: 0.82; perspective: 600px; }
.rc .face, .rc .back { position: absolute; inset: 0; backface-visibility: hidden; transition: transform 0.45s; }
.rc .back { background: url(img/card-back.webp) center / contain no-repeat; }
.rc .face { transform: rotateY(180deg); }
.rc.open .back { transform: rotateY(180deg); } .rc.open .face { transform: rotateY(360deg); }
.rc .ccard { width: 100%; height: 100%; }
.rc .burst { position: absolute; inset: -40%; background: center / contain no-repeat; mix-blend-mode: screen; opacity: 0; pointer-events: none; }
.rc.open .burst { animation: burst 0.9s ease-out; }
@keyframes burst { 0% { opacity: 0; transform: scale(0.4); } 30% { opacity: 1; } 100% { opacity: 0; transform: scale(1.2); } }
.rc .new { position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px #4a2e1f, 0 0 3px #b46cff; white-space: nowrap; }

@media (max-height: 430px) {
  .portrait { width: 52px; height: 52px; } .portrait img { width: 37px; height: 37px; }
  .lvl { left: 32px; top: 34px; }
  .pill { width: 200px; height: 42px; font-size: 18px; }
  .pill.clock { top: 50px; height: 34px; }
  #buttons { grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(2, 60px); }
  .rb { width: 60px; height: 60px; }
  .logo { width: min(240px, 40vw, 30vh); }
  .card { padding: 8px 16px; gap: 5px; }
  .btn { min-height: 42px; }
  #minimap { width: 84px; height: 84px; }
  #menu { right: 98px; }
  #info { top: 62px; }
  #partybox { top: 92px; }
}
/* จอแนวตั้ง */
@media (max-width: 560px) {
  .pill { top: 128px; width: 210px; height: 44px; font-size: 18px; }
  .pill.clock { top: 174px; }
  #bossbar { top: 130px; }
  #menu { right: auto; left: 50%; transform: translateX(-50%); top: auto; bottom: 168px; }
  #minimap { width: 84px; height: 84px; }
  #toast { font-size: 14px; padding: 12px 26px; white-space: normal; }
  #feed { top: 96px; }
}
