:root {
  --bg: #f6f3ec; --card: #ffffff; --ink: #1b2240; --muted: #6b7189; --line: #e4dfd3;
  --navy: #1d2a57; --red: #c8102e; --green: #1f8a5b; --amber: #c9831a;
  --soft: #eef0f8; --ok-bg: #e3f4ec; --no-bg: #fbe6e9; --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12152a; --card: #1c2040; --ink: #eceefa; --muted: #9aa0be; --line: #2c3160;
    --navy: #8fa2ff; --red: #ff6b81; --green: #56d39b; --amber: #f0b45a;
    --soft: #252a52; --ok-bg: #173a2d; --no-bg: #47202a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, a, select { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); overscroll-behavior-y: none;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", sans-serif;
}
#view {
  max-width: 600px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
h1 { font-size: 26px; margin: 4px 0 12px; letter-spacing: -0.02em; }
h2 { font-size: 19px; margin: 24px 0 10px; }
h3 { font-size: 16px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.center { text-align: center; }
.good { color: var(--green); } .bad { color: var(--red); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ico { display: inline-flex; line-height: 0; }

/* 학습 대상 언어의 글과 읽는 법 */
.tx { font-family: Georgia, "Times New Roman", serif; font-size: 20px; line-height: 1.45; }
.tx:lang(ja), .tx:lang(zh) { font-family: -apple-system, "Hiragino Sans", "PingFang SC", "Noto Sans CJK JP", sans-serif; }
.tx.big { font-size: 24px; }
.tx.line { font-size: 17px; }
.tx.huge { font-size: 64px; line-height: 1.2; }
.rd { font-size: 14px; color: var(--muted); letter-spacing: .01em; }
.rdbig { font-size: 22px; font-weight: 700; color: var(--red); margin-top: 6px; }
.bubble.me .rd { color: color-mix(in srgb, var(--bg) 75%, transparent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.tint { background: var(--soft); border-color: transparent; }
.card.warn { background: var(--no-bg); border-color: transparent; }
.card + .card, .card + .report, .report + .report { margin-top: 12px; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--soft); color: var(--navy); white-space: nowrap; }
.tag.red { background: var(--no-bg); color: var(--red); }

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  padding: 12px 18px; border-radius: 12px; font-weight: 700; background: var(--soft); color: var(--ink);
  border: 1px solid transparent; min-height: 46px;
}
.btn.primary { background: var(--navy); color: var(--bg); }
.btn.red { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.block { display: flex; width: 100%; }
.btn.sm { padding: 7px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.link { color: var(--navy); text-decoration: underline; font-size: 14px; padding: 6px; }
.icon { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; }
.icon:hover { background: var(--soft); }
.langpick { text-align: left; display: flex; flex-direction: column; line-height: 1.25; padding: 4px 0; }
.langpick b { font-size: 22px; letter-spacing: -0.02em; }

input[type=text], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
}
textarea { min-height: 90px; resize: vertical; }

/* 탭바 */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 5;
}
#tabs a { flex: 1; max-width: 120px; text-align: center; text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 4px 0; }
#tabs a svg { display: block; margin: 0 auto 2px; }
#tabs a.on { color: var(--navy); }
body.in-seq #tabs { display: none !important; }
body.in-seq #view { padding-bottom: 40px; }

/* 홈 */
.hero { display: flex; gap: 16px; align-items: center; margin-top: 10px; }
.ring { --p: 0; width: 92px; height: 92px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--red) calc(var(--p) * 1%), var(--line) 0); }
.ring > div { width: 74px; height: 74px; border-radius: 50%; background: var(--card); display: grid; place-items: center; text-align: center; font-weight: 800; line-height: 1.1; }
.ring small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.chip { background: var(--soft); border-radius: 99px; padding: 4px 11px; font-size: 13.5px; font-weight: 700; }
.task { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 14px; }
.task b { display: block; }
.task.done { opacity: .6; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.dot.on { background: var(--green); border-color: var(--green); color: #fff; }

/* 코스 */
.ep { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; }
.ep .num { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; font-weight: 800; flex: none; }
.ep.done .num { background: var(--green); color: #fff; }
.ep.next { border-color: var(--red); box-shadow: 0 0 0 2px color-mix(in srgb, var(--red) 25%, transparent); }
.report { display: flex; gap: 12px; align-items: center; text-decoration: none; padding: 6px 0; }

/* 시퀀스(학습 진행) */
.seq-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.pbar { flex: 1; height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .3s; }
.seq-title { font-size: 12.5px; color: var(--muted); font-weight: 700; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-label { font-size: 13px; font-weight: 800; color: var(--red); letter-spacing: .04em; margin-bottom: 6px; }
.actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.donemark { width: 84px; height: 84px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; margin: 28px auto 14px; animation: pop .45s ease-out; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }

/* 문제 */
.opts { display: grid; gap: 9px; margin-top: 14px; }
.opts.grid2 { grid-template-columns: 1fr 1fr; }
.opt { text-align: left; padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-weight: 600; }
.opts.grid2 .opt { text-align: center; }
.opt.tx { font-size: 22px; font-weight: 500; }
.opt:hover:not(:disabled) { border-color: var(--navy); }
.opt.ok { background: var(--ok-bg); border-color: var(--green); }
.opt.no { background: var(--no-bg); border-color: var(--red); }
.why { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--soft); font-size: 14.5px; }

/* 말하기 */
.mic { width: 76px; height: 76px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; margin: 14px auto 6px; box-shadow: 0 6px 18px color-mix(in srgb, var(--red) 35%, transparent); }
.mic.live { animation: pulse 1.1s infinite; background: var(--navy); color: var(--bg); }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.09); } }
.heard { min-height: 24px; text-align: center; color: var(--muted); font-style: italic; }
.marks span { border-radius: 5px; }
.marks .ok { color: var(--green); }
.marks .no { color: var(--red); background: var(--no-bg); }
.score { font-size: 30px; font-weight: 800; text-align: center; }
.score.good { color: var(--green); } .score.mid { color: var(--amber); } .score.low { color: var(--red); }

/* 대화 */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); align-self: flex-start; }
.bubble.active { outline: 2px solid var(--red); }
.bubble .who { font-size: 12px; font-weight: 800; color: var(--muted); }
.bubble .ko { font-size: 13.5px; color: var(--muted); }
.bubble.me { align-self: flex-end; background: var(--navy); color: var(--bg); border-color: transparent; }
.bubble.me .who, .bubble.me .ko { color: color-mix(in srgb, var(--bg) 75%, transparent); }

/* 복습 카드 */
.flash { text-align: center; padding: 28px 16px; min-height: 220px; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grades .btn { flex-direction: column; padding: 10px 4px; font-size: 14px; gap: 0; }
.grades small { font-weight: 500; color: var(--muted); font-size: 11.5px; }

/* 통계 */
.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.statgrid .card + .card { margin-top: 0; }
.stat b { font-size: 24px; display: block; }
.bars { display: flex; align-items: flex-end; gap: 5px; height: 110px; margin-top: 8px; }
.bars div { flex: 1; text-align: center; font-size: 10.5px; color: var(--muted); display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bars i { display: block; background: var(--navy); border-radius: 5px 5px 0 0; min-height: 2px; margin-bottom: 3px; }
.bars .hit i { background: var(--green); }
ul.clean { margin: 6px 0 0; padding-left: 20px; }
ul.clean li { margin-bottom: 5px; }
pre.code { background: var(--soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; overflow-x: auto; margin: 8px 0; white-space: pre-wrap; }

.timer { font-size: 46px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }

#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
