/* =========================================================
   Pika English — giao diện nền tối dịu mắt, responsive
   ========================================================= */
:root {
  --bg: #111729;
  --bg-2: #18213a;
  --card: #1e2846;
  --text: #eef2ff;
  --muted: #a3acc9;
  --accent: #ffd43b;       /* vàng Pika */
  --accent-2: #ffb703;
  --eye: #7fe7ff;          /* màu mắt phát sáng */
  --mouth: #ff8fa3;
  --listen: #4ade80;
  --think: #a78bfa;
  --speak: #60a5fa;
  --danger: #f87171;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 70%);
  background-color: var(--bg);
  color: var(--text);
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Thanh trên ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-size: 1.25rem; margin: 0; color: var(--accent); }
.lang { font-size: .9rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.lang select {
  background: var(--card); color: var(--text); border: 1px solid #33406a;
  border-radius: 10px; padding: 6px 8px; font: inherit;
}

/* ---------- Chế độ ---------- */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-btn {
  background: var(--card); color: var(--text); border: 2px solid transparent;
  border-radius: 14px; padding: 10px 6px; font-weight: 700; font-size: .95rem;
}
.mode-btn.active { border-color: var(--accent); background: #2a3560; }

.lesson-panel { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
.lesson-panel[hidden] { display: none; }
.lesson-panel textarea {
  width: 100%; resize: vertical; background: var(--card); color: var(--text);
  border: 1px solid #33406a; border-radius: 12px; padding: 10px; font: inherit; font-size: 1rem;
}

/* ---------- Bố cục chính ---------- */
.stage { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.robot-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 18px; }
.panel { width: 100%; display: flex; flex-direction: column; gap: 12px; }

/* Màn hình ngang (PC / tablet xoay ngang): mặt robot bên trái, phụ đề bên phải */
@media (min-width: 860px) and (orientation: landscape) {
  .stage { flex-direction: row; align-items: flex-start; gap: 32px; }
  .robot-wrap { flex: 0 0 42%; position: sticky; top: 16px; }
  .panel { flex: 1; }
}

/* =========================================================
   KHUÔN MẶT ROBOT
   ========================================================= */
.face {
  position: relative;
  width: min(68vw, 320px);
  aspect-ratio: 1.15 / 1;
  border-radius: 44% 44% 40% 40%;
  background: radial-gradient(circle at 35% 25%, #fff3a8, var(--accent) 45%, var(--accent-2));
  box-shadow: 0 18px 40px rgba(0,0,0,.45), inset 0 -10px 20px rgba(0,0,0,.12);
  transition: transform .3s ease;
}
/* Vòng sáng quanh mặt theo trạng thái */
.face::after {
  content: ""; position: absolute; inset: -10px; border-radius: inherit;
  border: 4px solid transparent; pointer-events: none; transition: border-color .3s;
}
.face[data-state="listening"]::after { border-color: var(--listen); animation: pulse 1.2s ease-in-out infinite; }
.face[data-state="thinking"]::after  { border-color: var(--think); }
.face[data-state="speaking"]::after  { border-color: var(--speak); }

.antenna {
  position: absolute; left: 50%; top: -34px; width: 6px; height: 34px;
  background: #e0a800; transform: translateX(-50%); border-radius: 3px;
}
.antenna-light {
  position: absolute; top: -12px; left: 50%; width: 20px; height: 20px; transform: translateX(-50%);
  border-radius: 50%; background: #ff6b6b; box-shadow: 0 0 12px #ff6b6b;
}
.face[data-state="listening"] .antenna-light { background: var(--listen); box-shadow: 0 0 16px var(--listen); }
.face[data-state="thinking"] .antenna-light { background: var(--think); animation: blinkLight .5s steps(2) infinite; }
.face[data-state="speaking"] .antenna-light { background: var(--speak); box-shadow: 0 0 16px var(--speak); }

.ear {
  position: absolute; top: 38%; width: 9%; height: 26%; background: #e0a800; border-radius: 40%;
}
.ear-left { left: -5%; } .ear-right { right: -5%; }
.face[data-state="listening"] .ear { background: var(--listen); }

.visor {
  position: absolute; inset: 16% 10% 18%;
  background: #141b33; border-radius: 40%;
  box-shadow: inset 0 0 18px rgba(0,0,0,.7);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10%;
}
.eyes { display: flex; gap: 22%; width: 100%; justify-content: center; height: 46%; align-items: center; }

/* Mắt */
.eye {
  position: relative; width: 24%; height: 100%;
  background: var(--eye); border-radius: 50%;
  box-shadow: 0 0 16px var(--eye);
  transition: transform .18s ease, height .25s ease, border-radius .25s ease;
}
.shine { position: absolute; top: 18%; right: 20%; width: 28%; height: 22%; background: #fff; border-radius: 50%; opacity: .85; }

/* Chớp mắt (JS thêm class .blink) */
.face.blink .eye { transform: scaleY(.08); }

/* Biểu cảm: vui (mắt cười hình vòm) */
.face[data-expression="happy"] .eye { height: 55%; border-radius: 50% 50% 12% 12% / 90% 90% 10% 10%; }
/* Tò mò: một mắt to, một mắt nhỏ */
.face[data-expression="curious"] .eye-left { transform: scale(.85); }
.face[data-expression="curious"] .eye-right { transform: scale(1.12); }
/* Khích lệ: mắt dịu, má hồng hơn */
.face[data-expression="encouraging"] .eye { height: 75%; }
.face[data-expression="encouraging"] .cheek { opacity: .95; }
/* Suy nghĩ: mắt nheo, nhìn lên */
.face[data-expression="thinking"] .eye,
.face[data-state="thinking"] .eye { height: 45%; transform: translateY(-30%); }
/* Đang nghe: mắt mở to */
.face[data-state="listening"] .eye { height: 100%; border-radius: 50%; transform: scale(1.08); }
.face.blink[data-state] .eye { transform: scaleY(.08); }

/* Miệng */
.mouth {
  width: 26%; height: 9%;
  background: var(--mouth);
  border-radius: 0 0 60% 60% / 0 0 100% 100%;
  transition: width .2s, height .2s, border-radius .2s;
}
.face[data-expression="happy"] .mouth { width: 34%; height: 13%; }
.face[data-state="thinking"] .mouth { width: 14%; height: 4%; border-radius: 6px; transform: translateX(30%); }
.face[data-state="listening"] .mouth { width: 14%; height: 10%; border-radius: 50%; }
/* Đang nói: miệng mấp máy */
.face[data-state="speaking"] .mouth { animation: talk .22s ease-in-out infinite alternate; border-radius: 40% 40% 60% 60%; }

.cheek {
  position: absolute; bottom: 20%; width: 12%; height: 7%; border-radius: 50%;
  background: #ff8fa3; opacity: .55; transition: opacity .3s;
}
.cheek-left { left: 6%; } .cheek-right { right: 6%; }

@keyframes talk { from { height: 5%; width: 22%; } to { height: 18%; width: 28%; } }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(1.03); } }
@keyframes blinkLight { 0% { opacity: 1; } 100% { opacity: .2; } }

/* Nhãn trạng thái */
.status {
  font-weight: 800; font-size: 1.05rem; padding: 8px 18px; border-radius: 999px;
  background: var(--card); color: var(--muted); min-width: 200px; text-align: center;
}
.status.listening { color: var(--listen); }
.status.thinking { color: var(--think); }
.status.speaking { color: var(--speak); }

/* =========================================================
   PHỤ ĐỀ & NÚT
   ========================================================= */
.heard { margin: 0; color: var(--muted); font-size: 1rem; font-style: italic; }
.subtitle { background: var(--card); border-radius: var(--radius); padding: 18px; }
.reply-en { margin: 0; font-size: clamp(1.35rem, 4.5vw, 1.9rem); font-weight: 800; line-height: 1.35; }
.reply-vi { margin: 10px 0 0; font-size: 1.05rem; color: var(--accent); }

.helpers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chip {
  background: #26315a; color: var(--text); border: 0; border-radius: 12px;
  padding: 12px 6px; font-weight: 700; font-size: .92rem;
}

.hint { margin: 0; min-height: 1.3em; color: var(--accent); text-align: center; font-weight: 700; }

.talk-btn {
  width: 100%; border: 0; border-radius: 22px; padding: 22px 12px;
  font-size: 1.35rem; font-weight: 900; color: #1b1b1b;
  background: linear-gradient(180deg, #ffe066, var(--accent-2));
  box-shadow: 0 8px 0 #c48a00, 0 12px 24px rgba(0,0,0,.35);
  transition: transform .08s, box-shadow .08s;
  touch-action: manipulation;
}
.talk-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #c48a00; }
.talk-btn.listening { background: linear-gradient(180deg, #86efac, var(--listen)); box-shadow: 0 8px 0 #15803d; }
.talk-btn.thinking { background: linear-gradient(180deg, #c4b5fd, var(--think)); box-shadow: 0 8px 0 #6d28d9; }
.talk-btn.speaking { background: linear-gradient(180deg, #93c5fd, var(--speak)); box-shadow: 0 8px 0 #1d4ed8; }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .92rem; margin-right: auto; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.ctrl {
  background: var(--card); color: var(--text); border: 1px solid #33406a;
  border-radius: 12px; padding: 10px 14px; font-weight: 700;
}
.ctrl.danger { color: var(--danger); }

.type-form { display: flex; gap: 8px; }
.type-form input {
  flex: 1; min-width: 0; background: var(--card); color: var(--text);
  border: 1px solid #33406a; border-radius: 12px; padding: 10px; font: inherit; font-size: 1rem;
}

.tip-box { background: #1a2a2a; border: 1px solid #2f5d50; border-radius: 12px; padding: 10px 14px; }
.tip-box summary { cursor: pointer; font-weight: 700; color: #6ee7b7; }
.tip-box p { margin: 8px 0 0; line-height: 1.5; }

.notice {
  background: #3a2330; border: 1px solid #7f3a52; border-radius: 12px;
  padding: 12px 14px; line-height: 1.55; font-size: .95rem;
}
.notice b { color: var(--accent); }

[hidden] { display: none !important; }

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