:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #e4e8ef;
  --primary: #3346d3;
  --primary-dark: #2636ad;
  --soft: #eef1ff;
  --success: #147a4f;
  --success-bg: #e8f7ef;
  --warning: #946200;
  --warning-bg: #fff7df;
  --danger: #b53a45;
  --danger-bg: #fff0f1;
  --shadow: 0 16px 40px rgba(20, 31, 58, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(980px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 56px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 26px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -0.04em; }
h2 { margin-bottom: 8px; letter-spacing: -0.03em; }
.eyebrow { margin-bottom: 6px; color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.small-note { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
.view { display: none; }
.view.active { display: block; }

.hero-card, .setup-card, .test-card, .result-card, .file-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.hero-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 28px; margin-bottom: 20px; }
.hero-card p { margin-bottom: 0; color: var(--muted); }
.hero-stat { min-width: 120px; padding: 18px 22px; background: var(--soft); border-radius: 18px; text-align: center; }
.hero-stat strong { display: block; font-size: 38px; line-height: 1; }
.hero-stat span { color: var(--muted); font-size: 13px; }
.badge { display: inline-flex; padding: 7px 10px; border-radius: 999px; background: var(--soft); color: var(--primary); font-size: 12px; font-weight: 800; }
.badge.success { color: var(--success); background: var(--success-bg); }

.menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.menu-card { padding: 24px; text-align: left; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.menu-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #cbd2e4; }
.menu-icon { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; margin-bottom: 18px; border-radius: 12px; color: var(--primary); background: var(--soft); font-weight: 800; }
.menu-card h3 { margin-bottom: 8px; }
.menu-card p { margin-bottom: 0; color: var(--muted); line-height: 1.6; }

.file-panel { padding: 24px; }
.section-title-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.section-title-row h2 { margin-bottom: 0; }
.file-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 10px; }
.file-chip { min-height: 58px; border: 1px solid var(--line); border-radius: 14px; background: #fff; font-weight: 800; }
.file-chip.available { border-color: #bfc8ff; color: var(--primary); background: var(--soft); }
.file-chip.locked { cursor: default; color: #a4acbb; background: #f6f7f9; }

.progress-text { font-weight: 800; }
.progress-bar { height: 8px; overflow: hidden; margin-bottom: 18px; border-radius: 999px; background: #e8ebf0; }
.progress-fill { width: 0; height: 100%; background: var(--primary); transition: width .25s ease; }

.flashcard { width: 100%; height: min(560px, 66vh); padding: 0; border: 0; background: transparent; perspective: 1200px; }
.flashcard-inner { position: relative; width: 100%; height: 100%; transition: transform .55s ease; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face { position: absolute; inset: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 28px; background: var(--panel); box-shadow: var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flashcard-front { align-items: center; justify-content: center; padding: 30px; }
.flashcard-back { transform: rotateY(180deg); padding: 28px; text-align: left; }
.solution-scroll { overflow-y: auto; width: 100%; padding-right: 6px; }
.problem-math { margin: 34px 0; font-size: clamp(24px, 4.8vw, 44px); text-align: center; }
.answer-math { margin-top: 16px; font-size: clamp(22px, 4vw, 34px); }
.flip-hint { margin-bottom: 0; color: var(--muted); }
.answer-block { padding: 20px; border-radius: 18px; background: var(--success-bg); }
.solution-list { padding-left: 22px; line-height: 1.8; }
.solution-list li + li { margin-top: 8px; }
.tip-box, .warning-box { margin-top: 16px; padding: 18px; border-radius: 16px; }
.tip-box { background: var(--soft); }
.warning-box { background: var(--warning-bg); }
.tip-box p, .warning-box p { margin: 8px 0 0; line-height: 1.65; }

.control-row { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }
.primary-btn, .secondary-btn, .ghost-btn { min-height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 800; }
.primary-btn { border: 1px solid var(--primary); color: #fff; background: var(--primary); }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { border: 1px solid var(--line); color: var(--text); background: #fff; }
.ghost-btn { border: 1px solid var(--line); background: transparent; color: var(--text); }
.full { width: 100%; }

.setup-card, .result-card { max-width: 680px; margin: 40px auto 0; padding: 30px; }
.setup-card > p { color: var(--muted); line-height: 1.65; }
fieldset { margin: 26px 0; padding: 0; border: 0; }
legend { margin-bottom: 12px; font-weight: 800; }
.choice-row { display: flex; flex-wrap: wrap; gap: 10px; }
.choice-btn, .radio-card { display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 16px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.choice-btn.selected { border-color: var(--primary); color: var(--primary); background: var(--soft); }

.score-pill { padding: 10px 16px; border-radius: 999px; color: var(--primary); background: var(--soft); font-weight: 900; }
.test-card { padding: 28px; }
.test-meta-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.answer-choices { display: grid; gap: 12px; margin: 22px 0; }
.answer-choice { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 12px; min-height: 64px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 16px; background: #fff; text-align: left; }
.answer-choice:hover:not(:disabled) { border-color: #b9c1dc; background: #fafbff; }
.answer-choice.correct { border-color: #65b48e; background: var(--success-bg); }
.answer-choice.wrong { border-color: #dc8991; background: var(--danger-bg); }
.answer-choice:disabled { cursor: default; }
.choice-index { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 10px; color: var(--primary); background: var(--soft); font-weight: 900; }
.feedback { margin: 16px 0; padding: 16px; border-radius: 14px; line-height: 1.65; }
.feedback.correct { color: var(--success); background: var(--success-bg); }
.feedback.wrong { color: var(--danger); background: var(--danger-bg); }

.result-card { text-align: center; }
.result-score { display: flex; flex-direction: column; margin: 32px 0; }
.result-score strong { font-size: 66px; letter-spacing: -0.06em; }
.result-score span { color: var(--muted); }
.result-message { margin-bottom: 20px; padding: 18px; border-radius: 16px; background: var(--soft); line-height: 1.65; }

@media (max-width: 700px) {
  .app-shell { width: min(100% - 20px, 980px); padding-top: 18px; }
  .hero-card { align-items: flex-start; }
  .hero-stat { min-width: 88px; }
  .menu-grid { grid-template-columns: 1fr; }
  .file-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .section-title-row { align-items: flex-start; }
  .flashcard { height: 68vh; }
  .control-row { flex-wrap: wrap; }
  .test-card, .setup-card, .result-card { padding: 20px; }
}

.file-select {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* Long-expression refinements requested for worksheet 19. */
.problem-math.problem-compact-strong { font-size: clamp(18px, 3.1vw, 30px); }
.problem-math.problem-compact-light { font-size: clamp(22px, 4.1vw, 38px); }
@media (max-width: 640px) {
  .problem-math.problem-compact-strong { font-size: clamp(16px, 4.4vw, 23px); }
  .problem-math.problem-compact-light { font-size: clamp(19px, 5.2vw, 28px); }
}
