:root {
    --bg: #ffffff;
    --fg: #1f2328;
    --muted: #656d76;
    --line: #d8dee4;
    --panel: #f6f8fa;
    --accent: #0969da;
    --radius: 8px;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    /* 큰 표시 글자에만 쓰는 웹폰트. 목록·칩까지 이걸로 그리면
       한 페이지가 100자 넘게 요구해 폰트 조각을 수십 개 받게 된다. */
    --font-hanja: "LXGW WenKai TC", "Noto Serif KR", "Apple SD Gothic Neo",
        "Malgun Gothic", "Songti SC", "Songti TC", "SimSun", serif;
    --font-hanja-plain: "Noto Serif KR", "Apple SD Gothic Neo", "Malgun Gothic",
        "Songti SC", "Songti TC", "SimSun", serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --fg: #e6edf3;
        --muted: #9198a1;
        --line: #30363d;
        --panel: #161b22;
        --accent: #4493f8;
    }
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-ui);
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 20px 64px;
    line-height: 1.65;
    color: var(--fg);
    background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.site { margin-bottom: 28px; }
header.site .bar { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }

/* 검색창은 브랜드·메뉴 아래 한 줄을 차지한다. 사이에 끼우면 좁은 화면에서
   줄바꿈이 일어나 메뉴가 결과 뒤로 밀린다. */
.search { position: relative; margin-top: 12px; max-width: 420px; }
.search input {
    width: 100%; padding: 8px 12px; font-size: .95em; font-family: inherit;
    color: var(--fg); background: var(--bg);
    border: 1px solid var(--line); border-radius: 6px; box-sizing: border-box;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* 찾아보기 페이지는 검색창을 본문에 세워 첫소리별 목록과 나란히 둔다.
   본문 폭을 쓰므로 머리글 것보다 넓다. */
body > .search { max-width: 520px; margin-bottom: 26px; }
body > .search input { padding: 11px 14px; font-size: 1.05em; }

/* 결과는 문서 흐름 밖에 띄운다. 흐름 안에 두면 아래 내용을 밀어낸다. */
.search .results {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
    max-height: 60vh; overflow-y: auto;
    background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.search .results a {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; border-bottom: 1px solid var(--line);
    color: var(--fg); text-decoration: none;
}
.search .results a:last-child { border-bottom: none; }
.search .results a:hover, .search .results a:focus { background: var(--panel); }
.result-glyph {
    font-family: var(--font-hanja-plain); font-size: 1.7em; line-height: 1;
    min-width: 1.3em; text-align: center; flex-shrink: 0;
}
.result-readings {
    color: var(--muted); font-size: .9em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
header.site .brand { font-weight: 700; font-size: 1.05em; color: var(--fg); }
header.site nav { display: flex; gap: 14px; font-size: .92em; }

.crumbs { font-size: .87em; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }

h1 { font-size: 1.6em; margin: 0 0 8px; line-height: 1.3; }
h2 { font-size: 1.15em; margin: 32px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
h2.plain { padding-bottom: 0; border-bottom: none; }
p.lead { color: var(--muted); margin-top: 0; }

textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    font-size: 16px;
    font-family: inherit;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    resize: vertical;
}

.controls { display: flex; gap: 8px; margin: 10px 0 0; flex-wrap: wrap; align-items: center; }
button {
    padding: 9px 18px;
    font-size: 15px;
    font-family: inherit;
    color: var(--fg);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:hover { filter: brightness(1.06); }
.status { color: var(--muted); font-size: .9em; }
.order { display: flex; align-items: center; gap: 6px; font-size: .9em; color: var(--muted); }
.order select {
    padding: 7px 8px; font-family: inherit; font-size: .95em;
    color: var(--fg); background: var(--bg);
    border: 1px solid var(--line); border-radius: 6px;
}
.card .sub.ja { color: var(--fg); font-family: var(--font-hanja-plain); }
.card .sub.muted { font-size: .8em; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }

.card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}
.card .glyph { font-family: var(--font-hanja); font-size: 2.7em; line-height: 1; min-width: 1.4em; text-align: center; }
.card .body { flex: 1; min-width: 0; }
.card .readings { font-weight: 500; }
.card .sub { color: var(--muted); font-size: .86em; margin-top: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
    padding: 4px 11px;
    font-size: .88em;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    white-space: nowrap;
}
.chip .glyph { font-family: var(--font-hanja-plain); font-weight: 700; margin-right: 3px; }

.error { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--muted); }

/* 한자 상세 페이지 */
.entry-head { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 8px; }
.entry-head .glyph { font-family: var(--font-hanja); font-size: 6em; line-height: 1; }
.entry-head .facts { flex: 1; min-width: 220px; }
.entry-head .korean { font-size: 1.35em; font-weight: 600; margin: 6px 0 10px; }

dl.facts-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts-list dt { color: var(--muted); font-size: .9em; }
dl.facts-list dd { margin: 0; }
.kun-list { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.kun { white-space: nowrap; }
.kun-ko { color: var(--muted); font-size: .88em; margin-left: 6px; }
.card .sub.ja .kun-ko { color: var(--muted); }
.word-list .word-ko { color: var(--fg); font-size: .93em; margin-right: 8px; }
.variants a { font-family: var(--font-hanja-plain); font-size: 1.25em; margin-right: 8px; }
.tag {
    display: inline-block;
    padding: 1px 9px;
    font-size: .84em;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
}
.tag-joyo { border-color: var(--accent); color: var(--accent); }
.tag-muted { color: var(--muted); }


.word-list { list-style: none; padding: 0; margin: 0; }
.word-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.word-list li:last-child { border-bottom: none; }
.word-list .word { font-weight: 600; }
.word-list .word-hanja { font-family: var(--font-hanja-plain); color: var(--muted); margin: 0 8px 0 4px; }
.word-list .word-gloss { color: var(--muted); font-size: .93em; }
.source { color: var(--muted); font-size: .82em; margin-top: 10px; }

.legal p { margin: 0 0 12px; }
.legal h2 { font-size: 1.05em; }
.link-list { padding-left: 20px; margin: 0; }
.link-list li { margin-bottom: 4px; }
.footer-links { margin-top: 10px; }

footer.site { margin-top: 48px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: .86em; }
footer.site a { color: var(--muted); text-decoration: underline; }

.index-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sound-block { margin-bottom: 20px; }
.sound-block h3 { font-size: 1em; margin: 0 0 6px; color: var(--muted); }
.hanja-list { display: flex; flex-wrap: wrap; gap: 8px; }
.hanja-list a { font-family: var(--font-hanja-plain); font-size: 1.5em; line-height: 1.2; }

@media (max-width: 520px) {
    .entry-head .glyph { font-size: 4.4em; }
    body { padding: 16px 14px 48px; }
}
