/* ─────────────────────────────────────────────────────────────
   style.css — เกมจับคู่ภาพ ⇄ คำ (แม่กก)
   ออกแบบสำหรับมือถือแนวตั้ง เด็ก ป.1 · ปุ่มใหญ่ ตัวหนังสือใหญ่
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #f2f7ff;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #dbe6f5;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;

  --r: 20px;
  --shadow: 0 6px 20px rgba(30, 60, 120, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Sarabun', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont,
               'Segoe UI', Roboto, sans-serif;
  font-size: 18px; line-height: 1.6;
  overscroll-behavior: none;
}

.wrap {
  max-width: 560px; margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(40px + env(safe-area-inset-bottom));
  min-height: 100vh; min-height: 100dvh;
}

h1 { font-size: 25px; margin: 8px 0 4px; }
h2 { font-size: 21px; margin: 20px 0 10px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 15px; }
.center { text-align: center; }
.hidden { display: none !important; }

.card {
  background: var(--card); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 18px; margin: 14px 0;
}

/* ── ปุ่ม ───────────────────────────────────────────────── */
.btn {
  display: block; width: 100%; min-height: 56px;
  border: none; border-radius: 16px;
  background: var(--primary); color: #fff;
  font-size: 20px; font-weight: 700; font-family: inherit;
  cursor: pointer; padding: 12px 16px; margin: 10px 0;
  touch-action: manipulation;
  transition: transform .08s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn.soft { background: var(--line); color: var(--ink); }
.btn.small { min-height: 44px; font-size: 16px; }
.btn.danger { background: var(--red); }

.input {
  width: 100%; min-height: 56px;
  border: 2px solid var(--line); border-radius: 16px;
  padding: 12px 16px; font-size: 20px; font-family: inherit;
  background: #fff; color: var(--ink);
}
.input:focus { outline: none; border-color: var(--primary); }

/* ── HUD ───────────────────────────────────────────────── */
.hud {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; font-weight: 700; color: var(--muted); padding: 4px 2px;
}
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 10px; }
.bar > i { display: block; height: 100%; background: var(--primary); width: 0; transition: width .3s; }

.hint {
  text-align: center; font-size: 16px; font-weight: 700; color: var(--primary-dark);
  background: #e0ecff; border-radius: 12px; padding: 8px 10px; margin-bottom: 10px;
  min-height: 40px;
}

/* ── การ์ดรูปภาพ + กล่องวางคำ ─────────────────────────── */
.cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.pcard {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow);
  padding: 8px 8px 10px; text-align: center;
}
.pic { height: 96px; display: flex; align-items: center; justify-content: center; }
.card-emoji { font-size: 62px; line-height: 1; }
.card-img { width: 100%; height: 96px; object-fit: contain; }

.drop {
  margin-top: 6px; min-height: 58px;
  border: 3px dashed #b9cdea; border-radius: 14px;
  background: #f7fbff;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 22px; font-weight: 800;
  padding: 4px 6px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.drop .ph { font-size: 13px; color: #9db4d4; font-weight: 400; }
.drop.over { border-color: var(--primary); background: #e0ecff; transform: scale(1.04); }
.drop.filled { border-style: solid; border-color: var(--green); background: var(--green-soft); }
.drop.good { animation: pop .4s; }
.drop.bad { border-color: var(--red); background: var(--red-soft); }
.drop .word { line-height: 1.3; word-break: keep-all; }
.drop .spk { font-size: 14px; opacity: .55; }

@keyframes pop { 0%{transform:scale(1)} 45%{transform:scale(1.12)} 100%{transform:scale(1)} }
.shake { animation: shake .45s; }
@keyframes shake {
  0%,100%{transform:translateX(0)} 20%{transform:translateX(-7px)}
  40%{transform:translateX(7px)} 60%{transform:translateX(-5px)} 80%{transform:translateX(5px)}
}

/* ── ถังคำ ─────────────────────────────────────────────── */
.bank-label { font-size: 14px; color: var(--muted); margin: 16px 0 6px; text-align: center; }
.bank {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  min-height: 62px;
}
.chip {
  border: 3px solid var(--line); border-radius: 14px;
  background: #fff; box-shadow: var(--shadow);
  font-family: inherit; font-size: 24px; font-weight: 800;
  padding: 10px 16px; min-height: 54px;
  cursor: grab;
  touch-action: none;               /* สำคัญ: กันจอเลื่อนตอนลากบนมือถือ */
  user-select: none; -webkit-user-select: none;
  transition: transform .1s, opacity .15s;
}
.chip:active { transform: scale(.96); }
.chip.selected { border-color: var(--primary); background: #e0ecff; transform: scale(1.06); }
.chip.dragging { opacity: .28; }
.chip.done { display: none; }
.chip.ghost {
  position: fixed; z-index: 9999; pointer-events: none;
  transform: translate(-50%, -50%) scale(1.1) rotate(-3deg);
  box-shadow: 0 12px 26px rgba(0,0,0,.28);
  opacity: .95; left: -999px; top: -999px;
}

/* ── คำอธิบายสี ────────────────────────────────────────── */
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center;
  font-size: 14px; margin-top: 12px;
}
.legend span b { font-size: 17px; }

/* ── หน้าสรุป ──────────────────────────────────────────── */
.big-score { font-size: 56px; font-weight: 800; line-height: 1.1; }
.stat-row { display: flex; justify-content: space-around; text-align: center; margin: 12px 0; }
.stat-row .v { font-size: 24px; font-weight: 800; }
.stat-row .k { font-size: 13px; color: var(--muted); }
.wchip {
  display: inline-block; background: #f1f5f9; border-radius: 10px;
  padding: 4px 10px; margin: 3px; font-size: 20px; font-weight: 800;
}

/* ── แท็บ / ตารางคะแนน ─────────────────────────────────── */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.tab {
  flex: 0 0 auto; border: 2px solid var(--line); background: #fff;
  border-radius: 99px; padding: 8px 16px; font-size: 16px;
  font-family: inherit; color: var(--ink); cursor: pointer;
}
.tab[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

.alert { border-radius: 16px; padding: 14px 16px; margin: 12px 0; font-size: 16px; }
.alert.warn { background: var(--amber-soft); color: #92400e; border: 2px solid #fcd34d; }
.alert.info { background: #e0f2fe; color: #075985; border: 2px solid #7dd3fc; }

/* ── กล่องปุ่มลบ ───────────────────────────────────────── */
.danger-zone {
  border: 2px dashed #fca5a5; background: #fff5f5;
  border-radius: 18px; padding: 14px 16px; margin-top: 28px;
}
.danger-zone .dz-title { font-weight: 800; color: var(--red); font-size: 17px; }
.danger-zone .dz-text { font-size: 14px; color: #7f1d1d; margin: 6px 0 10px; }

/* ── แถบเตือนเปิดจากในแอป ──────────────────────────────── */
.inapp-bar {
  position: relative;
  background: var(--amber-soft); border-bottom: 3px solid #fcd34d;
  color: #92400e; padding: 12px 44px 12px 16px; font-size: 15px;
}
.inapp-bar .ib-title { font-weight: 800; }
.inapp-bar .ib-text { margin: 4px 0 8px; }
.inapp-bar .ib-btns { display: flex; gap: 8px; }
.inapp-bar .ib-btns .btn { margin: 0; }
.inapp-bar .ib-close {
  position: absolute; top: 8px; right: 10px;
  border: none; background: transparent; font-size: 20px;
  color: #92400e; cursor: pointer; padding: 4px 8px;
}

/* ── บังคับแนวตั้ง ─────────────────────────────────────── */
.rotate-lock { display: none; }
@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .rotate-lock {
    position: fixed; inset: 0; z-index: 9500; background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 20px;
  }
  .rot-ico { font-size: 64px; animation: tilt 1.6s ease-in-out infinite; }
  .rotate-lock h2 { font-size: 24px; margin: 6px 0; }
  .rotate-lock p { color: var(--muted); }
}
@keyframes tilt { 0%,100%{transform:rotate(-90deg)} 55%,95%{transform:rotate(0deg)} }

/* ── จอเล็กมาก ─────────────────────────────────────────── */
@media (max-width: 360px) {
  .card-emoji { font-size: 52px; }
  .pic, .card-img { height: 82px; }
  .chip { font-size: 20px; padding: 8px 12px; }
  .drop { font-size: 19px; min-height: 52px; }
}

/* ── ระบายสีวรรณยุกต์ / สระบน-ล่าง (คู่กับ colorWord ใน app.js) ──
   ตัวฐาน + เครื่องหมายที่เกาะอยู่ ถูกวาดซ้อนกันหลายชั้น
   ชั้นแรกอยู่ใน flow (กำหนดขนาด) ชั้นถัดไปวางทับที่มุมเดียวกัน
   ⚠️ ห้ามมี letter-spacing ในนี้ ไม่งั้นแต่ละชั้นจะเลื่อนไม่ตรงกัน */
.cl { position: relative; display: inline-block; letter-spacing: normal; white-space: pre; }
.cl > .ab { position: absolute; left: 0; top: 0; }
