/* ตัวละครในแชท — หน้าตั้งค่า #/avatar3d + ชิ้นส่วนร่วม (.a3-stage / .a3-fig / .a3-img / .a3-tint)
 * ชิ้นส่วนร่วมใช้ทั้งหน้าตั้งค่า (พรีวิว) และหน้าแชท — ตำแหน่ง/การขยับในห้องแชทอยู่ที่ css/pages/chat.css
 * โทนสีตามชุด Wadee Vivid Blue (docs/VIVID-SPEC.md) · ตัวแปรสีมาจาก base.css จึงเปลี่ยนตามธีมทั้ง 4 แบบเอง */

/* ================= ชิ้นส่วนร่วม: เวทีตัวละคร =================
 * .a3-stage = หน้าต่างที่มองเห็น (ตัดส่วนเกินทิ้ง) · ตั้งความสูงจากข้างนอก แล้วความกว้างมาจาก aspect-ratio
 * .a3-fig   = ตัวละครขนาดเต็ม 512×768 (2:3) วางชิดบนของหน้าต่าง → ครึ่งตัว/เฉพาะหัวคือการหั่นหน้าต่างให้เตี้ยลง
 *   --a3-vis = สัดส่วนความสูงของภาพที่เห็น (เต็มตัว 1 · ครึ่งตัว .62 · เฉพาะหัว .34) */
.a3-stage{position:relative;overflow:hidden;pointer-events:none;
  opacity:var(--a3-op,.6);transition:opacity .3s ease}
.a3-stage[data-crop="full"]{--a3-vis:1;aspect-ratio:512/768}
.a3-stage[data-crop="half"]{--a3-vis:.62;aspect-ratio:512/476}
/* .44 ไม่ใช่ .34 — วัดกับตัวละครทั้ง 9 ตัวแล้ว ที่ .34 ตัดตรงระดับตา ไม่เห็นปาก/คาง ถึง 5 ตัว
   (กระต่าย คุณยาย แมว หมา และตัวผมดำ หัวกินพื้นที่มากกว่าตัวอื่น) · ตัวเลขหลัง / คือ 768×.44 */
.a3-stage[data-crop="head"]{--a3-vis:.44;aspect-ratio:512/338}
.a3-stage[data-crop="off"]{display:none}

.a3-fig{position:absolute;left:0;top:0;width:100%;height:calc(100% / var(--a3-vis,1));
  transform-origin:50% 100%;transition:opacity .3s ease}
.a3-fig.a3-fade{opacity:0}
.a3-img{display:block;width:100%;height:100%;object-fit:contain;object-position:top center;
  -webkit-user-drag:none;user-select:none}
/* ชั้นสีที่ผู้ใช้ปรับ (สีผม/สีชุด) — ทับแบบ soft-light แล้วตัดขอบด้วย mask ของภาพเดิม ไม่เลอะออกนอกตัว */
.a3-tint{position:absolute;inset:0;mix-blend-mode:soft-light;opacity:.85;pointer-events:none;
  -webkit-mask-size:100% 100%;mask-size:100% 100%;
  -webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;
  -webkit-mask-position:center;mask-position:center}
/* ชั้นไล่สีจาง กันตัวละครไปสู้กับตัวหนังสือ (ธีมสว่าง/เย็นสบายตา/ชมพู ใช้ขาว · ธีมเข้มใช้น้ำเงินเข้ม) */
.a3-scrim{position:absolute;inset:0;z-index:1;pointer-events:none;
  background:linear-gradient(180deg,rgba(255,255,255,.55),rgba(255,255,255,.34) 55%,rgba(255,255,255,.2))}
html[data-wtheme="dark"] .a3-scrim{
  background:linear-gradient(180deg,rgba(13,31,61,.6),rgba(13,31,61,.36) 55%,rgba(13,31,61,.2))}

/* ================= หน้าตั้งค่า ================= */
.a3-page{display:flex;flex-direction:column;height:100dvh;min-height:0}
.a3-body{flex:1;min-height:0;overflow-y:auto;padding:12px 15px calc(28px + env(safe-area-inset-bottom))}
.a3-intro{font-size:13px;line-height:1.6;color:var(--ink-dim);margin:2px 2px 12px}

.a3-card{background:var(--surface);border:1px solid var(--card-brd);border-radius:var(--r-lg);
  padding:13px 14px;margin-bottom:12px}
.a3-h{font-size:13px;font-weight:700;color:var(--ink-dim);margin:0 0 10px;letter-spacing:.2px}
.a3-h2{margin-top:14px}
.a3-note{font-size:12px;line-height:1.6;color:var(--ink-dim);margin:8px 2px 0}
.a3-privacy{display:flex;align-items:center;gap:6px;margin:2px 4px 14px}
.a3-privacy svg{width:16px;height:16px;flex:none}

/* ---- พรีวิวสด: ฟองแชทปลอม + ตัวละคร (เหมือนที่อีกฝ่ายเห็นจริง ๆ) ----
 * ต้องตรงกับ .ch-a3 ใน css/pages/chat.css เป๊ะ: มุมซ้ายล่าง · ความสูงคงที่ตามครอป · ทึบเต็มสี
 * ถ้าแก้ตำแหน่งในแชท ต้องแก้ที่นี่ด้วย ไม่งั้นพรีวิวหลอกตา */
.a3-prev-card{padding-bottom:11px}
.a3-prev{position:relative;height:270px;border-radius:var(--r-md);overflow:hidden;
  border:1px solid var(--card-brd);background:var(--bg-0)}
.a3-prev-chat{position:absolute;inset:0;z-index:2;display:flex;flex-direction:column;
  justify-content:flex-end;padding:12px 14px 188px}
.a3-prev-bubble{align-self:flex-start;max-width:72%;padding:9px 13px;border-radius:16px;
  background:var(--surface);border:1px solid var(--card-brd);color:var(--ink);
  font-size:14px;line-height:1.45;box-shadow:0 2px 8px rgba(var(--shadow-rgb),.06)}
.a3-prev .a3-stage{position:absolute;left:-14px;bottom:0;z-index:1;--a3-op:1;height:150px}
.a3-prev .a3-stage[data-crop="head"]{height:98px}
.a3-prev .a3-stage[data-crop="full"]{height:176px}
.a3-prev .a3-img{filter:drop-shadow(0 5px 11px rgba(var(--shadow-rgb),.28))}

/* ---- แท็บสไตล์ ---- */
.a3-tabs{display:flex;gap:8px;overflow-x:auto;padding-bottom:2px;-webkit-overflow-scrolling:touch}
.a3-tab{flex:none;display:flex;flex-direction:column;align-items:center;gap:1px;
  min-height:44px;padding:8px 14px;border-radius:var(--r-pill);
  background:var(--bg-0);border:1px solid var(--card-brd);color:var(--ink);
  font-size:13.5px;font-weight:600;transition:background .14s,border-color .14s,color .14s}
.a3-tab small{font-size:10.5px;font-weight:500;color:var(--ink-faint)}
.a3-tab.on{background:var(--accent);border-color:var(--accent);color:var(--on-accent)}
.a3-tab:disabled{opacity:.55}

/* ---- กริดเลือกตัวละคร ---- */
.a3-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(86px,1fr));gap:9px}
.a3-cell{display:flex;flex-direction:column;align-items:center;gap:5px;padding:7px 5px 8px;
  border-radius:var(--r-md);background:var(--bg-0);border:1px solid var(--card-brd);
  color:var(--ink);font-size:12px;font-weight:600;transition:border-color .14s,box-shadow .14s}
.a3-cell img{width:100%;max-width:70px;aspect-ratio:1;border-radius:14px;
  background:var(--surface-2);object-fit:cover}
.a3-cell span{max-width:100%}
.a3-cell.on{border-color:var(--accent);box-shadow:0 0 0 2px rgba(var(--accent-rgb),.22)}

/* ---- ปรับสี ---- */
.a3-tint-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.a3-color{display:flex;align-items:center;gap:8px;min-height:44px;padding:0 10px;
  border-radius:var(--r-md);background:var(--bg-0);border:1px solid var(--card-brd);
  font-size:13px;font-weight:600;color:var(--ink)}
.a3-color input[type="color"]{width:34px;height:30px;padding:0;border:none;border-radius:9px;
  background:none;cursor:pointer}
.a3-reset{min-height:44px;padding:0 14px;border-radius:var(--r-pill);
  background:var(--bg-0);border:1px solid var(--card-brd);color:var(--accent);
  font-size:13px;font-weight:600}

/* ---- ชิป (ขนาด / อารมณ์ / ระยะเวลา) ---- */
.a3-chips{display:flex;flex-wrap:wrap;gap:8px}
.a3-chip{min-height:40px;padding:0 14px;border-radius:var(--r-pill);
  background:var(--bg-0);border:1px solid var(--card-brd);color:var(--ink);
  font-size:13.5px;font-weight:600;transition:background .14s,border-color .14s,color .14s}
.a3-chip.on{background:var(--accent);border-color:var(--accent);color:var(--on-accent)}

/* ---- สวิตช์เปิด/ปิดทั้งแอป ---- */
.a3-switch-row{display:flex;align-items:center;gap:12px;min-height:48px}
.a3-sw-txt{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}
.a3-sw-title{font-size:14.5px;font-weight:600;color:var(--ink)}
.a3-sw-sub{font-size:12px;line-height:1.5;color:var(--ink-dim)}

.a3-remove{display:block;width:100%;min-height:48px;margin-top:10px;border-radius:var(--r-md);
  background:none;border:1px solid var(--card-brd);color:var(--danger);
  font-size:14px;font-weight:600}
