/* =====================================================
   ./style.css — Giao diện ứng dụng Luyện Nghe Tiếng Nhật
   Phong cách: Minimalist hiện đại, accent Coral
   ===================================================== */

/* ─── BIẾN THIẾT KẾ ─────────────────────────────────── */
:root {
  --coral:        #ff7a6b;        /* Màu chủ đạo Cam san hô */
  --coral-dark:   #ff5c4a;        /* Coral đậm hơn khi hover */
  --coral-light:  #fff0ee;        /* Coral cực nhạt làm nền nhấn */
  --coral-muted:  rgba(255,127,102,.15);

  --bg:           #f0ece8;        /* Nền trang tổng thể */
  --surface:      #f7f4f1;        /* Nền card / sidebar */
  --card-bg:      #ffffff;
  --border:       #e0dbd5;        /* Đường kẻ nhẹ */
  --shadow-sm:    0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --shadow-md:    0 2px 8px rgba(0,0,0,.07), 0 8px 32px rgba(0,0,0,.07);

  --text-primary:   #1e1e1e;
  --text-secondary: #4a4a4a;
  --text-muted:     #9e9a96;

  --sidebar-w:    288px;          /* Chiều rộng cố định của sidebar */
  --header-h:     54px;

  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;

  --font-ui:      'Noto Sans JP', 'M PLUS Rounded 1c', sans-serif;
  --font-jp:      'Noto Sans JP', 'M PLUS Rounded 1c', sans-serif;

  --transition:   .18s cubic-bezier(.4,0,.2,1);
}

/* ─── RESET & BASE ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── HEADER ────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--card-bg);
  border-bottom: 2px solid var(--coral);
  flex-shrink: 0;
  z-index: 10;
}

.header-inner {
  max-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

/* Logo + tên */
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--coral);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.header-brand .gate-icon {
  font-size: 20px;
}

/* ─── CÔNG TẮC CHẾ ĐỘ ──────────────────────────────── */
.mode-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
}

.mode-label {
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--transition);
  user-select: none;
  cursor: default;
}

#label-practice { color: var(--coral); }
body.exam-mode #label-practice { color: var(--text-muted); }
body.exam-mode #label-exam     { color: var(--coral); }

/* Toggle switch kiểu iOS */
.toggle-switch { position: relative; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  display: block;
  width: 40px;
  height: 22px;
  border-radius: 99px;
  background: var(--border);
  position: relative;
  transition: background var(--transition);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: transform var(--transition), background var(--transition);
}

.toggle-switch input:checked ~ .toggle-track {
  background: var(--coral);
}
.toggle-switch input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(18px);
}

/* ─── BỐ CỤC CHÍNH ──────────────────────────────────── */
.app-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-h));
  max-height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ─── SIDEBAR ───────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Skeleton loading ── */
.sidebar-loading { padding: 12px 20px; }

.skeleton-group { margin-bottom: 24px; }

.skeleton {
  background: linear-gradient(90deg, #efefef 25%, #fafafa 50%, #efefef 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-label { height: 10px; width: 60%; margin-bottom: 10px; }
.skeleton-item  { height: 32px; margin-bottom: 6px; border-radius: var(--radius-sm); }

/* ── Nhóm cấp độ ── */
.level-group { margin-bottom: 8px; }

.level-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 20px 4px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.level-badge-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 7px;
  background: var(--coral-muted);
  color: var(--coral);
  border-radius: 99px;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .06em;
}

/* ── Mỗi bài nghe trong sidebar ── */
.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px 9px 24px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  font-size: .88rem;
  color: var(--text-secondary);
  font-weight: 400;
  line-height: 1.35;
  font-family: var(--font-jp);
}

.lesson-item:hover {
  background: var(--coral-light);
  color: var(--coral-dark);
}

.lesson-item.active {
  background: var(--coral-light);
  border-left-color: var(--coral);
  color: var(--coral-dark);
  font-weight: 500;
}

/* Icon hoàn thành */
.lesson-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .55rem;
  color: transparent;
  transition: all var(--transition);
}

.lesson-item.completed .lesson-check {
  background: #4caf89;
  border-color: #4caf89;
  color: #fff;
}

.lesson-item.completed .lesson-check::after { content: '✓'; }

/* ─── NỘI DUNG CHÍNH ─────────────────────────────────── */
.main-content {
  max-height: calc(100vh - var(--header-h));
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.main-content::-webkit-scrollbar { width: 5px; }
.main-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── MÀN HÌNH CHÀO ─────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  text-align: center;
  animation: fadeUp .5s ease;
}

.welcome-icon {
  font-family: var(--font-jp);
  font-size: 4rem;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--coral-light);
  color: var(--coral);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  box-shadow: 0 0 0 6px var(--coral-muted);
}

.welcome-heading {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-sub {
  color: var(--text-muted);
  font-size: .9rem;
  max-width: 340px;
  margin-bottom: 24px;
  line-height: 1.6;
}

.welcome-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 14px;
  font-size: .78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ─── CARD ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

/* ─── KHU VỰC BÀI NGHE ──────────────────────────────── */
.listening-area {
  display: flex;
  flex-direction: row;
  gap: 32px;
  height: 100%;
  max-height: calc(100vh - var(--header-h) - 64px);
}

.listening-media-section {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  padding-right: 16px;
}

.listening-question-section {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-right: 16px;
}

.listening-question-section::-webkit-scrollbar { width: 4px; }
.listening-question-section::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.listening-meta-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.listening-level-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  background: var(--coral-light);
  color: var(--coral);
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.listening-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Thẻ audio iframe */
.audio-card {
  padding: 0;
  overflow: hidden;
  min-height: 300px;
}

.audio-iframe {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border: none;
}

/* ─── CÂU HỎI TRẮC NGHIỆM ───────────────────────────── */
.questions-section { 
  margin-top: 4px; 
  overflow-y: auto;
  scrollbar-width: none;
  scrollbar-color: transparent transparent;
}

.questions-section::-webkit-scrollbar { width: 0; display: none; }

.no-questions {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

.question-card {
  margin-bottom: 20px;
}

.question-number {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  color: var(--coral);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 8px;
}

.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* Danh sách đáp án */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: .95rem;
  color: var(--text-secondary);
  transition: all var(--transition);
  text-align: left;
  font-family: var(--font-jp);
}

.option-btn:hover:not(:disabled) {
  border-color: var(--coral);
  background: var(--coral-light);
  color: var(--coral-dark);
  transform: translateX(4px);
}

.option-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  background: var(--surface);
  border-radius: 4px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all var(--transition);
}

/* Trạng thái đáp án đúng */
.option-btn.correct {
  border-color: #4caf89;
  background: #edfdf5;
  color: #1a6646;
}
.option-btn.correct .option-key {
  background: #4caf89;
  color: #fff;
}

/* Trạng thái đáp án sai */
.option-btn.wrong {
  border-color: #e85d4f;
  background: #fff5f5;
  color: #b83232;
}
.option-btn.wrong .option-key {
  background: #e85d4f;
  color: #fff;
}

/* Đáp án bị vô hiệu hóa sau khi trả lời */
.option-btn:disabled { cursor: default; transform: none; }

/* Trạng thái đã chọn (chế độ Kiểm tra) */
.option-btn.selected {
  border-color: var(--coral);
  background: var(--coral-light);
  color: var(--coral-dark);
}

.option-btn.selected .option-key {
  background: var(--coral);
  color: #fff;
}

/* Hộp giải thích */
.explanation-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: var(--coral-light);
  border-left: 4px solid var(--coral);
  border-radius: var(--radius-md);
  margin-top: 12px;
}

.explanation-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }

.explanation-text {
  font-size: .9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.explanation-text strong {
  color: var(--coral-dark);
}

.explanation-text p {
  margin: 4px 0 0 0;
}

/* ─── NÚT NỘP BÀI ───────────────────────────────────── */
.submit-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 20px 0;
  margin-top: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: all var(--transition);
  font-family: var(--font-ui);
}

.btn-submit {
  background: var(--coral);
  border-color: var(--coral);
  color: #fff;
  font-weight: 700;
}

.btn-submit:hover {
  background: var(--coral-dark);
  border-color: var(--coral-dark);
  transform: translateY(-2px);
}

.btn-submit:active { transform: translateY(0); }

/* ─── KẾT QUẢ TỔNG QUÁT ─────────────────────────────── */
.result-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 32px;
  margin: 20px 0;
}

.result-icon {
  font-size: 3rem;
}

.result-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.result-message {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ─── SCRIPT (TRANSCRIPT) ────────────────────────────── */
.script-section {
  display: flex;
  flex-direction: column;
  gap: 0;
  animation: slideUp .4s ease;
  max-height: 400px;
}

.script-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0;
}

.script-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.script-lock-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  background: var(--coral-light);
  color: var(--coral);
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  transition: all var(--transition);
  flex-shrink: 0;
}

.script-lock-badge.unlocked {
  background: #edfdf5;
  color: #4caf89;
}

.script-content {
  font-size: .95rem;
  line-height: 1.8;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--font-jp);
  min-height: 80px;
  padding: 16px;
  background: #f9f9f9;
  border-left: 4px solid var(--coral);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  overflow-y: auto;
  scrollbar-width: none;
  scrollbar-color: transparent transparent;
}

.script-content::-webkit-scrollbar { width: 0; display: none; }

.script-content.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ─── ANIMATIONS ────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── SKELETON LOADER ĐỘC LẬP ───────────────────────── */
.loading-wrap {
  padding: 20px;
}

@media (max-width: 1024px) {
  .listening-area {
    flex-direction: column;
    gap: 24px;
    max-height: none;
  }

  .listening-media-section {
    flex: 1 1 auto;
    max-height: 600px;
  }

  .listening-question-section {
    flex: 1 1 auto;
    max-height: none;
  }
}

@media (max-width: 768px) {
  .sidebar { width: 200px; --sidebar-w: 200px; }
  .main-content { padding: 24px 20px; }
  .listening-title { font-size: 1.2rem; }
  
  .listening-area {
    flex-direction: column;
  }

  .listening-media-section,
  .listening-question-section {
    flex: 1 1 auto;
    padding-right: 0;
  }
}

@media (max-width: 560px) {
  .sidebar { display: none; }
  .app-layout { display: flex; }
  .main-content { padding: 20px 16px; }
  .listening-area { gap: 20px; flex-direction: column; }
  .listening-title { font-size: 1rem; }
  .option-btn { gap: 8px; padding: 10px 12px; }
  .audio-card { min-height: 200px; }
  .audio-iframe { min-height: 200px; }
  
  .listening-media-section,
  .listening-question-section {
    flex: 1 1 auto;
    max-height: none;
    overflow-y: auto;
  }
}
