/* ============ Thầy AI — giao diện cho trẻ em, tối ưu iPad ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --nen: #FFF8E7;
  --chu: #3E3A33;
  --phu: #8A8273;
  --the-bong: 0 6px 20px rgba(80, 60, 20, 0.12);
  --xanh: #42A5F5;
  --do: #EF5350;
}

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--nen);
  color: var(--chu);
  font-family: -apple-system, "SF Pro Rounded", "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 20px;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; } /* chống kéo trang trên iPad */

.screen[hidden] { display: none !important; }
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; }

/* ============ Màn hình PIN ============ */
#screen-pin { align-items: center; justify-content: center; }
.pin-box { text-align: center; padding: 16px; }
.pin-logo { font-size: 72px; }
.pin-box h1 { margin: 8px 0 4px; font-size: 40px; }
.pin-hint { color: var(--phu); margin: 0 0 20px; }
.pin-dots { display: flex; gap: 18px; justify-content: center; margin-bottom: 24px; }
.pin-dots span {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid #D8CFBA; background: transparent;
}
.pin-dots span.full { background: var(--xanh); border-color: var(--xanh); }
.pin-pad {
  display: grid; grid-template-columns: repeat(3, 84px); gap: 14px;
  justify-content: center;
}
.pin-pad button {
  width: 84px; height: 84px; border-radius: 50%;
  font-size: 34px; background: #fff; box-shadow: var(--the-bong);
  color: var(--chu);
}
.pin-pad button:active { transform: scale(0.93); }
.pin-pad .pad-empty { background: transparent; box-shadow: none; }
.pin-error { color: var(--do); min-height: 28px; margin-top: 16px; font-size: 18px; }

/* ============ Trang chính ============ */
.home-header { text-align: center; padding: 28px 16px 8px; }
.home-header h1 { font-size: 44px; margin: 0; }
.home-header p { font-size: 24px; color: var(--phu); margin: 8px 0 0; }
.teacher-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px;
  padding: 24px clamp(16px, 6vw, 80px);
  align-content: center;
  overflow-y: auto;
}
.teacher-card {
  border-radius: 28px;
  color: #fff;
  padding: 26px 20px;
  min-height: 170px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  box-shadow: var(--the-bong);
  font-size: 28px; font-weight: 700;
  position: relative;
}
.teacher-card:active { transform: scale(0.96); }
.teacher-card .icon { font-size: 64px; line-height: 1; }
.teacher-card .tag {
  position: absolute; top: 12px; right: 16px;
  font-size: 14px; font-weight: 600;
  background: rgba(255,255,255,0.3);
  padding: 3px 10px; border-radius: 999px;
}
.home-note { text-align: center; color: var(--phu); font-size: 16px; padding: 0 16px 18px; min-height: 22px; }

/* ============ Màn hình trò chuyện ============ */
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(80,60,20,0.08);
}
.btn-back {
  font-size: 28px; width: 52px; height: 52px; border-radius: 16px;
  background: #F1EADA; color: var(--chu);
}
.chat-title { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 700; }
#chat-icon { font-size: 34px; }
.btn-end {
  font-size: 20px; font-weight: 700; padding: 12px 18px; border-radius: 16px;
  background: #FFE3B3; color: #7A5200;
}
.btn-end:active, .btn-back:active { transform: scale(0.95); }

.transcript {
  flex: 1; overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex; flex-direction: column; gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 78%;
  padding: 14px 18px;
  border-radius: 22px;
  font-size: 22px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: var(--xanh); color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble.bot {
  align-self: flex-start;
  background: #fff; color: var(--chu);
  box-shadow: var(--the-bong);
  border-bottom-left-radius: 6px;
}
.bubble.hint { align-self: center; background: transparent; color: var(--phu); font-size: 17px; box-shadow: none; }

.chat-footer {
  display: flex; align-items: center; justify-content: center; gap: 26px;
  padding: 10px 20px calc(16px + env(safe-area-inset-bottom));
}
.mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.btn-mic {
  width: 110px; height: 110px; border-radius: 50%;
  background: linear-gradient(145deg, #FF8A65, #FF5252);
  box-shadow: 0 8px 24px rgba(255, 82, 82, 0.4);
  font-size: 52px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.3s ease;
}
.btn-mic:active { transform: scale(0.92); }
.btn-mic.listening {
  background: linear-gradient(145deg, #66BB6A, #43A047);
  box-shadow: 0 8px 24px rgba(67, 160, 71, 0.45);
  animation: pulse 1.4s infinite;
}
.btn-mic.speaking {
  background: linear-gradient(145deg, #42A5F5, #1E88E5);
  box-shadow: 0 8px 24px rgba(30, 136, 229, 0.45);
}
.btn-mic.thinking { background: linear-gradient(145deg, #BCAAA4, #8D6E63); }
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.mic-status { font-size: 18px; color: var(--phu); font-weight: 600; min-height: 24px; text-align: center; }
.btn-round {
  width: 64px; height: 64px; border-radius: 50%;
  background: #fff; box-shadow: var(--the-bong); font-size: 26px;
}
.btn-round:active { transform: scale(0.92); }
.btn-round.off { opacity: 0.45; }

.type-row {
  display: flex; gap: 10px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: #fff;
}
.type-row input {
  flex: 1; font-size: 22px; padding: 14px 16px;
  border: 2px solid #E3DAC5; border-radius: 16px; outline: none;
}
.type-row button {
  font-size: 20px; font-weight: 700; padding: 0 22px; border-radius: 16px;
  background: var(--xanh); color: #fff;
}

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: rgba(50, 45, 35, 0.92); color: #fff;
  padding: 14px 22px; border-radius: 16px; font-size: 18px;
  max-width: 86%; text-align: center; z-index: 99;
}

@media (prefers-color-scheme: dark) {
  :root { --nen: #1E1B16; --chu: #F2EDE2; --phu: #A89F8D; }
  .chat-header, .bubble.bot, .btn-round, .pin-pad button, .type-row { background: #2A261F; color: var(--chu); }
  .btn-back { background: #3A352C; color: var(--chu); }
  .type-row input { background: #1E1B16; color: var(--chu); border-color: #4A443A; }
  .pin-dots span { border-color: #5A5344; }
}
