/* Layout */
:root{
  --bg:#0b1220;
  --text:#e8eefc;
  --muted:#93a3c7;
  --tileTop:#3b4150;
  --tileSide:#2b3141;
}

*{ box-sizing:border-box; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 30% 20%, #16213b 0%, var(--bg) 55%);
  color: var(--text);
}

.app{
  display:grid;
  grid-template-columns: 1fr 320px;
  height:100vh;
  gap:14px;
  padding:14px;
}

.play{
  position:relative;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius:16px;
  overflow:hidden;
}

#gameCanvas{
  width:100%;
  height: calc(100% - 110px);
  display:block;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.00));
}

.tray{
  height:110px;
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.18);
  overflow-x:auto;
}

.cmdBtn{
  background-color: transparent;

  width:64px; height:64px;
  border:none;
  background: transparent;
  padding:0;
  cursor:pointer;
  border-radius:14px;
  outline: none;
  transition: transform .12s ease, box-shadow .12s ease;
}
.cmdBtn:hover{ transform: translateY(-1px); }
.cmdBtn:active{ transform: translateY(1px); }

/* Right panel */
.side{
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius:16px;
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.sideTop{
  padding:14px;
  display:flex;
  align-items:flex-start;
  gap:12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.12);
}

/* Run button (CSS) */
.runBtn{
  width:74px;
  height:56px;
  border:none;
  border-radius:14px;
  cursor:pointer;
  background: linear-gradient(#6CFF3F, #3EDB1F);
  box-shadow: 0 7px 0 #1B8F0B;
  transition: all .15s ease;
  display:flex;
  align-items:center;
  justify-content:center;
  flex: 0 0 auto;
}
.runBtn:active{
  transform: translateY(5px);
  box-shadow: 0 2px 0 #1B8F0B;
}
.runBtn.stop{
  background: linear-gradient(#FF5A5A, #D63232);
  box-shadow: 0 7px 0 #8F0B0B;
}
.icon.play{
  width:0;height:0;
  border-left: 22px solid #fff;
  border-top: 14px solid transparent;
  border-bottom: 14px solid transparent;
  transform: translateX(2px);
}
.icon.stop{
  width:22px;height:22px;
  background:#fff;
  border-radius:3px;
}

.status{
  display:flex;
  flex-direction:column;
  gap:8px;
  flex: 1 1 auto;
}
.levelRow{
  display:flex;
  gap:8px;
  align-items:center;
  color: var(--muted);
  font-size: 13px;
}
.levelRow label{ width:52px; color: var(--muted); }
.levelRow select, .levelRow input{
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--text);
  border-radius:10px;
  padding:6px 8px;
  outline:none;
}
.levelRow .unit{ color: var(--muted); }

.panelTabs{
  display:flex;
  gap:8px;
  padding:10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.08);
}
.tab{
  padding:8px 10px;
  border-radius:12px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  cursor:pointer;
  user-select:none;
  font-weight:600;
  font-size:13px;
}
.tab.active{
  color: var(--text);
  border-color: rgba(76,201,255,0.40);
  box-shadow: 0 0 0 2px rgba(76,201,255,0.18) inset;
}

.panelWrap{
  padding:14px;
}
.panelGrid{
  display:grid;
  /* grid-auto-rows: 64px; */
  gap:4px;
  padding:10px;
  border-radius:14px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.10);
  min-height: 168px;
  width: calc(4 * 64px + 3 * 10px);
  margin: 0 auto;
}

.slot{
  width:64px; height:64px;
  border-radius:14px;
  border: 1px dashed rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.03);
  display:flex;
  align-items:center;
  justify-content:center;
  position:relative;
}
.slot.filled{
  border-style:solid;
  border-color: rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  cursor:grab;
}
.slot.dragOver{
  outline: 3px solid rgba(76,201,255,0.35);
}

.slot img{
  width:64px; height:64px;
  border-radius:14px;
  pointer-events:none;
}

.hint{
  margin-top:auto;
  padding:12px 14px;
  color: rgba(232,238,252,0.65);
  font-size: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.10);
}


/* Overlay modal */
.overlay{
  position:fixed;
  align-items: flex-start;
  padding-top: 60px; /* เพิ่ม/ลด */
  inset:0;
  display:flex;
  /* align-items:center; */
  justify-content:center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  z-index: 9999;
}
.overlay.hidden{ display:none; }
.overlayCard{
  width: min(420px, calc(100vw - 32px));
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(18,26,43,0.92);
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  padding: 16px 16px 14px 20px;
  transform: translateY(16px);
}
.overlayActions{
  display: flex;
  gap: 12px;                 /* ระยะห่างระหว่างปุ่ม */
  margin-top: 14px;
}
.overlayTitle{
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 6px;
}
.overlayMsg{
  color: rgba(232,238,252,0.75);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
}
.restartBtn{
  width:100%;
  height:46px;
  border:none;
  border-radius: 14px;
  cursor:pointer;
  font-weight: 800;
  letter-spacing: .2px;
  color: #ffffff;
  font-size: 32px;
  background: linear-gradient(#3fffef, #1fa6db);
  box-shadow: 0 7px 0 #0b5a8f;
  transition: all .15s ease;
}
.restartBtn:active{
  transform: translateY(5px);
  box-shadow: 0 2px 0 #0b5f8f;
}

.hidden{ display:none !important; }

.nextBtn{
  width:100%;
  height:46px;
  border:none;
  border-radius: 14px;
  cursor:pointer;
  font-weight: 800;
  letter-spacing: .2px;
  color: #ffffff;
  font-size: 32px;
  background: linear-gradient(#3fff59, #2fdb1f);
  box-shadow: 0 7px 0 #358f0b;
  transition: all .15s ease;
}
.nextBtn:active{ transform: translateY(2px); }

.supportBlock{
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.supportText{
  font-size: 12.5px;
  color: rgba(232,238,252,0.78);
  line-height: 1.35;
  margin-bottom: 10px;
}
.supportEn{ color: rgba(232,238,252,0.62); margin-top: 2px; }

.supportBtns{
  display:flex;
  gap:10px;
}
.supportBtn{
  flex: 1 1 0;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: rgba(232,238,252,0.92);
  font-weight: 700;
  cursor: pointer;
}
.supportBtn:active{ transform: translateY(2px); }

.ppPanel{
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.16);
}
.ppQr{
  width: 100%;
  max-width: 240px;
  display:block;
  margin: 0 auto 8px auto;
  border-radius: 10px;
}
.ppHint{
  text-align:center;
  font-size: 12px;
  color: rgba(232,238,252,0.70);
}
.ppActions{
  display:flex;
  justify-content:center;
  margin-top: 10px;
}
.ppClose{
  height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: rgba(232,238,252,0.92);
  cursor:pointer;
}

/* ========== Mobile-safe Overlay ========== */
:root{
  /* ป้องกันปัญหา 100vh บนมือถือ: ใช้ dynamic viewport */
  --vh: 1dvh;
}

/* ถ้าอยากเข้ากันทุก browser มากขึ้น (optional) */
@supports not (height: 100dvh){
  :root{ --vh: 1vh; }
}

/* overlay backdrop */
.overlay{
  position: fixed;
  inset: 0;
  width: 100%;
  height: calc(var(--vh) * 100);   /* ใช้ 100dvh ถ้าได้ */
  display: flex;
  align-items: center;
  justify-content: center;

  padding: 16px;
  z-index: 9999;

  /* กันข้างหลังเลื่อน */
  overflow: hidden;

  /* backdrop */
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  /* กัน double-tap zoom / scroll แปลกๆ */
  touch-action: none;
}

.overlay.hidden{ display:none; }

/* ========== Overlay Card ========== */
/* สมมติของเดิมใช้ .overlayCard */
.overlayCard{
  width: min(92vw, 520px);
  max-height: calc(var(--vh) * 100 - 32px); /* เผื่อ padding overlay */
  overflow: auto; /* ให้สกอลล์ใน card แทน */
  -webkit-overflow-scrolling: touch;

  /* ทำให้สวย/อ่านง่าย */
  border-radius: 18px;
  padding: 18px 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);

  /* กันปุ่ม/QR ล้น */
  box-sizing: border-box;
}

/* ========== Buttons Row (Replay + Next แถวเดียว) ========== */
.overlayActions{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: center;
}

/* ถ้าจอแคบมาก ให้กลับเป็น 1 คอลัมน์ */
@media (max-width: 380px){
  .overlayActions{
    grid-template-columns: 1fr;
  }
}

/* ========== Support buttons wrap สวย ๆ ========== */
.supportRow{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ========== PromptPay QR panel ให้ไม่ล้น ========== */
.ppPanel{
  max-width: 100%;
  overflow: hidden;
}
.ppPanel img{
  max-width: 100%;
  height: auto;
  display: block;
}

/* ========== (Optional) ตอน overlay โผล่ ล็อค body ไม่ให้เลื่อน ========== */
body.overlayOpen{
  overflow: hidden;
  touch-action: none;
}

.slot.dragging {
  z-index: 20;
  opacity: 0.8;
  transition: none;
}
