/* ═══════════════════════════════════════════════════════════════════
   AgingOne · หน้าจอโหมดพูดคุยกับไอด้า (#vm · 26 พ.ย. 2569)
   ใช้คู่กับ css/home-aida-chat.css (ตัวแปรสี --violet* --orange* มาจาก #aida) · พฤติกรรม = js/home-v6.js
   ตามรายงาน voice UX ผู้สูงอายุ: วงกลมใหญ่กลางจอบอกสถานะ · ข้อความสถานะตัวใหญ่ · คำที่พูด/คำตอบ ≥22px
   ตัวอักษรเข้มบนพื้นสว่าง (คอนทราสต์ ≥7:1) · ปุ่มล่าง ≥64×64px มีข้อความไทยใต้ไอคอน ห่างกัน ≥16px
   แผง #aida เต็มจออยู่แล้วทุกขนาดจอ → #vm คลุมทั้งแผง = เต็มจอบนมือถือ
   ═══════════════════════════════════════════════════════════════════ */
#aida .ac-card { position: relative; }
#aida.vm-on .card-top, #aida.vm-on .card-b { display: none; }   /* ซ่อนแชทใต้จอเสียง (โฟกัส Tab ไม่หลุดไปข้างหลัง) */

#aida .vm {
  --vm-ink: #2A1B4A; --vm-red: #a11d1d; --vm-red-d: #7f1414;
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #fbf8ff 0%, #ffffff 55%); color: var(--vm-ink);
  padding: max(10px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
#aida .vm[hidden] { display: none; }
#aida .vm-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 12px; min-height: 44px; text-align: center; }
#aida .vm-tt { font-weight: 700; color: var(--violet-dd); font-size: max(18px, 1em); }
#aida .vm-demo { padding: 4px 12px; border-radius: var(--pill); background: #fff4d6; border: 1.5px solid #8a5a00; color: #5c3c00; font-size: max(16px, .85em); font-weight: 600; }
#aida .vm-demo[hidden] { display: none; }

#aida .vm-main { flex: 1; min-height: 0; width: 100%; max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 14px; overflow-y: auto; padding: 8px 2px; }

/* ── วงกลมกลางจอ: ฟัง = หายใจช้า ๆ + วงแหวนกระจาย (ขยายตามเสียง --lv) · คิด = หมุนช้า · พูด = แท่งคลื่นขยับ · พักไมค์ = นิ่ง สีจาง ── */
#aida .vm-orb { --lv: 0; position: relative; flex: 0 0 auto; width: min(46vw, 34vh, 220px); aspect-ratio: 1; margin-top: 6px; }
#aida .vm-core {
  position: absolute; inset: 14%; border-radius: 50%; display: flex; align-items: center; justify-content: center; gap: 6%;
  background: radial-gradient(circle at 35% 30%, #a77bf0 0%, var(--violet) 45%, #9b2a86 100%);
  box-shadow: 0 14px 40px rgba(106,44,198,.32);
  transform: scale(calc(1 + var(--lv) * .12)); transition: transform .25s ease-out, filter .4s, opacity .4s;
}
#aida .vm-core i { display: block; width: 7%; height: 18%; border-radius: 99px; background: #fff; opacity: .95; }
#aida .vm-ring { position: absolute; inset: 14%; border-radius: 50%; border: 3px solid rgba(106,44,198,.35); opacity: 0; }
#aida .vm[data-st="listen"] .vm-core { animation: vmBreath 3.2s ease-in-out infinite; }
#aida .vm[data-st="listen"] .vm-ring { animation: vmRing 2.6s ease-out infinite; }
#aida .vm[data-st="listen"] .vm-ring.r2 { animation-delay: 1.3s; }
#aida .vm[data-st="think"] .vm-core { animation: vmSpin 2.4s linear infinite; filter: saturate(.8); }
#aida .vm[data-st="think"] .vm-core i { height: 10%; animation: vmDot 1.2s ease-in-out infinite; }
#aida .vm[data-st="speak"] .vm-core i { animation: vmBar 1s ease-in-out infinite; }
#aida .vm-core i:nth-child(2) { animation-delay: .15s !important; }
#aida .vm-core i:nth-child(3) { animation-delay: .3s !important; }
#aida .vm-core i:nth-child(4) { animation-delay: .45s !important; }
#aida .vm-core i:nth-child(5) { animation-delay: .6s !important; }
#aida .vm[data-st="mute"] .vm-core { filter: grayscale(.85); opacity: .55; }
@keyframes vmBreath { 0%, 100% { transform: scale(calc(1 + var(--lv) * .12)); } 50% { transform: scale(calc(1.05 + var(--lv) * .12)); } }
@keyframes vmRing { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(1.3); opacity: 0; } }
@keyframes vmSpin { to { transform: rotate(360deg); } }
@keyframes vmDot { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }
@keyframes vmBar { 0%, 100% { height: 18%; } 50% { height: 46%; } }

/* ── ข้อความสถานะ + คำที่พูด/คำตอบ (ตัวใหญ่ · เข้มบนพื้นขาว) ── */
#aida .vm-st { margin: 0; text-align: center; white-space: pre-line; text-wrap: balance; font-size: max(26px, calc(26px * var(--fz, 1))); line-height: 1.4; font-weight: 700; color: var(--violet-dd); }
#aida .vm-st:focus { outline: none; }
#aida .vm[data-st="mute"] .vm-st { color: var(--vm-ink); }
#aida .vm-tx { width: 100%; display: flex; flex-direction: column; gap: 12px; }
#aida .vm-you, #aida .vm-ai {
  margin: 0; padding: 14px 18px; border-radius: 18px; font-size: max(22px, calc(22px * var(--fz, 1))); line-height: 1.55;
  color: var(--vm-ink); background: #fff; border: 2px solid var(--line); word-wrap: break-word;
}
#aida .vm-you[hidden], #aida .vm-ai[hidden] { display: none; }
#aida .vm-ai { background: var(--violet-ll); }
#aida .vm-ai a.refs-link { display: block; width: fit-content; margin-top: 6px; font-size: max(15px, .75em); font-weight: 400; color: #6b6288; text-decoration: underline; text-underline-offset: 3px; }
#aida .vm-you b, #aida .vm-ai b { display: block; font-size: max(18px, .8em); font-weight: 600; color: var(--c-ink6); margin-bottom: 2px; }

/* ── ปุ่มล่าง: ≥64×64 · ไอคอน + ข้อความไทยใต้ไอคอน · ห่างกัน 16px · จอแคบเรียง 2×2 ── */
#aida .vm-ctl { flex: 0 0 auto; width: 100%; max-width: 820px; margin: 10px auto 0; display: grid; grid-template-columns: repeat(4, minmax(64px, 1fr)); gap: 16px; }
#aida .vm-b {
  min-width: 64px; min-height: 84px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border-radius: 20px; border: 2px solid var(--violet-dd); background: #fff; color: var(--violet-dd);
  font: inherit; font-size: max(18px, 1em); font-weight: 700; line-height: 1.2; text-align: center; cursor: pointer; touch-action: manipulation;
}
#aida .vm-b svg { width: 34px; height: 34px; flex: 0 0 auto; }
#aida .vm-b:hover { background: var(--violet-ll); }
#aida .vm-b .vm-slash { display: none; }
#aida .vm-b[aria-pressed="true"] { background: var(--violet-dd); color: #fff; }
#aida .vm-b[aria-pressed="true"] .vm-slash { display: inline; }
#aida .vm-b.vm-end { background: var(--vm-red); border-color: var(--vm-red); color: #fff; }
#aida .vm-b.vm-end:hover { background: var(--vm-red-d); border-color: var(--vm-red-d); }
#aida .vm :focus-visible { outline: 4px solid var(--orange-d); outline-offset: 3px; }
@media (max-width: 519px) {
  #aida .vm-ctl { grid-template-columns: repeat(2, minmax(64px, 1fr)); }
  #aida .vm-b { min-height: 76px; gap: 4px; }   /* จอแคบ 2×2 · ข้อความยังอยู่ใต้ไอคอน */
  #aida .vm-b svg { width: 30px; height: 30px; }
  #aida .vm-orb { width: min(42vw, 26vh, 200px); }
}
@media (max-width: 519px) and (max-height: 640px) {
  #aida .vm-orb { width: min(34vw, 20vh); }
}

/* ── การ์ดเต็มจอเสียง: ก่อนขอสิทธิ์ไมค์ · สิทธิ์ถูกบล็อก · ฉุกเฉิน ── */
#aida .vm[data-card="perm"] .vm-main, #aida .vm[data-card="perm"] .vm-ctl,
#aida .vm[data-card="block"] .vm-main, #aida .vm[data-card="block"] .vm-ctl,
#aida .vm[data-card="sos"] .vm-main, #aida .vm[data-card="sos"] .vm-ctl { display: none; }
#aida .vm-card {
  flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 640px; margin: 8px auto 0; padding: 20px 18px;
  display: flex; flex-direction: column; align-items: stretch; gap: 16px; text-align: center;
  font-size: max(22px, calc(22px * var(--fz, 1))); line-height: 1.55; color: var(--vm-ink);
}
#aida .vm-card[hidden] { display: none; }
#aida .vm-card-ic { width: 88px; height: 88px; margin: 8px auto 0; color: var(--violet-dd); }
#aida .vm-card-t { margin: 0; font-weight: 600; }
#aida .vm-card-t b, #aida .vm-steps b, #aida .vm-card-s b { color: var(--violet-dd); }
#aida .vm-card-h { margin: 0; font-size: 1.15em; font-weight: 700; color: var(--violet-dd); }
#aida .vm-steps { margin: 0; padding: 0 0 0 1.4em; text-align: left; display: flex; flex-direction: column; gap: 10px; }
#aida .vm-card-s { margin: 0; font-size: max(18px, .85em); text-align: left; color: var(--c-ink6); }
#aida .vm-go, #aida .vm-back {
  min-height: 64px; padding: 0 24px; border-radius: var(--pill); font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
#aida .vm-go { background: var(--violet-dd); border: 2px solid var(--violet-dd); color: #fff; }
#aida .vm-back { background: #fff; border: 2px solid var(--c-ink6); color: var(--vm-ink); font-size: max(18px, .9em); }
#aida .vm-sos { border: 4px solid var(--vm-red); border-radius: 24px; background: #fff; }
#aida .vm-sos .vm-card-h { color: var(--vm-red); font-size: 1.3em; }
#aida .vm-sos-t { margin: 0; text-align: left; font-weight: 600; }
#aida .vm-call {
  display: flex; align-items: center; justify-content: center; gap: 16px; min-height: 96px; padding: 12px 20px; border-radius: 24px;
  background: var(--vm-red); color: #fff; text-decoration: none; font-size: 1.5em; font-weight: 700; line-height: 1.2;
  box-shadow: 0 10px 28px rgba(161,29,29,.35);
}
#aida .vm-call:hover { background: var(--vm-red-d); }
#aida .vm-call svg { width: 48px; height: 48px; flex: 0 0 auto; }
#aida .vm-call small { display: block; font-size: max(16px, .5em); font-weight: 500; }

html.easy #aida .vm *, html.easy #aida .vm-core { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  #aida .vm *, #aida .vm-core { animation: none !important; transition: none !important; }
  #aida .vm[data-st="speak"] .vm-core i { height: 36%; }
}
