/* ==========================================================================
   Shadow4You v2.0 — Giao diện chuẩn 100% 4You trên iPadOS (Dark Teal Theme)
   ========================================================================== */

:root {
  --bg-deep: #081012;
  --bg-main: #0b1619;
  --bg-surface: #122327;
  --bg-surface-elevated: #182e34;
  --border-subtle: rgba(124, 232, 223, 0.12);
  --border-active: rgba(94, 234, 212, 0.6);

  --teal-primary: #5eead4;
  --teal-mid: #4ecdc4;
  --teal-bright: #88f4ea;
  --teal-dim: rgba(94, 234, 212, 0.14);

  --word-active-orange: #f59e0b;
  --word-drag-bg: rgba(94, 234, 212, 0.3);

  --text-primary: #eff7f8;
  --text-secondary: #95b3b8;
  --text-muted: #628085;
  --text-dark: #05191b;

  --lvl-easy: #4ade80;
  --lvl-mid: #fbbf24;
  --lvl-hard: #f87171;

  --chunk-amber: #fbbf24;
  --chunk-sky: #38bdf8;
  --chunk-emerald: #34d399;
  --chunk-violet: #a78bfa;
  --chunk-rose: #fb7185;

  --nav-height: 76px;
  --radius-xl: 20px;
  --radius-lg: 15px;
  --radius-md: 11px;
  --radius-pill: 999px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.48;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px calc(var(--nav-height) + env(safe-area-inset-bottom, 10px) + 24px);
}

/* Khi đang ở màn hình xem Video (Study), tràn sát viền trên đẹp như ảnh 2 của 4You */
.app-shell.video-immersive {
  max-width: 980px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  padding-left: 0;
  padding-right: 0;
}

/* ==========================================================================
   HEADER & TRANG THƯ VIỆN (ẢNH 1)
   ========================================================================== */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.greeting-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.greeting-name {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.16s ease;
}

.pill-badge:active {
  transform: scale(0.96);
}

.pill-badge.accent-outline {
  background: rgba(94, 234, 212, 0.11);
  border-color: rgba(94, 234, 212, 0.42);
  color: var(--teal-bright);
}

.pill-badge.yt-connected {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 48%, #6a82fb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.22);
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 11px 16px;
}

.search-box:focus-within {
  border-color: var(--teal-mid);
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 0.98rem;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.add-video-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(94, 234, 212, 0.35);
  background: rgba(22, 58, 64, 0.92);
  color: var(--teal-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* Thẻ Tiếp tục học */
.continue-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 13px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, #132b30 0%, #0e1f23 100%);
  border: 1px solid rgba(94, 234, 212, 0.2);
  margin-bottom: 15px;
  cursor: pointer;
}

.continue-thumb {
  position: relative;
  width: 144px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
  background: #060e10;
}

.continue-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play-overlay-circle {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(94, 234, 212, 0.92);
  color: #052022;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.continue-tag {
  font-size: 0.82rem;
  font-weight: 600;
  color: #eab308;
  margin-bottom: 3px;
}

.continue-title {
  font-size: 1.04rem;
  font-weight: 700;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.continue-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Filter Pills ngang */
.filter-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 14px;
  scrollbar-width: none;
}
.filter-strip::-webkit-scrollbar { display: none; }

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.filter-pill.active {
  background: rgba(26, 76, 82, 0.8);
  border-color: var(--teal-mid);
  color: var(--teal-bright);
  font-weight: 600;
}

/* Segmented Control 3 nguồn: YouTube | Tài khoản YouTube của tôi | 4You Podcast */
.source-segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #0c191c;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 4px;
  margin-bottom: 20px;
}

.seg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: rgba(28, 72, 78, 0.82);
  border-color: rgba(94, 234, 212, 0.45);
  color: var(--teal-bright);
}

/* Hàng Kênh YouTube có Avatar tròn thật & nút Xem tất cả > */
.channel-section {
  margin-bottom: 24px;
}

.channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 11px;
}

.channel-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.channel-avatar-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
}

.channel-badge-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--teal-bright);
}

.channel-name {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 0;
}

.see-all-btn {
  background: none;
  border: none;
  color: var(--teal-mid);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.video-carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(248px, 31%);
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.video-carousel::-webkit-scrollbar { display: none; }

.video-grid-all {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 16px;
}

.video-card {
  scroll-snap-align: start;
  cursor: pointer;
}

.thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  margin-bottom: 8px;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.level-chip {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: rgba(8, 15, 17, 0.84);
  backdrop-filter: blur(6px);
  font-size: 0.76rem;
  font-weight: 700;
  color: #fff;
}

.level-dot { width: 7px; height: 7px; border-radius: 50%; }
.level-dot.easy { background: var(--lvl-easy); }
.level-dot.mid { background: var(--lvl-mid); }
.level-dot.hard { background: var(--lvl-hard); }

.duration-chip {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(5, 10, 12, 0.88);
  font-size: 0.76rem;
  font-weight: 600;
  color: #f1f5f9;
}

.video-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.36;
  margin: 0 0 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ==========================================================================
   MÀN HÌNH HỌC VIDEO ĐA CHẾ ĐỘ (GIỐNG HỆT 100% BỨC ẢNH 2 CỦA 4YOU!)
   ========================================================================== */

.video-sheet-handle-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px 8px;
}

.sheet-pill-indicator {
  width: 42px;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.28);
  margin: 0 auto;
}

/* Khung Video lớn + Phụ đề đè nổi trực tiếp dưới đáy Video (Overlay Subtitle) */
.study-video-hero {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 46dvh;
  background: #000;
  overflow: hidden;
}

@media (min-width: 900px) {
  .study-video-hero {
    border-radius: 18px;
  }
}

.study-video-hero iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.podcast-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  background: radial-gradient(circle at center, #17383e 0%, #071114 100%);
}

/* Phụ đề song ngữ nổi ngay dưới cằm người nói giống hệt ảnh 2 */
.video-subtitle-overlay {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: 92%;
  width: max-content;
  background: rgba(10, 14, 16, 0.82);
  backdrop-filter: blur(8px);
  padding: 7px 15px;
  border-radius: 11px;
  text-align: center;
  pointer-events: auto;
  z-index: 15;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.overlay-en {
  font-size: 1.02rem;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.38;
}

.overlay-vi {
  font-size: 0.86rem;
  color: #cbd5e1;
  margin-top: 2px;
}

/* Phần thân bên dưới Video */
.study-below-video {
  padding: 12px 16px 0;
}

/* Hàng Tiêu đề Video + 3 nút tròn (♡, ☰+, ⚙️) giống hệt ảnh 2 */
.lesson-title-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.lesson-dropdown-title {
  background: none;
  border: none;
  padding: 0;
  font-size: 1.06rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.lesson-dropdown-title span.title-txt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.circle-icon-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

.circle-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.circle-action-btn.liked {
  color: #fb7185;
  border-color: rgba(251, 113, 133, 0.45);
  background: rgba(251, 113, 133, 0.12);
}

.circle-action-btn.gear-teal {
  border-color: var(--teal-mid);
  color: var(--teal-bright);
  background: rgba(20, 56, 62, 0.75);
}

/* Dải 7 Chế độ học tập ngang (Phụ đề | Shadowing | Chính tả | Điền từ | Quiz | Cấu trúc câu | Trò chuyện) */
.study-modes-strip {
  display: flex;
  align-items: center;
  gap: 9px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 8px;
  scrollbar-width: none;
}
.study-modes-strip::-webkit-scrollbar { display: none; }

.mode-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: #122125;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.16s ease;
}

.mode-pill-btn.active {
  background: rgba(20, 62, 67, 0.85);
  border-color: var(--teal-mid);
  color: var(--teal-bright);
}

/* Thanh gợi ý "Chạm từ để xem nghĩa · giữ & kéo để dịch cụm" giống hệt ảnh 2 */
.gesture-tip-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-radius: 10px;
  background: #142226;
  color: var(--text-muted);
  font-size: 0.86rem;
  margin-bottom: 10px;
}

/* Danh sách dòng phụ đề chuẩn 4You (Mốc giờ 00:11 bên trái + vạch dọc xanh ngọc + từ đang đọc màu cam gạch chân) */
.fouryou-subtitle-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 44dvh;
  overflow-y: auto;
  padding-right: 4px;
}

.fy-sub-item {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: baseline;
  gap: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  border-left: 3.5px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
}

.fy-sub-item.active-line {
  background: #132529;
  border-color: rgba(94, 234, 212, 0.22);
  border-left: 3.5px solid var(--teal-primary);
}

.fy-timestamp {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.fy-sub-item.active-line .fy-timestamp {
  color: var(--teal-mid);
}

.fy-en-words {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 5px;
  font-size: 1.12rem;
  font-weight: 600;
  color: #e6f1f3;
  user-select: none;
  touch-action: pan-y;
}

.fy-vi-line {
  font-size: 0.94rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Từng từ tiếng Anh: hỗ trợ chạm 1 từ, giữ-kéo chọn cụm, và highlight cam gạch chân theo giọng nói! */
.w-tok {
  padding: 1px 3px;
  border-radius: 5px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.1s ease, background 0.1s ease;
}

.w-tok:hover {
  background: rgba(94, 234, 212, 0.18);
  color: var(--teal-bright);
}

/* Từ đang được người bản xứ đọc tới trong Video: màu cam vàng + gạch chân cam giống hệt chữ 'and' trong ảnh 2! */
.w-tok.spoken-now {
  color: var(--word-active-orange) !important;
  border-bottom-color: var(--word-active-orange) !important;
}

/* Các từ đang được giữ & kéo chọn thành cụm từ */
.w-tok.drag-selected {
  background: var(--word-drag-bg);
  color: #ffffff;
  border-bottom-color: var(--teal-bright);
}

.w-tok.pron-good {
  background: rgba(74, 222, 128, 0.22);
  color: #86efac;
  border-bottom-color: #4ade80;
}

.w-tok.pron-miss {
  background: rgba(248, 113, 113, 0.22);
  color: #fca5a5;
  border-bottom-color: #f87171;
}

.inline-struct-drawer {
  grid-column: 1 / -1;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(94, 234, 212, 0.22);
}

/* Các nút điều khiển chuẩn */
.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn.active {
  background: var(--teal-dim);
  border-color: var(--teal-mid);
  color: var(--teal-bright);
}

.ctrl-btn.primary-teal {
  background: var(--teal-primary);
  border-color: var(--teal-primary);
  color: var(--text-dark);
}

/* Khung dùng chung cho các chế độ Shadowing / Chính tả / Điền từ / Quiz / Cấu trúc / Chat bên dưới Video */
.mode-workspace-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 18px;
  margin-top: 4px;
}

.syntax-chunks-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 14px;
}

.syntax-chunk {
  flex: 1 1 auto;
  min-width: 118px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  background: rgba(8, 18, 21, 0.78);
  border-left: 4px solid var(--chunk-sky);
}
.syntax-chunk.amber { border-left-color: var(--chunk-amber); }
.syntax-chunk.sky { border-left-color: var(--chunk-sky); }
.syntax-chunk.emerald { border-left-color: var(--chunk-emerald); }
.syntax-chunk.violet { border-left-color: var(--chunk-violet); }
.syntax-chunk.rose { border-left-color: var(--chunk-rose); }

.chunk-role { font-size: 0.72rem; text-transform: uppercase; color: var(--text-secondary); }
.chunk-en { font-size: 0.96rem; font-weight: 700; color: #fff; }
.chunk-vi { font-size: 0.82rem; color: var(--text-secondary); }

.grammar-rule-item {
  padding: 11px 13px;
  border-radius: var(--radius-md);
  background: rgba(24, 46, 52, 0.65);
  border: 1px solid var(--border-subtle);
  margin-bottom: 9px;
}

.grammar-formula {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 0.86rem;
  font-weight: 700;
  color: #fde68a;
  background: rgba(251, 191, 36, 0.12);
  padding: 3px 8px;
  border-radius: 6px;
}

/* Shadowing Mic */
.big-mic-btn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #7beae1 0%, #44b8af 100%);
  color: #052022;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 0 7px rgba(94, 234, 212, 0.15);
}

.big-mic-btn.recording {
  background: linear-gradient(135deg, #fb7185 0%, #e11d48 100%);
  color: #fff;
  animation: pulseRing 1.3s infinite;
}

@keyframes pulseRing {
  0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.55); }
  70% { box-shadow: 0 0 0 16px rgba(244, 63, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

/* Chép chính tả (Dictation) & Điền từ (Cloze) & Quiz */
.word-bank-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.word-tile-btn {
  padding: 8px 14px;
  border-radius: 10px;
  background: #1a353b;
  border: 1px solid rgba(94, 234, 212, 0.3);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
}

.word-tile-btn.used {
  opacity: 0.3;
  pointer-events: none;
}

.quiz-opt-btn {
  width: 100%;
  text-align: left;
  padding: 12px 15px;
  border-radius: 12px;
  background: #0e1d21;
  border: 1px solid var(--border-subtle);
  font-size: 0.96rem;
  font-weight: 600;
  margin-bottom: 9px;
  cursor: pointer;
}

.quiz-opt-btn.correct {
  background: rgba(74, 222, 128, 0.18);
  border-color: #4ade80;
  color: #86efac;
}

.quiz-opt-btn.wrong {
  background: rgba(248, 113, 113, 0.18);
  border-color: #f87171;
  color: #fca5a5;
}

/* Chat messages */
.chat-log-box {
  max-height: 270px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding-right: 4px;
}

.chat-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.chat-bubble.ai {
  background: #0e1e22;
  border: 1px solid var(--border-subtle);
}

.chat-bubble.user {
  align-self: flex-end;
  background: rgba(94, 234, 212, 0.2);
  border: 1px solid rgba(94, 234, 212, 0.4);
}

/* Flashcard & Vườn từ */
.flashcard-box {
  max-width: 620px;
  margin: 16px auto;
  min-height: 270px;
  padding: 26px;
  border-radius: 22px;
  background: linear-gradient(160deg, #163137 0%, #0f2024 100%);
  border: 1px solid rgba(94, 234, 212, 0.28);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
}

.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 13px;
}

.vocab-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 9, 11, 0.76);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 220;
}

.modal-sheet {
  width: 100%;
  max-width: 580px;
  max-height: 88dvh;
  overflow-y: auto;
  background: #122529;
  border: 1px solid rgba(94, 234, 212, 0.32);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.input-field {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: #0a1619;
  color: var(--text-primary);
  font-size: 0.96rem;
  margin-bottom: 10px;
}

/* Bottom Dock 5 Tabs */
.bottom-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 8px));
  padding-bottom: env(safe-area-inset-bottom, 8px);
  background: rgba(11, 24, 27, 0.95);
  backdrop-filter: blur(18px);
  border-top: 1px solid rgba(124, 232, 223, 0.14);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  z-index: 140;
}

.dock-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.dock-item.active {
  color: var(--teal-bright);
}

.dock-speak-circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7beae1 0%, #4ec4bb 100%);
  color: #062124;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -16px;
  box-shadow: 0 6px 18px rgba(92, 200, 192, 0.4);
  border: 3px solid #0b181b;
}

.hidden { display: none !important; }

.toast-banner {
  position: fixed;
  bottom: calc(var(--nav-height) + 18px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a3b41;
  border: 1px solid var(--teal-primary);
  color: #fff;
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 320;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   TỐI ƯU BỐ CỤC MÀN HÌNH DỌC & NGANG CHO IPHONE (iOS Mobile Responsive)
   ========================================================================== */
@media (max-width: 680px) {
  .app-shell {
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px calc(var(--nav-height) + env(safe-area-inset-bottom, 10px) + 20px);
  }

  .top-header {
    gap: 8px;
    margin-bottom: 12px;
  }

  .greeting-sub {
    font-size: 0.78rem;
  }

  .greeting-name {
    font-size: 1.22rem;
  }

  .hide-mobile-badge {
    display: none !important;
  }

  .pill-badge {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .avatar-circle {
    width: 35px;
    height: 35px;
    font-size: 0.82rem;
  }

  .continue-card {
    gap: 11px;
    padding: 10px;
  }

  .continue-thumb {
    width: 116px;
  }

  .continue-title {
    font-size: 0.94rem;
  }

  .source-segmented {
    padding: 3px;
    margin-bottom: 15px;
  }

  .seg-btn {
    padding: 8px 5px;
    font-size: 0.78rem;
    gap: 4px;
  }

  .video-carousel {
    grid-auto-columns: minmax(228px, 78%);
    gap: 11px;
  }

  .video-grid-all,
  .vocab-grid {
    grid-template-columns: 1fr;
    gap: 13px;
  }

  /* Màn hình xem Video trên iPhone dọc: hộp phụ đề đè nổi gọn để không che mặt người nói */
  .video-subtitle-overlay {
    bottom: 6px;
    max-width: 96%;
    padding: 4px 10px;
    border-radius: 8px;
  }

  .overlay-en {
    font-size: 0.86rem;
    line-height: 1.3;
  }

  .overlay-vi {
    font-size: 0.74rem;
    margin-top: 1px;
  }

  .study-below-video {
    padding: 10px 11px 0;
  }

  .mode-pill-btn {
    padding: 7px 12px;
    font-size: 0.84rem;
  }

  .gesture-tip-banner {
    font-size: 0.78rem;
    padding: 7px 11px;
  }

  .fouryou-subtitle-list {
    max-height: none;
  }

  .fy-sub-item {
    grid-template-columns: 40px 1fr auto;
    padding: 9px 10px;
    gap: 6px;
  }

  .fy-en-words {
    font-size: 1rem;
  }

  .fy-vi-line {
    font-size: 0.86rem;
  }

  .mode-workspace-card {
    padding: 13px;
  }

  /* Chuyển hộp thoại thành iOS Bottom Sheet trên iPhone */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-sheet {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: 22px 22px 0 0;
    padding: 18px 15px calc(env(safe-area-inset-bottom, 12px) + 16px);
  }
}

@media (max-width: 410px) {
  .hide-xs-label {
    display: none;
  }
}
