:root {
  --color-bg: #f4f4f2;
  --color-surface: #ffffff;
  --color-primary: #ff9600;
  --color-primary-dark: #e08600;
  --color-ink: #131f24;
  --color-text: #3c3c3c;
  --color-muted: #8a8a8a;
  --color-success: #58cc02;
  --color-danger: #ff4b4b;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Apple SD Gothic Neo", "Segoe UI", "Noto Sans KR", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-surface);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.06);
  padding: 24px 20px 40px;
}

@media (min-width: 640px) {
  .app-shell {
    margin: 24px auto;
    min-height: calc(100vh - 48px);
    border-radius: var(--radius-lg);
  }
}

.hidden { display: none !important; }

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

/* ---- 공통 컴포넌트 ---- */
.btn-primary, .btn-secondary {
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.btn-primary {
  background: var(--color-ink);
  color: #fff;
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:not(:disabled):active { transform: scale(0.98); }
.btn-secondary {
  background: #eee;
  color: var(--color-ink);
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.text-input, .quiz-textarea {
  width: 100%;
  border: 2px solid #e5e5e5;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-family: inherit;
}
.text-input:focus, .quiz-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.field-label { font-size: 13px; color: var(--color-muted); margin-bottom: -8px; }
.subtitle { color: var(--color-muted); font-size: 14px; margin: 0; }
.section-title { font-size: 18px; margin: 4px 0; }
.error-text { color: var(--color-danger); font-size: 13px; margin: -8px 0 0; }

/* ---- 1. 로그인 ---- */
.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding-top: 12vh;
}
.login-hero {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 50%;
  margin-bottom: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.brand { font-size: 26px; margin: 0; }
.login-card .text-input { margin-top: 12px; text-align: center; font-size: 20px; }
.login-card .btn-primary { margin-top: 12px; }

/* ---- 2. 캐릭터 선택 ---- */
.view-header { display: flex; align-items: center; gap: 10px; }
.view-header h2 { margin: 0; font-size: 18px; flex: 1; }

.character-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.character-tile {
  border: 2px solid #eee;
  background: #fafafa;
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.character-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
}
.character-tile span { font-size: 12px; color: var(--color-text); }
.character-tile.selected {
  border-color: var(--color-primary);
  background: #fff4e5;
}

/* ---- 3. 홈 ---- */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.profile-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f4f4f2;
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
}
.avatar-sm { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); }

.verse-list { display: flex; flex-direction: column; gap: 12px; }
.verse-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: none;
  border-radius: var(--radius-md);
  background: #fdf1e0;
  padding: 16px;
  text-align: left;
  cursor: pointer;
}
.verse-card.completed { background: #eaf7d9; }
.verse-card-ref { margin: 0; font-weight: 700; font-size: 15px; }
.verse-card-status { margin: 4px 0 0; font-size: 13px; color: var(--color-muted); }
.verse-card-check { font-size: 20px; color: var(--color-success); }

/* ---- 4. 퀴즈 ---- */
.quiz-ref { font-weight: 700; font-size: 16px; }
.quiz-card {
  background: #fafafa;
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-hint-label { margin: 0; font-size: 12px; color: var(--color-muted); }
.quiz-start-word { margin: 0; font-size: 18px; font-weight: 700; color: var(--color-primary-dark); }
.quiz-textarea { min-height: 160px; resize: vertical; }
.audio-player { width: 100%; height: 40px; }
.mode-label {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary-dark);
  background: #fff4e5;
  padding: 4px 10px;
  border-radius: 999px;
  margin: 0;
}

/* ---- 5. 결과 ---- */
.result-badge {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  padding: 10px;
  border-radius: var(--radius-md);
}
.result-badge.success { background: #eaf7d9; color: #3d8b00; }
.result-badge.retry { background: #fdeaea; color: #c62828; }
.result-score { text-align: center; font-size: 32px; font-weight: 800; margin: 0; }
.result-diff {
  background: #fafafa;
  border-radius: var(--radius-md);
  padding: 16px;
  line-height: 2;
  font-size: 16px;
}
.diff-word { padding: 2px 4px; border-radius: 6px; }
.diff-correct { color: var(--color-ink); }
.diff-missing { background: #eee; color: var(--color-muted); text-decoration: underline dotted; }
.diff-extra { background: #fdeaea; color: var(--color-danger); text-decoration: line-through; }
.result-actions { display: flex; gap: 10px; }
.result-actions .btn-secondary, .result-actions .btn-primary { flex: 1; }

/* ---- 6. 마이페이지 ---- */
.mypage-profile { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.mypage-username { font-size: 18px; font-weight: 700; margin: 0; }
.mypage-list { display: flex; flex-direction: column; gap: 8px; }
.mypage-row {
  display: grid;
  grid-template-columns: 1fr auto 24px;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: #fafafa;
  border-radius: var(--radius-sm);
}
.mypage-row-ref { font-size: 14px; }
.mypage-row-score { font-size: 14px; color: var(--color-muted); }
.mypage-row-badge { color: var(--color-success); text-align: center; }
.mypage-row-wrap { display: flex; flex-direction: column; gap: 6px; }
.mypage-row-wrap .mypage-row { border: none; width: 100%; text-align: left; cursor: pointer; font-family: inherit; }
.mypage-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 14px 12px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: var(--radius-sm);
}
.mypage-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--color-text);
  padding: 4px 0;
  border-bottom: 1px solid #f4f4f2;
}
.mypage-detail-row:last-child { border-bottom: none; }

/* ---- 홈 액션 카드 ---- */
.action-card-row { display: flex; gap: 10px; }
.action-card {
  flex: 1;
  position: relative;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
  text-align: center;
}
.action-card-test { background: linear-gradient(135deg, #ff9600, #ff6b00); }
.action-card-review { background: linear-gradient(135deg, #58cc02, #3d8b00); }
.action-card-icon { font-size: 24px; }
.action-card-label { font-size: 13px; font-weight: 700; }
.action-card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #fff;
  color: var(--color-danger);
  font-size: 12px;
  font-weight: 800;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ---- 활동 선택 ---- */
.activity-list { display: flex; flex-direction: column; gap: 10px; }
.activity-option {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: #fafafa;
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.activity-option-icon { font-size: 24px; }
.activity-option-text { display: flex; flex-direction: column; gap: 2px; }

/* ---- 빈칸 채우기 ---- */
.fillblank-sentence { font-size: 17px; line-height: 2.4; overflow-wrap: break-word; }
.blank-input {
  display: inline-block;
  box-sizing: content-box;
  max-width: 100%;
  min-width: 3ch;
  border: none;
  border-bottom: 2px solid var(--color-primary);
  background: #fff4e5;
  font-size: 16px;
  font-family: inherit;
  text-align: center;
  padding: 2px 4px;
  border-radius: 4px;
  margin: 0 2px;
  transition: width 0.1s ease;
}
.blank-input:focus { outline: none; border-bottom-color: var(--color-primary-dark); }

/* ---- 문장 고르기 ---- */
.choice-options { display: flex; flex-direction: column; gap: 10px; }
.choice-option {
  border: 2px solid #eee;
  background: #fafafa;
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;
  font-family: inherit;
}
.choice-option:disabled { cursor: default; }
.choice-option.choice-correct { border-color: var(--color-success); background: #eaf7d9; }
.choice-option.choice-wrong { border-color: var(--color-danger); background: #fdeaea; }

/* ---- 대기실(로비) ---- */
.lobby-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
  text-align: center;
}
.lobby-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.lobby-greeting { font-size: 16px; font-weight: 700; margin: 0; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.lobby-tile {
  position: relative;
  border: none;
  border-radius: var(--radius-md);
  padding: 22px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
}
.lobby-tile-icon { font-size: 28px; }
.lobby-tile-label { font-size: 14px; font-weight: 700; }
.lobby-tile-random { background: linear-gradient(135deg, #5b8def, #3d6fd6); }
.lobby-tile-test { background: linear-gradient(135deg, #ff9600, #ff6b00); }
.lobby-tile-flashcard { background: linear-gradient(135deg, #b46cf0, #8a3ee0); }
.lobby-tile-review { background: linear-gradient(135deg, #58cc02, #3d8b00); }

.lobby-list-link {
  border: none;
  background: transparent;
  color: var(--color-primary-dark);
  font-size: 14px;
  font-weight: 700;
  padding: 8px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}

/* ---- 랜덤 연습 설정 ---- */
.count-chip-row { display: flex; gap: 10px; flex-wrap: wrap; }
.count-chip {
  border: 2px solid #eee;
  background: #fafafa;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.count-chip.selected { border-color: var(--color-primary); background: #fff4e5; color: var(--color-primary-dark); }

/* ---- 플래시카드 ---- */
.flashcard-card {
  min-height: 320px;
  background: #fafafa;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 24px;
}
.flashcard-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  width: 100%;
}
.flashcard-ref { font-size: 22px; font-weight: 800; margin: 0; }
.flashcard-startword { font-size: 16px; font-weight: 700; color: var(--color-primary-dark); margin: 0; }
.flashcard-content { font-size: 17px; line-height: 1.7; margin: 0; }
.flashcard-nav { display: flex; gap: 10px; }
.flashcard-nav button { flex: 1; }

/* ---- 시험 힌트 바 ---- */
.hint-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff4e5;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  flex-wrap: wrap;
}
.hint-count { font-size: 12px; font-weight: 700; color: var(--color-primary-dark); flex: 1 0 100%; }
.hint-btn {
  border: none;
  background: #fff;
  border: 1px solid var(--color-primary);
  color: var(--color-primary-dark);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.hint-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- 플래시카드 스와이프 힌트 ---- */
.flashcard-swipe-hint { text-align: center; margin: 0; }
.flashcard-card { touch-action: pan-y; user-select: none; }

/* ---- 화면 전환 애니메이션 ---- */
@keyframes viewEnter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.view:not(.hidden) { animation: viewEnter 0.22s ease; }

/* ---- 완료 축하 애니메이션 ---- */
@keyframes celebratePop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.result-badge.celebrate { animation: celebratePop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* ---- 탭 피드백(누르는 느낌) 일관 적용 ---- */
.lobby-tile, .activity-option, .choice-option, .count-chip, .hint-btn,
.verse-card, .character-tile {
  transition: transform 0.12s ease;
}
.lobby-tile:active, .activity-option:active, .choice-option:not(:disabled):active,
.count-chip:active, .hint-btn:not(:disabled):active, .verse-card:active, .character-tile:active {
  transform: scale(0.97);
}
.lobby-tile { box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08); }
