/* 한자 도감 — 디자인 토큰(밝은 테마 고정), 세이프 에어리어, 390×844 높이 예산(명세 6.1, 20.2절) */
:root {
  color-scheme: light;
  --bg: #fff8ec;
  --surface: #ffffff;
  --ink: #2b2118;
  --ink-2: #6b5d50;
  --muted: #a39686;
  --line: #e6dccd;
  --primary: #2f7d5b;
  --primary-ink: #ffffff;
  --primary-soft: #e3f3ea;
  --good: #2f9e62;
  --near: #e8892b;
  --near-soft: #fff1e0;
  --warn: #b35c00;
  --gold: #d4a017;
  --danger: #a33a2c;
  --radius: 14px;
  --gutter: 16px;
  --key-h: 50px;
  --field-h: 52px;
  --hanja: clamp(72px, 14dvh, 120px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --font-hanja: "Apple SD Gothic Neo", "Noto Serif KR", "Noto Sans CJK KR", "Malgun Gothic", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; }
/* 아이 화면 전체(문제 한자 포함): 길게 눌러도 선택·돋보기·공유 메뉴가 뜨지 않게(E0-3). 부모 입력 칸만 예외 */
body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  min-height: 100%;
  min-height: 100dvh;
  overscroll-behavior: none;
  touch-action: manipulation;
}
.app {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hidden-file { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }
.noscript { padding: 24px; }

/* ---- 화면 틀 ---- */
.screen {
  padding: calc(var(--safe-top) + 12px) var(--gutter) max(16px, var(--safe-bottom));
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.screen.center { justify-content: center; text-align: center; align-items: stretch; }
.with-banner .screen { padding-top: 12px; }
.tab-banner {
  flex: 0 0 auto;
  padding: calc(var(--safe-top) + 6px) var(--gutter) 6px;
  background: var(--near-soft); color: var(--warn); font-size: 14px; text-align: center;
  border-bottom: 1px solid var(--line);
}
h1 { font-size: 24px; margin: 4px 0; }
h2 { font-size: 18px; margin: 4px 0; }
h3 { font-size: 16px; margin: 8px 0 4px; color: var(--ink-2); }
p { margin: 4px 0; }
.lead { font-size: 19px; }
.small { font-size: 14px; color: var(--ink-2); }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.center { text-align: center; }
.note { background: var(--primary-soft); border-radius: var(--radius); padding: 8px 12px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.topbar h1 { font-size: 20px; flex: 1; text-align: right; }
.row { display: flex; align-items: center; gap: 8px; }
.row > .btn, .row > .chip { flex: 0 0 auto; white-space: nowrap; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.block { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }

/* ---- 버튼 ---- */
.btn {
  min-height: 44px; min-width: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 17px; cursor: pointer;
}
.btn:disabled { opacity: 0.45; }
/* 화면을 연 직후 잠깐 잠근 버튼(두 번 누르기로 넘어가지 않게): 흐리게 보이다 켜진다 */
.btn.locked { opacity: 0.45; transition: opacity 0.25s ease-out; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.wide { width: 100%; }
.btn.big { min-height: 56px; font-size: 19px; }
.btn.huge { width: 100%; min-height: 96px; font-size: 28px; border-radius: 20px; }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 15px; }
.link { background: none; border: none; color: var(--primary); text-decoration: underline; min-height: 44px; padding: 8px 4px; font-size: 16px; cursor: pointer; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 999px; min-width: 44px; min-height: 44px; font-size: 20px; cursor: pointer; vertical-align: middle; }
.icon-btn.big { min-width: 56px; min-height: 56px; font-size: 26px; }
.chip { min-height: 44px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; cursor: pointer; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); font-weight: 600; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.beta { background: var(--near-soft); color: var(--warn); }
.badge.off { background: #eee; color: var(--muted); }
.links { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }
.ext-link { color: var(--primary); min-height: 44px; display: inline-flex; align-items: center; }

/* ---- 입력(부모 칸만 OS 키보드 허용, 16px 이상) ---- */
.text-input { font-size: 17px; min-height: 48px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); width: 100%; user-select: text; -webkit-user-select: text; }
.field-row { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.promise { text-align: left; padding-left: 20px; margin: 8px 0; }
.promise li { margin: 4px 0; }
.msg { min-height: 1.4em; color: var(--warn); }

/* ---- 한자 ---- */
.hanja { font-family: var(--font-hanja); line-height: 1; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.q-hanja { font-size: var(--hanja); display: block; text-align: center; }
.q-word { font-family: var(--font-hanja); font-size: clamp(48px, 9dvh, 80px); text-align: center; line-height: 1.1; letter-spacing: 0.04em; }
.small-q.q-hanja { font-size: clamp(56px, 10dvh, 88px); }
.small-q.q-word { font-size: clamp(40px, 7dvh, 64px); }
.big-word { font-size: 40px; text-align: center; }

/* ---- 판 화면(스크롤 없음) ---- */
.screen.pan { gap: 0; padding-bottom: max(16px, var(--safe-bottom)); }
.screen.pan.view-q, .screen.pan.view-copy { height: 100vh; height: 100dvh; overflow: hidden; }
/* 배치 진단 '아이 혼자 패드로'(연습 2문항과 문항)도 판 화면처럼 높이를 고정하고 패드를 줄인다 */
.screen.placement.view-q { height: 100vh; height: 100dvh; overflow: hidden; gap: 0; }
.placement.view-q .topbar { flex: 0 0 auto; }
.placement.view-q .big-word { font-size: 34px; line-height: 1.2; }
.placement.view-q .q-hanja { font-size: clamp(52px, 11dvh, 110px); }
.placement .practice-row { display: flex; align-items: center; justify-content: center; gap: 16px; }
.placement .practice-line { font-size: 26px; margin: 0; }
.placement .topbar .btn { flex: 0 0 auto; white-space: nowrap; }
.placement .level-dots { flex: 1 1 auto; min-width: 0; gap: 4px 8px; font-size: 13px; }
.pan-top { display: flex; align-items: center; gap: 10px; height: 44px; flex: 0 0 auto; }
.close { flex: 0 0 auto; font-size: 18px; }
.progress { flex: 1; display: flex; gap: 4px; height: 12px; }
.progress .cell { flex: 1; border-radius: 6px; background: var(--line); }
.progress .cell.on { background: var(--primary); }
.q-head { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 8px; }
.prompt { font-size: 17px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.fields-wrap { flex: 0 0 auto; margin-top: 8px; }
.answer-fields { display: flex; flex-direction: column; gap: 8px; }
.answer-field {
  height: var(--field-h); border: 2px solid var(--line); border-radius: 12px; background: var(--surface);
  display: flex; align-items: center; gap: 10px; padding: 0 12px; cursor: pointer; overflow: hidden;
}
.answer-field.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field-label { font-size: 15px; color: var(--ink-2); flex: 0 0 auto; min-width: 2.2em; }
.field-text { font-size: 28px; flex: 1; white-space: nowrap; overflow: hidden; display: flex; align-items: center; }
.field-text .composing { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.field-text .jamo { color: var(--near); }
.caret { width: 2px; height: 28px; background: var(--primary); margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.ghost { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 700; color: var(--warn); background: var(--near-soft); border: 1px solid var(--near); border-radius: 10px; padding: 0 10px; letter-spacing: 0.1em; line-height: 1.3; }
.ghost-tag { font-size: 13px; font-weight: 600; letter-spacing: 0; }
.pad-msg { min-height: 18px; font-size: 14px; line-height: 18px; color: var(--warn); text-align: center; margin-top: 2px; }
.pad { flex: 0 0 auto; display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.pad-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.key {
  height: var(--key-h); border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-size: 22px; padding: 0; box-shadow: 0 1px 0 var(--line);
}
/* 판 화면: 패드가 남은 높이 안에서 줄어든다(키 높이 최대 50px). 화면이 짧아도 맨 아랫줄이 잘리지 않는다 */
.view-q .pad, .view-copy .pad { flex: 1 1 auto; min-height: 0; max-height: calc(6 * var(--key-h) + 25px); }
.view-q .pad-row, .view-copy .pad-row { flex: 1 1 0; min-height: 0; }
.view-q .key, .view-copy .key { height: 100%; min-height: 0; }
.view-q .q-head, .view-copy .q-head { margin-top: 4px; }
.key.pressed { background: var(--primary-soft); border-color: var(--primary); transform: translateY(1px); }
.key-del { grid-column: span 2; font-size: 16px; }
.pad-bottom { flex: 0 0 auto; display: flex; align-items: stretch; gap: 8px; margin-top: 8px; height: 52px; }
.pad-bottom .spacer { width: 0; }
.pad-bottom .dontknow { min-width: 64px; flex: 0 0 auto; font-size: 15px; }
.pad-bottom .hint { flex: 0 0 auto; font-size: 15px; padding: 6px 10px; }
.pad-bottom .done { flex: 1; font-size: 18px; }
.adult-zone { flex: 1; display: flex; align-items: center; }
.reveal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; margin: 8px 0; }
.reveal-line { font-size: 26px; font-weight: 600; text-align: center; }
.judge-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.judge-row.three { grid-template-columns: 1fr 1fr 1.3fr; }
.judge-row .btn { min-height: 60px; }
.judge-col { display: flex; flex-direction: column; gap: 10px; }
.judge-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.judge-line .jl { min-width: 3em; font-weight: 600; }

/* 피드백 */
.fb { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.fb-answers { display: flex; gap: 8px; width: 100%; }
.fb-field { flex: 1; min-height: 52px; border: 3px solid var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 24px; background: var(--surface); }
.fb-field.good { border-color: var(--good); }
.fb-field.near, .fb-field.miss { border-color: var(--near); background: var(--near-soft); }
.fb-text { font-size: 20px; line-height: 1.5; }
.fb-text.ok { color: var(--ink); }
.fb-actions { flex: 0 0 auto; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.copy-target { font-size: 56px; font-weight: 700; color: var(--primary); }

/* 소개 카드 */
.intro { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.intro-tag { font-size: 15px; color: var(--primary); background: var(--primary-soft); padding: 2px 12px; border-radius: 999px; }
.intro-hanja { font-size: clamp(110px, 22dvh, 180px); }
.intro-hunum { font-size: 34px; font-weight: 700; }
.intro-word { font-size: 22px; color: var(--ink-2); }

/* 결과: 카드가 많아도 [다음 판]/[홈으로]가 첫 화면에 보이게, 목록만 안에서 스크롤한다 */
.screen.pan.view-result { height: 100vh; height: 100dvh; overflow: hidden; gap: 8px; }
.view-result .result-cards { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view-result .fb-actions { margin-top: auto; }
.result-cards { display: flex; flex-direction: column; gap: 10px; }
.result-card { display: grid; grid-template-columns: 64px 36px 1fr; grid-template-rows: auto auto; align-items: center; gap: 2px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.result-card .rc-hanja { font-size: 48px; grid-row: span 2; }
.result-card .rc-icon { font-size: 28px; grid-row: span 2; }
.result-card .rc-name { font-weight: 700; }
.result-card .rc-text { font-size: 14px; color: var(--ink-2); grid-column: 3; }
.result-card.adult { border-color: var(--primary); }
.result-card.legend { border-color: var(--gold); box-shadow: 0 0 0 2px #f5e6b0; }
.wake { animation: wake 0.6s ease-out; }
@keyframes wake { 0% { transform: scale(0.85); opacity: 0.4; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
.stamp-anim { text-align: center; font-size: 22px; animation: stamp-pop 1.1s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes stamp-pop { 0% { transform: scale(2.2) rotate(-12deg); opacity: 0; } 45% { transform: scale(0.9) rotate(4deg); opacity: 1; } 70% { transform: scale(1.08) rotate(-2deg); } 100% { transform: scale(1) rotate(0); } }

/* ---- 홈 ---- */
.home .greet { font-size: 26px; margin-top: 12px; }
.mode-line { color: var(--ink-2); }
.home-main { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.home-msg { font-size: 20px; text-align: center; padding: 16px 0; }
.today-dots { display: flex; justify-content: center; gap: 8px; }
.today-dots .dot { width: 14px; height: 14px; }
.stamp-box h2 { font-size: 16px; color: var(--ink-2); text-align: center; }
.stamps { display: flex; justify-content: center; gap: 12px; align-items: center; }
.stamp { width: 56px; height: 56px; border-radius: 50%; border: 2px dashed var(--line); display: flex; align-items: center; justify-content: center; font-size: 28px; }
.stamp.on { border: 2px solid var(--primary); background: var(--primary-soft); }
.stamp-extra { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.stamps.small .stamp { width: 36px; height: 36px; font-size: 18px; }
.stamp.rest { border: 2px solid var(--gold); background: #fff6d6; }
.last-week { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.home-foot { margin-top: auto; display: flex; gap: 10px; align-items: center; }
.home-foot .btn.wide { flex: 1; }
.adult-btn { flex: 0 0 auto; color: var(--ink-2); }

/* 점 */
.dots { display: inline-flex; gap: 4px; vertical-align: middle; margin-left: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--primary); display: inline-block; }
.dot.on { background: var(--primary); }
.dots.mini .dot { width: 7px; height: 7px; border-width: 1.5px; }

/* ---- 도감 ---- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.tab { min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; cursor: pointer; }
.tab.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.dex-legend { margin: 4px 2px 8px; color: var(--muted, #666); line-height: 1.4; }
.dex-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.dex-card { position: relative; aspect-ratio: 1 / 1.15; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; cursor: pointer; }
.dex-hanja { font-size: 30px; }
.dex-icon { font-size: 18px; line-height: 1; min-height: 18px; }
.dex-card.unseen { border-style: dashed; }
.dex-card.unseen .dex-hanja { color: var(--muted); }
.dex-card.dormant { opacity: 0.75; }
.dex-card.adult { border-color: var(--primary); background: var(--primary-soft); }
.dex-card.legend { border-color: var(--gold); background: #fff6d6; }
.pencil { position: absolute; top: 2px; right: 3px; font-size: 11px; }
.detail-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.detail-hanja { font-size: clamp(110px, 22dvh, 170px); }
.detail-hunum { font-size: 30px; font-weight: 700; }
.detail-due { font-size: 18px; }

/* ---- 배치 ---- */
.level-dots { display: flex; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--ink-2); }
.level-dots .ld.pass { color: var(--primary); font-weight: 600; }
.level-dots .ld.now { color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.celebrate { font-size: 48px; text-align: center; margin-top: 24px; }
.parent-card .big-line { font-size: 22px; font-weight: 700; }
.scope { font-size: 15px; background: var(--bg); border-radius: 10px; padding: 8px; }
.forecast .num { font-weight: 700; }
.level-choices, .exam-choices { display: flex; flex-wrap: wrap; gap: 6px; }
details.more summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--primary); }

/* ---- 부모 ---- */
.parent .block.head { text-align: center; }
.head-label { font-size: 15px; color: var(--ink-2); }
.head-num { font-size: 34px; font-weight: 800; }
.head-level { font-size: 16px; font-weight: 400; color: var(--ink-2); margin-left: 6px; }
.exam-line { font-weight: 600; }
.apply-help { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.alert { background: var(--near-soft); border-radius: 10px; padding: 8px 10px; }
.offapp { list-style: none; padding: 0; margin: 4px 0; }
.offapp li { min-height: 44px; display: flex; align-items: center; }
.offapp input { width: 22px; height: 22px; }
.backup-text { width: 100%; font-size: 12px; font-family: ui-monospace, Menlo, monospace; user-select: text; -webkit-user-select: text; }
.pre { font-size: 12px; white-space: pre-wrap; background: var(--bg); padding: 8px; border-radius: 8px; }
.level-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.level-list li { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.level-list li.cur { border-color: var(--primary); background: var(--primary-soft); }
.doc .block p { line-height: 1.6; }
.block.kid { background: var(--primary-soft); }

/* ---- PIN ---- */
.numpad-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pin-title { font-size: 19px; font-weight: 600; }
.pin-slots { display: flex; gap: 14px; }
.pin-slot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink-2); }
.pin-slot.on { background: var(--ink); }
.pin-msg { min-height: 1.4em; color: var(--warn); }
.numpad { display: grid; grid-template-columns: repeat(3, 76px); gap: 10px; }
.numkey { height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 26px; cursor: pointer; }
.numkey.del { font-size: 16px; }
.numkey.blank { visibility: hidden; }

/* ---- 모달·알림 ---- */
.modal-layer { position: fixed; inset: 0; background: rgba(43, 33, 24, 0.35); display: flex; align-items: center; justify-content: center; padding: var(--gutter); z-index: 10; }
.modal { background: var(--surface); border-radius: 18px; padding: 18px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.modal-text { font-size: 18px; }
.modal-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-buttons .btn { flex: 1 1 40%; min-height: 52px; }
/* 알림 줄은 누름을 가로채지 않는다(pointer-events: none). 패드·주 버튼이 있는 아래쪽 대신 화면 위에 띄운다 */
.toast { position: fixed; left: 50%; top: calc(var(--safe-top) + 8px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 20; font-size: 16px; max-width: 90vw; text-align: center; pointer-events: none; opacity: 0.94; }

/* ---- 세로 고정 안내 ---- */
.rotate-hint { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .rotate-hint { display: flex; position: fixed; inset: 0; background: var(--bg); align-items: center; justify-content: center; font-size: 22px; z-index: 50; }
}

/* ---- 짧은 화면(SE) ---- */
@media (max-height: 760px) {
  :root { --hanja: clamp(56px, 10dvh, 96px); }
}
@media (max-height: 700px) {
  :root { --key-h: 44px; --field-h: 44px; --hanja: clamp(52px, 9dvh, 72px); }
  .placement.view-q .q-hanja { font-size: 52px; }
  .view-q .prompt .icon-btn { font-size: 17px; }
  .field-text { font-size: 24px; }
  .pad { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .wake, .stamp-anim { animation: none; }
  .caret { animation: none; }
}
