:root {
  --red: #c8102e; --red2: #fbe9eb; --ink: #1d1d1f; --muted: #6b6b70; --line: #e4e2dd; --bg: #f7f5f0; --card: #fff;
  --ok: #1f8a4c; --okbg: #e3f4ea; --tone: #c46a00; --tonebg: #fff1dc; --bad: #c62828; --badbg: #fde8e8; --weak: #8a7a00; --weakbg: #fbf6d6;
  --zh: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; }
body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }
[hidden] { display: none !important; }

#top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--red); color: #fff; }
.brand { font: 700 20px var(--zh); letter-spacing: 1px; }
.brand span { font: 600 15px system-ui, sans-serif; opacity: .85; }
#who { font-size: 13px; display: flex; gap: 10px; align-items: center; }
#who button { background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 8px; padding: 4px 8px; font-size: 12.5px; white-space: nowrap; }
#who { flex-wrap: nowrap; gap: 6px !important; }

main { max-width: 760px; margin: 0 auto; padding: 14px; }
.center { text-align: center; padding: 40px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h2 { font-size: 18px; margin: 6px 0 12px; }
h3 { font-size: 15px; margin: 16px 0 6px; color: var(--muted); }

#tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs button { flex: 1; min-width: 0; border: 0; background: none; padding: 7px 0 8px; font-size: 11.5px; white-space: nowrap; color: var(--muted); display: flex; flex-direction: column; align-items: center; position: relative; }
#tabs button b { font-size: 20px; line-height: 1.2; font-weight: normal; filter: grayscale(1); opacity: .6; }
#tabs button.on { color: var(--red); font-weight: 600; }
#tabs button.on b { filter: none; opacity: 1; }
#dueBadge { position: absolute; top: 3px; left: 54%; background: var(--red); color: #fff; font-style: normal; font-size: 11px; border-radius: 9px; padding: 0 6px; min-width: 18px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 14px; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.big { width: 100%; padding: 13px; font-size: 17px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.icon { border: 0; background: var(--red2); color: var(--red); border-radius: 50%; width: 38px; height: 38px; font-size: 18px; flex: none; }
textarea { width: 100%; min-height: 96px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; resize: vertical; background: #fff; font-family: var(--zh), system-ui, sans-serif; font-size: 17px; }
input[type=text], input[type=password], input[type=search], input:not([type]) { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
label.f { display: block; margin: 10px 0 4px; font-size: 14px; color: var(--muted); }
.thumb { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; margin: 8px 0; border: 1px solid var(--line); }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 9px; background: #f0eee9; color: var(--muted); }

.zh { font-family: var(--zh); font-size: 24px; line-height: 1.5; }
.zh.xl { font-size: 34px; }
.py { color: var(--red); font-size: 15px; }
.ko { font-size: 16px; }
.lit { font-size: 13px; color: var(--muted); }
.sent-head { display: flex; gap: 10px; align-items: flex-start; }
.sent-head .grow > * { margin: 0 0 2px; }

table.words { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 14px; }
table.words td { border-top: 1px solid var(--line); padding: 6px 4px; vertical-align: top; }
table.words td:first-child { font-family: var(--zh); font-size: 18px; white-space: nowrap; }
table.words td.p { color: var(--red); white-space: nowrap; }
.gram { border-left: 3px solid var(--red); padding: 4px 10px; margin: 8px 0; background: #fcfbf8; border-radius: 0 8px 8px 0; }
.gram b { display: block; }
.gram .ex { margin-top: 4px; font-size: 14px; }
.gram .ex .zh { font-size: 17px; }

/* 플래시카드 */
.flash { min-height: 300px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 26px 16px; cursor: pointer; }
.flash .zh { font-size: 40px; }
.flash .zh.sent { font-size: 26px; }
.flash .back { margin-top: 14px; width: 100%; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grades button { border: 0; border-radius: 10px; padding: 11px 0; color: #fff; font-weight: 600; }
.grades small { display: block; font-weight: normal; opacity: .85; font-size: 11px; }
.g1 { background: #c62828; } .g2 { background: #d9822b; } .g3 { background: #1f8a4c; } .g4 { background: #1565c0; }

/* 퀴즈 */
.opts { display: grid; gap: 8px; }
.opt { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 14px; font-size: 16px; }
.opt.zhopt { font-family: var(--zh); font-size: 22px; }
.opt.right { background: var(--okbg); border-color: var(--ok); }
.opt.wrong { background: var(--badbg); border-color: var(--bad); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.progress div { height: 100%; background: var(--red); }
.qtypes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.qtypes button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px; }
.qtypes button b { display: block; }

/* 발음 */
.mic { width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--red); color: #fff; font-size: 34px; box-shadow: 0 4px 14px rgba(200,16,46,.3); }
.mic.rec { animation: pulse 1s infinite; background: #8b0a1f; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(200,16,46,.15); } }
.chars { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0; }
.ch { min-width: 52px; text-align: center; border-radius: 10px; padding: 4px 6px 6px; border: 1px solid transparent; }
.ch .c { font: 28px var(--zh); display: block; }
.ch .e { font-size: 13px; display: block; }
.ch .h { font-size: 12px; display: block; min-height: 16px; }
.ch .s { font-size: 11px; display: block; opacity: .8; }
.ch.ok { background: var(--okbg); color: var(--ok); }
.ch.tone { background: var(--tonebg); color: var(--tone); border-color: var(--tone); }
.ch.sound { background: var(--badbg); color: var(--bad); border-color: var(--bad); }
.ch.missing { background: #eee; color: #888; border-style: dashed; border-color: #aaa; }
.ch.weak { background: var(--weakbg); color: var(--weak); border-color: var(--weak); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; font-size: 12px; }
.legend span { padding: 1px 8px; border-radius: 8px; }
.score { font-size: 42px; font-weight: 700; text-align: center; }
.scores { display: flex; justify-content: center; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.tip { white-space: pre-wrap; background: #fcfbf8; border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); }

/* 목록 */
.seg { display: flex; background: #ebe8e1; border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 7px; }
.seg button.on { background: #fff; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.list .it { display: flex; gap: 10px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list .it .zh { font-size: 19px; }
.list .it .meta { font-size: 13px; color: var(--muted); }
.stat { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin-bottom: 12px; }
.stat div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 0; }
.stat b { display: block; font-size: 20px; color: var(--red); }
.stat span { font-size: 12px; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 20; max-width: 90vw; font-size: 14px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; display: flex; align-items: flex-end; justify-content: center; }
.modal > div { background: var(--bg); width: 100%; max-width: 760px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px; }

/* 영어판: 파란 색, 일반 글꼴, 단어 칩은 작게 */
html[data-lang="en"] { --red: #1d4ed8; --red2: #e7eefc; --zh: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif; }
html[data-lang="en"] .ch .c { font: 600 19px var(--zh); }
html[data-lang="en"] .ch { min-width: 0; padding: 4px 8px 6px; }
html[data-lang="en"] .flash .zh { font-size: 34px; }
html[data-lang="en"] .flash .zh.sent { font-size: 22px; }
html[data-lang="en"] .mic { box-shadow: 0 4px 14px rgba(29,78,216,.3); }
html[data-lang="en"] .mic.rec { background: #1e3a8a; }
/* 영어판: 발음기호 끄기 */
html.no-ipa .py { display: none !important; }
