/* ============================================================
   영어문법학습 — 디자인 토큰
   톤: 차분하고 따뜻한 저채도 + 둥글고 친근한 형태
   ============================================================ */

:root {
  /* Surface */
  --bg: #F6F2EC;            /* 따뜻한 오프화이트 */
  --bg-elevated: #FFFFFF;
  --surface: #FBF8F3;
  --surface-muted: #EEE9E0;
  --surface-deep: #E3DCD0;

  /* Text */
  --text: #2A2622;
  --text-soft: #5C544A;
  --text-muted: #948A7C;
  --text-faint: #BFB6A6;

  /* Borders / shadows */
  --border: #E2DBCD;
  --border-strong: #C9C0AE;
  --shadow-card: 0 1px 0 #00000008, 0 6px 18px -8px #4a3a2014;
  --shadow-lift: 0 1px 0 #00000010, 0 14px 30px -12px #4a3a2024;
  --shadow-press: 0 1px 0 #00000010;

  /* Brand — muted sage / teal */
  --brand: #5C8478;
  --brand-deep: #44685D;
  --brand-soft: #DBE6E0;
  --brand-faint: #ECF1EE;

  /* States */
  --correct: #6B9D80;
  --correct-deep: #4F7D63;
  --correct-soft: #DDEBE0;
  --correct-faint: #EFF6F0;

  --wrong: #C77A6C;
  --wrong-deep: #A55A4D;
  --wrong-soft: #F1D8D0;
  --wrong-faint: #F9ECE7;

  --gold: #C9A26B;
  --gold-soft: #F0E2C8;
  --gold-faint: #F8F0DC;

  /* Type scale */
  --font-sans: "Pretendard Variable", "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  --font-eng: "Pretendard Variable", "Pretendard", "Inter", system-ui, sans-serif;

  /* Radii */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
}

/* Pretendard from CDN */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");

* { box-sizing: border-box; }

html, body, #root {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-feature-settings: "ss01", "tnum";
  letter-spacing: -0.01em;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

button:disabled { cursor: not-allowed; }

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: inherit; text-decoration: none; }

/* ============================================================
   레이아웃 셸
   ============================================================ */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 600px at 50% -200px, #ffffff 0%, transparent 60%),
    var(--bg);
}

.app-container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 80px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

@media (max-width: 540px) {
  .app-container { padding: 0 16px 24px; }
}

/* ============================================================
   상단 바
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 70%, #f6f2ec00 100%);
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--brand);
  display: grid;
  place-items: center;
  color: white;
  font-size: 16px;
  font-weight: 800;
  box-shadow: inset 0 -2px 0 var(--brand-deep);
}

.topbar-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: var(--text-soft);
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
}
.stat-chip:hover { background: var(--surface-muted); }

.stat-chip svg { width: 16px; height: 16px; }

/* ============================================================
   버튼
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: var(--r-md);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: transform .06s ease, box-shadow .12s ease, background .15s ease, color .15s ease;
  user-select: none;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--brand);
  color: white;
  box-shadow: inset 0 -3px 0 var(--brand-deep), 0 1px 2px #00000010;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); }
.btn-primary:disabled {
  background: var(--surface-deep);
  color: var(--text-faint);
  box-shadow: inset 0 -3px 0 var(--border-strong);
}

.btn-correct {
  background: var(--correct);
  color: white;
  box-shadow: inset 0 -3px 0 var(--correct-deep);
}
.btn-correct:hover:not(:disabled) { background: var(--correct-deep); }

.btn-wrong {
  background: var(--wrong);
  color: white;
  box-shadow: inset 0 -3px 0 var(--wrong-deep);
}

.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
  box-shadow: inset 0 -2px 0 var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface); }

.btn-soft {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: inset 0 -2px 0 var(--border);
}
.btn-soft:hover:not(:disabled) { background: var(--surface-muted); }

.btn-block { width: 100%; }
.btn-sm { padding: 9px 14px; font-size: 13px; border-radius: var(--r-sm); }
.btn-lg { padding: 18px 28px; font-size: 17px; border-radius: var(--r-lg); }

/* ============================================================
   카드 / 컨테이너
   ============================================================ */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 28px 4px 12px;
}

/* ============================================================
   챕터 카드 (홈)
   ============================================================ */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (max-width: 540px) {
  .chapter-grid { grid-template-columns: 1fr; gap: 12px; }
}

.chapter-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  text-align: left;
  transition: transform .12s ease, box-shadow .15s ease, border-color .15s ease;
  cursor: pointer;
  overflow: hidden;
}

.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: var(--border-strong);
}

.chapter-card.completed { border-color: var(--correct-soft); }
.chapter-card.completed::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--correct-faint) 0%, transparent 40%);
  pointer-events: none;
}

.chapter-card-icon {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  background: var(--brand-faint);
  color: var(--brand-deep);
  font-size: 22px;
  font-weight: 800;
}

.chapter-card.review .chapter-card-icon {
  background: var(--gold-faint);
  color: #8B6A30;
}
.chapter-card.mega-review .chapter-card-icon {
  background: linear-gradient(135deg, #efe1c2, #e3cfa1);
  color: #6A4F1A;
}

.chapter-card-body { flex: 1; min-width: 0; }
.chapter-card-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.chapter-card.review .chapter-card-kicker { color: #B58A3F; }
.chapter-card.mega-review .chapter-card-kicker { color: #8B6A30; }

.chapter-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.chapter-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chapter-card-meta-sep { opacity: 0.4; margin: 0 6px; }

.chapter-progress-track {
  position: relative;
  height: 6px;
  background: var(--surface-muted);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-top: 10px;
}
.chapter-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--correct);
  border-radius: var(--r-pill);
  transition: width .3s ease;
}

.chapter-card-checkmark {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--correct);
  color: white;
  display: grid;
  place-items: center;
  font-size: 13px;
}

/* ============================================================
   퀴즈 화면
   ============================================================ */
.quiz-screen {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 8px;
  flex: 1;
  min-height: calc(100vh - 80px);
}

.quiz-spacer { flex: 1; min-height: 8px; }

.quiz-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.quiz-close {
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-soft);
}
.quiz-close:hover { background: var(--surface-muted); }

.progress-track {
  flex: 1;
  height: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  position: relative;
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(180deg, #7CAE93, var(--correct));
  box-shadow: inset 0 -3px 0 var(--correct-deep);
  border-radius: var(--r-pill);
  transition: width .35s cubic-bezier(.2,.8,.2,1);
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: var(--gold-faint);
  color: #8B6A30;
  border-radius: var(--r-pill);
  font-weight: 800;
  font-size: 13px;
  border: 1px solid #E8D6AC;
  font-variant-numeric: tabular-nums;
}

.quiz-prompt {
  text-align: center;
  padding: 8px 0 0;
}
.quiz-prompt-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.quiz-prompt-text {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.3;
}
@media (max-width: 540px) {
  .quiz-prompt-text { font-size: 22px; }
}

.quiz-hint {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* Sentence with blanks */
.sentence-builder {
  margin: 8px 0;
  padding: 24px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  line-height: 1.6;
}

.sentence-word {
  font-family: var(--font-eng);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.sentence-blank {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 56px;
  min-height: 38px;
  padding: 4px 10px;
  border-bottom: 2px dashed var(--border-strong);
  flex-wrap: wrap;
  justify-content: center;
  transition: border-color .15s;
}
.sentence-blank.has-tokens { border-bottom-color: var(--brand); }
.sentence-blank.correct { border-bottom-color: var(--correct); }
.sentence-blank.wrong { border-bottom-color: var(--wrong); }

.token-in-slot {
  font-family: var(--font-eng);
  font-size: 20px;
  font-weight: 600;
  color: var(--brand-deep);
  padding: 4px 10px;
  background: var(--brand-faint);
  border: 1px solid var(--brand-soft);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: opacity .15s;
}
.token-in-slot:hover { opacity: 0.7; }

.sentence-blank.correct .token-in-slot {
  background: var(--correct-faint);
  border-color: var(--correct-soft);
  color: var(--correct-deep);
}
.sentence-blank.wrong .token-in-slot {
  background: var(--wrong-faint);
  border-color: var(--wrong-soft);
  color: var(--wrong-deep);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

/* Word card bank */
.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 10px;
  justify-content: center;
  padding: 4px 0;
  min-height: 120px;
}

.word-card {
  font-family: var(--font-eng);
  font-size: 18px;
  font-weight: 600;
  padding: 10px 18px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-width: 3px;
  border-radius: var(--r-md);
  cursor: pointer;
  letter-spacing: -0.01em;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, color .15s ease;
  user-select: none;
}
.word-card:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--border-strong);
}
.word-card:active:not(:disabled) { transform: translateY(1px); }
.word-card.used {
  background: var(--surface-muted);
  color: var(--text-faint);
  border-color: var(--border);
  border-bottom-width: 1px;
  cursor: default;
}
.word-card.used .word-card-inner { visibility: hidden; }

/* ============================================================
   결과 패널 (정/오)
   ============================================================ */
.result-panel {
  margin-top: 12px;
  border-radius: var(--r-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 1;
  transform: translateY(0);
}
.result-panel-enter {
  animation: slide-up .25s ease-out both;
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-panel.correct { background: var(--correct-faint); border: 1px solid var(--correct-soft); }
.result-panel.wrong { background: var(--wrong-faint); border: 1px solid var(--wrong-soft); }

.result-headline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.result-panel.correct .result-headline { color: var(--correct-deep); }
.result-panel.wrong .result-headline { color: var(--wrong-deep); }

.result-headline-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-size: 14px;
}
.result-panel.correct .result-headline-icon { background: var(--correct); }
.result-panel.wrong .result-headline-icon { background: var(--wrong); }

.result-correct-answer {
  font-family: var(--font-eng);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: #ffffff80;
  border-radius: var(--r-sm);
  padding: 8px 12px;
  border: 1px solid #ffffffaa;
}
.result-correct-answer-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-right: 6px;
}

.explanation {
  background: #ffffffa0;
  border: 1px solid #ffffffcc;
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-soft);
}
.explanation-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.explanation b, .explanation strong { color: var(--text); font-weight: 700; }
.explanation code {
  font-family: var(--font-eng);
  background: var(--surface-muted);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--brand-deep);
}

/* ============================================================
   완료 화면
   ============================================================ */
.completion-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 24px;
  flex: 1;
  text-align: center;
}

.completion-medal {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, #efe1c2 0%, #d4b478 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px -6px #C9A26B66, inset 0 -6px 0 #b18f4a;
  animation: medal-pop .5s cubic-bezier(.34, 1.56, .64, 1) both;
  color: #fff;
}
@keyframes medal-pop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.completion-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}
.completion-subtitle {
  font-size: 16px;
  color: var(--text-soft);
  max-width: 340px;
  line-height: 1.5;
}

.score-display {
  display: flex;
  gap: 16px;
  margin: 8px 0;
}
.score-cell {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 22px;
  min-width: 110px;
  text-align: center;
}
.score-cell-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.score-cell-value {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-top: 4px;
}
.score-cell.accent .score-cell-value { color: var(--correct-deep); }

/* ============================================================
   확인/취소 푸터 (퀴즈 하단 고정)
   ============================================================ */
.quiz-footer {
  display: flex;
  gap: 12px;
  padding-top: 4px;
  padding-bottom: 8px;
}

/* ============================================================
   정리(grammar reference) 카드
   ============================================================ */
.grammar-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px 22px;
  box-shadow: var(--shadow-card);
}
.grammar-block h3 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.grammar-block h4 {
  margin: 18px 0 8px;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--brand-deep);
}
.grammar-block p { margin: 6px 0; line-height: 1.7; color: var(--text-soft); font-size: 14px; }
.grammar-block code {
  font-family: var(--font-eng);
  background: var(--surface-muted);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--brand-deep);
}
.grammar-block table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.grammar-block th, .grammar-block td {
  padding: 8px 10px; border: 1px solid var(--border);
  text-align: left;
}
.grammar-block th { background: var(--surface); font-weight: 700; }

/* ============================================================
   관리자
   ============================================================ */
.admin-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  margin-top: 12px;
  font-size: 13px;
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.admin-field label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.admin-field input,
.admin-field textarea,
.admin-field select {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  outline: none;
  transition: border-color .15s;
  font-size: 14px;
}
.admin-field input:focus,
.admin-field textarea:focus,
.admin-field select:focus { border-color: var(--brand); }
.admin-field textarea { min-height: 60px; resize: vertical; font-family: inherit; }

/* ============================================================
   Confetti (클리어 축하)
   ============================================================ */
.confetti-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 99;
}
.confetti-piece {
  position: absolute;
  top: -10%;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
  opacity: 0.85;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0.6; }
}

/* ============================================================
   유틸
   ============================================================ */
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
.text-muted { color: var(--text-muted); }
.text-soft { color: var(--text-soft); }
.small { font-size: 12px; }
.center { text-align: center; }

.fade-in { opacity: 1; animation: fade-in .25s ease-out both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.slide-in-right { animation: slide-in-right .25s ease-out both; }
@keyframes slide-in-right { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) {
  .fade-in, .slide-in-right { animation: none; opacity: 1; transform: none; }
}
