/* ==========================================================
   Design System & Tokens
========================================================== */
:root {
  --primary:      #2c3e50;
  --accent:       #d4af37;
  --bg-app:       #f4f7f6;
  --bg-panel:     rgba(255,255,255,0.85);
  --text-main:    #333;
  --text-muted:   #666;
  --border-color: #ddd;
  --paper-bg:     #fdfcf7;
  --paper-border: #d4c4b7;
  --shadow:       0 10px 30px rgba(0,0,0,0.08);
  --glass-blur:   12px;
  --accent-color: #b14b3c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
}


/* ==========================================================
   Header
========================================================== */
.hdr h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin:  10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hdr h1 a {
  text-decoration: none;
  background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-family: 'Inter', sans-serif;
}

.hdr .sub-title {
  color: var(--text-main);
  letter-spacing: -1px;
  text-shadow: 1px 1px 0 var(--bg-panel), 2px 2px 0 var(--border-color);
}

.hdr .badge {
  font-size: 0.65rem;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  letter-spacing: 1px;
  margin-left: 2px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}


/* ==========================================================
   Layout
========================================================== */
.wrap {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
}


/* ==========================================================
   Input Panel (Sidebar)
========================================================== */
.inp {
  width: 380px;
  min-width: 320px;
  background: var(--bg-panel);
  backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 85px);
  position: sticky;
  top: 85px;
  z-index: 50;
  box-shadow: 10px 0 30px rgba(0,0,0,0.02);
}

.inp-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.inp-footer {
  padding: 16px 24px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -5px 15px rgba(0,0,0,0.03);
}

.stit {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1.8rem 0 0.8rem;
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 4px solid var(--accent);
  padding-left: 10px;
}
.stit:first-child { margin-top: 0; }

.stit_s {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin: 2.8rem 0 0.8rem;
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 4px solid #000;
  padding-left: 10px;
}
.stit_s:first-child { margin-top: 5px; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
  margin: 14px 0 6px;
}

.sub-info {
  font-size: 0.75rem;
  color: #e74c3c;
  margin-bottom: 8px;
  display: block;
  font-style: italic;
}

/* 고인 성별 */
.non-blood-gender-wrap {
    display: none;
    margin-top: 0px;
}

.non-blood-gender-wrap .stit-help {
    /* 필요한 경우 기존 stit-help 외 추가 스타일 정의 */
}

.gender-radio-group {
    display: flex;
    gap: 12px;
    margin-top: -15px;
    margin-bottom: 15px;
}

.gender-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.92rem;
}

select, input[type=text], input[type=number], input[type=date] {
  width: 100%;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #ced4da;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}
select:focus, input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(212,175,55,0.15);
}

.r2, .r3 { display: flex; gap: 10px; }
.r2 > div, .r3 > div { flex: 1; }

/* 날짜 행 */
.date-row { margin-bottom: 4px; }


/* ==========================================================
   Date Quick Buttons
========================================================== */
.date-quick { display: flex; gap: 8px; margin-top: 8px; }

.dqbtn {
  flex: 1;
  padding: 8px 5px;
  font-size: 0.8rem;
  background: #fff;
  border: 1px solid #ced4da;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
  text-align: center;
}
.dqbtn:hover  { background: #f8f9fa; border-color: var(--accent); color: var(--accent); }
.dqbtn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ==========================================================
   Buttons
========================================================== */
.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.bp { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(44,62,80,0.2); }
.bp:hover  { background: #34495e; transform: translateY(-2px); }
.bp:active { transform: translateY(0); }

.bs {
  background: #f1f3f5;
  color: var(--text-main);
  font-size: 0.82rem;
  margin-top: 10px;
  border: 1px solid #dee2e6;
}
.bs:hover { background: #e9ecef; }

.graybtn {
  background: #fff;
  border: 1px solid #ced4da;
  padding: 0 10px;
  height: 44px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  white-space: nowrap;
  width: fit-content;
}
.graybtn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ─── 발음 토글 버튼 ─── */
.tool-toggle {
  display: inline-flex;
  align-items: center;
  height: 44px;
  border: 1px solid #ced4da;
  border-radius: 8px;
  background: #fff;
  padding: 0 14px 0 12px;
  gap: 9px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
  white-space: nowrap;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  font-family: inherit;
}
.tool-toggle:hover { border-color: #adb5bd; color: #555; }

.tgl-track {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: #ced4da;
  position: relative;
  transition: background 0.18s;
  flex-shrink: 0;
}
.tgl-track::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: left 0.18s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.tool-toggle.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #f0f3f6;
}
.tool-toggle.active .tgl-track { background: var(--primary); }
.tool-toggle.active .tgl-track::after { left: 16px; }


/* ==========================================================
   Output Panel
========================================================== */
.out {
  flex: 1;
  padding: 40px;
  overflow-y: auto;
  height: calc(100vh - 85px);
  background: #ebedef;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tip {
  max-width: 800px;
  width: 100%;
  background-color: #fff3cd;
  border-left: 5px solid var(--accent);
  padding: 20px 24px;
  border-radius: 12px;
  font-size: 0.9rem;
  color: #856404;
  line-height: 1.8;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.toolrow {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  width: 100%;
  max-width: 794px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}


/* ==========================================================
   Font Size Control Bar
========================================================== */
.font-ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  width: 100%;
  max-width: 794px;
  justify-content: center;
  padding: 8px 14px;
  background: rgba(255,255,255,0.7);
  border: 1px solid #e2e2e2;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.font-ctrl-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 82px;
  text-align: right;
  margin-right: 2px;
}

.font-ctrl-btn {
  width: 30px;
  height: 30px;
  border: 1px solid #ced4da;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.05rem;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}
.font-ctrl-btn:hover  { border-color: var(--accent); color: var(--accent); background: #fffbf0; }
.font-ctrl-btn:active { background: #fef3cd; }

.font-ctrl-val {
  min-width: 44px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: 'Inter', monospace;
}
.font-ctrl-val--changed { color: #c0392b; }

.font-ctrl-reset {
  padding: 5px 11px;
  border: 1px solid #ced4da;
  background: #f8f9fa;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  margin-left: 10px;
  user-select: none;
}
.font-ctrl-reset:hover { margin-left: 10px; border-color: var(--accent); color: var(--accent); background: #fffbf0; }


/* ==========================================================
   Tabs
========================================================== */
.tab-row {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin: 10px 0 20px;
  width: 100%;
}

.tab-btn {
  padding: 10px 30px;
  border: 1px solid var(--border-color);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.tab-btn:hover  { border-color: var(--accent); color: var(--accent); }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.tab-content        { display: none; width: 100%; flex-direction: column; align-items: center; }
.tab-content.active { display: flex; }


/* ==========================================================
   Paper — 공통
========================================================== */
#paperCapture,
#paperCapture_jibang {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  background: #fdfcf7;
  border: 1px solid #d4c4b7;
  border-radius: 4px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.08);
  padding: 15px 10px;
  position: relative;
  overflow: hidden;
}

#paperCapture::before,
#paperCapture_jibang::before {
  content: '';
  position: absolute;
  top: 9px; left: 9px; right: 9px; bottom: 9px;
  border: 1px solid #e6dace;
  pointer-events: none;
  z-index: 0;
}

.paper {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 1123px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

/* 세로 글자 배열 */
.vbox {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: var(--col-gap, 16px);
  direction: rtl;
  unicode-bidi: bidi-override;
  padding: var(--pad-y, 24px) var(--pad-x, 28px) 0 5px;
}

.vcol {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 430px;
  direction: ltr;
}

.c-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-left: 10px;
  margin-bottom: 3px;
  min-height: var(--cell-h, 36px);
}

.sp {
  height: var(--cell-h, 36px);
  width: 100%;
}

/* 한자 */
.hj {
  font-family: 'cwTeXKai', 'Gungsuh', '궁서', serif;
  font-size: var(--hj-size, 28px);
  color: #111;
  line-height: 1;
  width: 0.97em;
  text-align: center;
  font-weight: 500;
  letter-spacing: var(--track, 0px);
}

/* 한글 발음 — 축문용 */
.hg {
  font-family: 'Malgun Gothic', sans-serif;
  font-size: var(--hg-size, 11px);
  color: #b14b3c;
  width: 0.8rem;
  text-align: left;
  margin-right: 2px;
  margin-left: 10px;
  line-height: 1;
}


/* ==========================================================
   Paper — 지방 전용
========================================================== */
#paperCapture_jibang { width: 397px; }

#paperCapture_jibang .vbox {
  justify-content: center;
  padding: 30px !important; /* fix: 단위 px 추가 */
  height: 100%;
  min-height: 1123px;
}

#paperCapture_jibang .vcol {
  justify-content: center;
  min-height: auto;
}

#paperCapture_jibang .c-wrap {
  margin-bottom: 6px;
  min-height: var(--cell-h, 54px);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 지방 한자 */
#paperCapture_jibang .hj {
  font-size: var(--hj-size, 42px);
  width: 1.16em;
}

/* 지방 한글 발음 */
#paperCapture_jibang .hg {
  font-size: var(--hg-size, 13px);
  width: auto;
  margin-left: 0;
  margin-right: 1px;
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  text-align: right;
  white-space: nowrap;
}


/* ==========================================================
   Help Modal
========================================================== */
.help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  margin-left: 6px;
  border-radius: 50%;
  border: 1px solid #888;
  color: #555;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  vertical-align: middle;
  background: #fff;
  user-select: none;
}
.help-link:hover { background: #f3f3f3; color: #222; border-color: #666; }

.label-help  { display: flex; align-items: center; gap: 4px; }
.stit-help   { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.help-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: none; align-items: center; justify-content: center; z-index: 9999; padding: 18px; }
.help-modal.show { display: flex; }

.help-box {
  width: min(92vw, 560px);
  max-height: 85vh;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  border: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid #eee;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
  flex-shrink: 0;
}
.help-head h3 { margin: 0; font-size: 1.05rem; }

.help-close {
  border: none;
  background: #f2f2f2;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.help-close:hover { background: #e7e7e7; }

.help-body {
  padding: 12px 16px 16px;
  font-size: 0.93rem;
  line-height: 1.55;
  color: #222;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.help-body .mini { display: block; margin-top: 10px; color: #666; font-size: 0.88rem; }

.help-group       { margin: 0 0 10px; }
.help-group-title { margin: 0 0 5px; font-size: 0.98rem; font-weight: 800; color: #111; border-bottom: 1px solid #eee; padding-bottom: 3px; }
.help-section     { margin-bottom: 8px; }
.help-section-title { margin: 0 0 2px; font-size: 0.93rem; font-weight: 700; color: #222; }
.help-section-body  { white-space: pre-line; line-height: 1.42; color: #444; font-size: 0.9rem; }


/* ==========================================================
   Surname / Bongan Dropdown
========================================================== */
.surname-search-wrap { position: relative; }

.surname-dropdown {
  display: none;
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1px solid #ced4da;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 6px 16px rgba(0,0,0,0.10);
}
.surname-dropdown.open { display: block; }

.sd-item {
  padding: 8px 12px;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.12s;
}
.sd-item:last-child          { border-bottom: none; }
.sd-item:hover, .sd-item.focused { background: #f8f4e8; }

.sd-hj  { font-family: 'cwTeXKai','Gungsuh','궁서',serif; font-size: 1.1rem; color: #222; min-width: 1.4rem; text-align: center; }
.sd-hg  { color: #555; font-size: 0.82rem; }
.sd-cnt { margin-left: auto; font-size: 0.75rem; color: #999; }
.sd-empty { padding: 10px 12px; font-size: 0.85rem; color: #999; text-align: center; }


/* ==========================================================
   Footer
========================================================== */
.main-footer {
  width: 100%;
  margin-top: 50px;
  padding: 30px 0;
  border-top: 1px solid #ececec;
  background-color: #fcfcfc;
  text-align: center;
}

.footer-content { font-size: 13px; color: #999; letter-spacing: -0.02em; }
.footer-content .brand  { font-weight: 700; color: #444; margin-right: 5px; }
.footer-content .links  { margin-bottom: 5px; }
.footer-content .links a { color: #777; text-decoration: none; transition: color 0.2s; }
.footer-content .links a:hover { color: #222; }
.footer-content .sep    { margin: 0 8px; color: #ddd; font-weight: 300; }
.footer-content .email-box { margin-top: 5px; }


/* ==========================================================
   Example Section
========================================================== */
.example-wrap {
  display: flex;
  gap: 20px;
  margin-top: 20px;
  align-items: flex-start;
  justify-content: center;
}

.example-item        { text-align: center; }
.example-item.chukmun { width: 397px; }
.example-item.jibang  { width: 198px; }

.img-container {
  border: 1px solid #e1e1e1;
  background-color: #f9f9f9;
  padding: 10px;
  border-radius: 4px;
  height: 561px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.img-container img { width: 100%; height: 100%; object-fit: contain; display: block; }

.example-caption { margin-bottom: 10px; font-size: 14px; color: #333; font-weight: bold; }


/* ==========================================================
   Print
========================================================== */
@media print {
  @page { size: A4; margin: 0; }

  header, .hdr, .inp, .tip, .toolrow, .font-ctrl-row, .optrow, .phbox { display: none !important; }

  body { background: #fff; padding: 0; margin: 0; }
  .wrap { display: block; max-width: none; margin: 0; }
  .out  { padding: 0; height: auto; overflow: visible; background: #fff; display: block; }

  #paperCapture,
  #paperCapture_jibang {
    width: 210mm !important;
    height: 297mm !important;
    border: none;
    box-shadow: none;
    margin: 0 !important;
    padding: 10mm !important;
    background: white;
  }
  #paperCapture_jibang { width: 105mm !important; }

  #paperCapture::before,
  #paperCapture_jibang::before {
    top: 2.5mm; left: 2.5mm; right: 2.5mm; bottom: 2.5mm;
    border: 0.25mm solid #d9d0c7;
  }

  .vbox   { gap: 3mm; padding: 0 1mm; }
  .vcol   { min-height: 117.5mm; }
  .c-wrap { min-height: 6.75mm; margin-bottom: 0.4mm; }
  .sp     { height: 6.75mm; }

  .hj { font-size: 13pt; width: 7mm; color: #000; }
  .hg { font-size: 3.25pt; width: 2mm; color: #000; margin-right: 0.1mm; margin-left: 30px; }
}


/* ==========================================================
   Mobile — 1024px 이하
========================================================== */
@media (max-width: 1024px) {
  .wrap {
    flex-direction: column;
  }

  .inp {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .out { padding: 20px 10px; height: auto; }

  #paperCapture {
    width: 210mm !important;
    height: 297mm !important;
    max-width: 794px;
    aspect-ratio: 794 / 1123;
  }

  #paperCapture_jibang {
    width: 100mm !important;
    height: 297mm !important;
    max-width: 397px;
    aspect-ratio: 397 / 1123;
  }

  .font-ctrl-row  { gap: 5px; padding: 7px 10px; }
  .font-ctrl-label { font-size: 0.78rem; min-width: 72px; }
  .font-ctrl-btn  { width: 28px; height: 28px; font-size: 1rem; }
  .font-ctrl-val  { font-size: 0.78rem; min-width: 38px; }
  .font-ctrl-reset { font-size: 0.74rem; padding: 4px 9px; }

  .example-wrap { flex-direction: column; align-items: center; gap: 30px; }
  .example-item.chukmun,
  .example-item.jibang { width: 100%; max-width: 350px; }
  .img-container { height: auto; aspect-ratio: 1 / 1.4; max-height: 450px; }
}


.mobile-only {
  display: none !important;
}

@media (max-width: 768px) {
  .mobile-only {
    display: inline-flex !important;
  }

  #paperCapture_jibang .hg {
    margin-right: 1px;
  }

  .help-modal {
    padding: 12px;
  }
  .help-box {
    width: 95vw;graybtn
    max-height: 88vh;
    border-radius: 14px;
  }
  .help-head {
    padding: 13px 14px 11px;
  }
  .help-body {
    padding: 11px 14px 14px;
    font-size: 0.92rem;
  }

  .help-group {
    margin: 0 0 9px;
  }
  .help-group-title {
    font-size: 0.95rem;
    margin: 0 0 5px;
  }
  .help-section {
    margin-bottom: 7px;
  }
  .help-section-title {
    font-size: 0.91rem;
  }
  .help-section-body {
    font-size: 0.88rem;
    line-height: 1.4;
  }
}