/* ── 색상 (여기 숫자만 바꾸면 전체 색이 바뀌어요) ──
   가나 퀴즈(보라)와 헷갈리지 않게 청록색 */
:root {
  --bg: #f4f8f7;
  --card: #ffffff;
  --text: #17201f;
  --muted: #64726f;
  --line: #dbe5e3;
  --primary: #0f766e;
  --primary-soft: #e0f2ef;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101615;
    --card: #19211f;
    --text: #e8efed;
    --muted: #8fa19d;
    --line: #2a3533;
    --primary: #2dd4bf;
    --primary-soft: #133a35;
    --ok: #4ade80;
    --bad: #f87171;
    --warn: #fbbf24;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101615;
  --card: #19211f;
  --text: #e8efed;
  --muted: #8fa19d;
  --line: #2a3533;
  --primary: #2dd4bf;
  --primary-soft: #133a35;
  --ok: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Hiragino Sans", "Noto Sans KR", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* 화면은 한 번에 하나만 보여요 */
.screen {
  display: none;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}
.screen.active { display: block; }

h1 { font-size: 26px; margin: 8px 0 4px; }
h2 { font-size: 15px; margin: 24px 0 10px; color: var(--muted); font-weight: 600; }
h2 small { font-weight: 400; }
.sub { margin: 0; color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; font-size: 14px; }
.count-note { text-align: center; color: var(--muted); font-size: 13px; }

/* 버튼 */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.big { display: block; width: 100%; padding: 16px; font-size: 17px; margin-top: 10px; }
.btn.small { padding: 6px 8px; font-size: 14px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn.primary { color: #06201d; }
}
:root[data-theme="dark"] .btn.primary { color: #06201d; }

/* 출제 범위 선택 */
.cat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px; border-radius: 12px;
  background: var(--card); border: 2px solid var(--line);
  cursor: pointer; user-select: none;
}
.cat .sample { font-size: 18px; }
.cat .name { font-size: 13px; color: var(--muted); }
.cat.on { border-color: var(--primary); background: var(--primary-soft); }
.cat:last-child:nth-child(odd) { grid-column: 1 / -1; } /* 혼자 남은 칸은 한 줄 전체로 */

/* 자주 틀리는 단어 */
.weak-box {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--bad) 10%, var(--card));
  border: 1px solid color-mix(in srgb, var(--bad) 30%, var(--line));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.weak-title { font-size: 13px; color: var(--muted); }
.weak-title small { font-size: 12px; }
.weak-list { font-size: 19px; margin-top: 2px; word-break: keep-all; overflow-wrap: anywhere; }
.weak-box .btn { flex: none; }

/* 버튼 묶음 (후리가나 / 제한 시간 / 문항 수) */
.segment { display: flex; gap: 6px; }
.segment button {
  flex: 1; padding: 11px 0; font-size: 15px; font-family: inherit;
  border-radius: 10px; border: 2px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer;
}
.segment button.on { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }

/* 퀴즈 화면: 한 화면에 딱 맞게 (단어 카드 + 보기 5개) */
#screen-quiz.active {
  display: flex;
  flex-direction: column;
  height: var(--vvh, 100dvh);
  min-height: 0;
  overflow: hidden;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.quiz-top { display: flex; align-items: center; justify-content: space-between; font-size: 15px; color: var(--muted); }
.combo { min-width: 70px; text-align: right; color: var(--warn); font-weight: 700; }

.timebar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 10px 0 12px; flex: none; }
#timebar-fill { height: 100%; width: 100%; background: var(--primary); transform-origin: left; }
#timebar-fill.low { background: var(--bad); }
.timebar.hidden { visibility: hidden; }

.q-card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 20px;
  flex: 1 1 auto;
  min-height: 140px;
  max-height: 260px;
  padding: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: border-color .15s;
}
.q-reading { font-size: 18px; color: var(--muted); min-height: 24px; font-family: "Hiragino Sans", "Noto Sans JP", sans-serif; }
.q-reading.hidden-reading { visibility: hidden; }
.q-word {
  /* 짧은 단어는 크게, 긴 단어(인사말 등)는 카드 너비에 맞게 작게 */
  font-size: min(clamp(44px, calc(var(--vvh, 100dvh) * 0.09), 76px), calc(min(84vw, 400px) / var(--qlen, 2)));
  line-height: 1.15;
  white-space: nowrap;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}
/* 답한 뒤에 나오는 발음: 자리는 미리 잡아두고 글자만 나타나게 (화면이 흔들리지 않게) */
.q-pron { min-height: 24px; font-size: 18px; color: var(--primary); font-weight: 600; visibility: hidden; }
.q-pron.show { visibility: visible; }
.tap-hint { margin: 8px 0 0; text-align: center; font-size: 13px; color: var(--muted); visibility: hidden; flex: none; }
.tap-hint.show { visibility: visible; }
.q-feedback { min-height: 24px; font-size: 17px; font-weight: 700; text-align: center; padding: 0 8px; }
.q-card.ok { border-color: var(--ok); }
.q-card.bad { border-color: var(--bad); }
.q-card.ok .q-feedback { color: var(--ok); }
.q-card.bad .q-feedback { color: var(--bad); }

/* 5지선다 보기: 한 줄에 하나씩 */
.choices { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; flex: none; }
.choice {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 8px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--card); color: var(--text);
  font-family: inherit; text-align: left; cursor: pointer;
}
.choice .num {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--muted); background: var(--bg);
}
.choice .mean { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; }
.choice .jp { flex: none; max-width: 45%; font-size: 13px; color: var(--muted); display: none; text-align: right; }
.choices.revealed .choice .jp { display: block; }  /* 틀리면 각 보기가 무슨 단어였는지 보여줘요 */
.choice.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--card)); }
.choice.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, var(--card)); }
.choice:focus-visible, .btn:focus-visible, .segment button:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 결과 화면 */
.score { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; text-align: center; margin-top: 12px; }
.score-big { font-size: 44px; font-weight: 800; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stats span { display: block; font-size: 13px; color: var(--muted); }
.stats b { font-size: 20px; }

.wrong-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.wrong-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; text-align: center; }
.wrong-item .k { font-size: 22px; overflow-wrap: anywhere; }
.wrong-item .r { font-size: 12px; color: var(--muted); min-height: 1em; }
.wrong-item .a { font-size: 14px; margin-top: 2px; }

/* ── 오늘의 학습 카드 ── */
.today-card {
  margin-top: 16px; padding: 16px; border-radius: 18px;
  background: var(--primary-soft); border: 2px solid var(--primary);
}
.today-head { display: flex; align-items: baseline; justify-content: space-between; }
.today-title { font-size: 18px; font-weight: 800; }
.today-date { font-size: 14px; color: var(--muted); }
.today-plan { margin-top: 8px; font-size: 17px; font-weight: 700; }
.today-note { margin-top: 2px; font-size: 14px; color: var(--muted); min-height: 1.2em; }
.progress { margin-top: 12px; height: 8px; border-radius: 4px; background: var(--card); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 4px; transition: width .3s; }
.progress-text { margin-top: 4px; font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.today-card .btn.big:first-of-type { margin-top: 12px; }
.btn:disabled { opacity: .55; cursor: default; }

/* 자유 연습 구역 */
.free-section { margin-top: 28px; padding-top: 4px; border-top: 1px dashed var(--line); }
.free-title { margin-top: 16px; }
.link-btn { border: none; background: none; padding: 0; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }
.r-note { margin: 0 0 4px; color: var(--muted); font-size: 14px; }

/* ── 공부 카드 ── */
#screen-study.active {
  display: flex; flex-direction: column;
  height: var(--vvh, 100dvh); min-height: 0; overflow: hidden;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.study-tag { font-size: 13px; font-weight: 700; color: var(--primary); min-width: 70px; text-align: right; }
.study-card {
  flex: 1 1 auto; min-height: 0; margin-top: 14px;
  background: var(--card); border: 2px solid var(--line); border-radius: 22px;
  padding: 20px 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
}
.sc-reading { font-size: 20px; color: var(--muted); min-height: 26px; font-family: "Hiragino Sans", "Noto Sans JP", sans-serif; }
.sc-word {
  font-size: min(80px, calc(min(84vw, 400px) / var(--qlen, 2)));
  line-height: 1.15; white-space: nowrap;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}
.sc-pron { font-size: 20px; font-weight: 700; color: var(--primary); }
.sc-mean { margin-top: 10px; font-size: 26px; font-weight: 800; }
.sc-group { margin-top: 4px; font-size: 13px; color: var(--muted); }
.study-nav { display: flex; gap: 10px; margin-top: 14px; flex: none; }
.study-nav .btn { flex: 1; padding: 16px; font-size: 17px; }
.study-nav .btn:first-child { flex: 0 0 34%; }
