/* 색·간격은 여기 변수 한곳에서만 정한다. 다크 모드는 변수만 바꾼다.
   기기 설정을 따르되, 버튼으로 고른 값(data-theme)이 있으면 그것이 우선한다 */
:root {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #fff; --text: #1a1d26; --muted: #737a8c; --line: #eceef3;
  --primary: #3b5bdb; --primary-ink: #fff; --danger: #d6336c; --ok: #2b8a3e;
  --radius: 12px; --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --surface: #0e1015; --text: #e9ebf2; --muted: #8e95a8; --line: #23283a;
    --primary: #7b96ff; --primary-ink: #0e1220; --danger: #ff6b9a; --ok: #69db7c; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #14161c; --surface: #0e1015; --text: #e9ebf2; --muted: #8e95a8; --line: #23283a;
    --primary: #7b96ff; --primary-ink: #0e1220; --danger: #ff6b9a; --ok: #69db7c; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0 auto; padding: 0 20px 40px; max-width: 1040px; background: var(--surface); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}
body > .narrow, main.narrow { max-width: 760px; margin: 0 auto; }
h1 { font-size: 1rem; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }
h3 { font-size: .85rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; font-size: .85em; }

/* 상단 */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 20px 0 14px; }
.brand { display: flex; align-items: center; min-width: 0; }
.brand img { border-radius: 7px; flex: none; width: 26px; height: 26px; margin-right: 12px; }
.brand #switch { display: flex; align-items: center; min-width: 0; color: inherit; text-decoration: none; } /* 로고·이름을 누르면 캘린더↔메모 전환 */
.actions, .tools { display: flex; align-items: center; gap: 8px; flex: none; }
.tools { flex-wrap: wrap; justify-content: flex-end; }
/* 넓은 화면: 로고 | 도구들 + 메모 버튼 한 줄. 좁은 화면(아래 미디어 쿼리)은 두 줄 */
.top { flex-wrap: wrap; }
.brand { margin-right: auto; }
.tools { order: 1; }
#add { order: 2; }
#room-btn { max-width: 11em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; } /* 긴 방 이름은 줄여 한 줄을 지킨다 */
.who { color: var(--muted); font-size: .85rem; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: transparent; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 분류 범례(필터 칩) */
.legend { display: flex; gap: 4px; overflow-x: auto; padding: 2px 0 14px; scrollbar-width: none; }
.legend::-webkit-scrollbar { display: none; }
.legend button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid transparent; border-radius: 999px; background: none; color: var(--muted); font: inherit; font-size: .78rem; white-space: nowrap; flex: none; cursor: pointer; }
.legend button:hover { background: var(--bg); }
.legend button[aria-pressed="true"] { border-color: var(--line); background: var(--bg); color: var(--text); font-weight: 600; }
.legend.filtering button[aria-pressed="false"] { opacity: .5; }
.legend button.reset { color: var(--primary); font-weight: 600; border-color: var(--line); position: sticky; right: 0; background: var(--surface); } /* 좁은 화면에서 범례가 옆으로 밀려도 오른쪽에 붙어 보인다 */
.legend i { width: 8px; height: 8px; border-radius: 50%; }
@media (min-width: 700px) { .legend { flex-wrap: wrap; overflow: visible; } }

/* 폴더 줄: 전체 · 폴더 없음 · 폴더들 · + 새 폴더. 하위 폴더 줄은 들여서 이어 붙인다 */
.folders { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.folders::-webkit-scrollbar { display: none; }
.folders.sub { padding-left: 14px; border-left: 2px solid var(--line); margin-left: 6px; }
.folders button { flex: none; max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.folders button:hover { border-color: var(--muted); }
.folders button[aria-pressed="true"] { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
.folders button.add { color: var(--primary); border-style: dashed; }
.folder-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.folder-tools .meta { font-size: .85rem; font-weight: 600; color: var(--text); margin-right: auto; overflow-wrap: anywhere; }
@media (min-width: 700px) { .folders { flex-wrap: wrap; overflow: visible; } }
.memo .path { color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 카드·알림 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.notice { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; }
.notice.bad { border-color: var(--danger); color: var(--danger); }
.notice.ok { border-color: var(--ok); color: var(--ok); }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 12px; }

/* 입력 */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; min-height: 36px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent); border-color: var(--primary); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); opacity: .8; }

/* 창 */
dialog {
  width: min(440px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 16px; padding: 22px; background: var(--surface);
  color: var(--text); box-shadow: 0 16px 48px rgba(10, 12, 24, .18);
}
dialog::backdrop { background: rgba(12, 14, 24, .38); }
dialog h2 { font-size: 1.1rem; margin-bottom: 14px; }
form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); font-weight: 500; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
label input, label select, label textarea { font-weight: 400; font-size: .95rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two input { min-width: 0; }
.btns { display: flex; gap: 8px; margin-top: 4px; }
.btns span { flex: 1; }
.meta { margin: 0; font-size: .75rem; color: var(--muted); }
.err { color: var(--danger); margin: 0; min-height: 1.2em; font-size: .85rem; }

/* 도움말 */
/* 공개 범위 창: 개인|공동 탭과 같은 두 칸 토글 */
.sh-seg { display: flex; width: 100%; margin: 4px 0 6px; }
.sh-seg button { flex: 1; }
.sh-seg button:disabled { cursor: default; }
.sh-seg button[aria-pressed="false"]:disabled { opacity: .5; }
.sh-people[hidden] { display: none; }
.sh-people input { width: 100%; margin-top: 4px; }
.help ul.sh-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 4px; }
.sh-list li { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 6px 4px 12px; border-radius: 8px; background: var(--bg); }
.sh-list li span { flex: 1; overflow-wrap: anywhere; }
.sh-list li .btn { min-height: 30px; padding: 0 10px; font-size: .85rem; }
.sh-list.chosen li { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.lock { margin-right: 4px; }
.md-user, .chip.user { background: color-mix(in srgb, var(--primary) 14%, transparent); border-radius: 999px; padding: 0 8px; }
.chip.user { cursor: default; text-decoration: none; }
/* 미리보기 디스코드식 문법: 스포일러·작은 글씨·글자 색 */
.e-preview .md-spoiler { background: color-mix(in srgb, var(--muted) 22%, transparent); border-radius: 4px; padding: 0 3px; cursor: pointer; }
.e-preview .md-spoiler:not(.revealed) { background: var(--text); }
.e-preview .md-spoiler:not(.revealed), .e-preview .md-spoiler:not(.revealed) * { color: transparent; }
.e-preview .md-sub { color: var(--muted); font-size: .8rem; }
.md-c { color: var(--mc); }
.md-c[data-c="red"] { --mc: #e03131; } .md-c[data-c="orange"] { --mc: #d9480f; } .md-c[data-c="yellow"] { --mc: #a67c00; } .md-c[data-c="green"] { --mc: #2b8a3e; }
.md-c[data-c="blue"] { --mc: #1971c2; } .md-c[data-c="purple"] { --mc: #7048e8; } .md-c[data-c="pink"] { --mc: #c2255c; } .md-c[data-c="gray"] { --mc: #6b7280; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .md-c[data-c="red"] { --mc: #ff8787; } :root:not([data-theme="light"]) .md-c[data-c="orange"] { --mc: #ffa94d; }
  :root:not([data-theme="light"]) .md-c[data-c="yellow"] { --mc: #ffd43b; } :root:not([data-theme="light"]) .md-c[data-c="green"] { --mc: #69db7c; }
  :root:not([data-theme="light"]) .md-c[data-c="blue"] { --mc: #74c0fc; } :root:not([data-theme="light"]) .md-c[data-c="purple"] { --mc: #b197fc; }
  :root:not([data-theme="light"]) .md-c[data-c="pink"] { --mc: #faa2c1; } :root:not([data-theme="light"]) .md-c[data-c="gray"] { --mc: #adb5bd; }
}
:root[data-theme="dark"] .md-c[data-c="red"] { --mc: #ff8787; } :root[data-theme="dark"] .md-c[data-c="orange"] { --mc: #ffa94d; }
:root[data-theme="dark"] .md-c[data-c="yellow"] { --mc: #ffd43b; } :root[data-theme="dark"] .md-c[data-c="green"] { --mc: #69db7c; }
:root[data-theme="dark"] .md-c[data-c="blue"] { --mc: #74c0fc; } :root[data-theme="dark"] .md-c[data-c="purple"] { --mc: #b197fc; }
:root[data-theme="dark"] .md-c[data-c="pink"] { --mc: #faa2c1; } :root[data-theme="dark"] .md-c[data-c="gray"] { --mc: #adb5bd; }
dialog.help { max-height: calc(100dvh - 32px); overflow-y: auto; word-break: keep-all; } /* 한글이 단어 중간에서 끊기지 않게 */
.help h3 { margin: 18px 0 6px; font-size: .95rem; color: var(--text); }
.help p { margin: 10px 0 4px; font-size: .9rem; }
.help ul, .help ol { margin: 0; padding-left: 20px; font-size: .9rem; }
.help li { margin: 4px 0; }
.help .meta { margin-top: 14px; }

/* 알림 */
.btn.icon { position: relative; width: 34px; padding: 0; }
#bell-dot { position: absolute; top: 5px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); box-sizing: content-box; }
dialog#notif { margin: 56px 16px auto auto; }
.n-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.n-head h2 { margin: 0; }
.n-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 55vh; overflow-y: auto; }
.n-list li { padding: 10px 0 10px 14px; border-bottom: 1px solid var(--line); position: relative; font-size: .9rem; }
.n-list li.unread { font-weight: 600; }
.n-list li.unread::before { content: ""; position: absolute; left: 0; top: 17px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.n-list li.empty { border: 0; padding-left: 0; color: var(--muted); }
.n-list .meta { font-weight: 400; }

/* 개인 | 공동 탭 */
.tabs { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg); margin-bottom: 10px; }
.tabs button { min-width: 72px; min-height: 32px; padding: 0 14px; border: 0; border-radius: 8px; background: none; color: var(--muted); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.search { width: 100%; margin-bottom: 14px; }

/* 메모 목록(최근 수정순 카드) */
.memo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.memo { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 12px 14px; border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 10px; color: inherit; text-decoration: none; min-width: 0; }
.memo:hover { background: var(--bg); }
.memo strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memo .preview { margin: 0; color: var(--muted); font-size: .88rem; min-height: 2.6em; overflow-wrap: anywhere; white-space: pre-line;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.memo .meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.memo-list li.empty { color: var(--muted); padding: 20px 0; grid-column: 1 / -1; }

/* 편집 화면 */
.edit-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.badge { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.badge.shared { color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); }
.memo .badge { padding: 0 6px; font-size: .7rem; }
.e-title { width: 100%; font-size: 1.15rem; font-weight: 700; border-color: transparent; padding-left: 4px; }
.e-row { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin: 8px 0 10px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
.e-body { border: 1px solid var(--line); border-radius: 10px; min-height: 50vh; margin-bottom: 10px; overflow: hidden; }
.e-body .cm-editor { min-height: 50vh; font-size: 1rem; background: var(--surface); color: var(--text); }
.e-body .cm-editor.cm-focused { outline: none; }
.e-body .cm-scroller { font-family: inherit; line-height: 1.6; }
.e-body .cm-content { caret-color: var(--text); }
.e-body .cm-cursor { border-left-color: var(--text); }
.e-body .cm-gutters { background: var(--bg); color: var(--muted); border-right: 1px solid var(--line); }
.e-body .cm-activeLine, .e-body .cm-activeLineGutter { background: color-mix(in srgb, var(--primary) 6%, transparent); }
.e-body .cm-selectionBackground, .e-body .cm-focused .cm-selectionBackground { background: color-mix(in srgb, var(--primary) 25%, transparent) !important; }
/* 상대 커서 위 이름표: 기본은 마우스를 올려야 보여서 늘 보이게 한다 */
.e-body .cm-ySelectionInfo { opacity: 1 !important; font-family: inherit !important; border-radius: 3px; top: -1.25em !important; }
.e-body[inert] { opacity: .85; }
/* 본문 속 주소: 밑줄 + 바로 뒤 ↗ 버튼(누르면 새 탭) */
.e-body .cm-url { color: var(--primary); text-decoration: underline; }
.e-body .cm-url-open { display: inline-flex; align-items: center; justify-content: center; min-width: 1.5em; height: 1.4em; margin: 0 2px; padding: 0; vertical-align: baseline;
  border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--primary); font: inherit; font-size: .8em; line-height: 1; cursor: pointer; }
.e-body .cm-url-open:hover { border-color: var(--primary); }
/* @ 태그 힌트(커서 위쪽 목록): 앱 색을 따른다 */
.e-body .cm-tooltip { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(10, 12, 24, .18); overflow: hidden; }
.e-body .cm-tooltip-autocomplete > ul { font-family: inherit; max-height: 15em; max-width: min(420px, calc(100vw - 32px)); }
.e-body .cm-tooltip-autocomplete > ul > li { padding: 6px 10px !important; overflow: hidden; text-overflow: ellipsis; }
.e-body .cm-tooltip-autocomplete > ul > li[aria-selected] { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--text); }
.e-body .cm-tooltip-autocomplete completion-section { padding: 4px 10px; font-size: .75rem; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
.e-body .cm-completionDetail { margin-left: .6em; font-style: normal; font-size: .8em; color: var(--muted); }
/* 연결 칩 줄(본문 위): 누르면 그 일정·메모로 같은 탭 이동 */
.e-links { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.e-links .chip { display: inline-flex; align-items: baseline; gap: 6px; max-width: 100%; min-height: 30px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); color: var(--text); font-size: .85rem; text-decoration: none; }
.e-links .chip:hover { border-color: var(--primary); }
.e-links .k { font-size: .72rem; font-weight: 700; color: var(--primary); flex: none; }
.e-links .chip[data-kind="memo"] .k { color: var(--ok); }
.e-links .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.e-links .d { font-size: .75rem; color: var(--muted); flex: none; }
.e-links .chip.gone .t { text-decoration: line-through; color: var(--muted); }
#edit-view .btns { flex-wrap: wrap; }
.e-mode { margin: 0 0 0 auto; }
.e-mode button { min-width: 0; }

/* 미리보기(마크다운) */
.e-preview { border: 1px solid var(--line); border-radius: 10px; min-height: 50vh; margin-bottom: 10px; padding: 12px 16px; overflow-wrap: anywhere; line-height: 1.6; }
.e-preview:empty::before { content: "내용이 없습니다"; color: var(--muted); }
.e-preview > :first-child { margin-top: 0; }
.e-preview .md-clip { margin: 1em 0 0; padding-top: .6em; border-top: 1px solid var(--line); color: var(--muted); font-size: .88rem; }
.e-preview h1, .e-preview h2, .e-preview h3, .e-preview h4, .e-preview h5, .e-preview h6 { margin: 1.1em 0 .4em; color: var(--text); line-height: 1.3; }
.e-preview h1 { font-size: 1.45rem; } .e-preview h2 { font-size: 1.25rem; } .e-preview h3 { font-size: 1.1rem; } .e-preview h4, .e-preview h5, .e-preview h6 { font-size: 1rem; }
.e-preview p, .e-preview ul, .e-preview ol, .e-preview blockquote, .e-preview pre, .e-preview table { margin: 0 0 .8em; }
.e-preview ul, .e-preview ol { padding-left: 1.4em; }
.e-preview li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.3em; }
.e-preview input[type="checkbox"] { margin: 0 .4em 0 0; vertical-align: middle; accent-color: var(--primary); }
.e-preview a { color: var(--primary); }
.e-preview blockquote { padding: 2px 0 2px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.e-preview pre { background: var(--bg); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; } /* 코드도 자동 줄바꿈 */
.e-preview pre code { padding: 0; background: none; }
.e-preview code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.e-preview table { border-collapse: collapse; display: block; max-width: 100%; overflow-x: auto; }
.e-preview th, .e-preview td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.e-preview th { background: var(--bg); }
.e-preview hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.e-preview img { max-width: 100%; }

/* 잠깐 뜨는 안내 */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--surface); font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 좁은 화면 */
@media (max-width: 560px) {
  body { padding: 0 10px 24px; }
  .top { padding: 14px 0 10px; row-gap: 8px; }
  .top { gap: 8px; } .head-actions { gap: 4px; } #add { padding: 0 12px; }
  .brand img { margin-right: 8px; } /* 360dp 폭에서도 헤더가 한 줄 */
  .tools { order: 3; flex: 1 0 100%; gap: 6px; }
  .tools .btn:not(.icon) { padding: 0 10px; }
  #room-btn { max-width: 8em; }
  .who { display: none; } /* 둘째 줄에 아이콘이 7개까지 늘어나 자리가 모자란다 */
  .card { padding: 6px; border-radius: 12px; }
  .memo-list { grid-template-columns: 1fr; }
  .folder-tools .meta { flex-basis: 100%; } /* 폴더 경로 한 줄, 버튼은 그 아래 한 줄 */
  dialog { padding: 18px; }
}

/* ===== 편집기: 디스코드식 라이브 표시 · 글자 색 · 서식 툴바 · 선택 버블 (tools/live-md.js, format.js) =====
   움직임(transition)은 쓰지 않는다(prefers-reduced-motion에도 그대로) */
/* 글자 색 {빨강|글자}: 이름 -> 키는 tools/text-colors.mjs, 색은 여기 두 벌 */
:root {
  --tc-red: #e03131; --tc-orange: #e8590c; --tc-yellow: #b08800; --tc-green: #2f9e44;
  --tc-blue: #1c7ed6; --tc-purple: #7048e8; --tc-pink: #d6336c; --tc-gray: #737a8c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tc-red: #ff6b6b; --tc-orange: #ff922b; --tc-yellow: #ffd43b; --tc-green: #69db7c;
    --tc-blue: #4dabf7; --tc-purple: #b197fc; --tc-pink: #f783ac; --tc-gray: #adb5bd;
  }
}
:root[data-theme="dark"] {
  --tc-red: #ff6b6b; --tc-orange: #ff922b; --tc-yellow: #ffd43b; --tc-green: #69db7c;
  --tc-blue: #4dabf7; --tc-purple: #b197fc; --tc-pink: #f783ac; --tc-gray: #adb5bd;
}
.cm-tc-red { color: var(--tc-red); } .cm-tc-orange { color: var(--tc-orange); } .cm-tc-yellow { color: var(--tc-yellow); }
.cm-tc-green { color: var(--tc-green); } .cm-tc-blue { color: var(--tc-blue); } .cm-tc-purple { color: var(--tc-purple); }
.cm-tc-pink { color: var(--tc-pink); } .cm-tc-gray { color: var(--tc-gray); }

/* 라이브 표시: 제목(#·##·###만), 인용, 작은 글씨, 코드 */
.e-body .cm-h1 { font-size: 1.6em; font-weight: 700; line-height: 1.3; }
.e-body .cm-h2 { font-size: 1.35em; font-weight: 700; line-height: 1.35; }
.e-body .cm-h3 { font-size: 1.15em; font-weight: 700; }
.e-body .cm-quote { border-left: 4px solid color-mix(in srgb, var(--muted) 45%, transparent); padding-left: 10px; color: var(--muted); }
.e-body .cm-sub { font-size: .8em; color: var(--muted); }
.e-body .cm-codeblock { background: var(--bg); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .92em; }
.e-body .cm-fence { color: var(--muted); }
.e-body .cm-code { background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); border-radius: 4px; padding: 0 3px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.e-body .cm-bullet { color: var(--muted); padding: 0 .15em; }
/* 링크 글·태그([@제목](…)·[@이름](user:id))는 작은 알약 */
.e-body .cm-mlink { color: var(--primary); }
.e-body .cm-tag { background: color-mix(in srgb, var(--primary) 14%, transparent); border-radius: 999px; padding: 0 6px; font-size: .92em; }
/* ||스포일러||: 커서가 없는 줄에서는 가린 알약, 올리면 보인다 */
.e-body .cm-spoiler { border-radius: 4px; cursor: pointer; }
.e-body .cm-spoiler:not(:hover) { background: var(--muted); color: transparent; }
.e-body .cm-spoiler:not(:hover) * { color: transparent !important; background: transparent !important; box-shadow: none !important; }
.e-body .cm-spoiler:hover, .e-body .cm-spoiler-on { background: color-mix(in srgb, var(--muted) 18%, transparent); border-radius: 4px; }
/* __밑줄__ 은 굵게가 아니다. 그 안의 **굵게** 는 굵게(cm-b가 뒤에 와서 이긴다), 제목 줄은 굵게 유지 */
.e-body .cm-u { text-decoration: underline; }
.e-body .cm-u, .e-body .cm-u * { font-weight: 400; }
.e-body .cm-b, .e-body .cm-b * { font-weight: 700; }
.e-body :is(.cm-h1, .cm-h2, .cm-h3) :is(.cm-u, .cm-u *) { font-weight: 700; }

/* 서식 툴바(본문 위 한 줄): 좁으면 가로 스크롤, 줄바꿈 없음 */
.e-tools { display: flex; flex-wrap: nowrap; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 0 6px; padding: 3px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.e-tools::-webkit-scrollbar { display: none; }
.e-tool, .cm-fmt-row button { flex: none; min-width: 34px; height: 34px; padding: 0 8px; border: 0; border-radius: 7px; background: none;
  font: inherit; font-size: .9rem; font-weight: 600; line-height: 1; cursor: pointer; white-space: nowrap; }
.e-tool, .cm-fmt-row button:not(.cm-fmt-swatch) { color: var(--text); }
.e-tool:hover, .cm-fmt-row button:hover { background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.e-tool[aria-expanded="true"], .cm-fmt-row button[aria-expanded="true"] { background: color-mix(in srgb, var(--primary) 14%, transparent); }
:is(.e-tool[data-cmd="bold"], .cm-fmt-bold) { font-weight: 800; }
:is(.e-tool[data-cmd="italic"], .cm-fmt-italic) { font-style: italic; font-family: Georgia, serif; }
:is(.e-tool[data-cmd="underline"], .cm-fmt-underline) { text-decoration: underline; }
:is(.e-tool[data-cmd="strike"], .cm-fmt-strike) { text-decoration: line-through; }
:is(.e-tool[data-cmd="code"], .cm-fmt-code) { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; }
:is(.e-tool[data-cmd="color"], .cm-fmt-color) { text-decoration: underline 3px var(--tc-red); text-underline-offset: 3px; }
:is(.e-tool[data-cmd="subtext"], .e-tool[data-cmd="link"], .e-tool[data-cmd="clear"], .cm-fmt-link) { font-size: .8rem; }
/* 글자 색 팝오버(툴바 바로 아래 작은 줄) */
.e-palette { display: flex; flex-wrap: wrap; gap: 4px; width: max-content; max-width: 100%; margin: -2px 0 6px; padding: 5px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 8px 24px rgba(10, 12, 24, .12); }
.e-swatch, .cm-fmt-row .cm-fmt-swatch { flex: none; width: 32px; min-width: 32px; height: 32px; padding: 0; border: 1px solid var(--line);
  border-radius: 50%; background: var(--surface); font: inherit; font-weight: 800; cursor: pointer; }
.e-swatch.off, .cm-fmt-row .cm-fmt-swatch:not([class*="cm-tc-"]) { color: var(--muted); font-weight: 600; }
/* 선택 위 버블(CodeMirror 툴팁) */
.e-body .cm-tooltip.cm-fmt-bubble { border-radius: 10px; }
.cm-fmt-row { display: flex; flex-wrap: nowrap; gap: 1px; padding: 3px; }
.cm-fmt-row button { min-width: 32px; height: 32px; padding: 0 6px; }
.cm-fmt-pal { flex-wrap: wrap; gap: 4px; max-width: min(330px, calc(100vw - 32px)); border-top: 1px solid var(--line); }
.cm-fmt-pal[hidden] { display: none; }
@media (max-width: 560px) {
  .e-tool { min-width: 36px; height: 36px; }
  .cm-fmt-row button { min-width: 34px; height: 34px; }
}

body { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }
#toast { bottom: calc(env(safe-area-inset-bottom) + 12px); }
body.editing { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
body.editing #toast { bottom: calc(24px + var(--ad-h, 0px) + env(safe-area-inset-bottom)); }

/* 도움말: 구역을 접어 두고 필요한 것만 펼친다 */
.help details.sec { border-top: 1px solid var(--line); }
.help details.sec:first-of-type { margin-top: 8px; }
.help details.sec > summary { cursor: pointer; list-style: none; padding: 12px 2px; font-size: .95rem; font-weight: 700; color: var(--text); display: flex; justify-content: space-between; align-items: center; }
.help details.sec > summary::-webkit-details-marker { display: none; }
.help details.sec > summary::after { content: ""; width: 8px; height: 8px; margin-right: 4px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; flex: none; }
.help details.sec[open] > summary::after { transform: rotate(-135deg); }
.help details.sec > :not(summary) { margin-left: 2px; margin-right: 2px; }
.help details.sec[open] { padding-bottom: 10px; }
.brand .switch-arrow { flex: none; margin-left: 6px; color: var(--muted); }
@media (max-width: 560px) { /* 360dp: 로고 옆 화살표가 들어가도 헤더가 한 줄. 위쪽 규칙의 gap은 뒤의 .head-actions 규칙에 덮여 여기서 다시 지정한다 */
  .top { gap: 6px; } .head-actions { gap: 4px; } .brand img { margin-right: 6px; } .brand .switch-arrow { width: 12px; height: 12px; margin-left: 4px; }
}
