/* ===== TOKENS ===== */
:root {
  --red: #DC143C;
  --red-dark: #b01030;
  --red-light: #fce4ea;
  --navy: #1a2b4a;
  --navy-light: #2c4066;
  --blue: #3a6ea8;
  --blue-light: #e8f0fb;
  --green: #2a9d5c;
  --green-light: #e6f7ee;
  --yellow: #f4a722;
  --yellow-light: #fef6e4;
  --gray-50: #f8f9fa;
  --gray-100: #f0f2f5;
  --gray-200: #e1e4e8;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --white: #ffffff;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.15);
  --transition: 0.2s ease;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }

/* ===== NAV ===== */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--navy);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  height: 56px;
  box-shadow: var(--shadow-md);
}
.nav-brand {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 700; font-size: 1.1rem; color: var(--white);
  margin-right: auto;
}
.flag { font-size: 1.3rem; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-link {
  color: rgba(255,255,255,0.7);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.15);
  color: var(--white);
}
.nav-streak {
  color: var(--yellow);
  font-size: 0.9rem;
  font-weight: 600;
}

/* ===== LAYOUT ===== */
#app { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }
.loading { text-align: center; padding: 4rem; color: var(--gray-400); }

/* ===== HOME ===== */
.home-header { margin-bottom: 2rem; }
.home-header h1 { font-size: 1.8rem; font-weight: 700; color: var(--navy); }
.home-header p { color: var(--gray-600); margin-top: 0.25rem; }

.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .stat-val {
  font-size: 2rem; font-weight: 700; color: var(--red);
}
.stat-card .stat-label {
  font-size: 0.8rem; color: var(--gray-600); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.05em;
}

.chapters-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.chapter-card {
  background: var(--white); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
}
.chapter-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--red-light); }
.chapter-card.active-card { border-color: var(--red); }

.chapter-num { font-size: 0.75rem; font-weight: 600; color: var(--red); text-transform: uppercase; letter-spacing: 0.1em; }
.chapter-title { font-size: 1rem; font-weight: 600; margin-top: 0.25rem; color: var(--navy); }
.chapter-title-en { font-size: 0.85rem; color: var(--gray-600); }
.chapter-progress { margin-top: 1rem; }
.progress-bar {
  height: 6px; background: var(--gray-200); border-radius: 99px; overflow: hidden; margin-bottom: 0.4rem;
}
.progress-fill {
  height: 100%; background: var(--red); border-radius: 99px;
  transition: width 0.4s ease;
}
.progress-label { font-size: 0.78rem; color: var(--gray-600); display: flex; justify-content: space-between; }

.chapter-modes {
  display: none; margin-top: 1rem; gap: 0.5rem; flex-wrap: wrap;
}
.chapter-card.active-card .chapter-modes { display: flex; }
.mode-btn {
  padding: 0.45rem 0.9rem; border-radius: 8px; font-size: 0.82rem; font-weight: 600;
  border: 2px solid; transition: var(--transition); flex: 1; min-width: 80px; text-align: center;
}
.mode-btn.flash { color: var(--red); border-color: var(--red); }
.mode-btn.flash:hover { background: var(--red); color: var(--white); }
.mode-btn.gender { color: var(--blue); border-color: var(--blue); }
.mode-btn.gender:hover { background: var(--blue); color: var(--white); }
.mode-btn.cases { color: var(--green); border-color: var(--green); }
.mode-btn.cases:hover { background: var(--green); color: var(--white); }

/* ===== VIEW HEADER ===== */
.view-header {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem;
}
.back-btn {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--gray-600); font-size: 0.9rem; font-weight: 500;
  padding: 0.4rem 0.7rem; border-radius: 8px;
  transition: var(--transition);
}
.back-btn:hover { background: var(--gray-100); color: var(--navy); }
.view-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--navy); flex: 1; }
.view-header .badge {
  background: var(--red-light); color: var(--red);
  padding: 0.3rem 0.7rem; border-radius: 99px; font-size: 0.8rem; font-weight: 600;
}

/* ===== FLASHCARDS ===== */
.flashcard-area {
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
}

/* Write mode */
.write-card {
  width: 100%; max-width: 480px;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  border-radius: var(--radius-lg); padding: 2rem 2rem 2.5rem;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 0.5rem; color: var(--white);
}
.write-prompt-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.65; margin-top: 0.5rem; }
.write-english { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.write-input-area { display: flex; gap: 0.75rem; width: 100%; max-width: 480px; }
.write-input {
  flex: 1; padding: 0.9rem 1rem;
  border: 2px solid var(--gray-200); border-radius: var(--radius);
  font-size: 1.2rem; font-family: inherit; color: var(--navy);
  transition: var(--transition); outline: none;
}
.write-input:focus { border-color: var(--red); }
.write-feedback {
  width: 100%; max-width: 480px;
  padding: 1rem 1.25rem; border-radius: var(--radius);
  font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 0.6rem;
}
.write-feedback.correct { background: var(--green-light); color: var(--green); }
.write-feedback.wrong { background: var(--red-light); color: var(--red-dark); }
.fb-icon { font-size: 1.2rem; }
.fb-diff { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.02em; }
.diff-ok { color: var(--green); }
.diff-wrong { color: var(--red); text-decoration: underline; }
.progress-indicator {
  font-size: 0.9rem; color: var(--gray-600);
  background: var(--white); padding: 0.5rem 1rem; border-radius: 99px; box-shadow: var(--shadow);
}
.flashcard-scene {
  width: 100%; max-width: 480px; height: 280px;
  perspective: 1200px; cursor: pointer;
}
.flashcard {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.flashcard.flipped { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}
.card-front {
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: var(--white);
}
.card-back {
  background: var(--white);
  color: var(--navy);
  transform: rotateY(180deg);
}
.card-word { font-size: 2rem; font-weight: 700; text-align: center; }
.card-hint { font-size: 0.85rem; margin-top: 0.75rem; opacity: 0.7; }
.card-translation { font-size: 1.6rem; font-weight: 600; text-align: center; }
.card-type-badge {
  position: absolute; top: 1rem; right: 1rem;
  padding: 0.25rem 0.6rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600;
}
.card-gender-M { background: rgba(58,110,168,0.15); color: var(--blue); }
.card-gender-F { background: rgba(220,20,60,0.15); color: var(--red); }
.card-gender-N { background: rgba(42,157,92,0.15); color: var(--green); }
.card-gender-null { background: rgba(156,163,175,0.15); color: var(--gray-600); }

.flashcard-actions {
  display: flex; gap: 1rem; width: 100%; max-width: 480px;
}
.action-btn {
  flex: 1; padding: 0.9rem; border-radius: var(--radius); font-size: 1rem; font-weight: 600;
  transition: var(--transition); display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.action-btn.wrong { background: var(--red-light); color: var(--red-dark); border: 2px solid transparent; }
.action-btn.wrong:hover { background: var(--red); color: var(--white); }
.action-btn.right { background: var(--green-light); color: var(--green); border: 2px solid transparent; }
.action-btn.right:hover { background: var(--green); color: var(--white); }
.action-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.session-end {
  text-align: center; padding: 3rem 1rem;
  background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.session-end h3 { font-size: 1.5rem; font-weight: 700; color: var(--navy); }
.session-end p { color: var(--gray-600); margin-top: 0.5rem; }
.session-score { font-size: 3rem; font-weight: 700; color: var(--red); margin: 1rem 0; }
.session-end .btn-group { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1.5rem; flex-wrap: wrap; }
.btn {
  padding: 0.75rem 1.5rem; border-radius: 10px; font-size: 0.95rem; font-weight: 600;
  transition: var(--transition); display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-primary { background: var(--red); color: var(--white); }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: var(--gray-100); color: var(--navy); }
.btn-secondary:hover { background: var(--gray-200); }

/* ===== GENDER QUIZ ===== */
.gender-area {
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
}
.gender-word-card {
  width: 100%; max-width: 480px;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: var(--white); border-radius: var(--radius-lg);
  padding: 2.5rem 2rem; text-align: center;
  box-shadow: var(--shadow-lg);
}
.gender-word { font-size: 2.2rem; font-weight: 700; }
.gender-translation { font-size: 1rem; margin-top: 0.5rem; opacity: 0.75; }
.gender-choices {
  display: flex; gap: 1rem; width: 100%; max-width: 480px;
}
.gender-btn {
  flex: 1; padding: 1rem; border-radius: var(--radius); font-size: 1.1rem; font-weight: 700;
  border: 3px solid; transition: var(--transition);
}
.gender-btn.M { color: var(--blue); border-color: var(--blue); background: var(--blue-light); }
.gender-btn.F { color: var(--red); border-color: var(--red); background: var(--red-light); }
.gender-btn.N { color: var(--green); border-color: var(--green); background: var(--green-light); }
.gender-btn:hover:not(:disabled) { transform: scale(1.04); box-shadow: var(--shadow-md); }
.gender-btn.correct { filter: brightness(1.05); }
.gender-btn.wrong-pick { opacity: 0.5; }
.gender-btn.reveal-correct { background: var(--green); color: var(--white); border-color: var(--green); }
.gender-btn.reveal-wrong { background: var(--red); color: var(--white); border-color: var(--red); }

.gender-result {
  min-height: 2rem; font-size: 1rem; font-weight: 600; text-align: center;
  transition: var(--transition);
}
.gender-result.correct { color: var(--green); }
.gender-result.wrong { color: var(--red); }

.score-bar {
  width: 100%; max-width: 480px;
  background: var(--white); border-radius: var(--radius); padding: 1rem;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 1rem;
}
.score-bar-inner { flex: 1; }
.score-numbers { font-size: 0.85rem; color: var(--gray-600); margin-bottom: 0.4rem; display: flex; justify-content: space-between; }
.score-val { font-size: 1.4rem; font-weight: 700; color: var(--navy); white-space: nowrap; }

/* ===== CASE DRILL ===== */
.cases-area { display: flex; flex-direction: column; gap: 1.5rem; }
.case-question-card {
  background: var(--white); border-radius: var(--radius-lg); padding: 2rem; box-shadow: var(--shadow-md);
}
.case-prompt { font-size: 0.85rem; color: var(--gray-600); margin-bottom: 1rem; }
.case-word-display {
  font-size: 2rem; font-weight: 700; color: var(--navy); margin-bottom: 0.5rem;
}
.case-word-en { color: var(--gray-600); font-size: 1rem; margin-bottom: 1.5rem; }
.case-target {
  display: inline-block;
  background: var(--red-light); color: var(--red-dark);
  padding: 0.3rem 0.8rem; border-radius: 8px; font-size: 0.9rem; font-weight: 600;
  margin-bottom: 1.5rem;
}
.case-input-row { display: flex; gap: 0.75rem; }
.case-input {
  flex: 1; padding: 0.85rem 1rem;
  border: 2px solid var(--gray-200); border-radius: var(--radius);
  font-size: 1.1rem; font-family: inherit; color: var(--navy);
  transition: var(--transition); outline: none;
}
.case-input:focus { border-color: var(--red); }
.case-input.correct { border-color: var(--green); background: var(--green-light); }
.case-input.wrong { border-color: var(--red); background: var(--red-light); }
.check-btn {
  padding: 0.85rem 1.5rem; background: var(--red); color: var(--white);
  border-radius: var(--radius); font-size: 1rem; font-weight: 600;
  transition: var(--transition);
}
.check-btn:hover { background: var(--red-dark); }
.check-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.case-feedback { margin-top: 1rem; font-size: 0.95rem; font-weight: 600; min-height: 1.5rem; }
.case-feedback.correct { color: var(--green); }
.case-feedback.wrong { color: var(--red); }

.case-next-btn {
  display: none; margin-top: 0.75rem;
  padding: 0.7rem 1.5rem; background: var(--navy); color: var(--white);
  border-radius: var(--radius); font-size: 0.95rem; font-weight: 600;
  transition: var(--transition);
}
.case-next-btn.visible { display: inline-block; }
.case-next-btn:hover { background: var(--navy-light); }

.case-selector {
  background: var(--white); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.case-selector h3 { font-size: 0.9rem; font-weight: 600; color: var(--gray-600); margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.case-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.case-chip {
  padding: 0.4rem 0.9rem; border-radius: 99px; font-size: 0.85rem; font-weight: 600;
  border: 2px solid var(--gray-200); color: var(--gray-600);
  transition: var(--transition); cursor: pointer; background: var(--white);
}
.case-chip.selected { background: var(--navy); color: var(--white); border-color: var(--navy); }
.case-chip:hover:not(.selected) { border-color: var(--navy); color: var(--navy); }

/* ===== REFERENCE ===== */
.reference-area { display: flex; flex-direction: column; gap: 1.5rem; }
.ref-card {
  background: var(--white); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow);
}
.ref-card h3 { font-size: 1.1rem; font-weight: 700; color: var(--navy); margin-bottom: 0.25rem; }
.ref-card .ref-subtitle { color: var(--gray-600); font-size: 0.85rem; margin-bottom: 1rem; }
.case-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.case-table th { background: var(--navy); color: var(--white); padding: 0.6rem 0.8rem; text-align: left; font-weight: 600; }
.case-table th:first-child { border-radius: 8px 0 0 0; }
.case-table th:last-child { border-radius: 0 8px 0 0; }
.case-table td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--gray-100); }
.case-table tr:hover td { background: var(--gray-50); }
.case-table .case-name { font-weight: 600; color: var(--navy); }
.case-table .case-q { color: var(--gray-600); font-size: 0.8rem; }
.gender-badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 99px; font-size: 0.75rem; font-weight: 700;
}
.gender-badge.M { background: var(--blue-light); color: var(--blue); }
.gender-badge.F { background: var(--red-light); color: var(--red); }
.gender-badge.N { background: var(--green-light); color: var(--green); }

/* ===== PAPERS ===== */
.papers-area { display: flex; flex-direction: column; gap: 1.5rem; }
.upload-zone {
  border: 2px dashed var(--gray-200); border-radius: var(--radius-lg);
  padding: 3rem; text-align: center; cursor: pointer;
  transition: var(--transition);
  background: var(--white);
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--red); background: var(--red-light); }
.upload-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.upload-zone h3 { color: var(--navy); font-size: 1.1rem; font-weight: 600; }
.upload-zone p { color: var(--gray-600); font-size: 0.9rem; margin-top: 0.3rem; }
.upload-input { display: none; }

.papers-list { display: flex; flex-direction: column; gap: 0.75rem; }
.paper-item {
  background: var(--white); border-radius: var(--radius); padding: 1rem 1.25rem;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 1rem;
  cursor: pointer; transition: var(--transition);
}
.paper-item:hover { box-shadow: var(--shadow-md); }
.paper-icon { font-size: 1.5rem; }
.paper-info { flex: 1; }
.paper-name { font-weight: 600; color: var(--navy); }
.paper-meta { font-size: 0.8rem; color: var(--gray-600); margin-top: 0.15rem; }
.paper-remove {
  color: var(--gray-400); font-size: 1.1rem; padding: 0.4rem;
  border-radius: 6px; transition: var(--transition);
}
.paper-remove:hover { background: var(--red-light); color: var(--red); }

.pdf-viewer {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.pdf-viewer iframe {
  width: 100%; height: 75vh; border: none; display: block;
}

/* ===== MASTERY INDICATORS ===== */
.mastery-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-left: 4px;
}
.mastery-0 { background: var(--gray-200); }
.mastery-1, .mastery-2 { background: var(--yellow); }
.mastery-3, .mastery-4 { background: var(--blue); }
.mastery-5 { background: var(--green); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  #app { padding: 1rem 0.75rem; }
  .card-word { font-size: 1.6rem; }
  .card-translation { font-size: 1.3rem; }
  .gender-word { font-size: 1.8rem; }
  .chapters-grid { grid-template-columns: 1fr; }
  .flashcard-scene { height: 240px; }
  .flashcard-actions { flex-direction: column; }
  .gender-choices { gap: 0.5rem; }
}
