:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2826;
  --muted: #66716e;
  --line: #e3dfd6;
  --brand: #1f6f68;
  --brand-ink: #ffffff;
  --brand-soft: #e3f0ee;
  --accent: #c8793a;
  --accent-soft: #fbefe3;
  --ok: #2f7d4f;
  --ok-soft: #e4f3ea;
  --warn: #a8461f;
  --warn-soft: #fbe9e1;
  --todo: #6b5a12;
  --todo-soft: #fbf4d6;
  --enamel: #fbfaf5;
  --dentin: #f1e3c4;
  --pulp: #e8a59c;
  --gum: #e9a2a8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 28, .05), 0 4px 16px rgba(20, 30, 28, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141917; --card: #1c2321; --ink: #e8ece9; --muted: #9aa5a1; --line: #2c3532;
    --brand: #5fb5aa; --brand-ink: #0d1514; --brand-soft: #1f3330;
    --accent: #e3a066; --accent-soft: #33271c;
    --ok: #6cc28f; --ok-soft: #1b3024; --warn: #f08a62; --warn-soft: #3a2219;
    --todo: #e8d27a; --todo-soft: #332d14;
    --enamel: #e9e7df; --dentin: #cdb88f; --pulp: #c9786f; --gum: #b9737a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px; line-height: 1.7; word-break: keep-all; overflow-wrap: anywhere;
}
a { color: var(--brand); }
.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 80px; }
.loading { color: var(--muted); text-align: center; padding: 60px 0; }

/* 상단 */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 600; white-space: nowrap; }
.brand b { color: var(--brand); }
.logo { width: 22px; height: 22px; border-radius: 7px; background: var(--brand); display: inline-block;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 4c4 0 5 2 8 2s4-2 8-2 6 4 5 9-3 7-4 13c-.5 3-3 3-3.5 0L18 19c-.5-2-3.5-2-4 0l-1.5 7c-.5 3-3 3-3.5 0C8 20 4 18 3 13S4 4 8 4z'/%3E%3C/svg%3E") center/contain no-repeat; }
nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav a { padding: 6px 10px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; white-space: nowrap; }
nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* 공통 */
h1 { font-size: 26px; line-height: 1.35; margin: 8px 0 6px; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 32px 0 12px; letter-spacing: -.01em; }
h3 { font-size: 17px; margin: 28px 0 8px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.crumb { font-size: 14px; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 4px; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 11px 18px; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn-small { padding: 6px 12px; min-height: 34px; font-size: 14px; border-radius: 8px; }
.btn-danger { background: var(--warn); }
.btn-block { width: 100%; }
input, select {
  font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); min-height: 44px;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check-label input { width: 20px; height: 20px; min-height: 0; }
.err { color: var(--warn); font-size: 14px; min-height: 1.4em; margin: 10px 0 0; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.opt { background: var(--accent-soft); color: var(--accent); }
.badge.gray { background: var(--line); color: var(--muted); }

/* 로그인 */
.auth { max-width: 400px; margin: 8vh auto 0; }
.auth h1 { text-align: center; }
.auth .logo { width: 44px; height: 44px; border-radius: 12px; display: block; margin: 0 auto 12px; }
.auth .switch { text-align: center; margin-top: 16px; font-size: 14px; }

/* 홈 */
.hero { display: flex; gap: 20px; align-items: center; }
.ring { --p: 0; width: 96px; height: 96px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--line) 0); }
.ring span { width: 76px; height: 76px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.next { margin-top: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--brand-soft); border-radius: 12px; padding: 12px 14px; }
.next b { display: block; }
.modules { display: grid; gap: 12px; }
.mod { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.mod .no { width: 40px; height: 40px; flex: none; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.mod.done .no { background: var(--ok-soft); color: var(--ok); }
.mod h3 { margin: 0; font-size: 16px; }
.mod p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.mod.done .bar i { background: var(--ok); }

/* 단원 목록 */
.lessons { list-style: none; padding: 0; margin: 0; }
.lessons li a { display: flex; gap: 12px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.lessons li:last-child a { border-bottom: 0; }
.dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 13px; }
.dot.on { background: var(--ok); border-color: var(--ok); color: #fff; }

/* 본문 */
.lesson { font-size: 16.5px; }
.lesson .lead { font-size: 18px; }
.lesson ul, .lesson ol { padding-left: 1.3em; }
.lesson li { margin: 4px 0; }
.lesson blockquote { margin: 16px 0; padding: 14px 18px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 12px 12px 0; font-size: 19px; font-weight: 700; }
.lesson code { font-size: 14px; background: var(--brand-soft); padding: 1px 6px; border-radius: 6px; }
.facts { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 15px; }
.facts th, .facts td { text-align: left; vertical-align: top; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.facts th { width: 32%; color: var(--brand); font-weight: 600; }
@media (max-width: 480px) {
  .facts th, .facts td { display: block; width: 100%; padding: 2px 0; border: 0; }
  .facts tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
}
.tip, .warn, .todo { border-radius: 12px; padding: 12px 14px; margin: 16px 0; font-size: 15px; }
.tip { background: var(--brand-soft); }
.warn { background: var(--warn-soft); }
.todo { background: var(--todo-soft); color: var(--todo); border: 1px dashed currentColor; }
.tip b:first-child, .warn b:first-child, .todo b:first-child { display: block; margin-bottom: 2px; }
.draft { border: 2px dashed var(--accent); border-radius: 14px; padding: 4px 16px 12px; margin: 20px 0; }
.draft-tag { display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; }
.script { position: relative; margin: 14px 0; padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; }
.script span { display: block; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.flow { counter-reset: f; list-style: none; padding: 0 !important; }
.flow li { counter-increment: f; position: relative; padding: 8px 0 8px 40px !important; margin: 0 !important; }
.flow li::before { content: counter(f); position: absolute; left: 0; top: 8px; width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.flow li:not(:last-child)::after { content: ""; position: absolute; left: 12px; top: 36px; bottom: -6px; width: 2px; background: var(--line); }
.rules > li { margin: 14px 0 !important; }
.values { list-style: none; padding: 0 !important; }
.values li { padding: 10px 0 10px 16px !important; border-left: 3px solid var(--brand); margin: 10px 0 !important; }
.tooth-figure { max-width: 300px; margin: 8px auto; }
.tooth-figure svg { width: 100%; height: auto; }
.fdi { display: grid; gap: 4px; max-width: 360px; margin: 12px auto; }
.fdi-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.fdi .q { background: var(--brand-soft); color: var(--brand); text-align: center; padding: 14px 6px; border-radius: 10px; font-weight: 600; font-size: 15px; }
.fdi-teeth { overflow-x: auto; margin: 12px 0; }
.arch { display: grid; grid-template-columns: repeat(16, minmax(30px, 1fr)); gap: 3px; min-width: 520px; margin-bottom: 4px; }
.arch span { text-align: center; font-size: 13px; padding: 6px 0; border-radius: 6px; background: var(--card); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.arch span:nth-child(8) { margin-right: 6px; }
.arch span.mid { background: var(--accent-soft); border-color: var(--accent); font-weight: 700; }
.lesson-foot { display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); }

/* 퀴즈 */
.qz { margin-bottom: 18px; }
.q-title { font-weight: 600; margin-bottom: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; cursor: pointer; background: var(--card); }
.opt input { width: 18px; height: 18px; min-height: 0; margin-top: 4px; flex: none; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--warn); background: var(--warn-soft); }
.explain { font-size: 14px; color: var(--muted); margin: 4px 2px 0; }
.result { text-align: center; padding: 24px; }
.result .big { font-size: 40px; font-weight: 800; }

/* 체크리스트 */
.ck { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ck:last-child { border-bottom: 0; }
.ck .txt { flex: 1; }
.ck .meta { font-size: 13px; color: var(--muted); }
.ck-self { width: 24px; height: 24px; min-height: 0; flex: none; margin-top: 3px; }

/* 용어 사전 */
.gl dt { font-weight: 700; color: var(--brand); margin-top: 14px; }
.gl dd { margin: 2px 0 0; }

/* 팀 */
.team-row { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.team-row:last-child { border-bottom: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 22px; letter-spacing: .12em; font-weight: 700; background: var(--accent-soft); color: var(--accent); padding: 8px 14px; border-radius: 10px; display: inline-block; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 50; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } h1 { font-size: 23px; } .hero { gap: 14px; } .ring { width: 80px; height: 80px; } .ring span { width: 62px; height: 62px; font-size: 17px; } }
@media print { .top, .lesson-foot, button { display: none !important; } body { background: #fff; } }
