* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4a90d9;
  --primary-dark: #3a7bc8;
  --correct: #27ae60;
  --correct-bg: #e8f5e9;
  --wrong: #e74c3c;
  --wrong-bg: #fde8e8;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen-result.active {
  align-items: flex-start;
  padding-top: 40px;
}

.container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
}

/* 시작 화면 */
h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 16px;
  line-height: 1.3;
}

.lang-selector {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 32px;
}

.lang-btn {
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text-light);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #eef2ff;
}

h1 .subtitle {
  font-size: 1.4rem;
  font-weight: 600;
}

.level-section {
  margin-bottom: 16px;
}

.level-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.level-btn {
  padding: 10px 28px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.level-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.filter-section {
  background: var(--card);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.filter-label {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 12px;
  font-weight: 600;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.question-count {
  text-align: center;
  color: var(--text-light);
  font-size: 0.85rem;
  margin-top: 16px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 14px;
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:active {
  background: var(--primary);
  color: white;
}

/* 퀴즈 화면 */
#screen-quiz.active {
  display: flex;
  align-items: stretch;
}

#screen-quiz > .container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
  padding-top: 12px;
  padding-bottom: 12px;
}

@supports (height: 100dvh) {
  #screen-quiz > .container {
    height: 100dvh;
  }
}

.quiz-header {
  margin-bottom: 12px;
  flex-shrink: 0;
}

.progress-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

#score-text {
  color: var(--primary);
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.btn-home {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-light);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.type-badge {
  padding: 2px 10px;
  background: #eef2ff;
  color: var(--primary);
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.quiz-body {
  background: var(--card);
  border-radius: 16px;
  padding: 20px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  flex-shrink: 1;
  overflow-y: auto;
  min-height: 0;
}

.sentence {
  font-size: 1.15rem;
  line-height: 1.7;
  margin-bottom: 12px;
  word-break: keep-all;
}

.sentence u {
  text-decoration-color: var(--primary);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  font-weight: 600;
}

.question {
  font-size: 0.95rem;
  color: var(--text-light);
  font-weight: 500;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.choice-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.choice-btn:active {
  transform: scale(0.98);
}

.choice-btn .choice-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-light);
  flex-shrink: 0;
}

.choice-btn.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
}

.choice-btn.correct .choice-label {
  background: var(--correct);
  color: white;
}

.choice-btn.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
}

.choice-btn.wrong .choice-label {
  background: var(--wrong);
  color: white;
}

.choice-reading {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 400;
}

.choice-btn.disabled {
  cursor: default;
  opacity: 0.6;
}

.choice-btn.correct.disabled,
.choice-btn.wrong.disabled {
  opacity: 1;
}

.explanation {
  background: #f0f4ff;
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  animation: fadeIn 0.3s ease;
}

.btn-next {
  margin-top: 4px;
  flex-shrink: 0;
}

/* 결과 화면 */
.result-title {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 24px;
  color: var(--text-light);
}

.result-score {
  text-align: center;
  margin-bottom: 8px;
}

.score-num {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--primary);
}

.score-divider {
  font-size: 2rem;
  color: var(--text-light);
  margin: 0 4px;
}

.total-num {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-light);
}

.result-percent {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-light);
  margin-bottom: 8px;
}

.result-message {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 32px;
}

.wrong-section {
  margin-bottom: 24px;
}

.wrong-section h3 {
  font-size: 1rem;
  color: var(--text-light);
  margin-bottom: 12px;
}

.wrong-item {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--wrong);
}

.wrong-item .wrong-sentence {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 8px;
}

.wrong-item .wrong-sentence u {
  text-decoration-color: var(--wrong);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.wrong-item .wrong-answer {
  font-size: 0.85rem;
  color: var(--correct);
  font-weight: 600;
}

.wrong-item .wrong-yours {
  font-size: 0.85rem;
  color: var(--wrong);
  margin-bottom: 4px;
}

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

/* 애니메이션 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.quiz-body {
  animation: fadeIn 0.3s ease;
}

.choice-btn {
  animation: fadeIn 0.3s ease backwards;
}

.choice-btn:nth-child(1) { animation-delay: 0.05s; }
.choice-btn:nth-child(2) { animation-delay: 0.1s; }
.choice-btn:nth-child(3) { animation-delay: 0.15s; }
.choice-btn:nth-child(4) { animation-delay: 0.2s; }

.review-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 9px;
  background: var(--wrong);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.review-count:empty {
  display: none;
}
