:root {
  --bg: #faf7f2; --fg: #222; --muted: #777; --line: #e3dccf; --card: #fff;
  --accent: #7a2e1d; --accent-soft: #f3e4dc; --chip: #f1ece3;
  --han: "Apple SD Gothic Neo", "Noto Serif CJK KR", "Noto Sans CJK KR", "Malgun Gothic", serif;
}
/* 테마: 기본은 시스템 설정을 따르고, data-theme 가 있으면 그것을 따른다 */
:root { --head: #7a2e1d; color-scheme: light; }
:root[data-theme="dark"] { --bg: #1b1a18; --fg: #eee; --muted: #9a958c; --line: #3a3631; --card: #252320;
    --accent: #e08a6d; --accent-soft: #3a2a24; --chip: #2f2c28; --head: #4a1d13; color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #1b1a18; --fg: #eee; --muted: #9a958c; --line: #3a3631; --card: #252320;
    --accent: #e08a6d; --accent-soft: #3a2a24; --chip: #2f2c28; --head: #4a1d13; color-scheme: dark; }
}
/* 글자 크기 */
:root[data-scale="s"] { font-size: 13px; }
:root[data-scale="l"] { font-size: 18px; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 1rem/1.55 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
a { color: inherit; text-decoration: none; }
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--head); color: #fff; }
.logo { font-family: var(--han); font-size: 22px; font-weight: 700; letter-spacing: 2px; }
.search { display: flex; flex: 1; gap: 6px; min-width: 0; }
.search select, .search input, .search button { font: inherit; border: 0; border-radius: 8px; padding: 8px 10px; }
.search input { flex: 1; min-width: 0; }
.search button { background: #fff2; color: #fff; cursor: pointer; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--card); }
.tabs a { flex: 1; text-align: center; padding: 10px 0; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }
main { max-width: 920px; margin: 0 auto; padding: 14px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 40px 0; }
h2 { font-size: 16px; margin: 22px 0 8px; color: var(--accent); }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
.han { font-family: var(--han); }

/* 글자 격자 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr)); gap: 6px; }
.cell { background: var(--card); border: 1px solid var(--line); border-radius: 8px; text-align: center;
  padding: 6px 2px 4px; cursor: pointer; transition: border-color .1s; }
.cell:hover { border-color: var(--accent); }
.cell .g { font-family: var(--han); font-size: 2rem; line-height: 1.2; }
.cell .m { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell.edu .g { color: var(--accent); }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
.grid.small .g { font-size: 24px; }

/* 결과 목록 */
.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.row:hover { border-color: var(--accent); }
.row .g { font-family: var(--han); font-size: 2.5rem; width: 3.2rem; text-align: center; }
.row .info { flex: 1; min-width: 0; }
.row .hun { font-weight: 600; }
.row .sub { font-size: .87rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 상세 */
.detail-head { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.big { font-family: var(--han); font-size: 128px; line-height: 1; width: 160px; height: 160px; display: flex;
  align-items: center; justify-content: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 50% 50%; background-position: center; }
.head-info { flex: 1; min-width: 220px; }
.hun-big { font-size: 1.47rem; font-weight: 700; }
.hun-big span + span::before { content: " · "; color: var(--muted); font-weight: 400; }
.badges { margin: 6px 0; display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
table.kv { border-collapse: collapse; width: 100%; }
table.kv th { text-align: left; width: 96px; color: var(--muted); font-weight: 500; padding: 4px 8px 4px 0; vertical-align: top; }
table.kv td { padding: 4px 0; }
.ref { color: var(--accent); cursor: pointer; font-family: var(--han); }
.ref:hover { text-decoration: underline; }
.forms { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.form { background: var(--card); border: 1px solid var(--line); border-radius: 10px; text-align: center; padding: 8px; cursor: pointer; }
.form .g { font-size: 52px; line-height: 1.2; }
.form .lbl { font-size: 12px; color: var(--muted); }
.form.same { opacity: .55; }
.words { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.6rem, 1fr)); gap: 6px; }
.word { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.word .w { font-family: var(--han); font-size: 1.33rem; }
.word .w b { color: var(--accent); font-weight: 400; }
.word .r { font-size: .87rem; color: var(--muted); }
.word .n { font-size: 11px; color: var(--muted); }
.more { margin-top: 8px; font: inherit; background: var(--chip); color: var(--fg); border: 0; border-radius: 8px; padding: 6px 14px; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); border-radius: 99px; padding: 4px 12px; cursor: pointer; border: 1px solid transparent; font: inherit; color: inherit; }
.chip.on { background: var(--accent); color: #fff; }
.chip .han { font-size: 18px; }

/* 필기 */
.draw-wrap { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.pad { position: relative; }
#pad { width: 300px; height: 300px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; touch-action: none;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 50% 50%; background-position: center; cursor: crosshair; }
.pad-btns { display: flex; gap: 6px; margin-top: 8px; }
.pad-btns button { flex: 1; }
.cands { flex: 1; min-width: 240px; }
.cands .grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }

/* 부수 */
/* 왼쪽 획수 칸은 고정하고, 부수는 오른쪽 칸 안에서만 줄바꿈 */
.rad-group { display: grid; grid-template-columns: 34px 1fr; gap: 6px; align-items: start; margin-bottom: 8px;
  padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.rad-group:last-child { border-bottom: 0; }
.rad-group .sn { font-size: 12px; color: var(--muted); text-align: right; padding-top: 16px; white-space: nowrap; }
.rads { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.rad { width: 58px; height: 52px; overflow: hidden; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; padding: 2px 0; }
.rad:hover { border-color: var(--accent); }
.rad .g { font-family: var(--han); font-size: 24px; line-height: 1.3; }
.rad .n { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.opts { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 6px 0 12px; font-size: 14px; }
.sec-title { display: flex; align-items: baseline; gap: 8px; }
.sec-title .cnt { color: var(--muted); font-size: 12px; }
.ids { font-family: var(--han); font-size: 20px; }
@media (max-width: 560px) {
  .search select { max-width: 74px; padding: 8px 4px; }
  .big { width: 120px; height: 120px; font-size: 96px; }
  #pad { width: calc(100vw - 30px); height: calc(100vw - 30px); max-width: 360px; max-height: 360px; }
}
.muted { color: var(--muted); }
.help { padding-left: 18px; }
.help li { margin: 4px 0; }

html { font-size: 15px; }
.small { font-size: 12px; }
.icon-btn { font: inherit; font-size: 20px; line-height: 1; background: #fff2; color: #fff; border: 0; border-radius: 8px;
  width: 38px; height: 38px; cursor: pointer; flex: none; }
.icon-btn.plain { background: transparent; color: var(--muted); }
.foot-links { margin-top: 6px; }
.foot-links a { color: var(--accent); }

/* 설정 모달 */
dialog#settings { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 24px));
  background: var(--card); color: var(--fg); box-shadow: 0 20px 60px #0006; }
dialog#settings::backdrop { background: #0007; }
.dlg { padding: 6px 18px 16px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 12px 0 4px; }
.dlg fieldset { border: 0; padding: 0; margin: 14px 0 0; }
.dlg legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { flex: 1; text-align: center; padding: 7px 0; border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--card); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px #0002; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.line { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.dlg-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

/* 즐겨찾기 */
.star { font: inherit; font-size: 15px; background: var(--chip); color: var(--fg); border: 1px solid var(--line);
  border-radius: 99px; padding: 5px 14px; cursor: pointer; }
.star.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #222e; color: #fff;
  padding: 8px 16px; border-radius: 99px; font-size: 14px; z-index: 20; pointer-events: none; }

/* 내 한자 */
.my-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.hist-day { margin-top: 10px; }
.cell .cnt { font-size: 10px; color: var(--accent); }

/* 카드 학습 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; min-height: 320px; display: flex;
  flex-direction: column; align-items: center; justify-content: center; padding: 20px; cursor: pointer; user-select: none; text-align: center; }
.card .g { font-family: var(--han); font-size: 120px; line-height: 1.1; }
.card .g.word { font-size: 64px; }
.card .ans { margin-top: 12px; }
.card .ans .hun-big { font-size: 24px; }
.card .hint { color: var(--muted); font-size: 13px; margin-top: 14px; }
.study-btns { display: flex; gap: 8px; margin-top: 12px; }
.study-btns button { flex: 1; padding: 12px; font-size: 15px; }
.progress { height: 4px; background: var(--chip); border-radius: 4px; margin: 8px 0 12px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }

/* 소개 / 후원 */
.prose { max-width: 680px; }
.prose p, .prose li { line-height: 1.7; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin: 8px 0; }
.box h3 { margin-top: 4px; color: var(--fg); }
.btn { display: inline-block; font: inherit; background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 18px; cursor: pointer; margin: 4px 6px 4px 0; }
.btn.ghost { background: var(--chip); color: var(--fg); }
.donate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.donate-grid .box { text-align: center; }
.donate-grid img { width: 160px; height: 160px; border-radius: 8px; background: #fff; }

/* 검색엔진용 정적 페이지 (/c/學, /w/學校, /r/85, /list/edu) */
.static main a.cell, .static main a.word, .static main a.row, .static main a.form, .static main a.rad { display: block; color: inherit; }
.static main a.row { display: flex; }
.crumbs { font-size: 13px; color: var(--muted); margin: 2px 0 12px; }
.crumbs a { color: var(--accent); }
h1.hun-big { margin: 0 0 4px; }
.h1-hun { font-weight: 700; }
h1.hun-big > .h1-hun { margin-left: 4px; }
.word-h1 { font-size: 1.6rem; margin: 6px 0; }
.word-h1 .han { font-size: 3rem; margin-right: 10px; }
.page-h1 { font-size: 1.4rem; margin: 8px 0 10px; }
.page-h1 .han { font-size: 2rem; }
.app-cta { margin-top: 28px; }
.rad .g small { font-size: 14px; }

/* 급수 */
.badge.grade { background: var(--accent); color: #fff; cursor: pointer; }
.row .g.grade-g { font-family: inherit; font-size: 1.1rem; font-weight: 700; color: var(--accent); width: 3.6rem; }
.row .progress { margin: 4px 0; }
.extra-hun { margin: 2px 0 4px; }
.opts select { font: inherit; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--fg); }

/* hidden 속성이 .btn 등의 display 에 덮이지 않게 */
[hidden] { display: none !important; }
.grid-msg { grid-column: 1 / -1; margin: 8px 0; }
dialog.sheet { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 24px));
  background: var(--card); color: var(--fg); box-shadow: 0 20px 60px #0006; }
dialog.sheet::backdrop { background: #0007; }
dialog.sheet ol { padding-left: 20px; line-height: 1.8; }
.share-ico { display: inline-block; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }
