/* 배치: 위에 파일 동작과 서식 도구, 가운데에 작업 창과 참조 창(탭), 아래에 글자 수와 상태. */
:root {
  --bg: #eef2f1;
  --panel: #ffffff;
  --panel-2: #f5f8f7;
  --line: #d3dcda;
  --fg: #1a2426;
  --muted: #586769;
  --accent: #0b6b64;
  --accent-ink: #ffffff;
  --accent-soft: #d8eeeb;
  --code-bg: #e8efed;
  --warn-bg: #fbeed8;
  --warn-fg: #6b3d07;
  --overlay: rgba(10, 20, 22, .5);
  --font-ui: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", system-ui, sans-serif;
  --font-read: "Noto Serif KR", "Nanum Myeongjo", "나눔명조", "Apple Myungjo", "Batang", "바탕", Georgia, serif;
  --font-edit: "JetBrains Mono", "D2Coding", "Consolas", "Menlo", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", monospace;
  --editor-size: 15px;
  --pv-size: 16.5px;
  --err: #d3302f;
  --mm-w: 72px;
  --find-bg: rgba(255, 205, 60, .55);
  --find-cur: rgba(255, 140, 0, .8);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1516; --panel: #162021; --panel-2: #1b2627; --line: #2a3839;
    --fg: #dce6e4; --muted: #8fa3a3; --accent: #52c7bb; --accent-ink: #06201d;
    --accent-soft: #1d3b38; --code-bg: #1e2b2c; --warn-bg: #3a2c12; --warn-fg: #f0d9a8;
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  padding-inline: 16px;
  padding-block: 12px;
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd { font-family: var(--font-edit); font-size: 11.5px; padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); color: var(--muted); }
.btn.primary kbd { background: transparent; border-color: color-mix(in srgb, var(--accent-ink) 45%, transparent); color: var(--accent-ink); }

.app { height: 100%; display: flex; flex-direction: column; gap: 10px; min-height: 0; }

.btn {
  min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel); color: var(--fg); }

.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.pane-switch, .seg { display: flex; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 2px; gap: 2px; }
.pane-switch button, .seg button { min-height: 34px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; }
.pane-switch button:hover, .seg button:hover { background: var(--accent-soft); }
.pane-switch button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 500; }

.compat { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; }
.compat .btn { min-height: 32px; color: inherit; }

.tools {
  display: flex; align-items: center; gap: 2px; padding: 4px; min-width: 0;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  overflow-x: auto; scrollbar-width: thin;
}
.tools button { flex: 0 0 auto; min-width: 40px; height: 36px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; }
.tools button:hover { background: var(--accent-soft); }
.tools button:disabled { opacity: .4; cursor: not-allowed; background: transparent; }
.tools .sep { flex: 0 0 1px; height: 20px; margin-inline: 4px; background: var(--line); }
.t-b { font-weight: 700; } .t-i { font-style: italic; } .t-s { text-decoration: line-through; }
.t-mono { font-family: var(--font-edit); font-size: 13px; }

/* 두 창 */
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.app[data-side="on"] .panes { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.app[data-side="off"] .pane-1 { display: none; }
.pane {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden;
}
.pane.focused { border-color: var(--accent); }

.phead { flex: 0 0 auto; display: flex; align-items: stretch; gap: 8px; padding-right: 6px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.plabel { flex: 0 0 auto; align-self: center; margin-left: 10px; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 500; }
.tabstrip { flex: 1; min-width: 0; display: flex; overflow-x: auto; scrollbar-width: none; }
.tabstrip::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; max-width: 220px; display: flex; align-items: center; gap: 2px; height: 38px; padding-left: 12px; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; }
.tab:hover { background: var(--panel); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); background: var(--panel); }
.tab .tname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .dot { color: var(--accent); font-size: 11px; }
.tab .x { width: 28px; height: 28px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }
.tab .x:hover { background: var(--accent-soft); color: var(--fg); }
.pseg { align-self: center; border: 0; background: transparent; padding: 0; }
.pseg button { min-height: 30px; padding: 0 10px; font-size: 13px; }

.notice { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 14px; background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; }
.notice .ntext { flex: 1 1 220px; min-width: 0; }
.notice button { min-height: 32px; padding: 0 10px; border: 1px solid currentColor; border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }
.notice button.main { background: var(--warn-fg); color: var(--warn-bg); border-color: var(--warn-fg); }

.pbody { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); position: relative; }
.pane.m-split .pbody { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.pane.m-split .pv { border-left: 1px solid var(--line); }
.pane.m-edit .pv, .pane.m-preview .edwrap { display: none; }
.edwrap { min-width: 0; min-height: 0; position: relative; }
.editor { position: absolute; inset: 0 var(--mm-w) 0 0; z-index: 1; background: transparent; }
.editor .cm-editor { height: 100%; background: transparent; outline: 0; }
.editor .cm-editor.cm-focused { outline: 0; }
.editor .cm-scroller { overflow: auto; font-family: var(--font-edit); font-size: var(--editor-size); line-height: 1.8; }
.editor .cm-content { padding: 16px 20px; caret-color: var(--fg); color: var(--fg); tab-size: 2; }
.editor .cm-line { padding: 0; }
.editor .cm-placeholder { color: var(--muted); white-space: pre-wrap; }
.editor .cm-pairerr { color: var(--err); text-decoration: underline wavy var(--err); text-underline-offset: 3px; text-decoration-thickness: 1.5px; background: color-mix(in srgb, var(--err) 14%, transparent); border-radius: 2px; }
.editor .cm-spell { background: color-mix(in srgb, var(--muted) 30%, transparent); border-radius: 3px; }
.editor .cm-find { background: var(--find-bg); border-radius: 3px; box-shadow: 0 0 0 1px var(--find-bg); }
.editor .cm-find-cur { background: var(--find-cur); box-shadow: 0 0 0 1px var(--find-cur); }
.pv { min-width: 0; min-height: 0; overflow: auto; padding: 22px 28px 40px; }
.pane.empty .edwrap, .pane.empty .pv { display: none; }
.empty-state { display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; padding: 24px; text-align: center; color: var(--muted); }
.pane.empty .empty-state { display: flex; }
.empty-state .row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* 미리보기 글꼴 */
.prose { font-family: var(--font-pv, var(--font-read)); font-size: var(--pv-size, 16.5px); line-height: 1.9; overflow-wrap: anywhere; }
.prose > * { max-width: 42rem; margin-inline: auto; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.4; margin-block: 1.6em .5em; text-wrap: balance; }
.prose h1 { font-size: 1.8em; font-weight: 700; }
.prose h2 { font-size: 1.36em; font-weight: 700; }
.prose h3 { font-size: 1.15em; font-weight: 600; }
.prose h4 { font-size: 1em; font-weight: 600; }
.prose h1.ln, .prose h2.ln, .prose h3.ln { padding-bottom: .25em; border-bottom: 1px solid var(--line); }
.prose h1.nl, .prose h2.nl, .prose h3.nl { padding-bottom: 0; border-bottom: 0; }
.prose .gap { display: block; margin: 0; padding: 0; border: 0; }
.prose p { margin-block: 0 1em; }
.prose a { color: var(--accent); text-underline-offset: 3px; }
.prose a.wl { text-decoration-style: dotted; cursor: pointer; }
.prose a.wl.missing { color: var(--muted); text-decoration-style: wavy; }
.prose mark.find { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.prose blockquote { margin-block: 1.2em; padding: .1em 1.1em; border-left: 3px solid var(--accent); color: var(--muted); }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose ul, .prose ol { margin-block: 0 1em; padding-left: 1.6em; }
.prose li { margin-block: .15em; }
.prose li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.3em; }
.prose li > input[type="checkbox"] { margin-right: .5em; accent-color: var(--accent); }
.prose code { font-family: var(--font-edit); font-size: .86em; padding: .12em .4em; border-radius: 4px; background: var(--code-bg); }
.prose pre { margin-block: 1.2em; padding: 14px 16px; border-radius: 6px; background: var(--code-bg); overflow-x: auto; line-height: 1.6; }
.prose pre code { padding: 0; background: none; font-size: .85rem; }
.prose hr { margin-block: 2em; border: 0; border-top: 1px solid var(--line); }
.prose img { max-width: 100%; height: auto; }
.prose table { display: block; width: fit-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin-block: 1.2em; font-family: var(--font-ui); font-size: .92em; line-height: 1.6; }
.prose th, .prose td { padding: 6px 12px; border: 1px solid var(--line); text-align: left; }
.prose th { background: var(--panel-2); font-weight: 600; }
.prose .blank { color: var(--muted); font-family: var(--font-ui); font-size: 14px; }

/* 아래 줄 */
.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.stats { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.stats b { color: var(--fg); font-weight: 500; }
.foot-right { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.linkish { padding: 2px 4px; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.linkish:hover { color: var(--fg); }
#status { display: flex; align-items: center; gap: 8px; min-height: 28px; }
#status-undo { min-height: 28px; padding: 0 10px; border: 1px solid var(--accent); border-radius: 4px; background: transparent; color: var(--accent); cursor: pointer; }
#status-undo:hover { background: var(--accent-soft); }

/* 팝업 */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; background: var(--overlay); }
.card { width: min(640px, 100%); max-height: 78vh; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 18px 50px rgba(0, 0, 0, .28); overflow: hidden; }
.sw-top { display: flex; align-items: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
#sw-input { flex: 1; min-width: 0; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); font-size: 16px; }
#sw-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.sw-note { padding: 8px 14px; color: var(--muted); font-size: 12.5px; }
.sw-note:empty { display: none; }
.sw-note .btn { margin-top: 8px; }
.sw-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; min-height: 0; }
.sw-item { padding: 8px 14px; cursor: pointer; }
.sw-item.sel { background: var(--accent-soft); }
.sw-name { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.sw-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.sw-name .dir { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.sw-name .cnt { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.sw-snip { margin-top: 2px; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-item mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; }
.sw-empty { padding: 18px 14px; color: var(--muted); }
.sw-hint { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: 12px; }

.st-card { padding-bottom: 8px; overflow-y: auto; }
.st-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.st-head h2 { margin: 0; font-size: 17px; }
.st-sec { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.st-sec:last-child { border-bottom: 0; }
.st-sec h3 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 500; letter-spacing: .04em; }
.st-p { margin: 0; overflow-wrap: anywhere; }
.st-note { margin: 0; color: var(--muted); font-size: 12.5px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.keybtn { min-width: 150px; justify-content: center; font-family: var(--font-edit); }
.keybtn.rec { border-color: var(--accent); background: var(--accent-soft); }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
.st-ta { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.st-ta textarea { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--fg); font: inherit; resize: vertical; }
.inline-checks { display: flex; gap: 14px; }
.inline-checks .check { gap: 6px; align-items: center; }
.inline-checks .check input { margin-top: 0; }
.check code { font-family: var(--font-edit); }
select { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }

/* 좁은 화면: 창을 하나씩 보여 준다 */
@media (min-width: 981px) { .pane-switch { display: none !important; } }
@media (max-width: 980px) {
  .app[data-side="on"] .panes { grid-template-columns: minmax(0, 1fr); }
  .app[data-side="on"][data-vis="0"] .pane-1 { display: none; }
  .app[data-side="on"][data-vis="1"] .pane-0 { display: none; }
}
@media (max-width: 820px) {
  .pseg [data-pmode="split"] { display: none; }
  .pv { padding: 18px 16px 32px; }
  .editor .cm-content { padding: 14px 16px; }
  .overlay { padding-top: 6vh; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .tools button, .seg button, .tab { transition: background-color .12s, border-color .12s; }
}

.sw-hint .seg button { min-height: 28px; padding: 0 10px; font-size: 12px; }

@media (max-width: 600px) {
  .btn.ghost[id^="btn-copy"] { display: none; }
}

/* 글자 색, 그림, 표 편집 */
.t-color { font-weight: 700; color: #d64545; border-bottom: 3px solid #2f74dc; line-height: 1; }
.pop { position: fixed; z-index: 40; width: 244px; max-width: calc(100vw - 24px); padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: 0 10px 30px rgba(0, 0, 0, .22); display: flex; flex-direction: column; gap: 8px; }
.pop[hidden] { display: none; }
.pop.wide { width: 340px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); background: var(--c); cursor: pointer; }
.swatches button:hover { box-shadow: 0 0 0 2px var(--accent); }
.pop-note { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.pop-head { display: flex; align-items: center; justify-content: space-between; }
.pop-status { margin: 0; font-size: 13px; color: var(--muted); }
.pop-status.ok { color: var(--accent); }
.pt-count { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.pt-count input { width: 72px; min-height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--fg); font: inherit; }
.pt-grid { display: grid; grid-template-columns: 28px 1fr 1fr auto; gap: 6px; align-items: center; }
.pt-label { font-weight: 600; font-size: 14px; }
.pt-grid .btn { min-height: 34px; padding: 0 8px; font-size: 13px; }
.btn.danger { color: #b3261e; }
.pt-align { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pop button:disabled { opacity: .4; cursor: not-allowed; }
.prose img { border-radius: 4px; }

/* 문서 안 찾기, 위치 지도 */
@media (prefers-color-scheme: dark) { :root { --find-bg: rgba(255, 205, 60, .32); --find-cur: rgba(255, 140, 0, .6); } }
.mm { position: absolute; top: 0; right: 0; bottom: 0; width: var(--mm-w); z-index: 2; border-left: 1px solid var(--line); background: var(--panel-2); cursor: pointer; touch-action: none; user-select: none; }
.mm canvas { display: block; position: absolute; inset: 0; }
.mm-back { position: absolute; right: 6px; bottom: 6px; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: #7b3fe4; font-size: 16px; cursor: pointer; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
.mm-back:hover { background: var(--accent-soft); }
.mm-tip { position: absolute; right: calc(100% + 6px); width: 190px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); box-shadow: 0 6px 18px rgba(0, 0, 0, .2); font-size: 12.5px; line-height: 1.5; pointer-events: none; z-index: 5; }
.mm-tip[hidden] { display: none; }
.mm-tip span { color: var(--muted); }
.fbar { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.fbar[hidden] { display: none; }
.f-in { flex: 1; min-width: 0; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--fg); font: inherit; }
.f-in:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.f-count { min-width: 56px; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.f-count.none { color: #b3261e; }
.fbar .btn { min-height: 34px; padding: 0 10px; }
.prose mark.find { background: var(--find-bg); color: inherit; border-radius: 3px; }
.prose mark.find.cur { background: var(--find-cur); }
@media (max-width: 600px) { :root { --mm-w: 54px; } }

textarea.editor { width: auto; height: auto; padding: 16px 20px; border: 0; outline: 0; resize: none; font-family: var(--font-edit); font-size: var(--editor-size); line-height: 1.8; tab-size: 2; color: var(--fg); }
@media (max-width: 820px) { textarea.editor { padding: 14px 16px; } }

/* 동선 설계 + 시간계산기 */
.route-overlay { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--bg); }
.route-overlay[hidden] { display: none; }
.route-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.route-note { font-size: 13px; color: var(--muted); }
#rt-frame { flex: 1; width: 100%; border: 0; background: #4b97a7; }
