:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1f2522;
  --muted: #6b726e;
  --line: #e3e0d8;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --new: #2f6fb3;
  --due: #b5532f;
  --good: #2e7d4f;
  --bad: #b23b3b;
  --mark: #fbe7a1;
  --g1: #b23b3b;
  --g2: #a8742a;
  --g3: #2e7d4f;
  --g4: #2f6fb3;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917;
    --surface: #1f2522;
    --ink: #e9ece9;
    --muted: #9aa39e;
    --line: #313a35;
    --accent: #5fb39a;
    --accent-ink: #0f1513;
    --new: #7fb0e6;
    --due: #e59473;
    --good: #6fcf97;
    --bad: #ef8a8a;
    --mark: #5a4c1c;
    --g1: #ef8a8a;
    --g2: #e0b26a;
    --g3: #6fcf97;
    --g4: #7fb0e6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; margin: 0 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { background: var(--mark); padding: 10px 12px; border-radius: 10px; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 0 14px;
}
.back { text-decoration: none; font-weight: 600; }

.pack, .panel, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.pack-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tag { font-size: 0.75rem; border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); white-space: nowrap; }
.counts { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 12px; color: var(--muted); }
.counts b { color: var(--ink); font-variant-numeric: tabular-nums; }
.counts.small { margin: 0; font-size: 0.9rem; }
.c-new { color: var(--new) !important; }
.c-due { color: var(--due) !important; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.wide { width: 100%; }
.btn.big { flex: 1; flex-direction: column; min-height: 72px; font-size: 1.2rem; }
.btn.big small { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.btn:disabled { opacity: 0.55; cursor: default; }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.import-msg ul { padding-left: 20px; font-size: 0.9rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; }
.row input[type="number"] { width: 80px; min-height: 40px; font: inherit; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

/* 카드 */
.card { text-align: center; padding: 20px 16px 22px; min-height: 300px; }
.type { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.pic { display: flex; align-items: center; justify-content: center; margin: 6px auto; line-height: 1; }
.pic.big { font-size: 112px; height: 150px; }
.pic.mid { font-size: 72px; height: 96px; }
.pic.small { font-size: 52px; height: 70px; }
.pic.tiny { font-size: 30px; width: 40px; height: 40px; margin: 0; flex: none; }
img.pic { object-fit: contain; max-width: 100%; }
img.pic.big { width: auto; max-height: 180px; }
.word { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.01em; margin: 6px 0 2px; overflow-wrap: anywhere; }
.prompt { color: var(--muted); margin: 10px 0; }
.sentence { font-size: 1.35rem; margin: 12px 0; }
.line { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.ipa { color: var(--muted); font-family: "Charis SIL", "Doulos SIL", "Gentium Plus", "Lucida Grande", serif; }
.pos { font-size: 0.8rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; color: var(--muted); }
.speak {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 99px; min-width: 44px; min-height: 44px; padding: 0 14px;
  font: inherit; font-size: 1.05rem; cursor: pointer;
}
.speak:hover { border-color: var(--accent); }
.definition { font-size: 1.1rem; margin: 12px 0 6px; }
.example { color: var(--muted); margin: 6px 0; }
.example .speak { min-height: 32px; min-width: 32px; padding: 0 8px; font-size: 0.9rem; }
mark { background: var(--mark); color: inherit; border-radius: 4px; padding: 0 2px; }
.mnemonic { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.answer-side { border-top: 1px dashed var(--line); margin-top: 16px; padding-top: 12px; }
.answer {
  width: 100%; max-width: 360px; min-height: 48px; margin: 8px auto 0; display: block;
  font: inherit; font-size: 1.25rem; text-align: center;
  border: 2px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
}
.answer:focus { outline: none; border-color: var(--accent); }
.good { color: var(--good); font-weight: 700; }
.bad { color: var(--bad); font-weight: 700; }
.memory { display: block; text-align: left; margin-top: 14px; font-size: 0.85rem; color: var(--muted); }
.memory textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; resize: vertical;
  font: inherit; font-size: 0.95rem; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}

.footer { position: sticky; bottom: 0; padding: 10px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.hint { text-align: center; font-size: 0.8rem; margin: 6px 0 0; }
@media (hover: none) { .hint { display: none; } }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade {
  min-height: 60px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface);
  font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink);
}
.grade small { color: var(--muted); font-size: 0.8rem; }
.grade.g1 b { color: var(--g1); } .grade.g2 b { color: var(--g2); } .grade.g3 b { color: var(--g3); } .grade.g4 b { color: var(--g4); }
.grade.g1:hover, .grade.suggest { border-color: var(--g1); }
.grade.g2:hover { border-color: var(--g2); } .grade.g3:hover { border-color: var(--g3); } .grade.g4:hover { border-color: var(--g4); }

.done { text-align: center; padding: 30px 0; }
.intro { margin-top: 0; }
.pair { display: flex; gap: 10px; margin: 8px 0; }
.feedback { min-height: 1.6em; }

/* 단어 보기 */
.browse { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.browse li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.browse li:last-child { border-bottom: 0; }
.b-main { flex: 1; min-width: 0; }
.b-main .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dots { display: flex; gap: 3px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }
.d-new { background: var(--line); }
.d-learn { background: var(--g2); }
.d-mature { background: var(--g3); }
.legend { margin-top: 10px; }

@media (max-width: 420px) {
  .word { font-size: 1.9rem; }
  .grade { min-height: 56px; }
  .browse .b-main .muted { white-space: normal; }
}

/* 한자 */
.word.han { font-size: 4.5rem; font-weight: 500; line-height: 1.15; font-family: "Apple SD Gothic Neo", "Noto Serif KR", "Noto Sans KR", serif; }
.reading { font-size: 1.8rem; font-weight: 700; margin: 8px 0 4px; }
.browse .pic.tiny + .b-main b { font-size: 1.15rem; }
.hun { font-size: 1.45rem; font-weight: 700; }

/* 쓰기 한자 표시 */
.wbadge { display: inline-block; font-size: 0.8rem; line-height: 1.6; border: 1px solid var(--line); border-radius: 99px; padding: 0 9px; color: var(--muted); margin: 6px 0 0; white-space: nowrap; }
.wbadge.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.wbadge.sm { font-size: 0.7rem; padding: 0 6px; margin: 0; vertical-align: middle; }
.row select { min-height: 40px; font: inherit; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.row small { font-size: 0.8rem; }
.filter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; margin-bottom: 10px; }
.filter input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

/* 화면 필기 칸 */
.hw { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 6px 0 2px; }
.hw-box { position: relative; border: 2px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; touch-action: none; }
.hw-box::before, .hw-box::after { content: ""; position: absolute; pointer-events: none; }
.hw-box::before { left: 50%; top: 0; bottom: 0; border-left: 1px dashed var(--line); }
.hw-box::after { top: 50%; left: 0; right: 0; border-top: 1px dashed var(--line); }
.hw-canvas { position: relative; z-index: 1; display: block; color: var(--ink); touch-action: none; cursor: crosshair; }
.hw-answer { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; pointer-events: none; color: var(--bad); opacity: 0.38; line-height: 1; font-family: "Apple SD Gothic Neo", "Noto Serif KR", "Noto Sans KR", serif; }
.hw-answer[hidden] { display: none; }
.hw.revealed .hw-box { border-color: var(--bad); }
.hw-tools { display: flex; gap: 6px; }
.hw-btn { min-height: 36px; padding: 0 12px; font-size: 0.85rem; }
.hw.revealed .hw-tools { display: none; }

/* 팩 묶음(급수별 접기) */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.group > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 52px; padding: 10px 14px; cursor: pointer; list-style: none;
  font-weight: 700; -webkit-tap-highlight-color: transparent;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--muted); font-size: 1rem; width: 12px; transition: transform 0.15s; }
.group[open] > summary::before { transform: rotate(90deg); }
.g-name { flex: 1; min-width: 0; }
.g-name small { font-weight: 400; }
.g-counts { display: flex; gap: 10px; align-items: baseline; font-weight: 400; font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.group-body { padding: 0 10px 2px; }
.group-body .pack { margin-bottom: 10px; box-shadow: none; }

/* 터치 기기: 두 번 탭 확대 막기, 누를 때 반응, 마우스 올림 효과는 끔 */
.btn, .grade, .speak, .hw-btn, summary, a { touch-action: manipulation; }
.btn:active, .grade:active, .speak:active { transform: scale(0.97); }
@media (hover: none) {
  .btn:hover, .speak:hover { border-color: var(--line); }
  .btn.primary:hover { border-color: var(--accent); }
  .grade.g2:hover, .grade.g3:hover, .grade.g4:hover { border-color: var(--line); }
  .grade.g1:hover:not(.suggest) { border-color: var(--line); }
}
/* iOS 는 16px 보다 작은 입력칸을 누르면 화면을 확대하므로 16px 이상으로 */
.memory textarea, .row select, .row input[type="number"] { font-size: 16px; }

/* 휴대폰 */
@media (max-width: 480px) {
  main { padding: 10px 12px calc(24px + env(safe-area-inset-bottom)); }
  .top { padding: 2px 0 10px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: calc(6px + env(safe-area-inset-top)); }
  h1 { font-size: 1.3rem; }
  .pack { padding: 12px; }
  .pack h2 { font-size: 1.02rem; }
  .pack > p.muted { font-size: 0.85rem; margin: 4px 0; line-height: 1.45; }
  .counts { gap: 10px; margin: 6px 0 8px; font-size: 0.9rem; }
  .actions .btn { flex: 1; min-height: 42px; padding: 0 10px; }
  .group > summary { padding: 8px 12px; }
  .g-counts { gap: 8px; font-size: 0.8rem; }
  .card { padding: 14px 12px 16px; min-height: 0; }
  .pic.big { font-size: 88px; height: 112px; }
  .word.han { font-size: 3.6rem; }
  .reading { font-size: 1.5rem; }
  .hun { font-size: 1.3rem; }
  .sentence { font-size: 1.2rem; }
  .definition { font-size: 1rem; }
  .grades { gap: 6px; }
  .grade { min-height: 58px; }
  /* 정답 보기·평가 버튼은 엄지가 닿는 화면 아래에 고정 */
  .footer {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--line);
  }
  main:has(> .footer) { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .browse li { gap: 8px; padding: 8px 10px; }
  .browse .dots { display: none; }
  .row { flex-wrap: wrap; }
}
