:root {
  --bg: #e9ecf2; --bg2: #ffffff; --card: #ffffff; --line: #cfd4de; --line2: #e3e6ec; --band: #f2f4f8; --text: #15192a; --muted: #56607a; --accent: #4f6fe0;
  --mok: #2f9e63; --hwa: #e04b4b; --to: #e8b63c; --geum: #f4f4f6; --su: #2a3247;
  --mok-t: #fff; --hwa-t: #fff; --to-t: #1a1a1a; --geum-t: #1a1a1a; --su-t: #fff;
  --up: #e03b3b; --down: #2f6fe0;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: "Noto Sans KR", "Pretendard", -apple-system, "Malgun Gothic", system-ui, sans-serif; font-size: 16px; font-weight: 500; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.app { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--bg2); border-bottom: 2px solid var(--line); box-shadow: 0 1px 4px rgba(20,25,40,.06); }
.topbar-title { font-weight: 700; font-size: 19px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 18px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); }
.content { flex: 1; padding: 12px 12px 76px; }
.view[hidden] { display: none; }

/* form */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.field input[type=text], .field input[type=number], .field select, .field textarea, .list-tools input {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; color: var(--text); width: 100%; min-width: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .field { margin-bottom: 12px; }
.grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--bg2); border: none; padding: 9px 16px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; margin-bottom: 12px; }
.check.inline { margin: 0; }
.date-inputs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.field .date-inputs input[type=number] { width: 74px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 8px; text-align: center; }
.field .date-inputs input[type=number]:first-child { width: 88px; }
.date-inputs em { font-style: normal; color: var(--muted); margin-right: 8px; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); width: 100%; }
.adv { margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.adv summary { cursor: pointer; padding: 4px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px; cursor: pointer; color: var(--text); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--up); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.btn-row.wrap .btn { flex: 0 0 auto; }
.err { color: var(--up); font-size: 13px; margin-top: 8px; min-height: 1em; }

/* chart */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 14px; box-shadow: 0 2px 6px rgba(20,25,40,.07); }
.card h3 { margin: -12px -12px 10px; padding: 9px 12px; font-size: 14px; color: var(--text); font-weight: 700; letter-spacing: .02em; display: flex; justify-content: space-between; align-items: center; background: var(--band); border-bottom: 1px solid var(--line); border-radius: 12px 12px 0 0; }
.card h3 .sub { font-weight: 500; font-size: 13px; color: var(--muted); }
.head-name { font-size: 20px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.head-name .g { font-size: 14px; color: var(--muted); font-weight: 400; }
.head-line { font-size: 14px; color: var(--muted); margin-top: 4px; line-height: 1.6; }
.head-line b { color: var(--text); font-weight: 700; }
.pill { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }

.pillars { display: grid; grid-template-columns: 54px repeat(4, 1fr); gap: 0; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pillars > div { border-right: 1px solid var(--line2); border-bottom: 1px solid var(--line2); padding: 5px 3px; }
.pillars > div:nth-child(5n) { border-right: none; }
.pillars > div:nth-last-child(-n+5) { border-bottom: none; }
.pillars > .cell.head { background: var(--band); border-bottom: 1px solid var(--line); }
.pillars .rowlab { font-size: 12px; font-weight: 600; white-space: nowrap; letter-spacing: -.02em; color: var(--muted); display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.2; background: var(--band); border-right: 1px solid var(--line); }
.pillars .cell { text-align: center; font-size: 14px; display: flex; align-items: center; justify-content: center; flex-direction: column; min-height: 30px; }
.pillars .cell.head { font-size: 13px; color: var(--muted); font-weight: 600; padding-bottom: 2px; }
.pillars .cell.head b { color: var(--text); font-size: 15px; }
.pillars .cell.empty { color: var(--line); }
.gz { width: calc(100% - 4px); margin: 1px 0; border-radius: 9px; box-shadow: 0 1px 2px rgba(0,0,0,.18); padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; position: relative; }
.gz .h { font-size: 38px; font-weight: 900; font-family: "Noto Serif KR", "Batang", serif; text-shadow: 0 1px 1px rgba(0,0,0,.15); }
.gz .k { font-size: 13px; font-weight: 700; margin-top: 4px; }
.gz .ey { position: absolute; top: 4px; right: 5px; font-size: 11px; font-weight: 700; }
.gz.gm::after { content: '空'; position: absolute; top: 3px; left: 5px; font-size: 12px; font-weight: 700; }
.oh-목 { background: var(--mok); color: var(--mok-t); }
.oh-화 { background: var(--hwa); color: var(--hwa-t); }
.oh-토 { background: var(--to); color: var(--to-t); }
.oh-금 { background: var(--geum); color: var(--geum-t); box-shadow: inset 0 0 0 1px #c9ccd6; }
.oh-수 { background: var(--su); color: var(--su-t); }
.t-목 { color: #22894f; } .t-화 { color: #d63c3c; } .t-토 { color: #b8860b; } .t-금 { color: #7a7f8c; } .t-수 { color: #2a3247; }
.jjg { display: flex; flex-direction: column; gap: 2px; width: 100%; }
.jjg div { display: flex; justify-content: center; gap: 4px; font-size: 13px; line-height: 1.25; }
.jjg .jh { font-weight: 800; font-family: "Noto Serif KR", "Batang", serif; font-size: 14px; }
.jjg .js { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; color: var(--muted); }
.ss { font-size: 14px; font-weight: 600; }
.ss.ilgan { color: var(--accent); font-weight: 700; }

.ohbar { display: flex; gap: 4px; margin-top: 6px; }
.ohbar div { flex: 1; text-align: center; border-radius: 8px; padding: 6px 0; font-size: 13px; font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.ohbar div b { display: block; font-size: 20px; }
.ohbar div.zero { opacity: .35; }
.ey-row { display: flex; gap: 12px; font-size: 13px; color: var(--muted); margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); flex-wrap: wrap; }

.strip { display: grid; gap: 0; direction: rtl; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.strip.c10 { grid-template-columns: repeat(10, 1fr); }
.strip.c12 { grid-template-columns: repeat(12, 1fr); }
.strip .col { direction: ltr; text-align: center; padding: 0 0 4px; cursor: pointer; background: var(--bg2); border-left: 1px solid var(--line2); }
.strip .col:last-child { border-left: none; }
.strip .col:hover { background: var(--band); }
.strip .col.sel { background: #e6edff; box-shadow: inset 0 0 0 2px var(--accent); }
.strip .col.now .age { background: var(--accent); color: #fff; }
.strip .age { font-size: 13px; font-weight: 700; color: var(--text); background: var(--band); border-bottom: 1px solid var(--line2); padding: 3px 0 2px; }

.strip .yr { font-size: 10px; color: var(--muted); padding-top: 2px; }
.strip .gzs { margin: 3px auto; width: 30px; border-radius: 5px; font-size: 19px; font-weight: 800; line-height: 1.3; font-family: "Noto Serif KR", "Batang", serif; }
.strip.c12 .gzs { width: 25px; font-size: 16px; }
.strip .gzs + .gzs { margin-top: 2px; }
.strip .ss { font-size: 10px; font-weight: 600; color: var(--muted); line-height: 1.15; }
.strip .gzs.gm { position: relative; }
.strip .gzs.gm::after { content: '空'; position: absolute; top: -2px; right: -1px; font-size: 7px; }
.sec-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 13px; color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 6px 9px; font-size: 14px; background: var(--bg2); }
.tag b { font-weight: 700; }
.tag .p { color: var(--accent); margin-left: 4px; }
.tag .d { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.rel { font-size: 14px; line-height: 1.8; }
.rel > div { border-bottom: 1px solid var(--line2); padding: 2px 0; }
.rel > div:last-child { border-bottom: none; }
.rel b { color: var(--muted); font-weight: 700; margin-right: 6px; font-size: 13px; }
.notes-list { font-size: 13px; color: var(--muted); line-height: 1.6; }
.notes-list li { margin-bottom: 4px; }
details.sec summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; padding: 4px 0; list-style: none; display: flex; justify-content: space-between; }
details.sec summary::after { content: '▾'; }
details.sec[open] summary::after { content: '▴'; }

.consult-note { display: flex; gap: 6px; margin-top: 8px; }
.consult-note textarea { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.note-item { border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; white-space: pre-wrap; }
.note-item .meta { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: 3px; }
.note-item .meta button { background: none; border: none; color: var(--muted); cursor: pointer; }

/* list */
.list-tools { margin-bottom: 10px; }
.list-tools input { margin-bottom: 8px; }
.list .item { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; box-shadow: 0 1px 3px rgba(20,25,40,.06); }
.list .item:hover { border-color: var(--accent); }
.list .item .dp { width: 34px; text-align: center; font-family: "Noto Serif KR", serif; font-size: 20px; font-weight: 800; line-height: 1.1; border-radius: 6px; padding: 3px 0; }
.list .item .info { flex: 1; min-width: 0; }
.list .item .nm { font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.list .item .nm span { font-size: 13px; color: var(--muted); font-weight: 400; }
.list .item .bd { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .item .hj { font-family: "Noto Serif KR", serif; font-size: 15px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: 13px; }

/* calendar */
.cal-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cal-title { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.cal-sub { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg2); }
.cal-grid .wd { text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); padding: 6px 0; background: var(--band); border-bottom: 1px solid var(--line); }
.cal-grid .wd.sun { color: var(--up); } .cal-grid .wd.sat { color: var(--down); }
.cal-grid .dc { background: var(--card); border-right: 1px solid var(--line2); border-bottom: 1px solid var(--line2); min-height: 72px; padding: 4px 2px; text-align: center; font-size: 12px; position: relative; }
.cal-grid .dc:nth-child(7n) { border-right: none; }
.cal-grid .dc.blank { background: var(--band); }
.cal-grid .dc .dn { font-size: 13px; font-weight: 700; }
.cal-grid .dc.sun .dn { color: var(--up); } .cal-grid .dc.sat .dn { color: var(--down); }
.cal-grid .dc.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-grid .dc .gj { font-family: "Noto Serif KR", serif; font-size: 17px; font-weight: 800; line-height: 1.15; margin: 2px auto; width: 28px; border-radius: 4px; }
.cal-grid .dc .ln { color: var(--muted); font-size: 11px; }
.cal-grid .dc .jq { color: var(--accent); font-size: 11px; font-weight: 700; }

/* settings */
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line2); font-size: 14px; }
.set-row:last-child { border-bottom: none; }
.set-row .lab { flex: 1; }
.set-row .lab small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.set-row select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; white-space: pre-wrap; word-break: break-all; color: #3a4052; }

.bottomnav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 520px; display: flex; background: var(--bg2); border-top: 2px solid var(--line); box-shadow: 0 -2px 6px rgba(20,25,40,.06); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.bottomnav button { flex: 1; background: none; border: none; padding: 8px 0 7px; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; }
.bottomnav button i { font-style: normal; font-size: 18px; line-height: 1; }
.bottomnav button.on { color: var(--accent); background: #eef2ff; }
.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: #2a3247; color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 9; }
.toast.show { opacity: 1; }
@media (max-width: 380px) { .gz .h { font-size: 32px; } .strip .gzs { font-size: 16px; width: 26px; } .pillars { grid-template-columns: 50px repeat(4, 1fr); } }

/* 입력 폼을 카드로 감싸 배경과 분리 */
#inputForm { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 12px 12px; box-shadow: 0 2px 6px rgba(20,25,40,.07); }
.list-tools { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.cal-nav { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.strip:not(:has(.col)) { border: none; }
.strip .small { padding: 6px 2px; }
.list .item .del { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 13px; color: var(--up); cursor: pointer; flex: 0 0 auto; }
.list .item .del:hover { background: #fff0f0; border-color: var(--up); }
.ss.dim { color: var(--muted); font-weight: 500; }
.card[hidden] { display: none; }

/* 목록: 등록일 필터·그룹 */
.list-filter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chips button { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 5px 11px; font-size: 13px; cursor: pointer; color: var(--text); }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips button em { font-style: normal; font-size: 11px; opacity: .8; margin-left: 2px; }
.chips.months { margin-bottom: 8px; }
.chips.months .small { margin-right: 2px; }
.range { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); width: 100%; }
.range input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
#listSort { margin-left: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.list-count { font-size: 13px; color: var(--muted); margin: 6px 2px 8px; }
.list .date-head { position: sticky; top: 55px; z-index: 2; background: var(--bg); padding: 6px 4px 4px; margin: 6px 0 4px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 2px solid var(--line); }
.list .item .reg { font-size: 11px; color: var(--muted); width: 36px; text-align: center; flex: 0 0 auto; }
.range[hidden] { display: none; }
