* { box-sizing: border-box; }

:root {
  --bg: #f7f7fb;
  --card: #ffffff;
  --text: #1f2330;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --correct: #10b981;
  --correct-bg: #ecfdf5;
  --wrong: #ef4444;
  --wrong-bg: #fef2f2;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Malgun Gothic", "맑은 고딕", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  min-height: 100%;
}

.screen { display: flex; flex-direction: column; gap: 20px; }
.hidden { display: none !important; }

h1 { font-size: 28px; margin: 16px 0 4px; }
h2 { font-size: 22px; margin: 8px 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.page-footer {
  margin-top: 48px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.page-footer p {
  margin: 0 auto;
  max-width: 260px;
  word-break: keep-all;   /* 한국어가 단어 중간에서 끊기지 않도록 */
}
.page-footer p + p { margin-top: 2px; opacity: 0.85; }
.refresh-button {
  margin-top: 12px;
  font-size: 12px;
  padding: 6px 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.refresh-button:hover { background: #f3f4f6; }
.screen-subtitle { color: var(--muted); margin: -4px 0 8px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; }

button {
  font: inherit;
  font-size: 16px;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.05s, background 0.15s, border-color 0.15s;
  text-align: center;
}
button:active { transform: scale(0.985); }
button:disabled { cursor: default; opacity: 0.7; }

button.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }

button.secondary { background: white; }
button.secondary:hover:not(:disabled) { background: #f3f4f6; }

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.test-launcher {
  margin-top: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}
.test-launcher .primary { width: 100%; }

.count-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}
.count-picker-label {
  font-size: 13px;
  color: var(--muted);
}
.count-chips {
  display: inline-flex;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.count-chip {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.count-chip.selected {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* 모드 토글 — 단어 맞추기 / 빈칸 채우기 페이지 전환 */
.mode-toggle {
  display: inline-flex;
  align-self: center;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  margin: 4px 0 8px;
}
.mode-toggle a {
  text-decoration: none;
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.mode-toggle a.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* === Test screen === */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, #7c6aff 100%);
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.test-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#score-text { transition: color 0.2s; display: inline-block; }
@keyframes score-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); color: var(--correct); }
  100% { transform: scale(1); }
}
#score-text.pop { animation: score-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes prompt-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
@keyframes choice-in {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes label-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.prompt.anim-in        { animation: prompt-in 0.32s ease-out; }
.direction-label.anim-in { animation: label-in 0.28s ease-out; }
.choice                { animation: choice-in 0.28s ease-out backwards; }
.choice:nth-child(1)   { animation-delay: 0.04s; }
.choice:nth-child(2)   { animation-delay: 0.10s; }
.choice:nth-child(3)   { animation-delay: 0.16s; }
.choice:nth-child(4)   { animation-delay: 0.22s; }

@keyframes correct-pulse {
  0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(16,185,129,0.45); }
  35%  { transform: scale(1.04); box-shadow: 0 0 0 10px rgba(16,185,129,0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px); }
  30% { transform: translateX(8px); }
  45% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
  90% { transform: translateX(3px); }
}
.choice.correct { animation: correct-pulse 0.55s ease-out; }
.choice.wrong   { animation: wrong-shake 0.5s ease-in-out; }

@keyframes next-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
#next-button:not(.hidden) { animation: next-in 0.3s ease-out; }

/* prefers-reduced-motion: disable bells & whistles */
@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
  #score-text.pop,
  .prompt.anim-in,
  .direction-label.anim-in,
  .choice,
  .choice.correct,
  .choice.wrong,
  #next-button:not(.hidden) {
    animation: none;
  }
}

.direction-label {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: #eef2ff;
  border: 1px solid #e0e7ff;
  color: #4338ca;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

/* 한글 뜻 중 정답 단어에 해당하는 부분 강조 (**...**) */
.hl {
  font-weight: 800;
  color: var(--primary);
  background: rgba(79, 70, 229, 0.1);
  padding: 0 3px;
  border-radius: 4px;
}
.wrong-item .dir .hl { background: rgba(79, 70, 229, 0.08); }

.prompt {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 20px;
  text-align: center;
  font-size: 32px;
  font-weight: 600;
  box-shadow: var(--shadow);
  min-height: 100px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.prompt-meaning {
  font-size: 17px;
  font-weight: 500;
  color: var(--muted);
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice {
  text-align: left;
  padding: 14px 16px;
  font-size: 16px;
  position: relative;
}

.choice .index {
  display: inline-block;
  width: 22px;
  color: var(--muted);
  font-size: 13px;
}

.choice.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
  color: var(--correct);
  font-weight: 600;
}
.choice.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong);
  color: var(--wrong);
  font-weight: 600;
}

/* === Input (예문 타이핑) === */
.input-answer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.answer-input {
  font: inherit;
  font-size: 20px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.02em;
  width: 100%;
}
.answer-input::placeholder { color: var(--muted); font-size: 16px; letter-spacing: 0; }
.answer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}
.answer-input.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: var(--correct);
  font-weight: 600;
}
.answer-input.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: var(--wrong);
  font-weight: 600;
}
.input-answer .primary { width: 100%; }
.input-feedback {
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  padding: 2px 0;
}
.input-feedback.correct { color: var(--correct); }
.input-feedback.wrong { color: var(--wrong); }

/* 힌트 */
.hint-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-height: 38px;
}
.hint-button {
  font-size: 14px;
  padding: 8px 14px;
  flex-shrink: 0;
}
/* 힌트 보기 4개: 같은 품사 단어. 누르면 입력창에 채워 따라 쓰기 */
.hint-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.hint-choices:empty { display: none; }
.hint-note {
  flex: 1 0 100%;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.hint-choice {
  flex: 1 1 0;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  color: var(--primary);
  text-align: center;
  word-break: break-all;
  user-select: none;
}

#next-button { margin-top: 8px; }

/* === Result === */
.result-score {
  text-align: center;
  font-size: 56px;
  font-weight: 700;
  color: var(--primary);
  padding: 8px 0 4px;
}
.result-score span { font-variant-numeric: tabular-nums; }

.result-time {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 0 0 16px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
}
@keyframes fade-in { to { opacity: 1; } }
.result-time.fade-in { animation: fade-in 0.4s ease-out 0.5s forwards; }
@media (prefers-reduced-motion: reduce) {
  .result-time { opacity: 1; }
  .result-time.fade-in { animation: none; }
}

.result-wrong {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wrong-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.wrong-item .dir { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.wrong-item .q { font-weight: 600; margin-bottom: 6px; }
.wrong-item .row { display: flex; gap: 8px; font-size: 14px; }
.wrong-item .row .label { color: var(--muted); width: 60px; }
.wrong-item .row.user .ans { color: var(--wrong); }
.wrong-item .row.correct .ans { color: var(--correct); font-weight: 600; }

.result-empty {
  text-align: center;
  color: var(--correct);
  font-weight: 600;
  padding: 12px;
}

/* === History === */
.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-section-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
  padding: 12px 4px 2px;
}
.history-section-header:first-child { padding-top: 4px; }

.history-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
}
.history-card .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.history-card .date { font-size: 14px; color: var(--muted); }
.history-card .score { font-weight: 700; font-size: 18px; color: var(--primary); }
.history-card .meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.history-card .detail { display: none; margin-top: 12px; }
.history-card.open .detail { display: flex; flex-direction: column; gap: 8px; }

.history-empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* === Wrong stats === */
#wrong-stats-groups,
#sentence-stats-groups { display: flex; flex-direction: column; gap: 12px; }

.stats-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.stats-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  cursor: pointer;
  user-select: none;
}
.stats-group-header .caret {
  color: var(--muted);
  font-size: 14px;
  transition: transform 0.15s;
  display: inline-block;
}
.stats-group.open .stats-group-header .caret { transform: rotate(90deg); }
.stats-group-header .title { flex: 1; font-weight: 600; font-size: 15px; }
.stats-group-header .count {
  font-size: 13px;
  color: var(--muted);
  background: #f3f4f6;
  border-radius: 999px;
  padding: 2px 10px;
  font-variant-numeric: tabular-nums;
}

.stats-group-body {
  display: none;
  border-top: 1px solid var(--border);
  max-height: 480px;
  overflow-y: auto;
}
.stats-group.open .stats-group-body { display: block; }

.stats-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.stats-item:first-child { border-top: none; }

.stats-item .word { min-width: 0; flex: 1; }
.stats-item .en { font-weight: 600; margin-right: 8px; }
.stats-item .ko { color: var(--muted); font-size: 14px; word-break: keep-all; }

.stats-item .stat {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.stats-empty { color: var(--muted); padding: 20px 14px; text-align: center; font-size: 14px; }

/* 예문 통계 항목: 예문 위, 뜻·정답 아래로 세로 배치 */
.stats-item.sentence-stat .word { display: flex; flex-direction: column; gap: 3px; }
.stats-item.sentence-stat .q { font-weight: 600; font-size: 15px; word-break: keep-all; }
.stats-item.sentence-stat .meaning {
  color: var(--muted);
  font-size: 14px;
  word-break: keep-all;
}
.stats-item.sentence-stat .meaning .ans {
  color: var(--primary);
  font-weight: 600;
}
