/* =============================================
   LOL English — 공통 스타일
   ============================================= */

/* 기본 폰트 */
* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* =============================================
   페이지 전환 애니메이션
   ============================================= */
.page {
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.page.active {
  display: block;
}

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

/* =============================================
   공통 레이아웃
   ============================================= */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: white;
  position: relative;
}

.page-inner {
  padding: 24px 20px;
}

/* 상단 네비게이션 바 */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f1f5f9;
  background: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  color: #0f172a;
}

.nav-back {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #64748b;
  cursor: pointer;
  transition: background 0.15s;
}

.nav-back:hover {
  background: #f1f5f9;
}

/* =============================================
   버튼
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  outline: none;
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #3b5bff;
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: #2033f5;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 91, 255, 0.35);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: #f1f5f9;
  color: #0f172a;
}
.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-outline {
  background: transparent;
  color: #3b5bff;
  border: 1.5px solid #3b5bff;
}
.btn-outline:hover:not(:disabled) {
  background: #f0f4ff;
}

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
}
.btn-danger:hover:not(:disabled) {
  background: #fecaca;
}

.btn-ghost {
  background: transparent;
  color: #64748b;
}
.btn-ghost:hover:not(:disabled) {
  background: #f8fafc;
  color: #0f172a;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-lg {
  padding: 16px 28px;
  font-size: 16px;
  border-radius: 14px;
}

.btn-loading {
  position: relative;
  color: transparent !important;
}
.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-color: white transparent white transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-primary.btn-loading::after {
  border-color: white transparent white transparent;
}

/* =============================================
   입력창
   ============================================= */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-label {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.input-field {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  font-size: 15px;
  color: #0f172a;
  background: #fafafa;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  font-family: inherit;
}

.input-field:focus {
  border-color: #3b5bff;
  background: white;
  box-shadow: 0 0 0 3px rgba(59, 91, 255, 0.1);
}

.input-field::placeholder {
  color: #94a3b8;
}

.input-field.error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.input-error-msg {
  font-size: 13px;
  color: #ef4444;
}

textarea.input-field {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

/* =============================================
   카드
   ============================================= */
.card {
  background: white;
  border-radius: 16px;
  border: 1px solid #f1f5f9;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  padding: 20px;
  transition: box-shadow 0.15s;
}

.card-hover:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: pointer;
}

.card-primary {
  background: linear-gradient(135deg, #3b5bff 0%, #2033f5 100%);
  color: white;
  border: none;
}

.card-accent {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: white;
  border: none;
}

/* =============================================
   배지 / 태그
   ============================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}

.badge-blue   { background: #eff6ff; color: #2563eb; }
.badge-green  { background: #f0fdf4; color: #16a34a; }
.badge-yellow { background: #fefce8; color: #ca8a04; }
.badge-red    { background: #fef2f2; color: #dc2626; }
.badge-gray   { background: #f8fafc; color: #64748b; }
.badge-primary { background: #f0f4ff; color: #3b5bff; }

/* 난이도 배지 */
.difficulty-beginner     { background: #f0fdf4; color: #16a34a; }
.difficulty-intermediate { background: #fefce8; color: #ca8a04; }
.difficulty-advanced     { background: #fef2f2; color: #dc2626; }

/* =============================================
   토스트 알림
   ============================================= */
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  animation: slideUp 0.25s ease-out;
  min-width: 240px;
  max-width: 340px;
}

.toast-success { background: #0f172a; color: white; }
.toast-error   { background: #dc2626; color: white; }
.toast-info    { background: #3b5bff; color: white; }
.toast-warning { background: #f59e0b; color: white; }

.toast.hide {
  animation: slideDown 0.2s ease-in forwards;
}

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

/* =============================================
   모달
   ============================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal-box {
  background: white;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 24px 20px 40px;
  animation: slideUp 0.25s ease-out;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: #e2e8f0;
  border-radius: 99px;
  margin: 0 auto 20px;
}

/* =============================================
   구분선
   ============================================= */
.divider {
  height: 1px;
  background: #f1f5f9;
  margin: 16px 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: #94a3b8;
  font-size: 13px;
}
.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

/* =============================================
   로딩
   ============================================= */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #e2e8f0;
  border-top-color: #3b5bff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 8px;
}

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

/* =============================================
   빈 상태
   ============================================= */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #94a3b8;
}
.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}
.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 8px;
}
.empty-state-desc {
  font-size: 14px;
  line-height: 1.6;
}

/* =============================================
   진행바
   ============================================= */
.progress-bar {
  width: 100%;
  height: 6px;
  background: #f1f5f9;
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b5bff, #5b87ff);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* =============================================
   하단 고정 영역
   ============================================= */
.bottom-action {
  position: sticky;
  bottom: 0;
  background: white;
  padding: 16px 20px;
  border-top: 1px solid #f1f5f9;
}

/* =============================================
   반응형
   ============================================= */
@media (min-width: 640px) {
  .app-container {
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
  }
}

/* =============================================
   선택 박스 (영어 수준 등)
   ============================================= */
.select-field {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  font-size: 15px;
  color: #0f172a;
  background: #fafafa;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

.select-field:focus {
  border-color: #3b5bff;
  background-color: white;
  box-shadow: 0 0 0 3px rgba(59, 91, 255, 0.1);
}

/* =============================================
   Range 슬라이더 (학습 목표 시간)
   ============================================= */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 99px;
  background: #e2e8f0;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3b5bff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(59,91,255,0.4);
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3b5bff;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(59,91,255,0.4);
}

/* =============================================
   LOL English 로고
   ============================================= */
.lol-logo {
  font-size: 24px;
  font-weight: 700;
  color: #3b5bff;
  letter-spacing: -0.5px;
}

.lol-logo span {
  color: #f97316;
}

/* =============================================
   플립 카드 (learn.js 핵심 표현)
   ============================================= */
.flip-card {
  perspective: 1000px;
  min-height: 220px;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  min-height: 220px;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 16px;
  overflow: hidden;
}

.flip-card-back {
  transform: rotateY(180deg);
}

/* badge 추가 색상 */
.badge-blue {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-red {
  background: #fee2e2;
  color: #dc2626;
}

/* safe-bottom (홈 버튼 있는 기기 대응) */
.safe-bottom {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* =============================================
   divider
   ============================================= */
.divider {
  border: none;
  border-top: 1px solid #f1f5f9;
  margin: 8px 0;
}

/* =============================================
   설정 페이지 — 행 버튼 공통
   ============================================= */
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.12s;
  border-radius: 4px;
}
.settings-row:hover {
  background: #f8fafc;
}
.settings-row:active {
  background: #f1f5f9;
}

/* =============================================
   BLOCK 6 — 롤플레잉 대화 버블
   ============================================= */

/* 버블 래퍼 */
.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  animation: bubbleIn 0.25s ease-out;
}
.chat-bubble-wrap--user {
  align-items: flex-end;
}

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

/* 버블 공통 */
.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.5;
  word-break: break-word;
}

/* AI 버블 (왼쪽) */
.chat-bubble--ai {
  background: #f1f5f9;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}

/* 내 버블 (오른쪽) */
.chat-bubble--user {
  background: #3b5bff;
  color: white;
  border-bottom-right-radius: 4px;
}

/* =============================================
   BLOCK 6 — 마이크 버튼
   ============================================= */
.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #3b5bff;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  outline: none;
  box-shadow: 0 4px 16px rgba(59, 91, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}

.mic-btn:active {
  transform: scale(0.95);
}

/* 활성(녹음 중) 상태 */
.mic-btn--active {
  background: #ef4444;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5);
  animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5); }
  50%       { box-shadow: 0 4px 32px rgba(239, 68, 68, 0.8), 0 0 0 12px rgba(239, 68, 68, 0.1); }
}

/* =============================================
   BLOCK 6 — TTS 재생 웨이브 애니메이션
   ============================================= */
.tts-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.tts-wave span {
  display: block;
  width: 4px;
  background: #3b5bff;
  border-radius: 99px;
  animation: ttsBar 0.8s ease-in-out infinite;
}

.tts-wave span:nth-child(1) { height: 8px;  animation-delay: 0s; }
.tts-wave span:nth-child(2) { height: 14px; animation-delay: 0.1s; }
.tts-wave span:nth-child(3) { height: 20px; animation-delay: 0.2s; }
.tts-wave span:nth-child(4) { height: 14px; animation-delay: 0.3s; }
.tts-wave span:nth-child(5) { height: 8px;  animation-delay: 0.4s; }

@keyframes ttsBar {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50%       { transform: scaleY(1);   opacity: 1; }
}

/* =============================================
   BLOCK 6 — STT 결과 텍스트
   ============================================= */
.stt-interim {
  font-size: 14px;
  color: #94a3b8;
  font-style: italic;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
}

.stt-final {
  color: #0f172a;
  font-style: normal;
  background: #f0f4ff;
  border-color: #c0d4ff;
  font-weight: 500;
}

/* STT 에러 박스 */
.stt-error-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #64748b;
  background: #fef9f0;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.6;
  text-align: center;
}

/* STT → 텍스트 전환 버튼 */
.stt-text-switch-btn {
  margin-top: 6px;
  padding: 6px 16px;
  background: #3b5bff;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s;
}
.stt-text-switch-btn:hover {
  background: #2033f5;
}

/* =============================================
   표현 학습 / 영어로 말하기 — 고정 높이 플립 카드
   (learn.js, practice.js 공통)
   헤더 고정 + 본문 내부 스크롤
   ============================================= */

/* 레거시 호환 — 구 클래스 유지 */
.flip-card-expr { perspective: 1000px; cursor: pointer; }
.flip-card-inner-expr {
  position: relative; width: 100%; min-height: 240px;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}
.flip-card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 16px; overflow: hidden; height: auto; min-height: 240px;
}
.flip-card-face--front { }
.flip-card-face--back { transform: rotateY(180deg); }

/* ── 새 카드 클래스 (expr-card-*) ── */

/* 카드 전체 래퍼: 고정 높이 */
.expr-card-wrap {
  perspective: 1000px;
  cursor: pointer;
  height: calc(100vh - 290px);
  min-height: 320px;
  max-height: 520px;
}

/* 회전 컨테이너 */
.expr-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

/* 앞/뒷면 공통: 헤더 고정 + 본문 스크롤을 위해 flex column */
.expr-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.expr-card-face--front { }
.expr-card-face--back { transform: rotateY(180deg); }

/* 뒷면 본문: 헤더 제외 나머지 영역 스크롤 */
.expr-back-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 16px;
  -webkit-overflow-scrolling: touch;
}

/* 직역/의역/뉘앙스 라벨 */
.expr-label {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  flex-shrink: 0;
  white-space: nowrap;
  line-height: 1.6;
}

/* ── TTS 웨이브 애니메이션 (표현 학습 카드 앞면) ── */
.tts-wave {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
  height: 40px;
}
.tts-wave span {
  display: block;
  width: 6px;
  border-radius: 3px;
  background: var(--color-primary, #6366f1);
  animation: tts-bar 1.1s ease-in-out infinite;
  opacity: 0.75;
}
.tts-wave span:nth-child(1) { height: 18px; animation-delay: 0s;    }
.tts-wave span:nth-child(2) { height: 30px; animation-delay: 0.15s; }
.tts-wave span:nth-child(3) { height: 40px; animation-delay: 0.3s;  }
.tts-wave span:nth-child(4) { height: 30px; animation-delay: 0.45s; }
.tts-wave span:nth-child(5) { height: 18px; animation-delay: 0.6s;  }

@keyframes tts-bar {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50%       { transform: scaleY(1.0); opacity: 1;   }
}

/* invisible 유틸 (visibility만 숨김 → 레이아웃 자리 확보) */
.invisible {
  visibility: hidden;
}

/* ── 대사 카드 스피커 버튼 — 모바일 터치 보정 ── */
.dialogue-speaker-btn {
  /* 최소 44×44px 터치 영역 (Apple HIG) */
  min-width: 44px;
  min-height: 44px;
  /* 버튼이 flex 컨테이너에서 절대 축소되지 않도록 */
  flex-shrink: 0 !important;
  /* 모바일에서 hover 스타일 대신 active 사용 */
  cursor: pointer;
}
