/**
 * หน้าตาของเกม — โต๊ะสักหลาดเข้ม ตัวเลขใหญ่อ่านออกจากระยะแขน
 *
 * งานศิลป์ทุกชิ้นที่นี่วาดเองด้วย CSS หรือใช้ยูนิโค้ด **ไม่มีการคัดลอกงานศิลป์ของเกมต้นฉบับ**
 * ปุ่มทุกตัวสูงอย่างน้อย 44px ตามสเปกข้อ 9
 */

:root {
  color-scheme: dark;

  /* โต๊ะสักหลาดเขียวเข้ม + แถบข้างสีน้ำเงินหม่น ตามหน้าจอที่ผู้ใช้ส่งมาเป็นแบบ (2026-08-04)
     สีทุกตัวไล่มาจากรูปนั้น ไม่ได้คัดลอกไฟล์ภาพใดๆ มาใช้ */
  --felt-deep: #10382c;
  --felt: #1b5c46;
  --ink: #f2efe4;
  --ink-dim: #9fb3ac;
  --edge: #2a4a3a;

  /* แถบซ้ายกับกล่องข้างใน */
  --panel: #12303d;
  --panel-2: #17404f;
  --panel-3: #0e2833;

  --chips: #3d8fdb;
  --mult: #e8437d;
  --money: #f0b429;
  --play-num: #35c8e8;
  --discard-num: #e8853a;

  --common: #4aa3ff;
  --uncommon: #4fd18b;
  --rare: #ff5b56;
  --legendary: #b07cff;

  --tap: 44px;
  --radius: 10px;
  --gap: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 120% at 20% 0%, var(--felt) 0%, var(--felt-deep) 70%);
  color: var(--ink);
  /* Prompt เป็นฟอนต์ไทยที่โหลดจาก Google Fonts ใน index.html
     ตัวสำรองไว้ให้หน้าอ่านออกได้ทันทีถ้าฟอนต์ยังมาไม่ถึงหรือโหลดไม่ได้ */
  font-family: 'Prompt', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

/* บังคับให้ทุกอย่างในหน้าใช้ฟอนต์เดียวกัน รวมถึงองค์ประกอบที่เบราว์เซอร์ตั้งฟอนต์ให้เอง
   (ปุ่ม ช่องกรอก กล่องยืนยัน) ซึ่งไม่สืบทอด font-family จาก body โดยปริยาย */
button, input, select, textarea {
  font-family: inherit;
}

.app { height: 100%; padding: var(--gap); }

.layout {
  display: grid;
  grid-template-columns: minmax(180px, 220px) 1fr;
  gap: var(--gap);
  height: 100%;
}

/* ---------- แถบซ้าย: สถานการณ์เป็นยังไง ---------- */

.status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 14px;
  overflow-y: auto;
}

/* ป้ายรอบ — แถบชื่อสีเต็มความกว้าง แล้วกล่องเป้าหมายสีเข้มอยู่ข้างใน (ตามรูปอ้างอิง) */
.blind-card {
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel-2);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.blind-title {
  padding: 6px 10px;
  font-weight: 700;
  text-align: center;
  letter-spacing: .02em;
  background: #3f6f8c;
}
.blind-small .blind-title { background: #2f7f9c; }
.blind-big .blind-title { background: #3d7fd0; }
.blind-boss .blind-title { background: #a3374f; }
.blind-none .blind-title { background: #3a4c56; }

.blind-goal { padding: 8px 10px 10px; text-align: center; }
.goal-label { font-size: .72rem; color: #cfe4f2; letter-spacing: .04em; }
.goal-value {
  margin-top: 2px;
  padding: 4px 6px;
  border-radius: 8px;
  background: var(--panel-3);
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.goal-reward { margin-top: 6px; display: flex; gap: 6px; align-items: center; justify-content: center; }
.goal-reward-label { font-size: .72rem; color: #cfe4f2; }
.reward-dots { display: flex; gap: 3px; }
.reward-dots .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--mult);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .3);
}

/* แต้มรอบนี้ — ป้ายซ้าย กล่องตัวเลขขวา · กล่องนี้คือที่ที่แต้มไต่ขึ้นตอนคิดแต้ม */
.score-row {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  align-items: stretch;
  gap: 2px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-2);
}
.score-label { padding: 8px 10px; font-size: .85rem; align-self: center; }
.score-box {
  padding: 8px 10px;
  background: var(--panel-3);
  text-align: right;
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* มือที่กำลังเล็ง / มือที่กำลังนับแต้ม */
.hand-panel { padding: 6px 4px 8px; text-align: center; }
.hand-name {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
}
.hand-value {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  align-items: center;
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hand-value .chips, .hand-value .mult {
  padding: .15rem .4rem;
  border-radius: 8px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .28);
}
.hand-value .chips { background: var(--chips); color: #06253f; }
.hand-value .mult { background: var(--mult); color: #3d0a1e; }
.hand-value .times { color: var(--mult); font-size: 1.3rem; }
/* เต้นหนึ่งจังหวะทุกครั้งที่ค่าเปลี่ยน — ชั้นแอนิเมชันเป็นคนติดคลาสให้ */
.hand-value .beat { animation: beat .16s ease-out; }
@keyframes beat {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); filter: brightness(1.35); }
  100% { transform: scale(1); }
}
.tally-source { font-size: .72rem; color: var(--ink-dim); min-height: 1.1em; margin-top: 4px; }

/* ตารางตัวเลข: เล่น · ทิ้ง · เงิน · สเตจ · รอบ */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cell {
  padding: 5px 8px;
  border-radius: 10px;
  background: var(--panel-2);
  text-align: center;
}
.cell-label { font-size: .72rem; color: #bcd3e0; }
.cell-value { font-size: 1.3rem; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.cell-play .cell-value { color: var(--play-num); }
.cell-discard .cell-value { color: var(--discard-num); }
/* เงินกินเต็มความกว้างเพราะเป็นเลขที่ผู้เล่นมองหาบ่อยที่สุดในร้าน */
.cell-money { grid-column: 1 / -1; background: #3a1f33; }
.cell-money .cell-value { color: var(--money); }

/* แถวล่างสุดของแถบซ้าย — seed กับปุ่มคู่มืออยู่ด้วยกัน */
.status-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
.seed { font-size: .7rem; color: var(--ink-dim); letter-spacing: .08em; }
.btn-guide {
  min-height: 34px;
  font-size: .8rem;
  border-color: rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .06);
}

/* ---------- คู่มือมือโป๊กเกอร์ ---------- */

.guide-card { max-width: 560px; width: 92vw; }
/* รายการยาวกว่าจอได้จริง (9 มือพร้อมคำอธิบาย) จึงต้องเลื่อนในกล่อง ไม่ใช่ดันกล่องทะลุจอ */
.guide-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(56vh, 420px);
  overflow-y: auto;
  margin: 10px 0;
  padding-right: 4px;
  text-align: left;
}
.guide-row {
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, .07);
}
.guide-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.guide-en { font-size: 1.02rem; font-weight: 800; letter-spacing: .01em; color: #ffffff; }
/* คำไทยกำกับกับคำอธิบายเคยใช้สีจางจนกลืนพื้นหลัง — ยกให้สว่างขึ้นทั้งคู่ */
.guide-th { font-size: .82rem; color: #9fd4ff; }
/* ค่าชิป × มัลติชิดขวาเสมอ เพื่อให้กวาดสายตาเทียบกันได้เป็นคอลัมน์เดียว */
.guide-value {
  margin-left: auto;
  display: flex;
  gap: 5px;
  align-items: baseline;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.guide-value .chips { color: var(--chips); }
.guide-value .mult { color: var(--mult); }
.guide-value .times { color: var(--ink-dim); font-size: .8rem; }
.guide-desc { margin-top: 3px; font-size: .82rem; line-height: 1.4; color: #dbe7ee; }

/* การ์ดตัวอย่างของแต่ละมือ — ใช้หน้าไพ่ชุดเดียวกับบนโต๊ะ ย่อด้วย .mini เท่านั้น */
.guide-example { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.card.mini {
  width: 32px;
  height: 44px;
  gap: 0;
  border-width: 1px;
  border-radius: 5px;
  cursor: default;
}
.card.mini .card-rank { font-size: .82rem; }
.card.mini .card-suit { font-size: .72rem; }
.card.mini:hover { transform: none; }

/* ---------- ฝั่งขวา: ทำอะไรได้บ้าง ---------- */

.board {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: var(--gap);
  min-width: 0;
  overflow: hidden;
}

.joker-row { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.joker-cards {
  display: flex;
  gap: 8px;
  align-items: stretch;
  justify-content: center;
  max-width: 100%;
  padding-bottom: 2px;
  overflow-x: auto;
}
/* ตัวนับช่องลอยอยู่เหนือแถวตรงกลาง เหมือน "6/6" ในหน้าจอต้นฉบับ */
.slot-count {
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .35);
  color: var(--ink);
  font-size: .8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ไพ่ Joker แบบ A — แถบซ้ายหนาบอกความหายาก · ล่างบอกเอฟเฟกต์ */
.joker {
  position: relative;
  width: 106px;
  min-height: 138px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 8px 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--edge);
  border-left: 10px solid var(--common);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.03));
}
.rarity-common { border-left-color: var(--common); }
.rarity-uncommon { border-left-color: var(--uncommon); }
.rarity-rare { border-left-color: var(--rare); }
.rarity-legendary { border-left-color: var(--legendary); }

.joker-empty {
  width: 106px;
  min-height: 138px;
  border: 2px dashed rgba(255, 255, 255, .16);
  border-left: 2px dashed rgba(255, 255, 255, .16);
  background: rgba(0, 0, 0, .12);
}

.joker-name { font-weight: 700; font-size: .78rem; line-height: 1.15; }
.joker-face {
  align-self: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: rgba(255, 255, 255, .55);
  line-height: 1;
}
.joker-effect { font-size: .68rem; line-height: 1.22; }
.effect-chips { color: var(--chips); }
.effect-mult { color: var(--mult); }
.effect-money { color: var(--money); }
.effect-plain { color: var(--ink-dim); }

/* สภาพปัจจุบันของใบที่มีสถานะของตัวเอง (ดอกที่ผูกอยู่ · ชิปที่สะสม)
   ต้องอ่านออกทันทีว่าเป็นค่าที่เปลี่ยนไปตามการเล่น ไม่ใช่ข้อความของการ์ด จึงเป็นแถบของตัวเอง */
.joker-note {
  margin-top: auto;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
  background: rgba(255, 255, 255, .1);
  border-radius: .35rem;
  padding: .1rem .3rem;
}

/* ---------- พื้นที่กลาง ---------- */

.stage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 8px;
  overflow: auto;
}

.section-title { margin: 0 0 4px; font-size: 1rem; letter-spacing: .04em; }
.notice p { margin: 0; color: var(--ink-dim); }

/* การ์ดรายละเอียดรอบที่กดเพื่อเริ่มรอบ — เป็นปุ่มจริงๆ ไม่ใช่ข้อความที่บังเอิญคลิกได้
   จึงต้องดูเหมือนกดได้ตั้งแต่ยังไม่เอาเมาส์ไปชี้ และมีสถานะปิดที่อ่านออก */
.blind-start {
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(460px, 92%);
  height: auto;
  padding: 18px 20px;
  border-radius: 14px;
  background: #1d6b46;
  border: 1px solid #2c8f60;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .3);
  text-align: center;
  cursor: pointer;
}
.blind-start:hover:not(:disabled) { background: #248055; }
.blind-start:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 4px 0 rgba(0, 0, 0, .3); }
.blind-start-title { font-size: 1.5rem; font-weight: 800; letter-spacing: .02em; }
.blind-start-detail { font-size: .95rem; color: #d8f0e4; }
/* ปุ่มเรียงไพ่ — เล็กกว่าปุ่มหลักเพราะเป็นของที่กดนานๆ ครั้ง แต่ยังสูงพอให้นิ้วกดโดน */
.sort-buttons { display: flex; gap: 4px; }
.btn-sort {
  min-height: 28px;
  padding: 0 10px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  background: rgba(0, 0, 0, .32);
  border-color: rgba(255, 255, 255, .18);
}
.btn-sort.is-on {
  background: var(--chips);
  border-color: #7fc0ff;
  color: #06253f;
}

.hand-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 2px;
}
.hand-count {
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .35);
  font-size: .8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
/* กองจั่วมุมขวาแบบหน้าจอต้นฉบับ — หลังไพ่ใบเดียวกับตัวเลข "เหลือ/ทั้งหมด" */
.deck-pile { display: flex; align-items: center; gap: 6px; }
.deck-face {
  width: 30px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 2px solid #d9d2be;
  background: linear-gradient(135deg, #b2413f, #8d2f2e);
  color: #f6f2e4;
  font-size: 1.3rem;
  line-height: 1;
}
.deck-count { font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.empty-note { color: var(--ink-dim); }

.hand { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* **ต้องประกาศตัวแปรสองตัวนี้ให้เบราว์เซอร์รู้ว่ามันเป็นความยาว** ไม่งั้นการเปลี่ยนค่าของมัน
   จะไม่ทำให้ transform ค่อยๆ ไหล — ตัวแปร CSS ที่ไม่ได้ประกาศชนิดไว้ถูกแทนที่ตอนคำนวณค่า
   เบราว์เซอร์จึงมองว่า transform "เปลี่ยนไปเป็นค่าใหม่" เฉยๆ ไม่มีอะไรให้ไล่ระหว่างทาง
   ผลคือไพ่กระโดดไปตำแหน่งใหม่ในเฟรมเดียวเหมือนไม่มีแอนิเมชัน
   (เจอจริงตอนวัดตำแหน่งไพ่ทีละเฟรมในเบราว์เซอร์ ไม่ได้เดา) */
@property --slide-x {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}
@property --slide-y {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}

.card {
  /* ระยะเลื่อนของ "การเรียงไพ่" ถูกยัดเข้ามาทางตัวแปรสองตัวนี้ ไม่ใช่เขียนทับ transform ตรงๆ
     เพราะการ์ดมี transform ของตัวเองอยู่แล้ว (ยกขึ้นตอนถูกเลือก · ตอนชี้) ถ้าเขียนทับ
     ไพ่ที่เลือกไว้จะร่วงลงมาหนึ่งจังหวะทุกครั้งที่เรียง — ทุกสถานะจึงต้องประกอบสองอย่างนี้เข้าด้วยกัน */
  --slide-x: 0px;
  --slide-y: 0px;

  width: 62px;
  height: 88px;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  border-radius: 8px;
  border: 2px solid #cfc9b6;
  background: #f6f2e4;
  color: #1a1a1a;
  font-family: inherit;
  transform: translate(var(--slide-x), var(--slide-y));
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.card .card-rank { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.card .card-suit { font-size: 1.2rem; line-height: 1; }
.card.suit-red { color: #c0392b; }
.card:hover { transform: translate(var(--slide-x), calc(var(--slide-y) - 4px)); }
.card.selected {
  transform: translate(var(--slide-x), calc(var(--slide-y) - 12px));
  box-shadow: 0 0 0 3px var(--money);
}

/* ระหว่างเรียงไพ่ — ไพ่ไหลไปที่ใหม่แทนที่จะกระโดดไปทันที
   ยาวกว่าการเปลี่ยนสถานะปกติเพราะมันคือการเดินทางข้ามจอ ไม่ใช่การยกขึ้นลงหนึ่งเซนติเมตร */
.card.sliding { transition: transform 260ms cubic-bezier(.2, .8, .3, 1); }

/* **จังหวะแรกของการเรียงต้องไม่มีแอนิเมชันเด็ดขาด** — ตอนนั้นคือการ "ดันไพ่กลับไปที่เดิม"
   ซึ่งเป็นการจัดฉาก ไม่ใช่สิ่งที่ผู้เล่นควรเห็น · ถ้าปล่อยให้ transition ปกติ (120ms) จับจังหวะนี้
   ไพ่จะไหลถอยหลังไปที่เก่าก่อน แล้วจังหวะไหลกลับจะถูกตัดกลางคัน = เห็นการเคลื่อนไหวแค่แวบเดียว
   (เจอจริงตอนวัดเวลาการเคลื่อนที่ในเบราว์เซอร์: ขยับแค่ ~30ms จากที่ตั้งไว้ 260ms) */
.card.snap { transition: none; }

/* ---------- โซนไพ่ที่เล่นออกไป + กระดานคะแนนของแอนิเมชัน (สเปกข้อ 9) ---------- */

/* เวทีของไพ่ที่เล่นออกไป — สูงคงที่เสมอแม้ยังไม่มีไพ่ ไม่งั้นมือข้างล่างจะกระโดดขึ้นลง
   ทุกครั้งที่เริ่มมือใหม่ ซึ่งเป็นการขยับที่ตาจับได้และน่ารำคาญกว่าที่ว่างเปล่าๆ */
.play-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 104px;
  padding: 6px 8px;
}

.played-cards { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

/* ไพ่บนโต๊ะย่อลงเล็กน้อยและกดไม่ได้ — มันไม่ใช่ของที่ผู้เล่นเลือกได้อีกแล้ว */
.played-cards .card {
  width: 52px;
  height: 74px;
  cursor: default;
  /* transform เท่านั้น (ข้อบังคับข้อ 1 ของสเปกข้อ 9) — ห้ามลด width/height จริงตอนแอนิเมชัน */
  transition: transform 140ms ease, opacity 140ms ease;
}
.played-cards .card .card-rank { font-size: 1.15rem; }
.played-cards .card .card-suit { font-size: 1rem; }

/* ใบที่กำลังทำแต้ม — ยกขึ้นและขยายด้วย transform ล้วน · เงาเป็นของนิ่ง ไม่ได้ถูกแอนิเมต */
.played-cards .card.scoring {
  transform: translateY(-10px) scale(1.12);
  box-shadow: 0 0 0 3px var(--chips), 0 6px 14px rgba(0, 0, 0, .45);
}

/* ร้านค้า — แผงสีน้ำเงินหม่นเหมือนแถบซ้าย ของขายเรียงในนั้น พร้อมป้ายราคาบนหัวการ์ด */
.shop {
  padding: 10px 12px 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, .07);
}
.shop .section-title { color: #cfe4f2; letter-spacing: .06em; }
/* ของขายอยู่ซ้าย ปุ่มของร้านอยู่ขวา — เหมือนหน้าจอต้นฉบับที่ Reroll กับ Next round
   อยู่ในแผงเดียวกับของ ไม่ได้อยู่รวมกับปุ่มอื่นของเกม */
.shop-body { display: flex; gap: 14px; align-items: stretch; flex-wrap: wrap; }
.shop-items { display: flex; gap: 12px; flex-wrap: wrap; align-items: stretch; flex: 1 1 auto; }
.shop-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  min-width: 150px;
}
.shop-actions .btn { width: 100%; }
.shop-slot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
/* ป้ายราคาเป็นเหรียญกลมสีชมพูเหนือการ์ด ตรงกับหน้าจอต้นฉบับ */
.price-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--mult);
  color: #3d0a1e;
  font-weight: 800;
  font-size: .85rem;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25);
}
.shop-item { width: 128px; min-height: 150px; }

.banner {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  padding: 24px 12px;
}
.banner-gameOver { color: var(--mult); }
.banner-won { color: var(--money); }

/* ---------- ปุ่ม ---------- */

.controls { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, .10);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 100ms ease, background-color 100ms ease;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .18); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--money); outline-offset: 2px; }

.btn-primary { background: #1d6b46; border-color: #2c8f60; }
.btn-primary:hover:not(:disabled) { background: #248055; }
.btn-warn { background: #7a2f2c; border-color: #a3423d; }
.btn-warn:hover:not(:disabled) { background: #8f3733; }
.btn-ghost { background: transparent; }
/* สองปุ่มนี้คือทางเดินหลักของหน้าร้าน จึงมีสีของตัวเองเหมือนหน้าจอต้นฉบับ
   (ส้ม = ไปรอบต่อไป · น้ำเงิน = รีโรล) ไม่ใช่เขียวเหมือนปุ่มทั่วไปทั้งแถว */
.btn-next { background: #c9701f; border-color: #e08a34; color: #fff; }
.btn-next:hover:not(:disabled) { background: #dd7f27; }
.btn-reroll { background: #2f6ea8; border-color: #3f8ac9; color: #fff; }
.btn-reroll:hover:not(:disabled) { background: #3a7fbe; }
.btn-small { min-height: 32px; padding: 0 8px; font-size: .75rem; margin-top: auto; }

/* ---------- ข้อความ ---------- */

.messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 84px;
  overflow-y: auto;
  font-size: .78rem;
}
.message { padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, .3); }
.message-error { color: var(--mult); }
.message-warn { color: var(--money); }
.message-info { color: var(--ink-dim); }

/* ---------- กล่องยืนยัน ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .6);
}
.modal-card {
  min-width: 280px;
  max-width: 90vw;
  padding: 20px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  /* พื้นทึบสีเดียวกับแถบซ้าย ไม่ใช่สีสักหลาดที่กลืนกับพื้นหลัง — ตัวหนังสือบนกล่องนี้
     ต้องอ่านง่ายกว่าของบนโต๊ะ เพราะมันคือข้อมูลที่ผู้เล่นเปิดมาอ่านโดยเฉพาะ */
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  text-align: center;
}
.modal-card h2 { margin: 0 0 10px; font-size: 1.15rem; }
.modal-detail { margin: 2px 0; color: #cfe0ea; font-size: .9rem; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* ---------- หน้าจอจบเกม (ชนะ/แพ้) ---------- */

.endscreen {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 12, 8, .88);
}
.endscreen-card {
  min-width: 300px;
  max-width: min(90vw, 520px);
  padding: 24px;
  border-radius: 16px;
  border: 1px solid var(--edge);
  border-top: 6px solid var(--money);
  background: var(--felt);
  text-align: center;
}
.endscreen-over .endscreen-card { border-top-color: var(--mult); }

.endscreen-title { margin: 0 0 6px; font-size: 1.8rem; }
.endscreen-won .endscreen-title { color: var(--money); }
.endscreen-over .endscreen-title { color: var(--mult); }
.endscreen-detail { margin: 4px 0; color: var(--ink); font-size: .95rem; }
.endscreen-seed { margin: 12px 0 0; color: var(--ink-dim); font-size: .78rem; letter-spacing: .08em; }

.btn-sound { font-size: .85rem; padding: 0 12px; }

/* แผ่นใสรับแตะระหว่างคิดแต้ม — อยู่ใต้หน้าจอจบเกมและกล่องยืนยัน แต่เหนือกระดานทั้งหมด */
.skip-overlay {
  position: fixed;
  inset: 0;
  z-index: 6;
  cursor: pointer;
  background: transparent;
}

/* ---------- แนวตั้ง: ขึ้นภาพให้หมุนจอ ---------- */

.rotate-hint { display: none; }

@media (orientation: portrait) and (max-width: 820px) {
  .rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 12px;
    background: var(--felt-deep);
    text-align: center;
  }
  .rotate-icon { font-size: 3rem; }
  .app { display: none; }
}

/* แอนิเมชันทั้งหมดของเกมแตะแค่ transform กับ opacity (ข้อบังคับข้อ 1 ของสเปกข้อ 9)
   ผู้เล่นที่ปิดการเคลื่อนไหวต้องไม่เห็นการขยับใดๆ — และฝั่ง JS (ui/app.js) ก็ข้ามแอนิเมชัน
   คิดแต้มไปที่ผลลัพธ์เลย ไม่ใช่เล่นลำดับเดิมแบบเงียบๆ ซึ่งยังกินเวลาผู้เล่นเท่าเดิม */
/* ---------- แจกไพ่ กับ ไพ่วิ่งออกจากโต๊ะ ---------- */

/* ไพ่ที่เพิ่งถูกแจกบินมาจากทางกองจั่ว (ขวาล่าง) แล้วลงที่ของมัน
   ระยะทางกับองศาเลือกให้ "อ่านออกว่ามาจากกอง" โดยไม่ต้องรอนาน — ชั้นแอนิเมชันเป็นคนหน่วง
   ทีละใบเอง (DEAL_STAGGER_MS ใน ui/app.js) ที่นี่จึงเป็นภาพของใบเดียวล้วนๆ
   `backwards` สำคัญ: ไพ่ต้องซ่อนอยู่ตั้งแต่ก่อนถึงคิวของตัวเอง ไม่ใช่โผล่ค้างแล้วค่อยบิน */
@keyframes deal-in {
  from { opacity: 0; transform: translate(150px, 40px) rotate(9deg) scale(.9); }
  to { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}
.card.deal-in { animation: deal-in 280ms cubic-bezier(.18, .9, .3, 1) backwards; }

/* นับแต้มจบแล้วไพ่บนโต๊ะวิ่งออกไปทางขวา — `forwards` เพื่อให้ค้างที่จอว่างจนกว่าจะวาดใหม่
   ถ้าไม่ค้าง ไพ่จะเด้งกลับมาให้เห็นหนึ่งเฟรมก่อนถูกวาดทับ ซึ่งตาจับได้ */
@keyframes fly-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translate(190px, -60px) rotate(12deg) scale(.85); }
}
.played-cards .card.fly-out { animation: fly-out 300ms ease-in forwards; }
/* ใบที่กำลังเรืองแสงอยู่ต้องเริ่มวิ่งจากตำแหน่งที่ยกไว้ ไม่ใช่กระตุกลงมาก่อน */
.played-cards .card.scoring.fly-out {
  animation: fly-out-scoring 300ms ease-in forwards;
}
@keyframes fly-out-scoring {
  from { opacity: 1; transform: translateY(-10px) scale(1.12); }
  to { opacity: 0; transform: translate(190px, -70px) rotate(12deg) scale(.85); }
}

/* ---------- จังหวะตอนคิดแต้ม ---------- */

/* ป้ายค่าที่ลอยขึ้นเหนือการ์ดที่เพิ่งทำงาน — ตัวเดียวกับ "+4 Mult" ในเกมต้นฉบับ
   ผูกกับตัวการ์ด จึงต้องให้การ์ดเป็นจุดอ้างอิงของตำแหน่งสัมบูรณ์ (ทั้งไพ่และ Joker) */
.card, .joker { position: relative; }
.pop-label {
  position: absolute;
  left: 50%;
  top: -.35rem;
  transform: translate(-50%, 0);
  padding: .05rem .3rem;
  border-radius: .3rem;
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  animation: pop-float .68s cubic-bezier(.18, .9, .3, 1) forwards;
}
.pop-chips { color: #fff; background: var(--chips); }
.pop-mult { color: #fff; background: var(--mult); }
/* คูณมัลติต้องอ่านออกว่า "หนักกว่า" การบวก ตั้งแต่ยังไม่ทันอ่านตัวเลข */
.pop-xmult {
  color: #fff;
  background: var(--mult);
  font-size: 1.35rem;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .55), 0 4px 12px rgba(0, 0, 0, .5);
}
.pop-money { color: #2b1d00; background: var(--money); }
.pop-retrigger { color: #fff; background: rgba(255, 255, 255, .28); }
.pop-dead { color: var(--ink-dim); background: rgba(0, 0, 0, .45); }

@keyframes pop-float {
  0%   { opacity: 0; transform: translate(-50%, .5rem) scale(.7); }
  18%  { opacity: 1; transform: translate(-50%, -.5rem) scale(1.15); }
  40%  { transform: translate(-50%, -.9rem) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -2.6rem) scale(1); }
}

/* การ์ดเด้งตอนถึงคิวของตัวเอง — ใช้กับทั้งไพ่บนโต๊ะและ Joker ที่กำลังทำงาน */
.hit { animation: card-hit .26s ease-out; z-index: 4; }
@keyframes card-hit {
  0%   { transform: translateY(0) scale(1); }
  35%  { transform: translateY(-12px) scale(1.16); }
  100% { transform: translateY(0) scale(1); }
}
/* ไพ่ที่กำลังทำแต้มยกตัวค้างไว้อยู่แล้ว การเด้งของมันจึงต้องเริ่มจากจุดที่ยกแล้ว
   ไม่งั้นมันจะกระตุกลงมาที่ศูนย์ก่อนเด้งขึ้น */
.played-cards .card.scoring.hit { animation: scoring-hit .26s ease-out; }
@keyframes scoring-hit {
  0%   { transform: translateY(-10px) scale(1.12); }
  35%  { transform: translateY(-20px) scale(1.26); }
  100% { transform: translateY(-10px) scale(1.12); }
}

/* สั่นตอนแต้มกระโดด — เบาสำหรับชิป/มัลติ หนักสำหรับคูณมัลติกับตอนรวมแต้ม */
.shake { animation: shake-soft .3s ease-in-out; }
.shake-hard { animation: shake-hard .32s ease-in-out; }
@keyframes shake-soft {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-2px, 1px); }
  50% { transform: translate(2px, -1px); }
  75% { transform: translate(-1px, 0); }
}
@keyframes shake-hard {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  15% { transform: translate(-6px, 2px) rotate(-.35deg); }
  35% { transform: translate(6px, -3px) rotate(.35deg); }
  55% { transform: translate(-4px, 2px) rotate(-.2deg); }
  75% { transform: translate(3px, -1px) rotate(.15deg); }
}

/* ตัวเลขบนกระดานคะแนนต้องดูมีน้ำหนักกว่าตัวหนังสือรอบๆ ระหว่างที่มันวิ่ง */
.tally-total { transition: color .12s linear; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .played-cards .card.scoring { transform: none; }
  /* ป้ายค่ายังต้องหายไปเอง แม้ไม่มีแอนิเมชันให้จบ — ตัวจับเวลาสำรองใน ui/app.js เป็นคนลบ
     ที่นี่แค่ทำให้มันไม่ค้างเป็นก้อนทึบกลางจอระหว่างรอ */
  .pop-label { opacity: .85; }
}
