/* ============================================================
   Speaking Coach — 스타일
   모바일 우선. 데스크톱에서는 가운데 폰 프레임 안에 렌더.
   ============================================================ */

:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f7f8fd;
  --ink: #1c1d2b;
  --ink-soft: #5a5c72;
  --ink-faint: #9a9cb2;
  --line: #e7e8f2;

  --brand: #6d5efc;
  --brand-ink: #4a3ee0;
  --brand-soft: #ede9ff;

  --good: #23c07a;
  --good-soft: #e3f8ee;
  --fair: #f4a72c;
  --fair-soft: #fdf1dc;
  --poor: #f26a6a;
  --poor-soft: #fde5e5;

  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(43, 39, 99, 0.08);
  --shadow-btn: 0 8px 20px rgba(109, 94, 252, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
          "Apple SD Gothic Neo", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: #e9eaf4;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- 폰 프레임 (데스크톱 전용 장식) ---------- */
.device {
  position: relative;
  width: 100%;
  max-width: 420px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}
.device__notch { display: none; }

@media (min-width: 480px) {
  body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
  .device {
    min-height: 860px;
    max-height: 92vh;
    border-radius: 44px;
    border: 10px solid #14131f;
    box-shadow: 0 40px 80px rgba(20, 19, 31, 0.4);
    overflow: hidden;
  }
  .device__notch {
    display: block;
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 150px; height: 26px;
    background: #14131f;
    border-radius: 0 0 18px 18px;
    z-index: 50;
  }
}

/* ---------- 앱 컨테이너 ---------- */
.app {
  position: relative;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 22px 20px 28px;
}
/* 모바일 노치/홈바 안전영역 */
@supports (padding: max(0px)) {
  @media (max-width: 479px) {
    .app {
      padding-top: max(22px, env(safe-area-inset-top));
      padding-bottom: max(28px, env(safe-area-inset-bottom));
    }
  }
}
@media (min-width: 480px) {
  .app { min-height: 840px; height: 840px; padding-top: 40px; }
}

/* ---------- 공통 요소 ---------- */
.stack { display: flex; flex-direction: column; }
.spacer { flex: 1 1 auto; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.center { text-align: center; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.topbar__title { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.iconbtn {
  border: none; background: var(--surface); color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px;
  box-shadow: var(--shadow); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}

/* 브랜드 로고 */
.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #7d6bff, #6d5efc 60%, #5a49f0);
  display: grid; place-items: center; color: #fff; font-size: 18px;
  box-shadow: var(--shadow-btn);
}
.brand__name { font-weight: 800; font-size: 17px; letter-spacing: -0.3px; }

/* 카드 */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card { margin-top: 14px; }

/* 스트릭 배너 */
.streak {
  background: linear-gradient(135deg, #7468ff, #6d5efc 55%, #5b8bff);
  color: #fff; border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-btn);
  display: flex; align-items: center; justify-content: space-between;
}
.streak__num { font-size: 34px; font-weight: 800; line-height: 1; }
.streak__label { font-size: 13px; opacity: 0.85; margin-top: 4px; }
.streak__flame { font-size: 40px; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2)); }

/* 진행 링/바 */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress__fill { height: 100%; background: linear-gradient(90deg, #7d6bff, #6d5efc); border-radius: 99px; transition: width .4s ease; }

/* 섹션 제목 */
.section-title { font-size: 13px; font-weight: 700; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.6px; margin: 22px 4px 10px; }

/* 시나리오 리스트 */
.lesson {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
  border: 1px solid transparent; transition: transform .12s ease, border-color .12s ease;
}
.lesson:active { transform: scale(0.98); }
.lesson__emoji { font-size: 26px; width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; }
.lesson__body { flex: 1; min-width: 0; }
.lesson__title { font-weight: 700; font-size: 15px; }
.lesson__meta { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.lesson__chev { color: var(--ink-faint); font-size: 18px; }
.lesson + .lesson { margin-top: 10px; }

/* 버튼 */
.btn {
  border: none; cursor: pointer; font-family: inherit;
  border-radius: 16px; font-weight: 700; font-size: 16px;
  padding: 16px 20px; width: 100%;
  transition: transform .1s ease, box-shadow .2s ease, opacity .2s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-btn); }
.btn--ghost { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow); }
.btn--soft { background: var(--brand-soft); color: var(--brand-ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- 연습 화면 ---------- */
.practice { height: 100%; display: flex; flex-direction: column; }

.practice__progress { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.practice__progress .progress { flex: 1; }
.practice__count { font-size: 12px; color: var(--ink-faint); font-weight: 700; white-space: nowrap; }

.prompt-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 22px; text-align: center; }
.prompt-card__ko { font-size: 14px; color: var(--ink-soft); margin-bottom: 14px; }
.prompt-card__en { font-size: 24px; font-weight: 700; line-height: 1.42; letter-spacing: -0.3px; }
.prompt-card__en .w { padding: 1px 2px; border-radius: 6px; transition: background .2s; }
.prompt-card__phonetic { margin-top: 12px; font-size: 14px; color: var(--ink-faint); font-style: italic; }

.listen-row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.chip {
  border: none; background: var(--surface-2); color: var(--brand-ink);
  border-radius: 99px; padding: 9px 16px; font-size: 13px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip:active { transform: scale(0.96); }
.chip.is-active { background: var(--brand-soft); }

/* 단어 상태 색상 */
.w--good { background: var(--good-soft); color: #167f52; }
.w--fair { background: var(--fair-soft); color: #9a6410; }
.w--poor { background: var(--poor-soft); color: #b23b3b; }

/* 마이크 */
.mic-zone { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px 0; }
.mic {
  width: 96px; height: 96px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 38px;
  box-shadow: var(--shadow-btn); display: grid; place-items: center;
  transition: transform .12s ease;
}
.mic:active { transform: scale(0.94); }
.mic.is-recording { background: var(--poor); animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(242,106,106,0.5); }
  70% { box-shadow: 0 0 0 22px rgba(242,106,106,0); }
  100% { box-shadow: 0 0 0 0 rgba(242,106,106,0); }
}
.mic-hint { font-size: 13px; color: var(--ink-faint); font-weight: 600; }

/* ---------- 결과 화면 ---------- */
.score-ring { width: 128px; height: 128px; margin: 6px auto 2px; position: relative; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring__num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; font-weight: 800; }
.score-ring__num small { font-size: 14px; color: var(--ink-faint); font-weight: 600; }

.verdict { text-align: center; font-size: 16px; font-weight: 700; margin-top: 4px; }
.metrics { display: flex; gap: 10px; margin-top: 16px; }
.metric { flex: 1; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.metric__v { font-size: 20px; font-weight: 800; }
.metric__l { font-size: 11px; color: var(--ink-faint); margin-top: 2px; }

.tip { display: flex; gap: 10px; background: var(--fair-soft); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 10px; }
.tip__icon { font-size: 18px; }
.tip__text { font-size: 13px; color: #7a5410; line-height: 1.5; }
.tip--good { background: var(--good-soft); }
.tip--good .tip__text { color: #167f52; }

.heard { font-size: 12px; color: var(--ink-faint); margin-top: 14px; text-align: center; }
.heard b { color: var(--ink-soft); font-weight: 600; }

/* 배지/알림 */
.banner {
  background: var(--brand-soft); color: var(--brand-ink);
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px;
  line-height: 1.5; margin-bottom: 14px;
}
.banner--warn { background: var(--fair-soft); color: #7a5410; }

/* 완료 화면 */
.done-hero { text-align: center; padding: 28px 0 10px; }
.done-hero__emoji { font-size: 64px; }
.done-hero__title { font-size: 24px; font-weight: 800; margin-top: 8px; }
.done-hero__sub { color: var(--ink-soft); margin-top: 6px; font-size: 14px; }

.summary-list { margin-top: 8px; }
.summary-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: none; }
.summary-row__label { font-size: 14px; }
.summary-row__val { font-weight: 700; }

/* 유틸 애니메이션 */
.fade-in { animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 하단 고정 액션 */
.bottom-actions { margin-top: 16px; }

/* ---------- 홈: 모드 버튼 ---------- */
.mode-btn {
  display: flex; align-items: center; gap: 14px; width: 100%;
  border: none; cursor: pointer; font-family: inherit; text-align: left;
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); transition: transform .1s ease;
}
.mode-btn:active { transform: scale(0.98); }
.mode-btn__icon { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-size: 24px; }
.mode-btn__icon--a { background: var(--brand-soft); }
.mode-btn__icon--b { background: var(--good-soft); }
.mode-btn__body { flex: 1; min-width: 0; }
.mode-btn__title { font-weight: 800; font-size: 16px; letter-spacing: -0.2px; }
.mode-btn__sub { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.mode-btn__badge {
  background: var(--brand); color: #fff; font-size: 12px; font-weight: 800;
  border-radius: 99px; padding: 4px 10px; white-space: nowrap;
}
.mode-btn__badge--zero { background: var(--good); }

/* 마스터 진행 미니바 */
.mini-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.mini-progress .progress { flex: 1; }
.mini-progress__label { font-size: 12px; color: var(--ink-faint); font-weight: 700; white-space: nowrap; }

/* ---------- 영작(SRS) 화면 ---------- */
.compose-hint { text-align: center; font-size: 13px; color: var(--ink-faint); margin: 8px 0 4px; font-weight: 600; }

.answer-box {
  margin-top: 14px; padding: 18px; border-radius: var(--radius);
  background: var(--good-soft); text-align: center;
}
.answer-box__label { font-size: 11px; font-weight: 800; color: #167f52; letter-spacing: 0.5px; text-transform: uppercase; }
.answer-box__en { font-size: 22px; font-weight: 700; color: #146c48; margin-top: 6px; line-height: 1.4; }

.badge-pill {
  display: inline-flex; align-items: center; gap: 6px; margin: 12px auto 0;
  border-radius: 99px; padding: 6px 14px; font-size: 13px; font-weight: 800;
}
.badge-pill--match { background: var(--good); color: #fff; }
.badge-pill--close { background: var(--fair); color: #fff; }

/* 자가평가 버튼 */
.rate-group { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.rate-btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 700; font-size: 15px;
  border-radius: 14px; padding: 15px 18px; width: 100%; text-align: center;
  transition: transform .1s ease;
}
.rate-btn:active { transform: translateY(1px); }
.rate-btn--again { background: var(--poor-soft); color: #b23b3b; }
.rate-btn--fuzzy { background: var(--fair-soft); color: #9a6410; }
.rate-btn--known { background: var(--good); color: #fff; box-shadow: 0 6px 16px rgba(35,192,122,.35); }
.rate-caption { text-align: center; font-size: 12px; color: var(--ink-faint); margin-top: 12px; }

/* 정답 미공개 상태의 은닉 카드 */
.hidden-answer {
  margin-top: 14px; padding: 22px; border-radius: var(--radius);
  background: var(--surface-2); text-align: center; color: var(--ink-faint);
  font-size: 14px; border: 1.5px dashed var(--line);
}

/* ---------- 새 주제 만들기 ---------- */
.lesson--add { border: 1.5px dashed var(--line); background: var(--surface-2); }
.lesson--add .lesson__emoji { color: var(--good); font-weight: 800; }

.topic-input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 13px 14px; font-size: 16px; font-family: inherit; color: var(--ink);
  background: var(--surface-2); outline: none;
}
.topic-input:focus { border-color: var(--brand); background: #fff; }

.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip--add { background: var(--good-soft); color: #167f52; }

/* 속도 슬라이더 */
input[type="range"] { accent-color: var(--brand); width: 100%; height: 30px; cursor: pointer; }

/* ---------- AI 회화 ---------- */
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat__messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 6px 2px 12px;
  display: flex; flex-direction: column; gap: 10px;
}
/* 회화 화면: 앱을 '보이는 뷰포트 높이'에 고정 + 메시지만 내부 스크롤 → 입력창 항상 노출 */
.app--chat { overflow: hidden; }
@media (max-width: 479px) {
  .app--chat {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    padding-top: max(12px, env(safe-area-inset-top));
  }
}
.bubble { max-width: 84%; padding: 11px 14px; border-radius: 16px; font-size: 15px; line-height: 1.45; animation: fadeIn .25s ease; }
.bubble--ai { align-self: flex-start; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); border-bottom-left-radius: 5px; }
.bubble--user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 5px; box-shadow: var(--shadow-btn); }
.bubble__tip { margin-top: 8px; font-size: 12px; background: var(--fair-soft); color: #7a5410; padding: 7px 10px; border-radius: 9px; line-height: 1.45; }
.chat__input { display: flex; align-items: center; gap: 8px; padding: 10px 0 4px; border-top: 1px solid var(--line); }
.chat__input .topic-input { flex: 1; }
.mic--sm { width: 46px; height: 46px; font-size: 20px; flex: 0 0 auto; box-shadow: var(--shadow-btn); }
.typing { color: var(--ink-faint); font-style: italic; }

/* 로딩(문장 생성) */
.loading-card {
  margin-top: 40%; display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--brand-soft); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { color: var(--ink-soft); font-weight: 600; font-size: 14px; }

/* 로그인 게이트 */
.gate { max-width: 320px; margin: 0 auto; padding: 20px; }
.gate__logo { width: 64px; height: 64px; font-size: 34px; margin: 0 auto 18px; border-radius: 18px; }
.gate__title { font-size: 26px; font-weight: 800; letter-spacing: -0.4px; }
.gate__sub { color: var(--ink-soft); margin-top: 6px; font-size: 14px; }
.gate__desc { color: var(--ink-soft); margin-top: 22px; font-size: 14px; line-height: 1.6; white-space: pre-line; }
.gate__btn { display: flex; justify-content: center; margin-top: 22px; }
.gate__note { color: var(--poor); font-size: 13px; margin-top: 14px; min-height: 18px; line-height: 1.5; }

/* 설치 힌트 */
.install-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--brand-soft); color: var(--brand-ink); border-radius: var(--radius-sm);
  padding: 10px 12px 10px 14px; font-size: 13px; font-weight: 600; margin-top: 12px;
}

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: #1c1d2b; color: #fff; padding: 12px 20px; border-radius: 99px;
  font-size: 14px; font-weight: 700; z-index: 999; box-shadow: 0 10px 30px rgba(0,0,0,.3);
  animation: toastIn .25s ease;
}
.toast--hide { opacity: 0; transition: opacity .3s; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
