/* 레이아웃: 왼쪽은 작성 패널, 오른쪽은 A4 용지 미리보기. 좁은 화면에서는 위아래로 쌓음 */
:root {
  --bg: #e9ecef;
  --surface: #ffffff;
  --surface-2: #f3f5f7;
  --fg: #1b2330;
  --muted: #5b6573;
  --line: #d3d8de;
  --accent: #23446e;
  --accent-fg: #ffffff;
  --seal: #b3302a;
  --warn-bg: #fbe9e6;
  --ok: #2f6b4a;
  --paper: #fdfdfb;
  --paper-ink: #1a1f27;
  --paper-faint: #9aa2ad;
  --paper-rule: #c9ced5;
  --font-ui: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-doc: "Nanum Myeongjo", "HY신명조", "Batang", "AppleMyungjo", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --surface: #1a2029; --surface-2: #222a35; --fg: #e4e8ee; --muted: #9aa5b3;
    --line: #313a47; --accent: #8fb0dc; --accent-fg: #0f1722; --seal: #f08a80; --warn-bg: #f6dcd7;
    --ok: #7cc49c; --paper: #f4f3ef; --paper-ink: #1a1f27; --paper-faint: #8e96a1; --paper-rule: #c4c9d0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1a2029; --surface-2: #222a35; --fg: #e4e8ee; --muted: #9aa5b3;
  --line: #313a47; --accent: #8fb0dc; --accent-fg: #0f1722; --seal: #f08a80; --warn-bg: #f6dcd7;
  --ok: #7cc49c; --paper: #f4f3ef; --paper-ink: #1a1f27; --paper-faint: #8e96a1; --paper-rule: #c4c9d0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 14px; line-height: 1.55;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 40px;
}
.wrap { max-width: 1240px; margin: 0 auto; display: grid; gap: 20px; }
header.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
header.top h1 { font-family: var(--font-doc); font-weight: 800; font-size: 26px; margin: 0; letter-spacing: -0.01em; }
header.top p { margin: 0; color: var(--muted); font-size: 13px; }
.main { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 880px) { .main { grid-template-columns: minmax(0, 1fr); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 16px; min-width: 0; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .row { grid-template-columns: 1fr; } }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg button:focus-visible, .btn:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, [contenteditable]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
input[type=text], select, textarea {
  width: 100%; font: inherit; color: var(--fg); background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.6; }
textarea.mono { font-family: ui-monospace, "D2Coding", "Consolas", monospace; font-size: 13px; white-space: pre; overflow-x: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn { font: inherit; font-weight: 600; border-radius: 8px; padding: 10px 16px; cursor: pointer; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.status { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.status.err { color: var(--seal); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -1px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* 미리보기 */
.preview { display: grid; gap: 12px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.chip.bad { color: var(--seal); border-color: color-mix(in srgb, var(--seal) 50%, var(--line)); }
.chip.ex { color: var(--accent); }
.paper {
  container-type: inline-size; background: var(--paper); color: var(--paper-ink); border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 8px 28px rgba(20,30,45,.12);
  padding: clamp(18px, 6%, 56px) clamp(14px, 6%, 56px); min-width: 0;
}
.doc { --cap: 34; font-family: var(--font-doc); font-size: min(18px, calc(100cqw / (var(--cap) + 3))); line-height: 1.75; word-spacing: 0.22em; margin: 0 auto; width: calc((var(--cap) + 0.2) * 1em); max-width: 100%; position: relative; }
.doc [contenteditable] { border-radius: 2px; }
.doc [contenteditable]:hover { background: rgba(35,68,110,.06); }
.org { text-align: center; font-weight: 800; font-size: 1.45em; letter-spacing: 0.08em; margin-bottom: 1.2em; }
.hdr { display: flex; gap: 0; }
.hdr .lab { flex: none; width: 4em; }
.hdr .val { flex: 1; min-width: 0; }
.hdr.ttl .val { font-weight: 700; }
.rule { border: 0; border-top: 1px solid var(--paper-rule); margin: 0.6em 0 0.9em; }
.it { display: flex; position: relative; padding-left: calc(var(--ind) * 1em); }
.it .sym { flex: none; }
.it .body { flex: 1; min-width: 0; word-break: keep-all; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.it.over .tx { background: var(--warn-bg); box-shadow: 0 0 0 2px var(--warn-bg); }
.ln { position: absolute; right: -2.4em; top: 0.35em; font-family: var(--font-ui); font-size: 0.55em; color: var(--paper-faint); font-variant-numeric: tabular-nums; }
.it.over .ln { color: #b3302a; font-weight: 700; }
.end { white-space: pre; }
.att { display: flex; margin-top: 1em; }
.att .lab { flex: none; width: 3em; }
.att .list { flex: 1; min-width: 0; }
.rtitle { text-align: center; font-weight: 800; font-size: 1.3em; border: 1.5px solid var(--paper-ink); padding: 0.45em 0.6em; margin-bottom: 1.3em; text-wrap: balance; }
.rep .it[style*="--ind:0"] { margin-top: 0.7em; font-weight: 700; }
.rep .it[style*="--ind:0"]:first-of-type { margin-top: 0; }
.empty { color: var(--paper-faint); text-align: center; padding: 3em 0; font-family: var(--font-ui); font-size: 0.8em; }
.notes { font-size: 12px; color: var(--muted); margin: 0; }
.drop { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px; border: 1.5px dashed var(--line); border-radius: 8px; }
.drop.on { border-color: var(--accent); background: var(--surface-2); }

body { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
.top nav { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.top .intro { flex: 1 1 100%; max-width: 850px; }
.version { color: var(--muted); font-size: 12px; }
.disclaimer { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.brand { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 24px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.brand img { display: block; height: 20px; width: auto; }
.brand .credit { flex: 1 1 100%; }
.build-page { max-width: 780px; }
.build-page h2 { font-size: 17px; margin: 0 0 12px; }
.build-page section { border-top: 1px solid var(--line); padding-top: 20px; }
.build-page ul { margin: 0; padding-left: 22px; }
.build-page li { margin: 8px 0; overflow-wrap: anywhere; }
@media (max-width: 420px) {
  body { padding-inline: 12px; }
  header.top h1 { font-size: 24px; }
  .panel { padding: 14px; }
  .btn { padding: 10px 12px; }
}

@media (max-width: 600px) {
  .paper { overflow-x: auto; padding: 24px; }
  .doc { font-size: 14px; min-width: calc((var(--cap) + 0.2) * 1em); max-width: none; margin-right: 24px; }
  .mobile-note { display: block; }
}
@media (min-width: 601px) { .mobile-note { display: none; } }
