✍️ 연플래닝 오리지널 — 「아하! 보이는 직관수학」 자체 제작. 모든 문제·정답 손검산 완료. 답안을 제출해야 해설·정답이 열립니다(먼저 스스로 풀어 보세요).
💬 더 필요한 게 있나요?
난이도 조절(더 쉽게 / 더 어렵게) · 다른 유형 · 특정 개념 집중 · 문항 수 등 무엇이든 적어 주세요. 선생님이 확인합니다. (공개 아님)
`; return s;
}
const P=[
{ tier:'기초', type:'self', kind:'num',
q:'12 ÷ 3 을(를) 계산하세요.',
fig:fbar({bars:[{parts:3,shade:3,label:'12개',color:'#C0503D',unitMark:true}],note:'12개를 3묶음으로 똑같이'}),
answer:4,
hint:'12 개를 3 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'4', fig:null,
steps:['12 ÷ 3 는 ‘12 를 3 묶음으로 똑같이 나누기’.','한 묶음에 4개씩.','확인: 3 × 4 = 12 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'20 ÷ 4 을(를) 계산하세요.',
fig:fbar({bars:[{parts:4,shade:4,label:'20개',color:'#C0503D',unitMark:true}],note:'20개를 4묶음으로 똑같이'}),
answer:5,
hint:'20 개를 4 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'5', fig:null,
steps:['20 ÷ 4 는 ‘20 를 4 묶음으로 똑같이 나누기’.','한 묶음에 5개씩.','확인: 4 × 5 = 20 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'15 ÷ 5 을(를) 계산하세요.',
fig:fbar({bars:[{parts:5,shade:5,label:'15개',color:'#C0503D',unitMark:true}],note:'15개를 5묶음으로 똑같이'}),
answer:3,
hint:'15 개를 5 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'3', fig:null,
steps:['15 ÷ 5 는 ‘15 를 5 묶음으로 똑같이 나누기’.','한 묶음에 3개씩.','확인: 5 × 3 = 15 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'18 ÷ 2 을(를) 계산하세요.',
fig:fbar({bars:[{parts:2,shade:2,label:'18개',color:'#C0503D',unitMark:true}],note:'18개를 2묶음으로 똑같이'}),
answer:9,
hint:'18 개를 2 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'9', fig:null,
steps:['18 ÷ 2 는 ‘18 를 2 묶음으로 똑같이 나누기’.','한 묶음에 9개씩.','확인: 2 × 9 = 18 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'24 ÷ 6 을(를) 계산하세요.',
fig:fbar({bars:[{parts:6,shade:6,label:'24개',color:'#C0503D',unitMark:true}],note:'24개를 6묶음으로 똑같이'}),
answer:4,
hint:'24 개를 6 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'4', fig:null,
steps:['24 ÷ 6 는 ‘24 를 6 묶음으로 똑같이 나누기’.','한 묶음에 4개씩.','확인: 6 × 4 = 24 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'21 ÷ 3 을(를) 계산하세요.',
fig:fbar({bars:[{parts:3,shade:3,label:'21개',color:'#C0503D',unitMark:true}],note:'21개를 3묶음으로 똑같이'}),
answer:7,
hint:'21 개를 3 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'7', fig:null,
steps:['21 ÷ 3 는 ‘21 를 3 묶음으로 똑같이 나누기’.','한 묶음에 7개씩.','확인: 3 × 7 = 21 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'16 ÷ 4 을(를) 계산하세요.',
fig:fbar({bars:[{parts:4,shade:4,label:'16개',color:'#C0503D',unitMark:true}],note:'16개를 4묶음으로 똑같이'}),
answer:4,
hint:'16 개를 4 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'4', fig:null,
steps:['16 ÷ 4 는 ‘16 를 4 묶음으로 똑같이 나누기’.','한 묶음에 4개씩.','확인: 4 × 4 = 16 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'30 ÷ 5 을(를) 계산하세요.',
fig:fbar({bars:[{parts:5,shade:5,label:'30개',color:'#C0503D',unitMark:true}],note:'30개를 5묶음으로 똑같이'}),
answer:6,
hint:'30 개를 5 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'6', fig:null,
steps:['30 ÷ 5 는 ‘30 를 5 묶음으로 똑같이 나누기’.','한 묶음에 6개씩.','확인: 5 × 6 = 30 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'14 ÷ 7 을(를) 계산하세요.',
fig:fbar({bars:[{parts:7,shade:7,label:'14개',color:'#C0503D',unitMark:true}],note:'14개를 7묶음으로 똑같이'}),
answer:2,
hint:'14 개를 7 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'2', fig:null,
steps:['14 ÷ 7 는 ‘14 를 7 묶음으로 똑같이 나누기’.','한 묶음에 2개씩.','확인: 7 × 2 = 14 ✓']}},
{ tier:'기초', type:'self', kind:'num',
q:'27 ÷ 9 을(를) 계산하세요.',
fig:fbar({bars:[{parts:9,shade:9,label:'27개',color:'#C0503D',unitMark:true}],note:'27개를 9묶음으로 똑같이'}),
answer:3,
hint:'27 개를 9 묶음으로 똑같이 나누면 한 묶음에 몇 개일까요?',
sol:{ ans:'3', fig:null,
steps:['27 ÷ 9 는 ‘27 를 9 묶음으로 똑같이 나누기’.','한 묶음에 3개씩.','확인: 9 × 3 = 27 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'12 안에 3 이(가) 몇 번 들어갈까요?',
fig:null,
answer:4,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 12 ÷ 3.',
sol:{ ans:'4', fig:null,
steps:['‘몇 번 들어가나’ = 12 ÷ 3.','4번 들어가요.','확인: 3 를 4 번 더하면 12 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'20 안에 5 이(가) 몇 번 들어갈까요?',
fig:null,
answer:4,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 20 ÷ 5.',
sol:{ ans:'4', fig:null,
steps:['‘몇 번 들어가나’ = 20 ÷ 5.','4번 들어가요.','확인: 5 를 4 번 더하면 20 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'18 안에 6 이(가) 몇 번 들어갈까요?',
fig:null,
answer:3,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 18 ÷ 6.',
sol:{ ans:'3', fig:null,
steps:['‘몇 번 들어가나’ = 18 ÷ 6.','3번 들어가요.','확인: 6 를 3 번 더하면 18 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'24 안에 4 이(가) 몇 번 들어갈까요?',
fig:null,
answer:6,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 24 ÷ 4.',
sol:{ ans:'6', fig:null,
steps:['‘몇 번 들어가나’ = 24 ÷ 4.','6번 들어가요.','확인: 4 를 6 번 더하면 24 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'15 안에 3 이(가) 몇 번 들어갈까요?',
fig:null,
answer:5,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 15 ÷ 3.',
sol:{ ans:'5', fig:null,
steps:['‘몇 번 들어가나’ = 15 ÷ 3.','5번 들어가요.','확인: 3 를 5 번 더하면 15 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'28 안에 7 이(가) 몇 번 들어갈까요?',
fig:null,
answer:4,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 28 ÷ 7.',
sol:{ ans:'4', fig:null,
steps:['‘몇 번 들어가나’ = 28 ÷ 7.','4번 들어가요.','확인: 7 를 4 번 더하면 28 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'36 안에 6 이(가) 몇 번 들어갈까요?',
fig:null,
answer:6,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 36 ÷ 6.',
sol:{ ans:'6', fig:null,
steps:['‘몇 번 들어가나’ = 36 ÷ 6.','6번 들어가요.','확인: 6 를 6 번 더하면 36 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'32 안에 8 이(가) 몇 번 들어갈까요?',
fig:null,
answer:4,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 32 ÷ 8.',
sol:{ ans:'4', fig:null,
steps:['‘몇 번 들어가나’ = 32 ÷ 8.','4번 들어가요.','확인: 8 를 4 번 더하면 32 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'45 안에 9 이(가) 몇 번 들어갈까요?',
fig:null,
answer:5,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 45 ÷ 9.',
sol:{ ans:'5', fig:null,
steps:['‘몇 번 들어가나’ = 45 ÷ 9.','5번 들어가요.','확인: 9 를 5 번 더하면 45 ✓']}},
{ tier:'중급', type:'self', kind:'num',
q:'42 안에 7 이(가) 몇 번 들어갈까요?',
fig:null,
answer:6,
hint:'‘몇 번 들어가나’도 나눗셈이에요: 42 ÷ 7.',
sol:{ ans:'6', fig:null,
steps:['‘몇 번 들어가나’ = 42 ÷ 7.','6번 들어가요.','확인: 7 를 6 번 더하면 42 ✓']}},
{ tier:'상위', type:'self', kind:'num',
q:'사탕 24개를 4명에게 똑같이 나누면 한 명이 몇 개씩 받을까요?',
fig:null,
answer:6,
hint:'똑같이 나누기·몇 개씩 담기 둘 다 나눗셈이에요.',
sol:{ ans:'6개', fig:null,
steps:['식: 24 ÷ 4.','답은 6개.','확인: 4 × 6 = 24 ✓']}},
{ tier:'상위', type:'self', kind:'num',
q:'연필 30자루를 한 명에게 5자루씩 주면 몇 명에게 줄 수 있을까요?',
fig:null,
answer:6,
hint:'똑같이 나누기·몇 개씩 담기 둘 다 나눗셈이에요.',
sol:{ ans:'6명', fig:null,
steps:['식: 30 ÷ 5.','답은 6명.','확인: 5 × 6 = 30 ✓']}},
{ tier:'상위', type:'self', kind:'num',
q:'쿠키 18개를 3접시에 똑같이 담으면 한 접시에 몇 개일까요?',
fig:null,
answer:6,
hint:'똑같이 나누기·몇 개씩 담기 둘 다 나눗셈이에요.',
sol:{ ans:'6개', fig:null,
steps:['식: 18 ÷ 3.','답은 6개.','확인: 3 × 6 = 18 ✓']}},
{ tier:'상위', type:'self', kind:'num',
q:'색종이 35장을 7명이 똑같이 나누면 한 명당 몇 장일까요?',
fig:null,
answer:5,
hint:'똑같이 나누기·몇 개씩 담기 둘 다 나눗셈이에요.',
sol:{ ans:'5장', fig:null,
steps:['식: 35 ÷ 7.','답은 5장.','확인: 7 × 5 = 35 ✓']}},
{ tier:'상위', type:'self', kind:'num',
q:'구슬 40개를 8개씩 봉지에 담으면 몇 봉지일까요?',
fig:null,
answer:5,
hint:'똑같이 나누기·몇 개씩 담기 둘 다 나눗셈이에요.',
sol:{ ans:'5봉지', fig:null,
steps:['식: 40 ÷ 8.','답은 5봉지.','확인: 8 × 5 = 40 ✓']}},
{ tier:'상위', type:'self', kind:'num',
q:'3 × 5 = 15 입니다. 그러면 15 ÷ 3 은 얼마일까요?',
fig:null,
answer:5,
hint:'곱셈과 나눗셈은 거꾸로 관계예요. 곱셈식을 그대로 뒤집으면 돼요.',
sol:{ ans:'5', fig:null,
steps:['곱셈식을 알면 나눗셈은 바로 나와요(거꾸로 관계).','답은 5.','구구단을 알면 나눗셈도 아는 셈이에요!']}},
{ tier:'상위', type:'self', kind:'num',
q:'4 × 6 = 24 입니다. 그러면 24 ÷ 6 은?',
fig:null,
answer:4,
hint:'곱셈과 나눗셈은 거꾸로 관계예요. 곱셈식을 그대로 뒤집으면 돼요.',
sol:{ ans:'4', fig:null,
steps:['곱셈식을 알면 나눗셈은 바로 나와요(거꾸로 관계).','답은 4.','구구단을 알면 나눗셈도 아는 셈이에요!']}},
{ tier:'상위', type:'self', kind:'num',
q:'7 × 8 = 56 입니다. 그러면 56 ÷ 7 은?',
fig:null,
answer:8,
hint:'곱셈과 나눗셈은 거꾸로 관계예요. 곱셈식을 그대로 뒤집으면 돼요.',
sol:{ ans:'8', fig:null,
steps:['곱셈식을 알면 나눗셈은 바로 나와요(거꾸로 관계).','답은 8.','구구단을 알면 나눗셈도 아는 셈이에요!']}},
{ tier:'상위', type:'self', kind:'num',
q:'9 × 3 = 27 입니다. 그러면 27 ÷ 9 는?',
fig:null,
answer:3,
hint:'곱셈과 나눗셈은 거꾸로 관계예요. 곱셈식을 그대로 뒤집으면 돼요.',
sol:{ ans:'3', fig:null,
steps:['곱셈식을 알면 나눗셈은 바로 나와요(거꾸로 관계).','답은 3.','구구단을 알면 나눗셈도 아는 셈이에요!']}},
{ tier:'상위', type:'self', kind:'num',
q:'6 × 6 = 36 입니다. 그러면 36 ÷ 6 은?',
fig:null,
answer:6,
hint:'곱셈과 나눗셈은 거꾸로 관계예요. 곱셈식을 그대로 뒤집으면 돼요.',
sol:{ ans:'6', fig:null,
steps:['곱셈식을 알면 나눗셈은 바로 나와요(거꾸로 관계).','답은 6.','구구단을 알면 나눗셈도 아는 셈이에요!']}},
{ tier:'최상위', type:'self', kind:'num',
q:'20 ÷ 4 = 5 입니다. 그러면 20 ÷ 5 는 얼마일까요?',
fig:null,
answer:4,
hint:'20을 4묶음으로 나누면 5개씩, 5묶음으로 나누면?',
sol:{ ans:'4', fig:null,
steps:['20 ÷ 4 = 5 → 20 = 4 × 5.','같은 식에서 20 ÷ 5 = 4.','묶음 수와 개수를 바꿔도 전체는 같아요!']}},
{ tier:'최상위', type:'self', kind:'num',
q:'□ ÷ 6 = 4 일 때, □ 에 알맞은 수는?',
fig:null,
answer:24,
hint:'나눗셈을 거꾸로! □ = 4 × 6.',
sol:{ ans:'24', fig:null,
steps:['□ ÷ 6 = 4 → □ = 4 × 6.','= 24.','확인: 24 ÷ 6 = 4 ✓']}},
{ tier:'최상위', type:'self', kind:'num',
q:'24 ÷ □ = 3 일 때, □ 에 알맞은 수는?',
fig:null,
answer:8,
hint:'나누는 수가 빈칸! □ = 24 ÷ 3.',
sol:{ ans:'8', fig:null,
steps:['24 ÷ □ = 3 → □ = 24 ÷ 3.','= 8.','확인: 24 ÷ 8 = 3 ✓']}},
{ tier:'최상위', type:'self', kind:'num',
q:'사탕 26개를 4명에게 똑같이 나누면 한 명당 몇 개이고 몇 개가 남을까요? (남는 개수를 답하세요)',
fig:null,
answer:2,
hint:'26 ÷ 4 는 딱 나눠지지 않아요. 몇 개씩 주고 몇 개가 남을까요?',
sol:{ ans:'2개 남음 (한 명당 6개)', fig:null,
steps:['4 × 6 = 24 → 한 명당 6개씩 주면 24개 사용.','26 − 24 = 2개가 남아요.','딱 나눠지지 않을 때 남는 수를 나머지라고 해요.']}},
{ tier:'최상위', type:'self', kind:'num',
q:'0 ÷ 5 는 얼마일까요?',
fig:null,
answer:0,
hint:'사탕 0개를 5명에게 나누면 한 명당 몇 개?',
sol:{ ans:'0', fig:null,
steps:['나눌 것이 하나도 없으니 한 명당 0개.','0 ÷ 5 = 0.','⚠️ 반대로 5 ÷ 0 은 답이 없어요 — 0묶음으로는 나눌 수 없으니까요!']}},
{ tier:'최상위', type:'self', kind:'num',
q:'35 ÷ 6 의 몫과 나머지 중, 나머지는 얼마일까요?',
fig:null,
answer:5,
hint:'6 × 5 = 30 이에요. 35에서 30을 빼면?',
sol:{ ans:'5 (몫은 5)', fig:null,
steps:['6 × 5 = 30 → 몫은 5.','35 − 30 = 5 → 나머지는 5.','⚠️ 나머지는 나누는 수(6)보다 항상 작아야 해요!']}},
{ tier:'최상위', type:'self', kind:'num',
q:'어떤 수를 7로 나누었더니 몫이 4, 나머지가 3 이었습니다. 어떤 수는?',
fig:null,
answer:31,
hint:'거꾸로! 어떤 수 = 7 × 4 + 3 이에요.',
sol:{ ans:'31', fig:null,
steps:['어떤 수 = 나누는 수 × 몫 + 나머지.','= 7 × 4 + 3 = 28 + 3 = 31.','확인: 31 ÷ 7 = 몫 4, 나머지 3 ✓']}},
{ tier:'최상위', type:'self', kind:'num',
q:'사탕 50개를 8명에게 똑같이 나눠 주려면, 몇 개가 더 있어야 남는 것 없이 나눌 수 있을까요?',
fig:null,
answer:6,
hint:'50 ÷ 8 은 몫 6, 나머지 2. 8명에게 7개씩 주려면 몇 개가 필요할까요?',
sol:{ ans:'6개', fig:null,
steps:['50 ÷ 8 = 몫 6, 나머지 2 (한 명당 6개, 2개 남음).','한 명당 7개씩 주려면 8 × 7 = 56개 필요.','56 − 50 = 6개가 더 있어야 해요.']}},
{ tier:'최상위', type:'self', kind:'choice',
q:'12 ÷ 4 와 12 ÷ 3 중 어느 것이 더 클까요?',
fig:null,
choices:['12 ÷ 4 가 크다','12 ÷ 3 이 크다','두 값은 같다','알 수 없다'], answer:'12 ÷ 3 이 크다',
hint:'같은 12를 더 적은 묶음으로 나누면 한 묶음이 어떻게 될까요?',
sol:{ ans:'12 ÷ 3 이 크다 (4 > 3)', fig:null,
steps:['12 ÷ 4 = 3, 12 ÷ 3 = 4.','같은 수를 더 적은 수로 나눌수록 몫은 커져요.','12개를 3묶음으로 나누면 한 묶음이 더 많아지죠!']}},
{ tier:'최상위', type:'self', kind:'num',
q:'연필 45자루를 한 명에게 6자루씩 나눠 주면 몇 명에게 줄 수 있고 몇 자루가 남을까요? (남는 자루 수)',
fig:null,
answer:3,
hint:'45 ÷ 6 을 계산해 몫과 나머지를 구하세요.',
sol:{ ans:'3자루 남음 (7명에게)', fig:null,
steps:['6 × 7 = 42 → 7명에게 줄 수 있어요.','45 − 42 = 3자루가 남아요.','나머지 3은 나누는 수 6보다 작죠 ✓']}},
];
const TIERS=['기초','중급','상위','최상위'];
const TIER_DESC={기초:'영상만 봐도 바로 풀려요 — 배운 걸 그대로 적용.',중급:'한 번 더 생각 — 거꾸로·변형. 영상 안에 답이 있어요.',상위:'아래 학년 개념(선수 단원)을 함께 써야 풀려요.',최상위:'여러 개념·역발상·함정까지. 최고 난도.'};
let curTier='기초';
function tierProblems(t){ return P.map((p,i)=>({p,i})).filter(o=>o.p.tier===t); }
function renderTabs(){
const tb=document.getElementById('tabs'); tb.innerHTML='';
TIERS.forEach(t=>{ const n=tierProblems(t).length;
const b=document.createElement('button'); b.className='tab'+(t===curTier?' on':''); b.textContent=`${t} (${n})`;
b.onclick=()=>{curTier=t; renderTabs(); renderList();}; tb.appendChild(b); });
document.getElementById('tierNote').textContent=TIER_DESC[curTier];
}
function esc(x){return String(x).replace(/&/g,'&').replace(//g,'>');}
function renderList(){
const L=document.getElementById('list'); L.innerHTML='';
const items=tierProblems(curTier);
if(!items.length){ L.innerHTML='이 난도는 곧 채워집니다 — 파일럿은 기초·중급·상위 예시.
'; return; }
items.forEach(({p,i},k)=>{
const badge = p.type==='video' ? '🎬 영상해설' : '✍ 텍스트해설';
const pre = p.prereq ? `🔗 ${p.prereq.name}` : '';
const c=document.createElement('div'); c.className='card'; c.id='card'+i;
let ansUI = p.kind==='choice'
? ``+p.choices.map(o=>``).join('')+`
`
: `← 내 답을 쓰고 제출
`;
c.innerHTML=`
${curTier} · 문제 ${k+1} ${badge} ${pre}
${mfx(p.q)}
${p.fig?`${p.fig}
`:''}
${ansUI}
🔒 답을 제출해야 해설·정답이 열려요.
💡 힌트 — ${p.hint}
`;
L.appendChild(c);
});
}
const picked={};
// 분수 답 입력 지원: '3/4', '1 1/2', '0.75' 모두 인식
function parseAns(v){ v=String(v).trim().replace(/\s+/g,' ');
let m=/^(-?\d+)\s+(\d+)\/(\d+)$/.exec(v);
if(m){ const s=(+m[1])<0?-1:1; return s*(Math.abs(+m[1])+(+m[2])/(+m[3])); }
m=/^(-?\d+)\/(-?\d+)$/.exec(v); if(m) return (+m[1])/(+m[2]);
return parseFloat(v.replace(/[^0-9.\-]/g,''));
}
function pick(i,val,el){ picked[i]=val; document.querySelectorAll('#ch'+i+' button').forEach(b=>b.classList.remove('sel')); el.classList.add('sel'); }
function mfx(t){ if(!window.mathToHTML) return t;
// HTML 태그( 등)는 그대로 두고, 태그 사이 텍스트만 교과서식 수식으로 변환
return String(t).split(/(<[^>]+>)/).map(s=> s.charAt(0)==='<' ? s : mathToHTML(s)).join(''); }
function submit(i){
const p=P[i]; let mine;
if(p.kind==='choice'){ mine=picked[i]; if(mine==null){ alert('보기 중 하나를 먼저 고르세요.'); return; } }
else { const v=document.getElementById('in'+i).value.trim(); if(v===''){ alert('답을 먼저 입력하세요.'); return; } mine=parseAns(v); if(isNaN(mine)){ alert('숫자나 분수(예: 3/4)로 입력해 주세요.'); return; } }
const correct = p.kind==='choice' ? (mine===p.answer) : (Math.abs(mine-p.answer)<1e-6);
const vd=document.getElementById('vd'+i); vd.classList.remove('hide');
document.getElementById('lock'+i).classList.add('hide');
document.getElementById('show'+i).classList.remove('hide'); // 제출했으니 해설 열람 가능
if(correct){ vd.className='verdict ok'; vd.innerHTML='✅ 정답이에요! 잘했어요.'; reveal(i); }
else{ vd.className='verdict no'; vd.innerHTML='❌ 아쉬워요. 힌트를 보고 다시 풀어 볼까요? (해설도 열렸어요)';
document.getElementById('hint'+i).classList.remove('hide'); }
}
function reveal(i){
const p=P[i], sol=document.getElementById('sol'+i); sol.classList.remove('hide');
let steps=p.sol.steps.map(s=>`• ${mfx(s)}
`).join('');
let pre=p.prereq?``:'';
let vsol = p.type==='video' ? `🎬 이 문제 영상 해설 보기 (짧게)` : '';
sol.innerHTML=`📝 해설
${pre}${p.sol.fig?`${p.sol.fig}
`:''}${steps}정답: ${mfx(p.sol.ans)}
${vsol}`
+`🙋 이 해설이 어렵거나 더 자세히 알고 싶으면 말씀해주세요 — 상세 해설지를 새로 만들어 보내드릴게요.
`
+``;
}
/* ───────── "이 해설도 어려워요" 체크 → 하단 요청 코너로 모으기 ───────── */
const hardSet=new Set();
function toggleHard(i,on){ on?hardSet.add(i):hardSet.delete(i); syncHard(); }
function syncHard(){
const box=document.getElementById('hardList'); if(!box) return;
if(!hardSet.size){ box.style.display='none'; box.textContent=''; return; }
const names=[...hardSet].sort((a,b)=>a-b).map(i=>{
const list=tierProblems(P[i].tier); const k=list.findIndex(o=>o.i===i);
return `${P[i].tier} ${k+1}번`;
});
box.style.display='block';
box.innerHTML='🙋 해설이 어렵다고 표시한 문제: '+names.join(', ')+' — 보내기를 누르면 함께 전달돼요.';
}
/* ───────── 추가요청 보내기 (선생님 확인용 · 이 기기에 저장) ───────── */
function reqKey(){ return 'pbreq:'+location.pathname; }
function loadReq(){ try{ return JSON.parse(localStorage.getItem(reqKey())||'[]'); }catch(e){ return []; } }
function nowStr(){ const d=new Date(), p=n=>(n<10?'0':'')+n; return d.getFullYear()+'-'+p(d.getMonth()+1)+'-'+p(d.getDate())+' '+p(d.getHours())+':'+p(d.getMinutes()); }
function sendReq(){
const ta=document.getElementById('reqText'), note=document.getElementById('reqNote');
const text=(ta.value||'').trim();
const hard=[...hardSet].sort((a,b)=>a-b).map(i=>{ const list=tierProblems(P[i].tier); const k=list.findIndex(o=>o.i===i); return `${P[i].tier} ${k+1}번`; });
if(!text && !hard.length){ note.style.color='#C0503D'; note.textContent='요청 내용을 적거나, 어려운 해설을 체크해 주세요.'; return; }
const arr=loadReq(); arr.push({ date:nowStr(), text, hard, unit:'초3 나눗셈의 뜻' });
try{ localStorage.setItem(reqKey(), JSON.stringify(arr)); }catch(e){}
ta.value=''; hardSet.clear(); syncHard();
document.querySelectorAll('.retag input').forEach(c=>c.checked=false);
note.style.color='#2c8a55'; note.textContent='✅ 보냈어요! 선생님이 확인합니다. (이 기기에 저장됨)';
renderReq();
}
function renderReq(){
const box=document.getElementById('reqMine'); if(!box) return;
const arr=loadReq(); box.innerHTML='';
if(!arr.length) return;
box.innerHTML='📒 내가 보낸 요청 ('+arr.length+')
'
+ arr.slice().reverse().map(it=>`${it.hard&&it.hard.length?'🙋 어려운 해설: '+it.hard.join(', ')+'
':''}${(it.text||'').replace(/(내용 없음)'}
${it.date}
`).join('');
}
/* ───────── 인쇄 2모드 — 절약 인쇄(2단·컬러 유지) ───────── */
function ecoPrint(){
document.body.classList.add('eco-print');
window.addEventListener('afterprint', function h(){ document.body.classList.remove('eco-print'); window.removeEventListener('afterprint',h); });
window.print();
}
/* ───────── DrawBoard (문항별 손으로 풀기 — 화면 가득 전체화면) ───────── */
const canvas=document.getElementById('drawCanvas'), ctx=canvas.getContext('2d');
const drawOverlay=document.getElementById('drawOverlay'), drawWrap=document.getElementById('drawCanvasWrap');
let drawOn=false, tool='pen', dsize=6, dcolor='#1f2a2a', drawing=false, last=null, currentDrawQ=null;
const drawings={}; // i -> dataURL (문항별 손풀이)
const photos={}; // i -> dataURL (문항별 사진)
function sizeCanvas(restore){
const rect=drawWrap.getBoundingClientRect(), dpr=window.devicePixelRatio||1;
canvas.width=Math.round(rect.width*dpr); canvas.height=Math.round(rect.height*dpr);
canvas.style.width=rect.width+'px'; canvas.style.height=rect.height+'px';
ctx.setTransform(dpr,0,0,dpr,0,0); ctx.clearRect(0,0,rect.width,rect.height);
if(restore){ const img=new Image(); img.onload=()=>ctx.drawImage(img,0,0,rect.width,rect.height); img.src=restore; }
}
window.addEventListener('resize',()=>{ if(drawOn) sizeCanvas(drawings[currentDrawQ]); });
window.openDraw=function(i){
drawOn=true; currentDrawQ=i;
const plain=String(P[i].q).replace(/<[^>]*>/g,'');
document.getElementById('drawQref').textContent=P[i].tier+' · '+plain.slice(0,30)+'…';
drawOverlay.classList.add('on');
sizeCanvas(drawings[i]);
const el2=document.documentElement, req=el2.requestFullscreen||el2.webkitRequestFullscreen||el2.msRequestFullscreen;
if(req){ try{ req.call(el2).catch(()=>{}); }catch(e){} }
};
window.closeDraw=function(){
if(currentDrawQ!=null){
const hasInk=(()=>{ const d=ctx.getImageData(0,0,canvas.width,canvas.height).data; for(let k=3;k0) return true; return false; })();
if(hasInk){ drawings[currentDrawQ]=canvas.toDataURL('image/png'); renderThumbs(currentDrawQ); }
}
drawOn=false; currentDrawQ=null; drawOverlay.classList.remove('on');
if(document.fullscreenElement||document.webkitFullscreenElement){
(document.exitFullscreen||document.webkitExitFullscreen).call(document).catch(()=>{});
}
};
window.submitFromDraw=function(){ const i=currentDrawQ; closeDraw(); if(i!=null) submit(i); };
document.addEventListener('fullscreenchange',()=>{ if(!document.fullscreenElement && drawOn) closeDraw(); });
window.setTool=t=>{ tool=t; document.getElementById('toolPen').classList.toggle('on',t==='pen'); document.getElementById('toolErase').classList.toggle('on',t==='erase'); };
window.setSize=s=>{ dsize=s; ['szS','szM','szL'].forEach(id=>document.getElementById(id).classList.remove('on')); document.getElementById(s===3?'szS':s===12?'szL':'szM').classList.add('on'); };
window.setColor=c=>{ dcolor=c; };
window.clearDraw=()=>{ if(confirm('그린 것을 모두 지울까요?')) ctx.clearRect(0,0,canvas.width,canvas.height); };
function dpos(e){ const r=canvas.getBoundingClientRect(), t=e.touches?e.touches[0]:e; return [t.clientX-r.left, t.clientY-r.top]; }
function dstart(e){ if(!drawOn) return; e.preventDefault(); drawing=true; last=dpos(e); }
function dmove(e){ if(!drawOn||!drawing) return; e.preventDefault(); const p=dpos(e);
ctx.lineCap='round'; ctx.lineJoin='round';
if(tool==='erase'){ ctx.globalCompositeOperation='destination-out'; ctx.lineWidth=dsize*4; }
else{ ctx.globalCompositeOperation='source-over'; ctx.strokeStyle=dcolor; ctx.lineWidth=dsize; }
ctx.beginPath(); ctx.moveTo(last[0],last[1]); ctx.lineTo(p[0],p[1]); ctx.stroke(); last=p;
}
function dend(){ drawing=false; }
canvas.addEventListener('mousedown',dstart); canvas.addEventListener('mousemove',dmove); window.addEventListener('mouseup',dend);
canvas.addEventListener('touchstart',dstart,{passive:false}); canvas.addEventListener('touchmove',dmove,{passive:false}); canvas.addEventListener('touchend',dend,{passive:false});
/* ───────── 사진으로 올리기 (문항별) ───────── */
window.onPhoto=function(i,inputEl){
const file=inputEl.files&&inputEl.files[0]; if(!file) return;
const reader=new FileReader();
reader.onload=ev=>{ const img=new Image();
img.onload=()=>{ const maxW=900, sc=Math.min(1,maxW/img.width), w=Math.round(img.width*sc), h=Math.round(img.height*sc);
const cv=document.createElement('canvas'); cv.width=w; cv.height=h; cv.getContext('2d').drawImage(img,0,0,w,h);
photos[i]=cv.toDataURL('image/jpeg',0.6); renderThumbs(i); };
img.src=ev.target.result; };
reader.readAsDataURL(file); inputEl.value='';
};
window.removePhoto=function(i){ delete photos[i]; renderThumbs(i); };
window.removeDrawing=function(i){ delete drawings[i]; renderThumbs(i); };
function renderThumbs(i){
const box=document.getElementById('thumbs'+i); if(!box) return;
let h='';
if(drawings[i]) h+=`
`;
if(photos[i]) h+=`
`;
box.innerHTML=h;
const db=document.getElementById('drawBtn'+i), pb=document.getElementById('photoBtn'+i);
if(db) db.classList.toggle('has', !!drawings[i]);
if(pb) pb.classList.toggle('has', !!photos[i]);
}
// 탭을 바꿔 다시 그려도 그 문항의 손풀이·사진 썸네일이 되살아나게
const _renderList=renderList;
renderList=function(){ _renderList(); tierProblems(curTier).forEach(({p,i})=>renderThumbs(i)); };
renderTabs(); renderList(); renderReq();