:root {
  --bg: #fff8ec;
  --card: #ffffff;
  --ink: #2b2a33;
  --muted: #6b6875;
  --line: #e7dfd0;
  --brand: #2f6fde;
  --brand-ink: #ffffff;
  --brand-soft: #e6efff;
  --good: #1f9d55;
  --good-soft: #e3f6ea;
  --bad: #d64545;
  --bad-soft: #fde8e8;
  --warn-soft: #fff3c4;
  --dot: #f08a24;
  --dot2: #2f6fde;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
/* 모바일 기본: 탭 깜빡임 제거(각 버튼에 :active 피드백을 따로 줌), 글자 확대 방지,
   당겨서 새로고침 막기(문제 푸는 중 새로고침되면 그 차시 진행이 사라짐) */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 18px;
  line-height: 1.5;
}
#app {
  max-width: 640px;
  margin: 0 auto;
  /* 노치·홈 표시줄·가로 화면의 둥근 모서리를 피해서 내용 배치 */
  padding: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
}
/* 버튼: 두 번 탭 확대 대기(300ms) 없애기, 길게 눌러도 글자 선택·말풍선 안 뜨게 (본문 글은 그대로 선택 가능) */
button {
  font: inherit; color: inherit; touch-action: manipulation;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}
/* 손가락이 닿는 순간 눌린 느낌 (떼기 전에 반응) */
button:not([disabled]):active { transform: scale(0.96); }
/* 마우스가 있는 기기에서만 hover (휴대폰에서 hover가 남지 않게) */
@media (hover: hover) and (pointer: fine) {
  .choice:not([disabled]):hover, .lesson-item:hover, .speak:hover { border-color: var(--brand); }
  .obj:hover, .animal:not([disabled]):hover, .frame button.cell:hover { background-color: var(--brand-soft); }
}
h1 { font-size: 28px; margin: 8px 0 4px; }
h2 { font-size: 22px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 15px; }
.noscript { padding: 16px; }

/* 카드·버튼 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 10px 20px;
  border-radius: 14px; border: 2px solid transparent;
  background: var(--brand); color: var(--brand-ink);
  font-weight: 700; font-size: 19px; cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 16px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* 홈 */
.lesson-list { list-style: none; margin: 0; padding: 0; }
.lesson-item {
  width: 100%; display: flex; align-items: center; gap: 12px;
  text-align: left; padding: 14px; margin: 8px 0;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px; cursor: pointer;
}
.lesson-item .num {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 800;
}
.lesson-item .title { flex: 1; font-weight: 700; }
.lesson-item.next { border-color: var(--brand); }
.stars { letter-spacing: 1px; font-size: 18px; white-space: nowrap; }
.stars .off { opacity: .2; }
.review-box { background: var(--warn-soft); border-color: #f0d77a; }
.soon li { color: var(--muted); }

/* 진행 표시 */
.steps { display: flex; gap: 6px; margin: 8px 0 4px; }
.steps span {
  flex: 1; text-align: center; font-size: 14px; padding: 4px 0;
  border-radius: 999px; background: #efe8da; color: var(--muted); font-weight: 700;
}
.steps span.on { background: var(--brand); color: #fff; }
.steps span.done { background: var(--brand-soft); color: var(--brand); }
.pbar { height: 8px; background: #efe8da; border-radius: 999px; overflow: hidden; margin: 6px 0 0; }
.pbar i { display: block; height: 100%; background: var(--good); border-radius: 999px; transition: width .3s; }

/* 문제 */
.prompt { display: flex; gap: 8px; align-items: flex-start; }
.prompt p { flex: 1; font-size: 21px; font-weight: 700; margin: 4px 0 0; }
.speak {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--card); font-size: 22px; cursor: pointer;
}
.hint {
  background: var(--brand-soft); color: #1d4fa8; border-radius: 12px;
  padding: 8px 12px; margin: 10px 0 0; font-size: 16px;
}
.visual { margin: 14px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 10px; }

.objs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.obj {
  position: relative; width: 56px; height: 60px; border-radius: 12px;
  border: 2px solid transparent; background: transparent; cursor: pointer;
  font-size: 40px; line-height: 1; display: grid; place-items: center; padding: 0;
}
.obj.marked { background: var(--warn-soft); border-color: #f0c64a; }
.obj .badge {
  position: absolute; right: -4px; top: -6px; min-width: 24px; height: 24px; border-radius: 12px;
  background: var(--dot); color: #fff; font-size: 14px; font-weight: 800; display: grid; place-items: center; padding: 0 4px;
}
.obj .under { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 15px; font-weight: 800; color: var(--dot); }
.objs.numbered { row-gap: 22px; padding-bottom: 14px; }
.plate { font-size: 64px; line-height: 1; }

.bignum { font-size: 88px; font-weight: 800; line-height: 1; color: var(--brand); }

.frame { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 4px; background: #5a5560; border-radius: 10px; width: min(300px, 100%); }
.frame .cell { aspect-ratio: 1; background: #fff; border-radius: 6px; display: grid; place-items: center; border: 0; padding: 0; }
.frame button.cell { cursor: pointer; }
.frame .cell i { width: 70%; height: 70%; border-radius: 50%; background: var(--dot); display: block; }
.frame.small { width: min(200px, 100%); }
.frame-count { font-size: 16px; color: var(--muted); }

.lineup { width: 100%; }
.lineup .ends { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-weight: 700; margin: 0 2px 2px; }
.lineup .animals { display: grid; gap: 2px; }
.lineup .animals > * { min-width: 0; width: 100%; }
.animal[disabled] { opacity: .35; }
.animal {
  position: relative; aspect-ratio: 1; max-height: 64px; border-radius: 10px; border: 2px solid transparent;
  background: transparent; font-size: min(7vw, 38px); padding: 0; cursor: pointer; display: grid; place-items: center;
}
.animal .lab { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 11px; letter-spacing: -.5px; font-weight: 800; color: var(--brand); white-space: nowrap; }
.lineup.labeled .animals { margin-top: 22px; }
.animal.hl { background: var(--good-soft); border-color: var(--good); }
.colored { background: var(--warn-soft); border-color: #f0c64a; }

.nline { width: 100%; display: grid; grid-template-columns: repeat(10, 1fr); border-top: 4px solid #5a5560; margin-top: 8px; }
.nline span { text-align: center; position: relative; padding-top: 8px; font-weight: 800; font-size: 18px; }
.nline span::before { content: ""; position: absolute; top: -10px; left: 50%; width: 3px; height: 14px; background: #5a5560; transform: translateX(-50%); }
.nline span.hl { color: var(--brand); }
.nline span.hl::after { content: ""; position: absolute; top: 4px; left: 50%; width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--brand); transform: translateX(-50%); }
.nline span.ans { color: var(--good); }
.nline span.ans::after { content: ""; position: absolute; top: 4px; left: 50%; width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--good); transform: translateX(-50%); }
.arrow-note { font-size: 16px; font-weight: 700; color: var(--good); }

.pairs { width: 100%; display: grid; gap: 4px 2px; align-items: center; }
.pairs .lbl { font-size: 15px; font-weight: 700; color: var(--muted); padding-right: 4px; white-space: nowrap; }
.pairs .it { font-size: min(7vw, 34px); text-align: center; line-height: 1.2; border-radius: 8px; }
.pairs .it.extra { background: var(--warn-soft); outline: 2px solid #f0c64a; }
.loose { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.loose .grp { display: flex; align-items: center; gap: 8px; }
.loose .grp .items { display: flex; flex-wrap: wrap; font-size: min(7vw, 34px); line-height: 1.2; }

.two { display: flex; gap: 16px; justify-content: center; align-items: flex-start; width: 100%; }
.two > div { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; }
.two .bignum { font-size: 64px; }

/* 선택지 */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin-top: 14px; }
.choices.nums { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
.choice {
  min-height: 64px; border-radius: 14px; border: 2px solid var(--line); background: var(--card);
  font-size: 24px; font-weight: 800; cursor: pointer; padding: 6px;
}
.choices.nums .choice { font-size: 32px; }
.choice.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.choice.right { background: var(--good-soft); border-color: var(--good); color: var(--good); }

/* 피드백 */
.fb { border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; border: 2px solid; }
.fb.good { background: var(--good-soft); border-color: var(--good); }
.fb.bad { background: var(--bad-soft); border-color: var(--bad); }
.fb.show { background: var(--warn-soft); border-color: #f0c64a; }
.fb .head { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.fb .visual { margin: 8px 0; }

/* 개념 카드 */
.concept .visual { margin: 12px 0; }
.dots-nav { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.dots-nav i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dots-nav i.on { background: var(--brand); }
.count-table { width: 100%; border-collapse: collapse; font-size: 18px; }
.count-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.count-table td.n { font-size: 30px; font-weight: 800; color: var(--brand); width: 44px; text-align: center; }
.count-table td.e { font-size: 22px; letter-spacing: -2px; }
.count-table td.r { white-space: nowrap; font-weight: 700; text-align: right; }

.result { text-align: center; }
.result .big-stars { font-size: 48px; letter-spacing: 4px; }

.settings { margin-top: 24px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.switch input { width: 24px; height: 24px; }

@media (max-width: 380px) {
  body { font-size: 17px; }
  .obj { width: 48px; height: 52px; font-size: 34px; }
  .choices.nums .choice { font-size: 28px; }
  .bignum { font-size: 72px; }
}
.loose .grp .lbl { flex: none; min-width: 3.5em; white-space: nowrap; }

/* --- 사용성 점검 후 추가 (2026-11-29) --- */
/* 음성을 못 쓰는 브라우저에서는 눌러도 아무 일 없는 스피커 버튼을 숨김 */
.no-tts .speak { display: none; }
/* 다음 문제 버튼을 화면 아래에 붙여, 풀이가 길어도 스크롤 없이 누를 수 있게 */
.next-bar {
  position: sticky; bottom: 0; z-index: 2;
  margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, rgba(255, 248, 236, 0), var(--bg) 35%);
}
#app:has(.next-bar) { padding-bottom: 0; }
/* 줄 세우기 동물: 칸이 좁아도 세로로 길게 눌러서 손가락으로 맞히기 쉽게 */
.animal { aspect-ratio: auto; min-height: 56px; max-height: none; }
.resume-box { background: var(--brand-soft); border-color: var(--brand); }
.lesson-item .go { color: var(--brand); font-weight: 800; white-space: nowrap; }
.solo-intro { background: var(--warn-soft); color: var(--ink); margin: 6px 0 0; }
.fb .prompt { align-items: center; }
.fb .speak { width: 44px; height: 44px; font-size: 20px; }
/* 보기 글자가 한 단어 중간에서 끊기지 않게 ("물고/기" 방지) */
.choice { word-break: keep-all; }
@media (max-width: 380px) { .choices:not(.nums) .choice { font-size: 20px; } }
/* 소리 켬/끔 버튼: 끈 상태는 회색으로 한눈에 */
.voice-toggle { white-space: nowrap; }
.voice-toggle.off { color: var(--muted); border-color: var(--line); background: #f1ece2; }
/* 좁은 폰(320px)에서도 숫자 보기 4개가 한 줄에 */
@media (max-width: 380px) { .choices.nums { grid-template-columns: repeat(auto-fit, minmax(52px, 1fr)); gap: 8px; } }
