/* =====================================================
   style.css — Giao diện ứng dụng Luyện Đọc 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;
}

/* Làm nổi nhãn đang hoạt động */
#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 đọc 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: 1.18rem;
  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);
  border: 1px solid var(--border);
  padding: 28px 32px;
  margin-bottom: 20px;
  animation: fadeUp .35s ease;
}

/* ─── KHU VỰC BÀI ĐỌC ───────────────────────────────── */
.reading-area { 
  display: flex; 
  gap: 32px;
  align-items: center;
  max-width: 1000px; 
  margin: 0 auto; 
  max-height: calc(100vh - var(--header-h) - 64px); /* Trừ header và padding */
}

.reading-text-section {
  width: 50%;
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
  scrollbar-width: none; /* Ẩn scrollbar mặc định */
  scrollbar-color: var(--border) transparent;
}

.reading-question-section {
  width: 50%;
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
  scrollbar-width: none; /* Ẩn scrollbar mặc định */
  scrollbar-color: var(--border) transparent;
}

.reading-meta-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  animation: fadeUp .3s ease;
}

.reading-level-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  background: var(--coral);
  color: #fff;
  border-radius: 99px;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: .08em;
  flex-shrink: 0;
}

.reading-title {
  font-family: var(--font-jp);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Nội dung bài đọc tiếng Nhật */
.reading-body {
  font-family: var(--font-jp);
  font-size: 1.3rem;
  line-height: 2.2;   /* Tăng khoảng cách dòng để thẻ ruby không chồng chéo */
  color: var(--text-primary);
}

.reading-body ruby { ruby-position: over; }
.reading-body rt {
  font-family: var(--font-ui);
  font-size: .58em;
  color: var(--coral);
  font-weight: 500;
}

.reading-body p { margin-bottom: 1.2em; }
.reading-body p:last-child { margin-bottom: 0; }

/* ─── CÂU HỎI TRẮC NGHIỆM ───────────────────────────── */
.questions-section { margin-top: 4px; }

.question-card {
  /* kế thừa .card */
  transition: box-shadow var(--transition);
}

.question-number {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.question-text {
  font-family: var(--font-jp);
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.7;
  margin-bottom: 18px;
}

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

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-jp);
  font-size: 1.2rem;
  color: var(--text-secondary);
  line-height: 1.6;
  transition: border-color var(--transition), background var(--transition), color var(--transition), transform var(--transition);
}

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

.option-key {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--border);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: .75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

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

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

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

/* Hộp giải thích */
.explanation-box {
  display: flex;
  gap: 12px;
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: #fffbf0;
  border: 1px solid #fde58a;
  animation: fadeUp .3s ease;
}

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

.explanation-text {
  font-size: .85rem;
  color: #6b5a1e;
  line-height: 1.65;
  font-weight: 400;
}

/* Nhãn kết quả nhanh (chế độ Luyện tập) */
.quick-result {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 600;
  margin-top: 12px;
}
.quick-result.correct { background: #edfdf5; color: #1a6646; }
.quick-result.wrong   { background: #fff5f5; color: #b83232; }

/* ─── NÚT NỘP BÀI ───────────────────────────────────── */
.submit-bar {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn-submit {
  background: var(--coral);
  color: #fff;
  box-shadow: 0 2px 12px rgba(255,127,102,.35);
}

.btn-submit:hover {
  background: var(--coral-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 18px rgba(255,127,102,.4);
}

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

/* ─── KẾT QUẢ TỔNG QUÁT ─────────────────────────────── */
.result-summary {
  display: flex;
  align-items: center;
  gap: 20px;
  animation: fadeUp .4s ease;
}

.result-icon {
  font-size: 2.4rem;
  flex-shrink: 0;
}

.result-score {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

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

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

/* ─── RESPONSIVE ────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 220px; }

  .main-content { padding: 20px 18px; }

  .card { padding: 20px 18px; }

  .header-title-vi { display: none; }

  .mode-switcher { padding: 5px 10px; }

  .mode-label { font-size: .75rem; }
}

/* ─── SKELETON LOADER ĐỘC LẬP ───────────────────────── */
/* Nằm song song với #reading-area, không bao giờ xóa DOM bên trong reading-area */
.reading-loader-wrap {
  padding: 32px 40px;
  animation: fadeUp .3s ease;
}

@media (max-width: 768px) {
  .reading-loader-wrap { padding: 20px 18px; }
}

@media (max-width: 560px) {
  .app-layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
    max-height: 220px;
    overflow-y: auto;
  }
}
