:root {
  --px: 4px;
  --ink: #2a1a10;
  --panel: #7a5234;
  --panel-dark: #573820;
  --cream: #f6ecd2;
  --red: #e8604c;
  --blue: #4a9fd8;
  --orange: #f29a3a;
  --green: #5cb84a;
  --gold: #f5cc3a;
  --label: #f3dcb8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
:root { --vw: 1vw; --vh: 1vh; }
body {
  font-family: "Pixelify Sans", "Kanit", "Press Start 2P", monospace;
  color: #fff;
  background: #8fd0ee;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: none;
}

/* หรี่ฉากพื้นหลังลงนิดหน่อยให้กระดานเด่น */
body::before {
  content: ''; position: fixed; inset: 0; z-index: 1;
  background: rgba(20, 12, 4, .08);
  pointer-events: none;
}
#fx {
  position: fixed; inset: 0;
  width: calc(100 * var(--vw)); height: calc(100 * var(--vh));
  pointer-events: none; z-index: 26;
}

/* ---------- เอฟเฟกต์จอ CRT ---------- */
.crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 30;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,.05) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 60%, rgba(40,20,0,.3) 100%);
}

/* ---------- กรอบแบบพิกเซล (มุมหยัก) ---------- */
.pixel-box {
  position: relative;
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(var(--px) * -1) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink),
    0 calc(var(--px) * 3) 0 var(--px) rgba(0,0,0,.45);
}

.layout {
  position: relative; z-index: 10;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 24px;
}

/* ---------- แถบด้านข้าง ---------- */
.sidebar {
  width: 240px; max-height: calc(calc(100 * var(--vh)) - 32px); overflow-y: auto;
  background: repeating-linear-gradient(0deg, transparent 0 22px, rgba(0,0,0,.12) 22px 24px), var(--panel);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: float 4s ease-in-out infinite;
}
.title {
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 22px;
  line-height: 1.3;
  text-align: center;
  color: #a6e35a;
  text-shadow: 3px 3px 0 #2e6b22, 6px 6px 0 rgba(0,0,0,.4);
  padding: 8px 0 0;
  animation: wiggle 2.4s ease-in-out infinite;
}
.subtitle {
  margin-top: -8px; text-align: center;
  font-family: 'Kanit', system-ui, sans-serif; font-size: 13px; font-weight: 700; letter-spacing: 2px;
  color: var(--label);
}
.mode-badge {
  align-self: center; padding: 4px 10px; margin-top: -6px;
  background: var(--gold); color: var(--ink);
  font-family: "Press Start 2P", "Kanit", monospace; font-size: 9px;
  box-shadow: 0 0 0 3px var(--ink);
}
.mode-badge[hidden] { display: none; }
.stat {
  background: var(--panel-dark);
  padding: 8px 10px;
}
.stat-label {
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--label);
  margin-bottom: 6px;
}
.stat-value {
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 22px;
  padding: 10px;
  text-align: center;
  text-shadow: 3px 3px 0 rgba(0,0,0,.35);
}
.stat-value.red  { background: var(--red); }
.stat-value.blue { background: var(--blue); }
.stat-value.grey { background: #8a7a62; font-size: 14px; }
.stat-value.bump { animation: bump .25s ease-out; }

.btn {
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 13px;
  color: #fff;
  border: none;
  padding: 14px 10px;
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0,0,0,.35);
  transform: translateY(0);
  transition: transform .06s;
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(var(--px) * -1) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink),
    inset 0 -6px 0 rgba(0,0,0,.3);
}
.btn:hover { filter: brightness(1.12); transform: translateY(-2px) rotate(-1deg); }
.btn:active { transform: translateY(3px); box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(var(--px) * -1) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink),
    inset 0 2px 0 rgba(0,0,0,.3); }
.btn.orange { background: var(--orange); }
.btn.red    { background: var(--red); }
.btn.blue   { background: var(--blue); }
.btn.grey   { background: #8a7a62; font-size: 11px; }
.btn.gold   { background: #e0a800; text-shadow: 2px 2px 0 #8a5a00; }
.btn.green  { background: var(--green); }
.btn.nope, .px-input.nope { animation: nope .28s linear; }
.stat-row { display: flex; gap: 12px; }
.stat-row .stat { flex: 1; min-width: 0; }
.stat-row .stat-value { font-size: 14px; padding: 10px 4px; }
.stat-value.gold { background: #d9a520; white-space: nowrap; }

/* ข้อความไทยในปุ่ม/ป้ายฟอนต์พิกเซล (JS ติด .thai-txt ให้อัตโนมัติ) */
.thai-txt { font-family: "Kanit", system-ui, sans-serif !important; font-weight: 500; letter-spacing: 0; text-shadow: 1px 2px 0 rgba(0,0,0,.35); }
.btn.thai-txt { font-size: 16px; line-height: 1.25; }
.btn.thai-txt.ghost { font-size: 15px; }
.hint { font-size: 15px !important; line-height: 1.55 !important; }

/* เหรียญพิกเซล */
.coin {
  display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px;
  background: #f7c843;
  box-shadow: inset -3px -3px 0 #c8901a, inset 3px 3px 0 #fff3b0;
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
}
.hint {
  font-size: 13px;
  line-height: 1.5;
  color: var(--label);
  font-family: 'Kanit', system-ui, sans-serif;
}

/* ---------- กระดาน + ถาดบล็อก ---------- */
.game {
  --size: min(calc(60 * var(--vh)), calc(48 * var(--vw)), 480px);
  --pad: 8px;
  --gap: 3px;
  --cell: calc((var(--size) - var(--pad) * 2 - var(--gap) * 7) / 8);
  --mini: calc(var(--cell) * 0.4);
  position: relative;
  display: flex; flex-direction: column; gap: 22px;
}
.board {
  width: var(--size);
  height: var(--size);
  padding: var(--pad);
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  gap: var(--gap);
  background: #3b2414;
}
.board::before {
  content: ''; position: absolute; left: 0; right: 0; top: -10px; height: 12px; pointer-events: none;
  background:
    linear-gradient(135deg, transparent 50%, #5cb84a 50%) 0 0 / 8px 8px repeat-x,
    linear-gradient(225deg, transparent 50%, #5cb84a 50%) 4px 0 / 8px 8px repeat-x,
    linear-gradient(#5cb84a, #5cb84a) 0 8px / 100% 4px no-repeat;
}
.board.shake { animation: shake .3s linear; }
.preview-cv { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
html body .game.fit { --size: var(--fit-size); }   /* ต้องชนะ --size ของ body.lay-* */

/* บล็อก 1 ช่อง: สีอ่านจากตัวแปร --xb/--xd/--xl ซึ่งเปลี่ยนตามสถานะ (วางแล้ว / เงา / ไฮไลต์) */
.cell {
  --xb: var(--b); --xd: var(--d); --xl: var(--l);
  background: repeating-linear-gradient(0deg, #5a3a22 0 5px, #50331d 5px 7px);
  box-shadow: inset 0 3px 0 rgba(0,0,0,.3);
}
.cell.filled, .cell.ghost, .cell.hint, .pc {
  background: var(--xb);
  box-shadow:
    inset 0 -5px 0 var(--xd),
    inset 0 4px 0 var(--xl),
    inset 4px 0 0 rgba(255,255,255,.12),
    inset -4px 0 0 rgba(0,0,0,.15);
}
.cell.ghost, .cell.hint { --xb: var(--pb); --xd: var(--pd); --xl: var(--pl); }
.cell.ghost { opacity: .45; }
.cell { position: relative; }
.cell.hint::after { content: ''; position: absolute; inset: 0; background: #fff; pointer-events: none; opacity: .3; }
.cell.drop { animation: drop .2s ease-out; }
.cell.clear { animation: zap .32s steps(4) forwards; }
.cell.clear-fx { position: absolute; z-index: 2; pointer-events: none; }

.tray {
  width: var(--size);
  height: calc(var(--cell) * 2.6);
  display: grid;
  grid-template-columns: 0.85fr 1fr 1fr 1fr;
  background: repeating-linear-gradient(90deg, transparent 0 46px, rgba(0,0,0,.15) 46px 48px), #8a5a36;
  touch-action: none;
}
.tray-slot.hold {
  position: relative; margin: 8px; padding-top: 14px;
  background: rgba(40, 24, 10, .35);
  outline: 3px dashed rgba(246, 236, 210, .45); outline-offset: -3px;
}
.tray-slot.hold::before {
  content: 'HOLD'; position: absolute; top: 5px; left: 0; right: 0; text-align: center;
  font-family: "Press Start 2P", "Kanit", monospace; font-size: 8px; color: var(--label); opacity: .8;
}
.tray-slot.hold.target { background: rgba(245, 204, 58, .35); outline-color: var(--gold); }
.tray-slot {
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
}
.piece { display: grid; gap: 2px; transition: transform .12s, opacity .2s; }
.tray-slot:hover .piece { transform: scale(1.08) rotate(-2deg); }
.piece.in { animation: spawn .28s cubic-bezier(.3,1.6,.5,1) backwards; }
.piece.dead { opacity: .3; }
.piece.hide { visibility: hidden; }
.piece .pc, .piece .gap { width: var(--mini); height: var(--mini); }
.piece .pc { box-shadow: inset 0 -3px 0 var(--xd), inset 0 3px 0 var(--xl); }

/* บล็อกที่กำลังลาก ใช้ขนาดช่องเท่ากระดาน */
.drag {
  position: fixed; left: 0; top: 0; z-index: 22;
  display: grid; gap: var(--gap);
  pointer-events: none;
}
.drag .pc { box-shadow: inset 0 -5px 0 var(--xd), inset 0 4px 0 var(--xl), 0 10px 0 rgba(0,0,0,.3); }
.drag .pc, .drag .gap { width: var(--cell); height: var(--cell); }
.drag.back { transition: transform .18s ease-in, opacity .18s; opacity: 0; }
/* ระหว่างลากไม่มี transition (เดิม .05s: iPad ส่งตำแหน่งนิ้วถี่ transition เริ่มใหม่ตลอด บล็อกเลยกระตุก/ดีด) */
.drag { will-change: transform; }

/* ข้อความคอมโบ / คำชม */
.shout {
  position: absolute; left: 50%; top: 38%; z-index: 21;
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 26px; white-space: nowrap; text-align: center; line-height: 1.5;
  color: var(--gold);
  text-shadow: 3px 3px 0 #9c5a00, 6px 6px 0 rgba(0,0,0,.45);
  pointer-events: none;
  animation: shout 1s ease-out forwards;
}
.shout small { display: block; font-size: 14px; color: #fff; text-shadow: 2px 2px 0 rgba(0,0,0,.5); }
/* คอมโบใหญ่กลางกระดาน (ยิ่งคอมโบสูงตัวยิ่งใหญ่ สียิ่งร้อน) */
.shout.big { top: 30%; font-size: calc(30px + var(--lv, 0) * 4px); animation-duration: 1.2s; }
.shout.big em { display: block; font-style: normal; font-size: .45em; color: #fff; letter-spacing: 2px; }
.shout.hot { color: #ff8a3d; text-shadow: 3px 3px 0 #8c2a00, 6px 6px 0 rgba(0,0,0,.45); }
.shout.fire { color: #ff4f6d; text-shadow: 3px 3px 0 #6e0020, 6px 6px 0 rgba(0,0,0,.45); }
.shout.bonus { top: 56%; font-size: 15px; color: #8ff0ff; text-shadow: 2px 2px 0 #0d4f6b, 4px 4px 0 rgba(0,0,0,.4); animation-duration: 1.3s; }
.shout.record { top: 14%; font-size: 18px; color: #fff; padding: 8px 14px; background: #e8424f; box-shadow: 0 0 0 3px #fff, 0 0 0 6px #8c1d28, 6px 6px 0 6px rgba(0,0,0,.35); text-shadow: 2px 2px 0 #8c1d28; animation-duration: 1.8s; }
/* +คะแนน ลอยขึ้นจากแถวที่เก็บเกี่ยว */
.pop-pts {
  position: absolute; z-index: 20; transform: translate(-50%, -50%);
  font-family: "Press Start 2P", monospace; font-size: 16px; color: #fff;
  text-shadow: 2px 2px 0 #3a2a10, 0 0 6px rgba(0,0,0,.4);
  pointer-events: none; animation: poppts .9s ease-out forwards;
}
@keyframes poppts { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; }
                    20% { transform: translate(-50%, -60%) scale(1.25); opacity: 1; }
                    100% { transform: translate(-50%, -190%) scale(1); opacity: 0; } }
/* แสงวาบทั้งจอ + กรอบเรืองรอบกระดาน (ชั่วคราว ลบทิ้งเมื่อจบ) */
.flash { position: fixed; inset: 0; z-index: 19; pointer-events: none; background: #fff; opacity: 0; animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: var(--a, .35); } 100% { opacity: 0; } }
.board-glow { position: absolute; z-index: 18; pointer-events: none; border: 4px solid var(--gc, #f7c843); box-shadow: 0 0 18px 6px var(--gc, #f7c843), inset 0 0 18px 4px var(--gc, #f7c843); opacity: 0; animation: bglow .8s ease-out; }
@keyframes bglow { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
/* จุดบอกว่าคอมโบเหลืออีกกี่ตา */
.combo-life { display: flex; justify-content: center; gap: 4px; margin-top: 5px; height: 6px; }
.combo-life i { width: 10px; height: 6px; background: rgba(0,0,0,.25); transition: background-color .2s; }
.combo-life.live i.on { background: #f7c843; }
.combo-life.live.warn i.on { background: #ff6b4a; }

/* ---------- หน้าต่างจบเกม ---------- */
.win {
  position: fixed; inset: 0; z-index: 25;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45);
}
.win.show { display: flex; }
.win-box {
  background: var(--panel);
  padding: 28px 36px;
  text-align: center;
  animation: winpop .45s cubic-bezier(.3,1.8,.5,1);
}
.win-title {
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 32px;
  color: var(--gold);
  text-shadow: 4px 4px 0 #9c5a00, 8px 8px 0 rgba(0,0,0,.4);
  margin-bottom: 18px;
  animation: wiggle 1.2s ease-in-out infinite;
}
.win-stats { font-size: 22px; margin-bottom: 22px; line-height: 1.6; }
.win-stats b { font-family: "Press Start 2P", "Kanit", monospace; font-size: 18px; }

/* ---------- ร้านค้า ---------- */
.shop-box {
  background: var(--panel);
  width: min(calc(94 * var(--vw)), 620px);
  max-height: calc(92 * var(--vh));
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  animation: winpop .35s cubic-bezier(.3,1.8,.5,1);
}
.shop-head { display: flex; align-items: center; justify-content: space-between; }
.shop-title {
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 26px;
  color: var(--gold);
  text-shadow: 3px 3px 0 #9c5a00, 6px 6px 0 rgba(0,0,0,.4);
}
.wallet {
  font-family: "Press Start 2P", "Kanit", monospace;
  font-size: 15px;
  background: var(--panel-dark);
  padding: 10px 12px;
}
.wallet.bump { animation: bump .25s ease-out; }
.tabs { display: flex; gap: 12px; }
.tabs .btn { flex: 1; background: #8a7a62; font-size: 11px; padding: 12px 4px; }
.tabs .btn.on { background: var(--blue); }
.items {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  overflow-y: auto; padding: 6px 6px 14px;
}
.item {
  background: var(--panel-dark);
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.item.using {
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--gold),
    0 var(--px) 0 0 var(--gold),
    calc(var(--px) * -1) 0 0 0 var(--gold),
    var(--px) 0 0 0 var(--gold);
}
.preview {
  height: 84px;
  display: flex; align-items: center; justify-content: center;
  background: #3b2414 center / cover;
  image-rendering: pixelated;
}
.mini { display: grid; grid-template-columns: repeat(4, 18px); grid-auto-rows: 18px; gap: 2px; }
.shop-tip { font-family: 'Kanit', system-ui, sans-serif; font-size: 13px; color: var(--label); text-align: center; margin: -4px 0 -6px; }
.preview.demo { cursor: pointer; }
.preview .mini-tree { height: 72px; margin-left: 8px; image-rendering: pixelated; }
.preview .mini { grid-template-columns: repeat(4, 14px); grid-auto-rows: 14px; }
.item.set .preview { justify-content: center; gap: 6px; background-size: cover; background-position: center; }
.preview { position: relative; }
.limited { position: absolute; left: 4px; top: 4px; background: #c8302a; color: #fff; font: 600 10px 'Kanit', sans-serif; padding: 1px 6px; box-shadow: 0 0 0 2px var(--ink); }
.preview .mini-cat { height: 46px; image-rendering: pixelated; align-self: flex-end; margin-bottom: 4px; }
.preview.cat-pv { background: linear-gradient(#e9d3a8, #d8bc8c); }
.preview.cat-pv .mini-cat { height: 70px; align-self: center; margin: 0; }
.item .btn s { opacity: .7; font-size: 9px; }
.item.set .item-desc { line-height: 1.5; display: block; }
.item-desc { margin-top: 5px; font-family: 'Kanit', system-ui, sans-serif; font-size: 11px; font-weight: 600; color: var(--label); }
.item-name { font-family: "Press Start 2P", "Kanit", monospace; font-size: 11px; text-align: center; }
.item .btn { font-size: 10px; padding: 10px 4px; }
.item .btn.poor { background: #8a7a62; }
.item .btn .coin { width: 10px; height: 10px; margin-right: 4px; }

/* ---------- สกินบล็อก (ตั้งที่ .game และการ์ดตัวอย่างในร้าน ผ่าน data-skin) ----------
   ทุกสกินมีลายประจำ (--spr จาก JS: ดอกไม้ ซากุระ สน เห็ด กระบองเพชร คริสตัล แอปเปิล) ซ้อนบนพื้นของสกินนั้น
   สกินคู่กับพันธุ์ต้นไม้ในกระถางและลายกระถาง (ดู TREES / POTS ใน JS) */
:is(.cell.filled, .cell.ghost, .cell.hint, .pc) { image-rendering: pixelated; }
.cell.filled, .cell.ghost, .cell.hint, .pc { background: var(--spr, none) center / 74% 74% no-repeat, var(--xb); }
/* SAKURA (key candy): มุมมนแบบพิกเซล พาสเทล */
[data-skin="candy"] :is(.cell.filled, .cell.ghost, .cell.hint, .pc) {
  background: var(--spr, none) center / 74% 74% no-repeat, var(--xb);
  clip-path: polygon(0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px));
}
/* GLOWSHROOM (key neon): ป่ากลางคืน เห็ดเรืองแสง */
[data-skin="neon"] .board { background: #0d0b16; }
[data-skin="neon"] :is(.cell.filled, .cell.ghost, .cell.hint, .pc) {
  background: var(--spr, none) center / 74% 74% no-repeat, #15131f;
  box-shadow: inset 0 0 0 3px var(--xb), inset 0 0 8px 2px var(--xd), 0 0 6px var(--xb);
}
/* CRYSTAL (key gem): เหลี่ยมเจียระไน */
[data-skin="gem"] :is(.cell.filled, .cell.ghost, .cell.hint, .pc) {
  background: var(--spr, none) center / 74% 74% no-repeat, linear-gradient(135deg, var(--xl) 0 30%, var(--xb) 30% 65%, var(--xd) 65%);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.22), inset 5px 5px 0 rgba(255,255,255,.22);
}
/* BONSAI (key wood): ลายไม้ */
[data-skin="wood"] :is(.cell.filled, .cell.ghost, .cell.hint, .pc) {
  background: var(--spr, none) center / 74% 74% no-repeat, repeating-linear-gradient(90deg, var(--xb) 0 5px, var(--xd) 5px 6px, var(--xb) 6px 11px, var(--xl) 11px 12px);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.3), inset 0 3px 0 rgba(255,255,255,.2), inset 0 0 0 2px rgba(40,20,0,.45);
}
/* CACTUS (key gameboy): ทรายทะเลทราย ขอบเหมือนอิฐดินเผา */
[data-skin="gameboy"] :is(.cell.filled, .cell.ghost, .cell.hint, .pc) {
  box-shadow: inset 0 -5px 0 var(--xd), inset 0 4px 0 var(--xl), inset 0 0 0 2px rgba(90,40,10,.35);
}
/* GOLDEN APPLE (key gold): แถบวาว */
[data-skin="gold"] :is(.cell.filled, .cell.ghost, .cell.hint, .pc) {
  background: var(--spr, none) center / 74% 74% no-repeat, linear-gradient(115deg, var(--xb) 0 38%, var(--xl) 38% 50%, var(--xb) 50%);
}

/* ท่าแตกของบล็อกตามสกิน (ยาวไม่เกิน .4s ให้ตรงกับ CLEAR_MS ใน JS) */
[data-skin="classic"] .cell.clear { animation: harvest .36s ease-in forwards; }
@keyframes harvest { 0% { transform: none; } 35% { transform: translateY(-6px) scale(1.12); }
                     100% { transform: translateY(-20px) scale(.3); opacity: 0; } }
[data-skin="candy"]   .cell.clear { animation: candyPop .34s ease-in forwards; }
[data-skin="wood"]    .cell.clear { animation: woodBreak .4s ease-in forwards; }
[data-skin="neon"]    .cell.clear { animation: neonGlitch .34s linear forwards; }
[data-skin="gameboy"] .cell.clear { animation: harvest .36s ease-in forwards; }
[data-skin="gem"]     .cell.clear { animation: gemShatter .32s ease-in forwards; }
[data-skin="gold"]    .cell.clear { animation: coinFlip .38s ease-in forwards; }

@keyframes candyPop   { 0% { transform: scale(1); } 45% { transform: scale(1.28); }
                        100% { transform: scale(0); opacity: 0; } }
@keyframes woodBreak  { 0% { transform: none; } 25% { transform: rotate(-9deg) scale(1.05); }
                        100% { transform: translateY(26px) rotate(28deg) scale(.6); opacity: 0; } }
@keyframes neonGlitch { 0% { opacity: 1; } 15% { opacity: .15; } 30% { opacity: 1; transform: translateX(3px); }
                        45% { opacity: .1; } 60% { opacity: .9; transform: translateX(-3px) scale(1.1); }
                        80% { opacity: .2; } 100% { opacity: 0; transform: scale(1.35); } }
@keyframes gbFade     { 0% { opacity: 1; } 25% { opacity: .9; } 50% { opacity: .75; }
                        75% { opacity: .4; } 100% { opacity: 0; } }
@keyframes gemShatter { 0% { transform: scale(1); } 30% { transform: scale(1.15) rotate(6deg); }
                        100% { transform: scale(.15) rotate(50deg); opacity: 0; } }
@keyframes coinFlip   { 0% { transform: scale(1); } 30% { transform: scale(1.12); }
                        100% { transform: scaleX(0) scaleY(.7); opacity: 0; } }

/* ---------- แอนิเมชัน ---------- */
@keyframes nope   { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px) rotate(-4deg); } 75% { transform: translateX(6px) rotate(4deg); } }
@keyframes float  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes wiggle { 0%,100% { transform: rotate(-2deg) scale(1); } 50% { transform: rotate(2deg) scale(1.04); } }
@keyframes bump   { 0%, 40% { color: #fff3a0; } 100% { color: inherit; } }
@keyframes spawn  { 0% { transform: scale(0) rotate(-20deg); } 100% { transform: scale(1); } }
@keyframes drop   { 0% { transform: scale(.7); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes glow   { from { opacity: 0; } to { opacity: .35; } }
@keyframes zap    { 0% { transform: scale(1.1); } 100% { transform: scale(0); opacity: 0; } }
@keyframes shake  { 0%,100% { transform: translate(0,0); } 25% { transform: translate(-4px,2px); } 50% { transform: translate(4px,-2px); } 75% { transform: translate(-2px,-2px); } }
@keyframes shout  { 0% { transform: translate(-50%, 0) scale(.3) rotate(-8deg); opacity: 0; }
                    20% { transform: translate(-50%, 0) scale(1.15) rotate(2deg); opacity: 1; }
                    70% { transform: translate(-50%, -10px) scale(1); opacity: 1; }
                    100% { transform: translate(-50%, -40px) scale(1); opacity: 0; } }
@keyframes winpop { 0% { transform: scale(.2) rotate(-12deg); } 100% { transform: scale(1) rotate(0); } }

/* ---------- ชื่อผู้เล่น / จดหมาย ---------- */
.player-row { display: flex; gap: 10px; }
.btn.name-btn {
  flex: 1; min-width: 0;
  font-family: "Pixelify Sans", 'Kanit', system-ui, sans-serif; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 10px 8px;
}
.name-btn::after { content: ' ✎'; opacity: .7; }
.mail-btn { position: relative; padding: 10px 12px; }
.btn.sfx-btn { padding: 10px 10px; font-size: 14px; }
.btn.sfx-btn.off { opacity: .55; text-decoration: line-through; }
.dot {
  position: absolute; top: -8px; right: -8px;
  min-width: 20px; height: 20px; padding: 0 4px;
  background: var(--red); color: #fff;
  font-family: "Press Start 2P", "Kanit", monospace; font-size: 9px; line-height: 20px; text-align: center;
  box-shadow: 0 0 0 3px var(--ink);
  animation: bump .6s ease-out infinite alternate;
}
.mail-list { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; padding: 6px 6px 14px; min-height: 120px; }
.mail {
  background: var(--panel-dark); padding: 12px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center;
}
.mail h4 { margin: 0; font-family: "Pixelify Sans", 'Kanit', system-ui, sans-serif; font-size: 18px; color: var(--gold); }
.mail p { margin: 0; grid-column: 1; font-family: 'Kanit', system-ui, sans-serif; font-size: 14px; line-height: 1.5; color: #fbf1dc; white-space: pre-line; }
.mail .meta { grid-column: 1; font-size: 13px; color: var(--label); display: flex; gap: 12px; align-items: center; }
.mail .gift { font-family: "Press Start 2P", "Kanit", monospace; font-size: 12px; color: #fff; }
.mail .btn { grid-column: 2; grid-row: 1 / span 3; font-size: 11px; }
.mail.claimed { opacity: .55; }
.empty { text-align: center; padding: 36px 0; font-family: 'Kanit', system-ui, sans-serif; color: var(--label); }

/* ---------- หน้าแรก ---------- */
.home { position: fixed; inset: 0; z-index: 24; display: none; overflow: hidden; background: #e2c99a; }
body.at-home .home { display: block; }
body.at-home .layout { visibility: hidden; }
.room { position: absolute; inset: 0; }
.room canvas { image-rendering: pixelated; display: block; }
.r-wall { position: absolute; inset: 0;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.14)),
    repeating-linear-gradient(90deg, #e9d3a8 0 22px, #e2c99a 22px 24px, #e9d3a8 24px 46px, #dcc190 46px 48px); }
.r-wall::before { content: ''; position: absolute; inset: 0; opacity: .35;
  background: radial-gradient(circle at 12px 14px, #c98a6a 0 2px, transparent 3px) 0 0 / 48px 40px,
              radial-gradient(circle at 36px 34px, #8aa86a 0 2px, transparent 3px) 0 0 / 48px 40px; }
.r-floor { position: absolute; left: 0; right: 0; bottom: 0; height: 15%;
  background: linear-gradient(#8a5a36 0 6px, #4a2e17 6px 10px, transparent 10px),
    repeating-linear-gradient(90deg, #8a5a36 0 96px, #6e4426 96px 100px, #946238 100px 196px, #6e4426 196px 200px); }
.r-floor::after { content: ''; position: absolute; inset: 10px 0 0; background: repeating-linear-gradient(0deg, transparent 0 22px, rgba(0,0,0,.14) 22px 24px); }
.r-light { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse 55% 60% at 68% 36%, rgba(255,240,190,.3), transparent 70%); }
/* หน้าต่าง */
.r-window-wrap { position: absolute; right: 8%; top: 8%; width: 48%; height: 52%; }
.r-window { position: absolute; inset: 0; background: #6b4423; padding: 18px; box-shadow: 0 0 0 5px var(--ink), 12px 14px 0 rgba(0,0,0,.22), inset 0 0 0 4px #8f6038; }
.r-view { position: relative; width: 100%; height: 100%; overflow: hidden; background: #8fd0ee center / cover; image-rendering: pixelated; box-shadow: 0 0 0 4px var(--ink); }
.r-view canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.r-view::after { content: ''; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 0 28%, rgba(255,255,255,.16) 28% 34%, transparent 34% 48%, rgba(255,255,255,.1) 48% 51%, transparent 51%); }
.r-sky-tint { position: absolute; inset: 0; pointer-events: none; }
.r-mullion-v, .r-mullion-h { position: absolute; background: #6b4423; box-shadow: 0 0 0 3px var(--ink); z-index: 1; }
.r-mullion-v { left: 50%; top: 0; bottom: 0; width: 14px; margin-left: -7px; }
.r-mullion-h { top: 46%; left: 0; right: 0; height: 14px; }
.r-curtain { position: absolute; top: -26px; bottom: 6%; width: 15%; z-index: 2;
  background: repeating-linear-gradient(90deg, #c8504a 0 12px, #a83a36 12px 18px, #d8645a 18px 26px); box-shadow: 0 0 0 4px var(--ink); }
.r-curtain.l { left: -7%; clip-path: polygon(0 0, 100% 0, 60% 100%, 0 100%); }
.r-curtain.r { right: -7%; clip-path: polygon(0 0, 100% 0, 100% 100%, 40% 100%); }
.r-rod { position: absolute; left: -10%; right: -10%; top: -34px; height: 12px; background: #c8901a; box-shadow: 0 0 0 4px var(--ink); z-index: 3; }
.r-sill { position: absolute; left: -5%; right: -5%; top: 100%; height: 30px; z-index: 3;
  background: linear-gradient(#a8744a 0 8px, #8a5a36 8px 22px, #5a3a22 22px); box-shadow: 0 0 0 5px var(--ink), 0 14px 0 rgba(0,0,0,.22); }
.r-tree { position: absolute; right: 4%; bottom: 0; height: 64%; z-index: 4; image-rendering: pixelated; cursor: pointer; }
.r-sleep { position: absolute; left: 6%; bottom: 0; height: 26%; aspect-ratio: 40 / 20; z-index: 4; cursor: pointer; }
.r-tag { display: none; }
/* ชั้นวางใต้หน้าต่าง: สูงเท่าขอบหน้าต่าง */
.r-shelf { position: absolute; right: calc(8% + 48% * 0.02); width: calc(48% * 0.96); top: calc(60% + 30px); bottom: calc(15% - 6px); z-index: 2; }
.r-shelf > canvas { width: 100%; height: 100%; }
.r-pot { position: absolute; z-index: 3; image-rendering: pixelated; cursor: pointer; }
.r-plaque { position: absolute; left: 82%; top: 9%; transform: translate(-50%, 0); z-index: 4; text-align: center;
  background: linear-gradient(#f7d870, #d8a830); color: #4a2e10; padding: 6px 14px; line-height: 1.3;
  font: 600 12px "Kanit", sans-serif; box-shadow: 0 0 0 3px var(--ink), inset 0 2px 0 #fff3b0, inset 0 -2px 0 #a87a10; white-space: nowrap; }
.r-plaque:empty { display: none; }
.r-plaque b { display: block; font: 12px "Press Start 2P", "Kanit"; color: #2e5a1a; margin-top: 3px; font-weight: normal; }
/* ของบนผนัง */
.r-deco { position: absolute; z-index: 4; cursor: pointer; }
.r-deco > canvas { width: 100%; height: 100%; }
.r-deco .lbl { position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); margin-bottom: 5px; white-space: nowrap;
  font: 500 12px "Kanit", sans-serif; color: #5a3a22; background: rgba(246,236,210,.88); padding: 1px 6px; box-shadow: 0 0 0 2px rgba(42,26,16,.4); }
.r-lamp { position: absolute; left: 36.95%; top: 2%; width: 2.6%; aspect-ratio: 10 / 22; z-index: 4; }
.r-calendar { left: 35%; top: 15%; width: 6.5%; aspect-ratio: 20 / 24; }
.r-frame { left: 34.3%; top: 39%; width: 8%; aspect-ratio: 26 / 32; }
.r-trophy { left: 6%; top: 70%; width: 24%; aspect-ratio: 72 / 18; }
.r-mailbox { left: 34.5%; bottom: calc(15% - 4px); width: 6.4%; aspect-ratio: 22 / 40; z-index: 5; }
.r-dot { position: absolute; right: -10px; top: -12px; background: var(--red); color: #fff; font: 10px "Press Start 2P"; padding: 3px 5px; box-shadow: 0 0 0 2px var(--ink); }
.r-playcat { position: absolute; left: 3%; bottom: 3%; width: 30%; height: 20%; z-index: 3; cursor: pointer; }
.r-playcat canvas { width: 100%; height: 100%; }
/* แสงตามเวลา (โคมไฟอยู่เหนือปฏิทิน ~38%, 6%) */
.r-lamp-glow { position: absolute; inset: 0; pointer-events: none; z-index: 1; opacity: 0;
  background: radial-gradient(circle at var(--lamp-x, 38.3%) var(--lamp-y, 7%), rgba(255,226,150,.85) 0, rgba(255,200,110,.45) 7%, rgba(255,180,90,.16) 20%, transparent 36%); }
.r-tint { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.home[data-tod="evening"] .r-tint { background: radial-gradient(circle at var(--lamp-x, 38.3%) var(--lamp-y, 7%), rgba(255,140,60,0) 0, rgba(255,120,40,.1) 30%); }
.home[data-tod="night"] .r-tint { background: radial-gradient(circle at var(--lamp-x, 38.3%) var(--lamp-y, 7%), rgba(20,24,60,0) 0, rgba(20,24,60,.1) 10%, rgba(20,24,60,.42) 38%, rgba(16,18,48,.5) 70%); }
.home[data-tod="evening"] .r-lamp-glow, .home[data-tod="night"] .r-lamp-glow { opacity: 1; }
.home[data-tod="night"] .r-light { opacity: 0; }

/* ฟองคำพูด (เปลี่ยนแค่ opacity) */
.r-bubble { position: fixed; z-index: 26; max-width: 270px; background: var(--cream); color: var(--ink); padding: 6px 10px; line-height: 1.35;
  font: 600 14px "Kanit", sans-serif; box-shadow: 0 0 0 3px var(--ink), 3px 3px 0 rgba(0,0,0,.2); opacity: 0; pointer-events: none; transition: opacity .2s; }
.r-bubble.show { opacity: 1; }
.r-bubble b { color: #2e6b22; }
/* ป้ายเมนูแขวนผนังซ้าย */
.r-sign { position: absolute; left: 5%; top: 7%; width: clamp(280px, 26%, 380px); z-index: 7; }
.r-rope { position: absolute; left: 22%; right: 22%; top: -40px; height: 44px; border: 4px solid #5a3a22; border-bottom: 0; border-radius: 50% 50% 0 0 / 100% 100% 0 0; }
.r-nail { position: absolute; left: 50%; top: -48px; width: 12px; height: 12px; margin-left: -6px; background: #b0a090; box-shadow: 0 0 0 3px var(--ink); }
.home-box { display: flex; flex-direction: column; gap: 11px; padding: 16px 16px 12px;
  background: repeating-linear-gradient(0deg, transparent 0 22px, rgba(0,0,0,.12) 22px 24px), var(--panel); }
.home-logo canvas { width: 100%; }
.home-box .subtitle { margin-top: -8px; }
.home-coins { padding: 10px 12px; font-size: 13px; }
.play-btn { font-size: 22px; padding: 16px 10px; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.home-grid .btn { font-size: 12px; padding: 12px 6px; }
.home .foot-links { flex-wrap: wrap; gap: 6px 16px; }

/* ---------- แถบระหว่างเล่น ---------- */
.hud-top { display: flex; align-items: center; gap: 8px; }
.hud-title { flex: 1; font-family: "Press Start 2P", "Kanit", monospace; font-size: 12px; color: #a6e35a; text-shadow: 2px 2px 0 #2e6b22; }
.hud-top .mode-badge { margin: 0; align-self: auto; }
/* ปุ่มไอคอนพิกเซลบนแถบระหว่างเล่น: กดง่าย (สูง 44px) มีป้ายเล็กใต้ไอคอน */
.hud-btns { display: flex; gap: 8px; }
.btn.icon-btn { width: 54px; height: 50px; padding: 4px 0 3px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.btn.icon-btn canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.btn.icon-btn span { font: 600 10px "Kanit", system-ui, sans-serif; letter-spacing: 0; text-shadow: 1px 1px 0 rgba(0,0,0,.4); line-height: 1; }
.btn.home-ic { background: var(--green); }
.btn.gear-ic { background: #8a7a62; }
.hud-tree { display: flex; flex-direction: column; gap: 2px; font-family: 'Kanit', system-ui, sans-serif; font-size: 13px; color: var(--label); }
.hud-tree b { font-size: 17px; color: #a6e35a; text-shadow: 2px 2px 0 #2e6b22; }
.hud-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hud-stats .stat-value { font-size: 14px; padding: 9px 2px; }
.stat-value.green { background: var(--green); }
.pot-slot { display: none; }

/* กระถางต้นไม้ (ขวาของกระดานบนจอคอม / มุมขวาบนบนมือถือ) */
.game { margin-right: 218px; }
.pot-panel {
  position: absolute; left: calc(100% + 28px); top: 0; bottom: 0; width: 190px;
  display: flex; flex-direction: column; gap: 8px; padding: 12px;
  background: repeating-linear-gradient(0deg, transparent 0 22px, rgba(0,0,0,.12) 22px 24px), var(--panel);
}
.pot-head { display: flex; justify-content: space-between; align-items: center; font-family: "Press Start 2P", "Kanit", monospace; font-size: 10px; color: var(--label); }
.pot-head b { color: var(--gold); font-weight: normal; }
.pot-view {
  flex: 1; min-height: 0; position: relative;
  background: linear-gradient(#a6daf1, #d6eef7 70%, #b7e2f3);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.25);
}
body[data-tod="evening"] .pot-view { background: linear-gradient(#f0a070, #f4c494 70%, #e8b088); }
body[data-tod="night"] .pot-view { background: linear-gradient(#141c40, #24305a 70%, #2c3a66); }
.pot-view canvas { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; object-position: bottom; image-rendering: pixelated; }
.pot-view canvas.bump { animation: tree-bump .45s cubic-bezier(.3,1.8,.5,1); transform-origin: 50% 100%; }
@keyframes tree-bump { 0% { transform: scale(1); } 40% { transform: scale(1.08, .94); } 100% { transform: scale(1); } }
.tree-name { text-align: center; font-family: 'Kanit', system-ui, sans-serif; font-weight: 800; font-size: 15px; color: #a6e35a; text-shadow: 2px 2px 0 #2e6b22; }
.exp-bar { height: 12px; background: rgba(0,0,0,.35); box-shadow: 0 0 0 3px var(--ink); }
.exp-bar i { display: block; height: 100%; width: 0; background: linear-gradient(#a6e35a, #5cb84a); transform-origin: left; transition: width .3s; }
.exp-num { text-align: center; font-family: "Press Start 2P", "Kanit", monospace; font-size: 10px; color: var(--cream); }
.exp-pop {
  position: absolute; left: 50%; top: 40%; z-index: 2; pointer-events: none; white-space: nowrap;
  font-family: "Press Start 2P", "Kanit", monospace; font-size: 11px; color: #a6e35a; text-shadow: 2px 2px 0 #2e6b22;
  animation: exp-rise .9s ease-out forwards;
}
.exp-pop.big { font-size: 14px; color: var(--gold); text-shadow: 2px 2px 0 #9c5a00; }
@keyframes exp-rise { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -46px); opacity: 0; } }

/* โปสการ์ดตอนจบเกม */
.win-box { max-height: calc(96 * var(--vh)); overflow-y: auto; }
.postcard { display: block; width: min(calc(76 * var(--vw)), 300px); margin: 0 auto 12px; image-rendering: pixelated; box-shadow: 0 0 0 4px var(--ink), 0 10px 0 4px rgba(0,0,0,.3); -webkit-touch-callout: default; user-select: auto; }
.win-btns { display: flex; gap: 12px; margin-bottom: 8px; }
.win-btns .btn { flex: 1; }
.card-tip { font-family: 'Kanit', system-ui, sans-serif; font-size: 12px; color: var(--label); margin-bottom: 12px; }
.win-stats { font-size: 18px; margin-bottom: 14px; }

/* วิธีเล่น */
.foot-links { display: flex; justify-content: center; gap: 14px; }
.howto-box { width: min(calc(94 * var(--vw)), 460px); }
.howto-art {
  --mini: 18px; --gap: 3px;
  min-height: 120px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  background: repeating-linear-gradient(0deg, #5a3a22 0 5px, #50331d 5px 7px); padding: 14px;
  box-shadow: 0 0 0 4px var(--ink), inset 0 6px 0 #5cb84a;
}
.howto-art .cell { width: 44px; height: 44px; }
.howto-art .art-tree { display: block; height: 84px; image-rendering: pixelated; }
.howto-art .arrow { font-family: "Press Start 2P", "Kanit", monospace; font-size: 14px; color: var(--cream); }
.howto-art .lbl { display: block; margin-top: 6px; text-align: center; font-family: 'Kanit', system-ui, sans-serif; font-size: 11px; color: var(--cream); }
.howto-art .tray-slot.hold { width: 96px; height: 96px; margin: 0; }
.howto-art .chip { font-size: 9px; padding: 10px 8px; pointer-events: none; }
.howto-head { font-family: 'Kanit', system-ui, sans-serif; font-size: 18px; font-weight: 800; color: #a6e35a; text-shadow: 2px 2px 0 #2e6b22; }
.howto-text { font-family: 'Kanit', system-ui, sans-serif; font-size: 15px; line-height: 1.65; color: #fbf1dc; min-height: 104px; }
.howto-text b { color: var(--gold); }
.howto-dots { display: flex; justify-content: center; gap: 8px; }
.howto-dots i { width: 10px; height: 10px; background: rgba(0,0,0,.35); box-shadow: 0 0 0 2px var(--ink); }
.howto-dots i.on { background: var(--gold); }
.howto-nav { display: flex; gap: 12px; }
.howto-nav .btn { flex: 1; }

/* บทสอนเล่น */
.tut-bubble {
  position: absolute; left: 50%; top: 12px; z-index: 21; transform: translateX(-50%);
  width: calc(var(--size) - 32px);
  background: var(--cream); color: var(--ink); padding: 8px 12px;
  font-family: 'Kanit', system-ui, sans-serif; font-size: 14px; line-height: 1.45; text-align: center;
}
.tut-bubble[hidden], .tut-hand[hidden] { display: none; }
.tut-bubble b { color: #2e6b22; }
.tut-btns { display: flex; justify-content: center; gap: 10px; margin-top: 4px; }
.tut-btns .btn { font-size: 10px; padding: 10px 12px; }
.tut-btns .btn.ghost { color: #8a7a62; padding: 4px 8px; }
.cell.tut-target::after {
  content: ''; position: absolute; inset: 3px; pointer-events: none;
  border: 3px dashed var(--gold);
}
@keyframes glow-target { from { opacity: .35; } to { opacity: 1; } }
.tut-hand {
  position: fixed; left: 0; top: 0; z-index: 23; pointer-events: none;
  font-size: 36px; line-height: 1;
  animation: tut-move 1.6s ease-in-out infinite;
}
@keyframes tut-move {
  0%, 15% { transform: translate(var(--x0), var(--y0)); opacity: 0; }
  25% { opacity: 1; }
  75% { transform: translate(var(--x1), var(--y1)); opacity: 1; }
  100% { transform: translate(var(--x1), var(--y1)); opacity: 0; }
}
body.tutorial .sidebar { opacity: .45; pointer-events: none; }

/* ตั้งค่า */
.settings-box { width: min(calc(94 * var(--vw)), 440px); }
/* ชั้นวางต้นไม้ (กดต้นบนขอบหน้าต่าง): ทุกพันธุ์ เลือกต้นที่จะโชว์หน้าแรก */
.gh-box { width: min(calc(96 * var(--vw)), 680px); }
.gh-info { font-size: 15px; line-height: 1.5; text-align: center; min-height: 46px; }
.gh-info b { color: var(--gold); }
.gh-shelf { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 16px 6px; padding: 6px 4px 10px;
            --gh-h: 140px; }
.gh-item { position: relative; z-index: 0; height: var(--gh-h); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; cursor: pointer; border: 3px solid transparent; padding-bottom: 6px; }
/* แผ่นไม้ใต้ต้นแต่ละต้น (ติดไปกับต้นตอนเลื่อน: เดิมวาดเป็นพื้นหลังของกล่องเลื่อน ไม้เลยอยู่กับที่) */
.gh-item::after { content: ""; position: absolute; left: -6px; right: -6px; bottom: -3px; height: 8px; z-index: -1; background: linear-gradient(#946238 0 75%, #6e4426 75%); }
.gh-item img { height: 96px; image-rendering: pixelated; }
.gh-item span { font-size: 11px; line-height: 1.2; text-align: center; color: #fff; text-shadow: 1px 1px 0 #000; margin-top: 2px; }
.gh-item.on { border-color: var(--gold); background: rgba(247,200,67,.16); }
.gh-item.on::before { content: "HOME"; position: absolute; top: -2px; left: 50%; transform: translateX(-50%); font: 8px "Press Start 2P", monospace; color: #3a2a10; background: var(--gold); padding: 3px 4px; }
.gh-item.new img { opacity: .55; }
body.lay-narrow .gh-shelf { grid-template-columns: repeat(3, 1fr); --gh-h: 116px; }
body.lay-narrow .gh-item img { height: 78px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel-dark); padding: 10px 12px; }
.set-row > span { font-family: 'Kanit', system-ui, sans-serif; font-weight: 700; font-size: 15px; color: var(--cream); }
.set-row .btn { font-size: 11px; padding: 10px 14px; }
.seg { display: flex; gap: 8px; }
.seg .btn { background: #8a7a62; font-family: 'Kanit', system-ui, sans-serif; font-weight: 800; font-size: 13px; }
.seg .btn.on { background: var(--green); }
#set-mute.on { background: var(--green); } #set-mute.off { background: #8a7a62; }
.vol { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: flex-end; }
.vol input { width: min(calc(46 * var(--vw)), 180px); accent-color: var(--gold); }
.vol b { font-family: "Press Start 2P", "Kanit", monospace; font-size: 11px; color: var(--gold); min-width: 34px; text-align: right; }
#set-name { font-family: "Pixelify Sans", 'Kanit', system-ui, sans-serif; font-size: 15px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.set-btns .btn { font-family: 'Kanit', system-ui, sans-serif; font-weight: 800; font-size: 14px; padding: 12px 6px; }
#settings:not(.ingame) .ingame { display: none; }

/* บังคับแบบแนวตั้งบนจอกว้าง: ทั้งหน้าแรกและหน้าเล่นเป็นคอลัมน์กลางจอ */
body.lay-col .room { left: 50%; right: auto; width: min(calc(100 * var(--vw)), 560px); margin-left: calc(min(calc(100 * var(--vw)), 560px) / -2); box-shadow: 0 0 0 9999px #3b2a1e; }
body.lay-col .layout { max-width: 560px; margin: 0 auto; }

/* แบบแนวตั้งที่มีที่ว่าง: แสดงของบนผนังเป็นแถว */
body.lay-narrow .home.deco-row .r-deco { display: block; }
.home.deco-row .r-deco .lbl { display: none; }

/* หมุนเครื่อง */
.rotate { position: fixed; inset: 0; z-index: 40; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px;
  background: repeating-linear-gradient(0deg, transparent 0 22px, rgba(0,0,0,.12) 22px 24px), var(--panel); text-align: center; }
.rotate.show { display: flex; }
.rotate canvas { width: 120px; height: 120px; image-rendering: pixelated; }
.rotate-msg { font: 600 20px "Kanit", sans-serif; color: var(--cream); line-height: 1.5; }
.seg .btn[data-orient], .seg .btn[data-tod] { font-size: 12px; padding: 9px 10px; }

/* อันดับ */
.rank-list { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 160px; padding: 4px 6px 10px; }
.rank-row {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px;
  background: var(--panel-dark); padding: 8px 12px;
  font-family: "Pixelify Sans", 'Kanit', system-ui, sans-serif; font-size: 17px;
}
.rank-row .no { font-family: "Press Start 2P", "Kanit", monospace; font-size: 11px; color: var(--label); }
.rank-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .sc { font-family: "Press Start 2P", "Kanit", monospace; font-size: 12px; }
.rank-row.top1 .no { color: var(--gold); } .rank-row.top2 .no { color: #e0e0e8; } .rank-row.top3 .no { color: #e09a5a; }
.rank-row.me { background: #2e6b22; box-shadow: 0 0 0 3px #a6e35a; }
.rank-me { text-align: center; font-family: 'Kanit', system-ui, sans-serif; font-size: 14px; color: var(--label); min-height: 18px; }

/* ลองธีม: ซ่อนร้านให้เห็นพื้นหลังเต็มจอ เหลือแถบล่าง */
.try-bar {
  position: fixed; left: 50%; bottom: 24px; z-index: 27;
  transform: translate(-50%, 140%); transition: transform .25s cubic-bezier(.3,1.4,.5,1);
  width: min(calc(94 * var(--vw)), 520px);
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); padding: 12px;
}
.try-bar.show { transform: translate(-50%, 0); }
.try-name { flex: 1; min-width: 0; font-family: "Press Start 2P", "Kanit", monospace; font-size: 14px; color: var(--gold); }
.try-name small { display: block; font-size: 9px; color: var(--label); margin-bottom: 6px; }
.try-bar .btn { font-size: 11px; padding: 12px 10px; white-space: nowrap; }
.try-bar .btn .coin { width: 10px; height: 10px; margin-right: 4px; }
.preview.try { cursor: zoom-in; }
.layout { transition: opacity .25s; }
body.trying .layout { opacity: .18; pointer-events: none; }
body.trying .home { visibility: hidden; }

/* เลขเวอร์ชัน (แตะ = มีอะไรใหม่) */
.version {
  background: none; border: none; padding: 2px 0 0; cursor: pointer;
  font-family: 'Kanit', system-ui, sans-serif; font-size: 12px; color: var(--label); opacity: .7; text-align: center;
}
.version:hover { opacity: 1; text-decoration: underline; }
.update-bar {
  position: fixed; top: 12px; left: 50%; z-index: 29;
  transform: translate(-50%, -160%); transition: transform .3s cubic-bezier(.3,1.4,.5,1);
  border: none; cursor: pointer; padding: 12px 16px;
  background: var(--green); color: #fff;
  font-family: 'Kanit', system-ui, sans-serif; font-size: 15px; font-weight: 600;
  box-shadow: 0 0 0 3px var(--ink), 0 6px 0 3px rgba(0,0,0,.35);
  max-width: calc(92 * var(--vw));
}
.update-bar.show { transform: translate(-50%, 0); }
.dlg-text.daily-intro { text-align: left; font-size: 15px; }
.dlg-text.log { max-height: calc(55 * var(--vh)); overflow-y: auto; text-align: left; font-size: 14px; }

/* กล่องถาม */
.win.dlg { z-index: 28; }
.dlg-box { width: min(calc(92 * var(--vw)), 420px); display: flex; flex-direction: column; gap: 14px; }
.dlg-title {
  font-family: "Press Start 2P", "Kanit", monospace; font-size: 20px; color: var(--gold);
  text-shadow: 3px 3px 0 #9c5a00, 6px 6px 0 rgba(0,0,0,.4);
}
.dlg-text { font-family: 'Kanit', system-ui, sans-serif; font-size: 15px; line-height: 1.6; color: #fbf1dc; white-space: pre-line; }
.px-input, .admin-body input, .admin-body select, .admin-body textarea {
  font-family: "Pixelify Sans", 'Kanit', system-ui, sans-serif; font-size: 18px;
  color: var(--ink); background: var(--cream);
  border: none; padding: 10px 12px; width: 100%;
  box-shadow: inset 0 4px 0 var(--cream-shade, #d4c6a4), 0 0 0 3px var(--ink);
  outline: none; user-select: text; -webkit-user-select: text;
}
.dlg-btns { display: flex; flex-direction: column; gap: 12px; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--label); text-shadow: none; font-size: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 40px; z-index: 29;
  transform: translate(-50%, 30px); opacity: 0; transition: transform .2s, opacity .2s;
  background: var(--ink); color: #fff; padding: 12px 18px;
  font-family: "Pixelify Sans", 'Kanit', system-ui, sans-serif; font-size: 16px;
  box-shadow: 0 0 0 3px var(--gold); pointer-events: none; max-width: calc(90 * var(--vw)); text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* หน้าแอดมิน */
.admin-box { width: min(calc(96 * var(--vw)), 760px); }
.admin-body { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; font-family: 'Kanit', system-ui, sans-serif; font-size: 14px; padding: 4px 6px 12px; }
.admin-body h3 { margin: 10px 0 0; font-family: 'Kanit', system-ui, sans-serif; font-size: 16px; color: var(--gold); }
.admin-body label { display: block; color: var(--label); font-size: 12px; margin-bottom: 4px; }
.admin-body input, .admin-body select, .admin-body textarea { font-size: 15px; padding: 8px 10px; }
.astats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.astats div { background: var(--panel-dark); padding: 10px; text-align: center; color: var(--label); }
.astats b { display: block; font-family: "Press Start 2P", "Kanit", monospace; font-size: 18px; color: #fff; margin-bottom: 6px; }
.aform { display: flex; flex-direction: column; gap: 10px; background: var(--panel-dark); padding: 12px; }
.aform .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.arow { display: flex; align-items: center; gap: 10px; background: var(--panel-dark); padding: 8px 10px; }
.arow .tx { flex: 1; min-width: 0; }
.arow small { display: block; color: var(--label); margin-top: 2px; }
.arow .btn { font-size: 10px; padding: 8px 10px; }

/* จอมือถือ: หัวจอ 2 ฝั่ง (ซ้ายข้อมูล ขวากระถางต้นไม้) กระดานกับถาดอยู่ในจอเดียว */
/* (@media (max-width: 820px) {) → ตั้งจาก JS ตามค่าแนวจอ (applyLayout) */
body.lay-narrow .layout { flex-direction: column; justify-content: flex-start; gap: 14px; padding: 12px; }
body.lay-narrow .sidebar {
    width: min(calc(94 * var(--vw)), 520px); padding: 10px; gap: 8px; animation: none;
    display: grid; grid-template-columns: 1fr 40%;
    grid-template-areas: "top top" "tree pot" "stats pot";
  }
body.lay-narrow .hud-top { grid-area: top; }
body.lay-narrow .hud-title { font-size: 10px; }
body.lay-narrow .btn.icon-btn { width: 44px; height: 44px; }
body.lay-narrow .btn.icon-btn canvas { width: 20px; height: 20px; }
body.lay-narrow .hud-tree { grid-area: tree; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 12px; }
body.lay-narrow .hud-tree b { font-size: 14px; }
body.lay-narrow .hud-stats { grid-area: stats; gap: 8px; }
body.lay-narrow .hud-stats .stat { padding: 5px 6px; }
body.lay-narrow .stat-label { font-size: 9px; letter-spacing: 1px; margin-bottom: 3px; }
body.lay-narrow .hud-stats .stat-value { font-size: 12px; padding: 6px 2px; }
body.lay-narrow .hint { display: none; }
body.lay-narrow .pot-slot { display: block; grid-area: pot; min-height: 0; }
body.lay-narrow .pot-slot .pot-panel { position: static; width: auto; height: 100%; padding: 6px; gap: 4px; }
body.lay-narrow .pot-head, body.lay-narrow .exp-num { display: none; }
body.lay-narrow .tree-name { font-size: 12px; }
body.lay-narrow .exp-bar { height: 7px; box-shadow: 0 0 0 2px var(--ink); }
body.lay-narrow .game { --size: min(calc(92 * var(--vw)), calc(calc(100 * var(--vh)) - 330px), 480px); gap: 14px; margin-right: 0; }
body.lay-narrow .r-floor, body.lay-narrow .r-shelf, body.lay-narrow .r-playcat, body.lay-narrow .r-rope, body.lay-narrow .r-nail, body.lay-narrow .r-deco, body.lay-narrow .r-lamp, body.lay-narrow .r-lamp-glow { display: none; }
body.lay-narrow .r-window-wrap { left: 9%; right: 9%; width: auto; top: 5%; height: 29%; }
body.lay-narrow .r-tree { height: 74%; }
body.lay-narrow .r-sleep { height: 26%; }
body.lay-narrow .r-tag { display: block; position: absolute; left: 50%; transform: translateX(-50%); top: calc(100% + 40px); z-index: 4; white-space: nowrap;
    background: linear-gradient(#f7d870, #d8a830); color: #4a2e10; padding: 3px 10px; font: 600 12px "Kanit", sans-serif; box-shadow: 0 0 0 3px var(--ink); }
body.lay-narrow .r-tag:empty { display: none; }
body.lay-narrow .r-sign { left: 5%; right: 5%; width: auto; top: auto; bottom: 2%; }
body.lay-narrow .home-box { gap: 8px; padding: 12px; }
body.lay-tab .r-sign { left: 0; right: 0; margin: 0 auto; width: min(430px, 64%); zoom: 1.3; }
body.lay-tab .sidebar { width: min(calc(92 * var(--vw)), 680px); }
body.lay-narrow .home-logo canvas { width: 62%; margin: 0 auto; }
body.lay-narrow .home-box .subtitle { display: none; }
body.lay-narrow .play-btn { font-size: 18px; padding: 13px 6px; }
body.lay-narrow .home-grid .btn { padding: 10px 6px; }
body.lay-narrow .postcard { width: min(calc(70 * var(--vw)), 260px); }
body.lay-narrow .shout { font-size: 20px; }
body.lay-narrow .shout.big { font-size: calc(26px + var(--lv, 0) * 3px); }
body.lay-narrow .shout.bonus, body.lay-narrow .shout.record { font-size: 13px; }
body.lay-narrow .shop-box { padding: 14px; }
body.lay-narrow .shop-title { font-size: 20px; }
body.lay-narrow .items { grid-template-columns: repeat(2, 1fr); gap: 12px; }

/* มือถือแนวนอน: ซ้าย = ข้อมูล + กระถาง, กลาง = กระดาน, ขวา = กระบะแนวตั้ง */
/* (@media (orientation: landscape) and (max-height: 560px) {) → ตั้งจาก JS ตามค่าแนวจอ (applyLayout) */
body.lay-short .layout { flex-direction: row; align-items: center; justify-content: center; gap: 14px; padding: 8px 12px; }
body.lay-short .sidebar {
    width: 210px; height: calc(calc(100 * var(--vh)) - 16px); padding: 10px; gap: 8px; animation: none;
    display: flex; flex-direction: column;
  }
body.lay-short .hud-tree { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 12px; }
body.lay-short .hud-tree b { font-size: 14px; }
body.lay-short .hud-stats { gap: 6px; }
body.lay-short .hud-stats .stat { padding: 4px 6px; }
body.lay-short .hud-stats .stat-value { font-size: 11px; padding: 5px 2px; }
body.lay-short .hint { display: none; }
body.lay-short .pot-slot { display: block; flex: 1; min-height: 0; }
body.lay-short .pot-slot .pot-panel { position: static; width: auto; height: 100%; padding: 6px; gap: 4px; }
body.lay-short .pot-head, body.lay-short .exp-num { display: none; }
body.lay-short .game { flex-direction: row; gap: 12px; margin-right: 0; }
body.lay-short .tray { width: calc(var(--cell) * 2.5); height: var(--size); grid-template-columns: 1fr; grid-template-rows: 0.8fr 1fr 1fr 1fr; }
body.lay-short .tray-slot.hold { margin: 5px; }
body.lay-short .tut-bubble { width: calc(var(--size) - 20px); font-size: 12px; }
/* หน้าแรก: ห้องเหมือนจอคอม ป้ายเมนูเล็กลง */
  /* กฎมือถือแนวตั้ง (max-width) ติดมาด้วย: คืนค่าห้องแบบจอคอม */
body.lay-short .r-floor, body.lay-short .r-shelf, body.lay-short .r-deco, body.lay-short .r-lamp, body.lay-short .r-lamp-glow { display: block; }
body.lay-short .r-trophy, body.lay-short .r-playcat, body.lay-short .r-tag { display: none !important; }
body.lay-short .r-window-wrap { left: auto; right: 4%; width: 52%; top: 9%; height: 46%; }
body.lay-short .r-tree { height: 64%; }
body.lay-short .r-shelf { right: calc(4% + 52% * 0.02); width: calc(52% * 0.96); }
body.lay-short .r-sign { left: 3%; right: auto; bottom: auto; }
body.lay-short .r-lamp { left: 38.3%; top: 1%; width: 2.2%; }
body.lay-short .r-calendar { left: 36.5%; top: 14%; width: 5.4%; }
body.lay-short .r-frame { left: 36%; top: 40%; width: 6.4%; }
body.lay-short .r-mailbox { left: 36.6%; width: 5%; }
body.lay-short .r-mailbox .lbl { display: none; }
body.lay-short .r-pot { display: none; }
body.lay-short .r-calendar .lbl, body.lay-short .r-frame .lbl { font-size: 9px; padding: 0 4px; }
body.lay-short .r-plaque { padding: 3px 8px; top: 6%; }
body.lay-short .r-sign { top: 3%; width: 31%; }
body.lay-short .r-rope, body.lay-short .r-nail, body.lay-short .home-box .subtitle, body.lay-short .home .foot-links { display: none; }
body.lay-short .home-box { gap: 6px; padding: 8px; }
body.lay-short .home-logo canvas { width: 78%; margin: 0 auto; }
body.lay-short .player-row .btn, body.lay-short .home-coins { padding: 6px 8px; font-size: 11px; }
body.lay-short .play-btn { font-size: 15px; padding: 9px 6px; }
body.lay-short .home-grid { gap: 6px; }
body.lay-short .home-grid .btn { font-size: 9px; padding: 7px 4px; }
body.lay-short .home-grid .btn.thai-txt { font-size: 13px; }
body.lay-short .r-window-wrap .r-window { padding: 10px; }
body.lay-short .r-sill { height: 18px; }
body.lay-short .r-shelf { top: calc(60% + 18px); }
body.lay-short .r-deco .lbl, body.lay-short .r-plaque { font-size: 10px; }
body.lay-short .r-plaque b { font-size: 9px; }
/* จบเกม: โปสการ์ดซ้าย ปุ่มขวา */
body.lay-short .win-box { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; align-items: center; max-width: calc(94 * var(--vw)); padding: 14px 20px; }
body.lay-short .postcard { grid-row: 1 / span 5; width: auto; height: min(calc(84 * var(--vh)), 420px); margin: 0; }
body.lay-short .win-title { font-size: 22px; margin: 0; }
body.lay-short .win-stats { margin: 0; font-size: 15px; }
body.lay-short .win-btns { margin: 0; }
body.lay-short .card-tip { margin: 0; }
body.lay-short .shop-box { max-height: calc(94 * var(--vh)); }
body.lay-short .items { grid-template-columns: repeat(4, 1fr); }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
