@font-face { font-family: "Noto Serif KR"; src: url("fonts/noto-serif-kr-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
:root {
  --desk: #d6e2de;
  --ground: #e6eeeb;
  --paper: #f7faf9;
  --label: #d2dfda;
  --ink: #1c2a4e;
  --ink-2: #3a4968;
  --muted: #55657f;
  --rule: #9db1ab;
  --rule-strong: #5c7771;
  --seal: #c3341b;
  --seal-soft: #f6dcd5;
  --warn: #8a4b00;
  --sans: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --serif: "Noto Serif KR", "AppleMyungjo", "Nanum Myeongjo", "Batang", serif;
  --r: 4px;
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #0c1416; --ground: #121b1d; --paper: #18242a; --label: #22323a; --ink: #e4ece9; --ink-2: #c4d0cc; --muted: #9fb0ab;
    --rule: #3c5058; --rule-strong: #6f8a90; --seal: #ff7a5c; --seal-soft: #3a1f19; --warn: #f0b35c; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #0c1416; --ground: #121b1d; --paper: #18242a; --label: #22323a; --ink: #e4ece9; --ink-2: #c4d0cc; --muted: #9fb0ab;
  --rule: #3c5058; --rule-strong: #6f8a90; --seal: #ff7a5c; --seal-soft: #3a1f19; --warn: #f0b35c; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--desk); color: var(--ink); font: 400 1rem/1.6 var(--sans); padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
::selection { background: var(--ink); color: var(--paper); }
input, select, textarea { caret-color: var(--seal); }
html { scrollbar-color: var(--rule-strong) var(--ground); }
a { color: var(--ink); text-underline-offset: .2em; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5rem; text-wrap: balance; }
h1 { font-size: 1.44rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* 상단 바와 탭 */
.bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--rule); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.brand { font: 700 1.2rem/1 var(--serif); text-decoration: none; letter-spacing: .02em; }
.bar-note { font-size: .8125rem; color: var(--ink-2); min-height: 44px; display: inline-flex; align-items: center; }
.tabs { position: fixed; inset: auto 0 0 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--paper); border-top: 1px solid var(--rule); z-index: 6; }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .75rem; color: var(--muted); text-decoration: none; min-height: 44px; }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 700; box-shadow: inset 0 3px 0 var(--ink); }
main { padding: 16px; max-width: 1240px; margin: 0 auto; outline: none; }
.loading { padding: 32px 16px; color: var(--ink-2); }

/* 입력 */
.inputs { display: grid; grid-template-columns: 72px 1fr 1.3fr; gap: 8px; margin-bottom: 12px; }
.field { display: grid; gap: 4px; font-size: .8125rem; color: var(--ink-2); font-weight: 600; }
.field input, .field select { font: 400 1rem/1.4 var(--sans); color: var(--ink); background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--r); min-height: 44px; padding: 8px 10px; width: 100%; }
.field input:focus, .field select:focus { border-color: var(--ink); outline: 2px solid var(--ink); outline-offset: -1px; }
.field.small input { width: 6.5rem; }
.check { display: flex; align-items: center; gap: 8px; font-size: .875rem; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }

/* 성명 칸: 시그니처 */
.form-strip { background: var(--ground); border: 1px solid var(--ink); padding: 14px; }
.cells { display: flex; align-items: stretch; overflow-x: auto; padding: 2px; }
.cells-gap { width: 10px; flex: none; }
.cell { flex: 0 0 72px; display: grid; grid-template-rows: 26px 60px 24px; border: 1px solid var(--ink); margin-left: -1px; background: var(--paper); color: var(--ink); padding: 0; font: inherit; text-align: center; cursor: pointer; position: relative; }
.cell:first-child, .cells-gap + .cell { margin-left: 0; }
.cell > span { display: flex; align-items: center; justify-content: center; }
.c-hangul { background: var(--label); border-bottom: 1px solid var(--rule-strong); font-size: .9375rem; font-weight: 700; }
.c-hanja { font: 700 2.25rem/1 var(--serif); }
.c-empty { font: 500 .8125rem/1 var(--sans); color: var(--muted); border: 1px dashed var(--rule-strong); padding: 6px 8px; border-radius: 2px; }
.c-meta { border-top: 1px solid var(--rule); font-size: .75rem; color: var(--ink-2); gap: 4px; font-variant-numeric: tabular-nums; }
.c-meta b { font-family: var(--serif); color: var(--ink); }
.cell-surname { cursor: default; background: var(--ground); }
.cell.is-active { z-index: 1; box-shadow: inset 0 0 0 3px var(--ink); }
.cell:not(.cell-surname):hover { background: var(--ground); }
.strip-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }
.hint, .note { color: var(--ink-2); font-size: .875rem; }

/* 버튼 */
.primary, .ghost, .more { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: var(--r); font: 600 .9375rem/1.2 var(--sans); cursor: pointer; text-decoration: none; transition: background-color .15s ease-out, transform .15s ease-out; }
.primary { background: var(--ink); color: var(--paper); border: 1px solid var(--ink); }
.primary:hover { background: var(--ink-2); }
.primary:active { transform: translateY(1px); }
.primary:disabled { background: var(--label); color: var(--muted); border-color: var(--rule); cursor: not-allowed; }
.ghost, .more { background: transparent; color: var(--ink); border: 1px solid var(--rule-strong); }
.ghost:hover, .more:hover { background: var(--label); }
.ghost.danger { border-style: dashed; }
.more { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--ink); text-decoration: underline; font: inherit; cursor: pointer; padding: 0; }
.as-link { margin-top: 8px; }

/* 모바일: 한자를 다 고르면 결과를 목록보다 먼저 */
.work { display: flex; flex-direction: column; }
.work .left { display: contents; }
.work .form-strip { order: 1; } .work .picker { order: 2; } .work .result { order: 3; }
.work.is-ready .result { order: 2; } .work.is-ready .picker { order: 3; }

/* 한자 고르기 */
.picker { margin-top: 16px; }
.picker-head h2 { display: flex; align-items: baseline; gap: 8px; }
.count { font: 500 .875rem/1 var(--sans); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.search { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--r); padding: 0 12px; min-height: 44px; color: var(--ink-2); }
.search:focus-within { outline: 2px solid var(--ink); outline-offset: -1px; }
.search input { border: 0; background: transparent; font: 400 1rem/1.4 var(--sans); color: var(--ink); flex: 1; min-width: 0; padding: 10px 0; outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.chip { min-height: 36px; padding: 4px 12px; border: 1px solid var(--rule-strong); border-radius: var(--r); background: var(--paper); color: var(--ink); font: 500 .875rem/1 var(--sans); cursor: pointer; }
.chip-suri { border-style: dashed; }
.chip-suri[aria-pressed="true"] { border-style: solid; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.picks { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; border-top: 1px solid var(--rule); }
.pick { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--rule); padding: 8px 4px; color: var(--ink); font: inherit; cursor: pointer; min-height: 60px; }
.pick:hover { background: var(--paper); }
.p-char { flex: none; width: 52px; height: 52px; display: grid; place-items: center; border: 1px solid var(--ink); background: var(--paper); font: 700 2rem/1 var(--serif); }
.pick.is-chosen .p-char { background: var(--ink); color: var(--paper); }
.p-body { display: grid; gap: 2px; min-width: 0; }
.p-mean { font-weight: 600; overflow-wrap: anywhere; }
.unsure { font-weight: 500; font-size: .8125rem; text-decoration: underline dashed; text-underline-offset: .25em; }
.work + .source { margin-top: 16px; }
.verify-line { font-size: .8125rem; color: var(--ink-2); margin: 10px 0 0; }
.tag { font-weight: 600; color: var(--ink); border: 1px solid var(--ink); border-radius: 2px; padding: 0 5px; margin-right: 6px; font-size: .75rem; }
.p-meta { font-size: .8125rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.empty { padding: 16px; border: 1px dashed var(--rule-strong); color: var(--ink-2); background: var(--ground); }

/* 결과 */
.result { margin-top: 16px; display: grid; gap: 0; border: 1px solid var(--ink); background: var(--ground); }
.block { background: var(--ground); border: 1px solid var(--ink); padding: 14px 16px; }
.result .block, .sheet .block { border: 0; border-top: 1px solid var(--ink); }
.result .block:first-child, .sheet .block:first-child { border-top: 0; }
.sheet { border: 1px solid var(--ink); background: var(--ground); }
.block > h3, .block > h2 { margin: -14px -16px 12px; padding: 6px 16px; background: var(--label); border-bottom: 1px solid var(--rule-strong); font-size: .875rem; color: var(--ink); }
.block.pending > p { border: 1px dashed var(--rule-strong); padding: 10px; }

.block.score { overflow: clip; }
.score-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.total { margin: 0; display: flex; align-items: baseline; gap: 6px; }
.total strong { font: 700 2.75rem/1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.total span { color: var(--ink-2); font-size: .875rem; }
.stamp { width: 84px; height: 84px; flex: none; border-radius: 50%; border: 3px solid var(--seal); box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 4px var(--seal); color: var(--seal); display: grid; place-content: center; text-align: center; transform: rotate(-9deg); line-height: 1.15; }
.stamp span { font-size: .75rem; font-weight: 700; letter-spacing: .08em; }
.stamp strong { font: 700 1.25rem/1.1 var(--serif); letter-spacing: .1em; }
.stamp.land { animation: land .42s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes land { from { opacity: 0; transform: rotate(-9deg) scale(1.6); filter: blur(2px); } to { opacity: 1; transform: rotate(-9deg) scale(1); filter: blur(0); } }
.problems, .warns { margin: 10px 0 0; padding-left: 1.2rem; font-size: .9375rem; }
.problems li { color: var(--ink); font-weight: 700; }
.problems { list-style: square; }
.warns li { color: var(--warn); }
details { margin-top: 10px; font-size: .875rem; color: var(--ink-2); }
summary { cursor: pointer; font-weight: 600; color: var(--ink); min-height: 32px; display: flex; align-items: center; }
details p { margin: 6px 0 0; }
.grid-table, .cand-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid-table th, .grid-table td, .cand-table th, .cand-table td { border-bottom: 1px solid var(--rule); padding: 8px 6px; text-align: left; vertical-align: middle; }
.grid-table thead th { white-space: nowrap; }
.grid-table thead th, .cand-table thead th { font-size: .75rem; color: var(--ink-2); font-weight: 600; background: var(--label); }
.grid-table tbody th { font-weight: 700; display: grid; }
.grid-table tbody th small { font-weight: 400; color: var(--ink-2); font-size: .75rem; }
.num { font-weight: 700; }
.num small { font-weight: 400; color: var(--ink-2); margin-left: 2px; }
.luck { white-space: nowrap; display: inline-block; font-weight: 700; padding: 0 2px; text-decoration-thickness: 2px; text-underline-offset: .28em; }
.luck-good { text-decoration-line: underline; text-decoration-style: solid; }
.luck-mixed { text-decoration-line: underline; text-decoration-style: dashed; color: var(--ink-2); }
.luck-bad { text-decoration-line: line-through; text-decoration-thickness: 3px; color: var(--ink); }
.facts { margin: 0 0 8px; display: grid; gap: 6px; }
.facts { border: 1px solid var(--rule-strong); gap: 0; }
.facts div { display: grid; grid-template-columns: 6.5rem 1fr; border-top: 1px solid var(--rule); }
.facts div:first-child { border-top: 0; }
.facts dt { color: var(--ink); font-size: .8125rem; font-weight: 600; background: var(--label); padding: 6px 8px; border-right: 1px solid var(--rule-strong); }
.facts dd { margin: 0; overflow-wrap: anywhere; padding: 6px 8px; background: var(--paper); }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 10px; }
.flow-node { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--ink); padding: 4px 8px; font-family: var(--serif); }
.flow-node b { font-family: var(--sans); }
.flow-rel { font-size: .75rem; color: var(--ink-2); padding: 0 2px; }
.flow-rel.rel-clash { color: var(--ink); text-decoration: line-through; text-decoration-thickness: 2px; font-weight: 700; }
.flow-rel.rel-generate { text-decoration: underline; text-underline-offset: .25em; }

/* 단일 화면 */
.single { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.single.wide { max-width: 1040px; }
.lede { color: var(--ink-2); }
.find-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.find-bar .search { flex: 1 1 260px; }
.count-line { color: var(--ink-2); font-size: .875rem; margin: 0; }
.find-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; border-top: 1px solid var(--rule); }
.find-grid li { display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--rule); }
.find-grid .p-char { grid-row: span 2; }
.find-grid small { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.source { font-size: .8125rem; color: var(--ink-2); }
.lock { display: flex; gap: 14px; background: var(--ground); border: 1px solid var(--ink); padding: 18px; }
.lock-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lock > svg { width: 28px; height: 28px; color: var(--ink); }
.lock ul { padding-left: 1.1rem; margin: 0 0 10px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.table-wrap { position: relative; overflow-x: auto; background: var(--ground); border: 1px solid var(--ink); }
.cand-table { min-width: 640px; }
.cand-table tbody th { font-weight: 700; white-space: nowrap; }
.cand-table td { white-space: nowrap; }
.cand-name { display: block; }
.cand-hanja { display: block; font: 700 1.25rem/1.3 var(--serif); }
.marks span + span { margin-left: 6px; }
.cand-table thead th { white-space: nowrap; }
.row-actions { text-align: right; }
.row-actions .ghost + .ghost { margin-left: 6px; }
.row-actions .ghost { min-height: 36px; padding: 4px 10px; font-size: .8125rem; }
.is-held .cand-name, .is-held .cand-hanja { text-decoration: line-through; color: var(--muted); }
.held-mark { display: inline-block; margin-top: 2px; font-size: .75rem; color: var(--ink); border: 1px dashed var(--ink); padding: 0 6px; border-radius: 2px; transform: rotate(-4deg); }
.vote-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
fieldset { min-width: 0; border: 0; border-top: 1px solid var(--rule-strong); padding: 10px 0 0; display: grid; gap: 8px; margin: 0; }
legend { font-weight: 700; padding: 0 4px; }
.verdict { margin-top: 12px; border-top: 1px solid var(--rule); padding-top: 12px; }
.verdict-name { font: 700 1.6rem/1.2 var(--sans); margin: 0 0 4px; }
.saju-form .inputs { grid-template-columns: 1fr 1fr; }
.feedback { color: var(--ink); font-weight: 700; margin: 8px 0 0; border: 1px dashed var(--ink); padding: 8px; }
.feedback:empty { display: none; }
.pillars { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--ink); }
.pillar { display: grid; text-align: center; border-left: 1px solid var(--ink); }
.pillar:first-child { border-left: 0; }
.p-label { background: var(--label); font-size: .8125rem; font-weight: 700; padding: 4px; border-bottom: 1px solid var(--rule-strong); }
.p-han { font: 700 1.9rem/1.5 var(--serif); }
.p-ko { font-size: .8125rem; color: var(--ink-2); border-top: 1px solid var(--rule); padding: 4px; }
.elements { display: grid; gap: 6px; margin-bottom: 12px; }
.el-row { display: grid; grid-template-columns: 6.5rem 1fr 4.5rem; align-items: center; gap: 8px; }
.el-name { font: 700 1.1rem/1 var(--serif); }
.el-name small { font: 400 .75rem/1 var(--sans); color: var(--ink-2); }
.el-cells { display: flex; gap: 0; }
.el-cells i { width: 22px; height: 22px; border: 1px solid var(--rule-strong); margin-left: -1px; }
.el-cells i.on { background: var(--ink); border-color: var(--ink); }
.el-count { font-size: .8125rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.el-row.is-lack .el-name, .el-row.is-lack .el-count { font-weight: 700; }
.el-row.is-lack .el-cells i { border-color: var(--ink); border-style: dashed; border-width: 2px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 8px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r); font-size: .9375rem; opacity: 0; pointer-events: none; transition: opacity .2s ease-out, transform .2s ease-out; z-index: 9; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
#print-note { display: none; }

@media (max-width: 599px) {
  .cand-table { min-width: 0; }
  .cand-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cand-table tbody tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name num" "marks marks" "flow flow" "reg act"; gap: 6px 10px; padding: 12px; border-bottom: 1px solid var(--ink); }
  .cand-table tbody tr:last-child { border-bottom: 0; }
  .cand-table tbody th, .cand-table tbody td { border: 0; padding: 0; white-space: normal; }
  .cand-table tbody th { grid-area: name; }
  .cand-table td.num { grid-area: num; font-size: 1.5rem; text-align: right; }
  .cand-table td.marks { grid-area: marks; }
  .cand-table td.flow { grid-area: flow; color: var(--ink-2); font-size: .875rem; }
  .cand-table td.reg { grid-area: reg; align-self: center; font-size: .875rem; }
  .cand-table td.row-actions { grid-area: act; }
}
@media (min-width: 600px) {
  .picks { grid-template-columns: 1fr 1fr; column-gap: 16px; }
  .find-grid { grid-template-columns: 1fr 1fr; column-gap: 16px; }
  .vote-grid { grid-template-columns: 1fr 1fr; }
  .cell { flex-basis: 84px; grid-template-rows: 28px 68px 26px; }
  .c-hanja { font-size: 2.6rem; }
}
@media (min-width: 960px) {
  body { padding-bottom: 0; display: grid; grid-template-columns: 184px 1fr; grid-template-rows: auto 1fr; }
  .bar { grid-column: 1 / -1; }
  .tabs { position: sticky; top: 57px; height: auto; align-self: start; grid-template-columns: 1fr; grid-auto-rows: 52px; border-top: 0; border-right: 1px solid var(--rule); background: transparent; padding: 12px 0; }
  .tabs a { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 0 20px; font-size: .9375rem; }
  .tabs a[aria-current="page"] { box-shadow: inset 0 0 0 2px var(--ink); background: var(--ground); margin: 0 10px; padding: 0 10px; }
  main { padding: 24px; width: 100%; }
  .toast { bottom: 24px; }
}
@media (min-width: 1120px) {
  .work { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
  .work .left { display: block; }
  .result { margin-top: 0; position: sticky; top: 81px; max-height: calc(100vh - 100px); overflow-y: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
  body { background: #fff; color: #000; display: block; padding: 0; }
  body > *:not(#print-note) { display: none !important; }
  #print-note { display: block; font: 12pt/1.6 var(--sans); }
  #print-note h1 { font: 700 20pt/1.2 var(--serif); }
  #print-note article { border-top: 1px solid #000; padding: 10pt 0; break-inside: avoid; }
  #print-note h2 span { font-family: var(--serif); margin-left: 8pt; }
  #print-note .small { font-size: 9pt; }
}
