/* ===== CSS 변수 ===== */
:root {
  --primary: #4f6ef7;
  --primary-dark: #3a55d4;
  --primary-light: #eef1fe;
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --white: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

/* ===== 리셋 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== 헤더 ===== */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 1.5rem; font-weight: 800; color: var(--primary); letter-spacing: -0.5px; }
.nav { display: flex; gap: 4px; }
.nav-btn {
  background: none;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--gray-500);
  transition: all 0.15s;
}
.nav-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }

/* ===== 메인 ===== */
.main {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* ===== 페이지 ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== 플레이어 컨트롤러 ===== */
.player-bar {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
}
.player-bar.playing {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.1);
}

.player-mode-toggle { display: flex; gap: 4px; flex-shrink: 0; }
.player-mode-btn {
  padding: 4px 10px;
  border: 1.5px solid var(--gray-200);
  border-radius: 99px;
  background: none;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--gray-500);
  transition: all 0.15s;
  white-space: nowrap;
}
.player-mode-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

.player-controls { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.player-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: var(--gray-100);
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--gray-700);
}
.player-btn:hover { background: var(--gray-200); }
.player-btn-main {
  width: 38px;
  height: 38px;
  background: var(--primary);
  color: var(--white);
  font-size: 0.9rem;
}
.player-btn-main:hover { background: var(--primary-dark); }
.player-btn-stop { color: var(--danger); }
.player-btn-stop:hover { background: var(--danger-light); }

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.player-word {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-progress { font-size: 0.78rem; color: var(--gray-400); white-space: nowrap; flex-shrink: 0; }

/* ===== 단어장 페이지 ===== */
.page-header {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  align-items: center;
}
.search-bar { flex: 1; }
.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--primary); }

.words-container { display: flex; flex-direction: column; gap: 16px; }

.date-group {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.date-group-header {
  padding: 12px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.date-label { font-weight: 600; font-size: 0.9rem; color: var(--gray-700); }
.date-count { font-size: 0.8rem; color: var(--gray-500); }
.date-toggle { color: var(--gray-400); font-size: 0.8rem; transition: transform 0.2s; }
.date-group.collapsed .date-toggle { transform: rotate(-90deg); }
.date-group.collapsed .word-list { display: none; }

.word-list { padding: 4px 0; }
.word-item {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.1s;
}
.word-item:last-child { border-bottom: none; }
.word-item:hover { background: var(--gray-50); }
.word-en { font-weight: 600; font-size: 1rem; color: var(--gray-900); }
.word-ko { color: var(--gray-500); font-size: 0.9rem; }
.word-example { font-size: 0.78rem; color: var(--gray-400); font-style: italic; margin-top: 2px; }
.word-actions { display: flex; gap: 5px; opacity: 0; transition: opacity 0.15s; flex-shrink: 0; }
.word-item:hover .word-actions { opacity: 1; }

.btn-icon {
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--gray-500);
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--gray-100); }
.btn-icon.delete:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.btn-icon.speak-btn {
  font-size: 0.9rem;
  border: none;
  padding: 4px 6px;
  color: var(--gray-400);
}
.btn-icon.speak-btn:hover { background: var(--primary-light); color: var(--primary); border-color: transparent; }

.word-stats-badges { display: flex; gap: 4px; margin-top: 4px; }
.badge { font-size: 0.7rem; padding: 1px 6px; border-radius: 99px; font-weight: 500; }
.badge-correct { background: var(--success-light); color: var(--success); }
.badge-wrong { background: var(--danger-light); color: var(--danger); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-500); }
.empty-icon { font-size: 3rem; margin-bottom: 12px; }

/* ===== 버튼 ===== */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; margin-top: 12px; }
.btn-text { background: none; border: none; cursor: pointer; font-size: 0.8rem; color: var(--primary); padding: 4px 8px; }
.btn-text:hover { text-decoration: underline; }

/* ===== 섹션 타이틀 ===== */
.section-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 20px; }

/* ===== 퀴즈 ===== */
.quiz-settings { max-width: 500px; margin: 0 auto; }
.settings-grid { display: flex; flex-direction: column; gap: 20px; margin-bottom: 28px; }
.setting-group {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.setting-label { font-weight: 600; font-size: 0.9rem; color: var(--gray-700); display: block; margin-bottom: 12px; }
.radio-group { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.15s;
}
.radio-label:has(input:checked) { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.radio-label input { display: none; }

.quiz-play { max-width: 500px; margin: 0 auto; }
.quiz-progress-bar { height: 6px; background: var(--gray-200); border-radius: 99px; margin-bottom: 12px; overflow: hidden; }
.quiz-progress-fill { height: 100%; background: var(--primary); border-radius: 99px; transition: width 0.3s ease; }
.quiz-counter { text-align: right; font-size: 0.85rem; color: var(--gray-500); margin-bottom: 16px; }
.quiz-card { background: var(--white); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow-md); }
.quiz-question { font-size: 1.8rem; font-weight: 700; text-align: center; margin-bottom: 8px; }
.quiz-context { font-size: 0.85rem; color: var(--gray-500); text-align: center; margin-bottom: 24px; font-style: italic; }
.quiz-input-area { display: flex; gap: 8px; }
.quiz-answer-input {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.quiz-answer-input:focus { border-color: var(--primary); }
.quiz-feedback { margin-top: 20px; text-align: center; }
.feedback-result { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.feedback-result.correct { color: var(--success); }
.feedback-result.similar { color: var(--warning); }
.feedback-result.wrong { color: var(--danger); }
.feedback-text { font-size: 0.9rem; color: var(--gray-500); margin-bottom: 4px; }
.feedback-word { font-size: 1rem; font-weight: 600; color: var(--gray-700); margin-bottom: 16px; }

.quiz-result { max-width: 500px; margin: 0 auto; text-align: center; }
.result-score-ring { margin: 20px 0; }
.score-circle {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 140px; height: 140px; border-radius: 50%;
  border: 8px solid var(--primary); background: var(--primary-light);
}
.score-number { font-size: 2rem; font-weight: 800; color: var(--primary); }
.score-label { font-size: 0.8rem; color: var(--gray-500); }
.result-breakdown { display: flex; justify-content: center; gap: 20px; margin: 20px 0; }
.breakdown-item { text-align: center; }
.breakdown-count { display: block; font-size: 1.8rem; font-weight: 700; }
.breakdown-label { font-size: 0.8rem; color: var(--gray-500); }
.breakdown-item.correct .breakdown-count { color: var(--success); }
.breakdown-item.similar .breakdown-count { color: var(--warning); }
.breakdown-item.wrong .breakdown-count { color: var(--danger); }
.result-wrong-list { background: var(--white); border-radius: var(--radius); padding: 16px; margin: 16px 0; text-align: left; box-shadow: var(--shadow); }
.result-wrong-list h4 { font-size: 0.9rem; color: var(--gray-700); margin-bottom: 10px; }
.wrong-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--gray-100); font-size: 0.88rem; }
.wrong-item:last-child { border-bottom: none; }
.wrong-en { font-weight: 600; min-width: 120px; }
.wrong-ko { color: var(--gray-500); flex: 1; }
.wrong-your { color: var(--danger); font-size: 0.8rem; }
.result-actions { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

/* ===== 통계 ===== */
.stats-overview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--gray-500); margin-top: 4px; }
.chart-section, .top-wrong-section { background: var(--white); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.chart-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--gray-700); }
.chart-wrapper { height: 200px; position: relative; }
.top-wrong-list { display: flex; flex-direction: column; gap: 8px; }
.top-wrong-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--gray-50); border-radius: var(--radius-sm); }
.top-wrong-rank { font-size: 0.8rem; font-weight: 700; color: var(--gray-500); min-width: 24px; }
.top-wrong-en { font-weight: 600; min-width: 130px; }
.top-wrong-ko { color: var(--gray-500); font-size: 0.9rem; flex: 1; }
.top-wrong-count { font-size: 0.8rem; color: var(--danger); font-weight: 600; }

/* ===== 모달 ===== */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); }
.modal-content {
  position: relative; background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 540px; max-height: 92vh;
  overflow-y: auto; padding: 20px;
  box-shadow: var(--shadow-lg);
}
@media (min-width: 600px) { .modal-content { border-radius: var(--radius); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-500); line-height: 1; padding: 4px; }
.modal-tabs { display: flex; margin-bottom: 20px; border-bottom: 2px solid var(--gray-200); }
.modal-tab {
  flex: 1; background: none; border: none;
  padding: 10px; cursor: pointer; font-size: 0.9rem; font-weight: 500;
  color: var(--gray-500); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s;
}
.modal-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== 폼 ===== */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-input { width: 100%; padding: 10px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 0.95rem; outline: none; transition: border-color 0.15s; }
.form-input:focus { border-color: var(--primary); }
.form-textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 0.9rem; outline: none; resize: vertical; font-family: inherit; transition: border-color 0.15s; }
.form-textarea:focus { border-color: var(--primary); }

/* ===== 이미지 업로드 ===== */
.mode-toggle { display: flex; gap: 8px; margin-bottom: 10px; }
.mode-btn { flex: 1; padding: 8px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); background: none; cursor: pointer; font-size: 0.85rem; font-weight: 500; color: var(--gray-500); transition: all 0.15s; }
.mode-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.mode-desc { font-size: 0.8rem; color: var(--gray-500); margin-bottom: 12px; }
.upload-area {
  border: 2px dashed var(--gray-300); border-radius: var(--radius);
  padding: 20px; text-align: center; cursor: pointer; transition: all 0.15s;
  margin-bottom: 12px; min-height: 120px; display: flex; align-items: center; justify-content: center;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-placeholder { font-size: 0.85rem; color: var(--gray-500); }
.upload-icon { font-size: 2rem; margin-bottom: 6px; }
.upload-hint { font-size: 0.75rem; color: var(--gray-400); margin-top: 4px; }
.upload-preview { max-width: 100%; max-height: 200px; border-radius: var(--radius-sm); object-fit: contain; }
.analyze-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; color: var(--gray-500); font-size: 0.9rem; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 추출 결과 ===== */
.extract-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.extract-title { font-size: 0.9rem; font-weight: 600; }
.extract-actions { display: flex; gap: 4px; }
.extract-hint { font-size: 0.78rem; color: var(--gray-400); margin-bottom: 10px; }
.article-summary { background: var(--primary-light); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.85rem; color: var(--primary-dark); margin-bottom: 12px; }
.extracted-words-list { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; margin-bottom: 4px; }
.extracted-word-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.15s;
}
.extracted-word-item.selected { border-color: var(--primary); background: var(--primary-light); }
.extracted-word-check { flex-shrink: 0; margin-top: 2px; }
.extracted-word-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.extracted-word-body { flex: 1; min-width: 0; }
.extracted-en { font-weight: 600; font-size: 0.95rem; border: none; outline: none; width: 100%; background: transparent; cursor: text; }
.extracted-ko { color: var(--gray-600, #4b5563); font-size: 0.85rem; border: none; outline: none; width: 100%; background: transparent; cursor: text; margin-top: 2px; }
.extracted-ex { color: var(--gray-400); font-size: 0.78rem; font-style: italic; margin-top: 3px; line-height: 1.4; }
.extracted-ctx { color: var(--gray-500); font-size: 0.75rem; margin-top: 2px; line-height: 1.4; background: rgba(0,0,0,0.04); border-radius: 4px; padding: 3px 6px; }
.extracted-en:focus, .extracted-ko:focus { background: var(--white); border-radius: 4px; padding: 1px 4px; }

/* ===== 에러 메시지 ===== */
.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 8px; padding: 8px 12px; background: var(--danger-light); border-radius: var(--radius-sm); }

/* ===== 로딩 ===== */
.loading { text-align: center; padding: 40px; color: var(--gray-500); font-size: 0.9rem; }

/* ===== 토스트 ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--gray-900); color: var(--white);
  padding: 10px 20px; border-radius: 99px; font-size: 0.9rem;
  z-index: 9999; box-shadow: var(--shadow-lg); white-space: nowrap;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ===== 반응형 ===== */
@media (max-width: 540px) {
  .player-bar { gap: 8px; padding: 10px 12px; }
  .player-info { display: none; }
  .header-inner { padding: 0 12px; }
  .logo { font-size: 1.2rem; }
  .nav-btn { padding: 6px 10px; font-size: 0.82rem; }
  .stats-overview { gap: 8px; }
  .stat-number { font-size: 1.5rem; }
  .quiz-question { font-size: 1.4rem; }
}
